Once actual chemistry broke open our ability to analyze that drug, related chemicals could be synthesized and studied, which led to biguanidines, of which metformin is one, which were tested in animals.
Many drugs are found this way by looking at chemicals related to ones we already know about, and then testing on animals and humans. Self testing of new drugs by researchers used to be very common.
How did folk medicine come to know the effects of guanidine? Dunno.
The same way we know a lot about other things in the chemistry domain - somebody tasted it, just to see what happens. "Mendeleyev's Dream" is a great book that contains many fascinating anecdotes of people going "let me just lick this, just to try". (Or, if you want to go more modern, the history of hallucinogens is pretty fun too)
Humans seem to have a strong tendency to stuff unknown things into their mouth, just because they can.
Summary: a chemist is interested in psychedelics so he starts creating candidate psychoactive substances, and he then tests them on himself and friends. He wrote a lovely book about his journey.
You take a cell culture model for the disease and see if the compounds affect the cells.
Then try it in animals, then humans.
Repeat this process until you have good safe drugs for all of the diseases.
It's actually the other way around. They didn't have very serious theories about the etiology of depression back then, the only clue they had was from the pharmacology of these drugs, which led to the situation where for many years the leading theory on depression was that it was caused by low levels of monoamine neurotransmitters(serotonin, norepinephrine and dopamine). The main evidence for this initially was the fact that these drugs seemed to work, and that they increased the levels or effects of monoamines. This theory has since become discredited as we've learned more, although the connection between monoamines and depression is still strong. It's just not the whole picture.
There are plenty of drugs I can think of (even relatively modern, specialised drugs) for which we kinda understand some parts of the mechanism of action, but not other parts.
Also, given how difficult and competitive developing new drugs is, the incentive is to do the minimum (as above) for approval in the shortest time possible.
i.e. "We don't quite know how it works... but statistically we think it will help, with these side-effects.. good luck" <gasp>
There is a sub-field called Computational Psychiatry [1] trying to do better. And interestingly, a person could argue that randomized controlled trials for medicine are only really necessary because we don't have good enough theory and/or good enough measurement devices. If we did, we could reliably predict the effects of a medication without the trial.
[0]: Yes there may be medical sass apps that are more serious
Of course, unlike with biology, it is usually not beyond my skills to eventually understand the whole system, but it may be beyond my time availability. With biology, the whole thing is just too complex to grok.
We the IT people love to complain about esoteric interplay of hardware, OS, apps and network. There is a lot more phenomena in constant interplay even in mere amoebas, not to speak of human bodies.
Not to mention that you just cannot put breakpoints into a living organism and read its current status on screen.
I find it positively crazy that we know something about biology at all. The intrinsic obstacles are just so much higher than in software.
We work with Phase-targeted auditory stimulation to enhance deep sleep (https://affectablesleep.com). We know we can stimulate the brain during sleep and measure the increase in electrical activity which is the result of increased synchronous firing of neurons, but the reason why we are able to create this result is just a theory. However, the behaviour itself is consistent, and replicated.
This extends all the way to surgical procedures, which often amount to "should fix your issues, IDK" especially when it comes to soft tissue.
I like to think of it as a stochastic discipline. (Which means that you want doctors who understand probabilities. Many don't. Filter well)
They've been in use since at least the early 19th century. We have had a bunch of them (though in humans, at least, we pretty much only use 4 or 5 in developed countries these days). We do this every day in surgical suites around the world. People expect to be unconscious during surgery. But we don't really know how they do it.
Or take antipsychotics: the companies were looking for antihistamines and noticed psychotic patients got better on some of them. If it works... you keep using it until something better shows up.
But my ocular pressure is definitely 30% lower than when not using rhopressa! (shrug)
Try that next time you submit a PR: Yeah... it works, but "I am unable to determine how exactly".
I find this concept absolutely mind blowing. We take drugs that the creators of the drugs don't understand how they work.
I realize that biology is hard to understand, but this sounds crazy.