Wakatime Exporter - Would love some feedback

67 views
Skip to first unread message

Jacob Colvin

unread,
Aug 22, 2020, 5:18:12 PM8/22/20
to Prometheus Developers
Hello Prometheus Developers,

I recently created my first exporter in Go, wakatime_exporter, which basically just converts data from the Wakatime API into the Prometheus exposition format.


I've been running it for a few weeks now and am happy with the results. But, I'm sure there are a lot of things I could have done better, specifically in terms of the design of the exporter. My code is all based on the HAProxy exporter, but my changes have been significant enough that it doesn't very closely resemble it anymore.

If any of you have time, I would greatly appreciate any feedback you might have. But, to give one thing I'm specifically concerned about: I feel like there is just too much duplication in my code. I separated my exporter into different modules for each Wakatime endpoint, because I had seen similar architecture in other exporters (and I think it generally makes sense for a number of other reasons). But the result is each modules' NewExporter, Collect, and Describe functions being nearly identical to each other. Does anyone know any way I could solve this?

Thank you!

Brian Brazil

unread,
Aug 24, 2020, 8:28:36 AM8/24/20
to Jacob Colvin, Prometheus Developers
Lots of duplication isn't uncommon, exporters often involve doing lots of repetitive data munging. Trying to generalise it is likely to make the code more complicated for no real gain in maintenance terms. I'd aim for understandable code over the fewest lines of code.

For example the ExportMetric and NewWakaMetric functions add indirection that only make the code harder to understand for me, as I now have to jump across several files to figure out what's actually being exposed.
BoolToBinary is also odd, bools should be gauges rather than label values usually.

Julius Volz

unread,
Aug 24, 2020, 11:13:49 AM8/24/20
to Jacob Colvin, Prometheus Developers
Nice.

Note that I pointed this out to the WakaTime owner (friend of mine), so it's linked off of https://wakatime.com/community now :)

--
You received this message because you are subscribed to the Google Groups "Prometheus Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-devel...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-developers/d61fe504-d5da-41e5-a495-6e50489aa43fn%40googlegroups.com.

Jacob Colvin

unread,
Aug 24, 2020, 4:10:40 PM8/24/20
to Prometheus Developers
Thank you very much for taking a look, Brian. I think that's a very good perspective, so I will definitely make some changes keeping all that in mind.

BoolToBinary really only exists the way it does due to how Grafana's value mapping works. But with some of the transformations added in 7.0, perhaps I will just stop doing things that way.

Jacob Colvin

unread,
Aug 24, 2020, 4:17:13 PM8/24/20
to Prometheus Developers
Julius, thanks for taking a look and sending this along to Alan! I'm very glad he liked the project. :)
Reply all
Reply to author
Forward
0 new messages