client_golang icon indicating copy to clipboard operation
client_golang copied to clipboard

Native histogram example

Open lilic opened this issue 1 month ago • 5 comments

Hello all 👋 With native histograms coming up could we add a best practices example to this library as well? I think it would be super useful. I went by the tests and API but it took a bit to understand how to create it to be compatible. Hopefully adding an example that is per best practices would help folks get it right and adopt it more.

lilic avatar Nov 27 '25 13:11 lilic

cc @beorn7 @bwplotka @kakkoyun

lilic avatar Nov 27 '25 13:11 lilic

The "random" example already uses a native histogram:

https://github.com/prometheus/client_golang/blob/5d937cd915c54803b5c46a276d6a5b731f26670c/examples/random/main.go#L66

It doesn't add NativeHistogramMaxBucketNumber and NativeHistogramMinResetDuration, but I'm not even sure if it should. (Arguably, if we believe that people should set this by default, we should set a reasonable default. It's just so hard in Go to have non-zero defaults while still allowing the user to set an actual zero explicitly.)

beorn7 avatar Nov 27 '25 13:11 beorn7

We could, of course, use those options in the example and explain them there.

beorn7 avatar Nov 27 '25 18:11 beorn7

We could, of course, use those options in the example and explain them there.

Sounds good, maybe one example with simple default (like now, missed that as it was under random) and then one where a user might want to finetune things and when. Could be useful to be under examples/histograms, what do you think?

lilic avatar Nov 28 '25 08:11 lilic

I leave it to @bwplotka and @kakkoyun to pick the right format and location. Happy to help with the wording, once we have arrived at that point.

beorn7 avatar Nov 28 '25 11:11 beorn7