Provide APIs to help application developers test their Histogram-using code
I have an application that uses Histogram. I want to write some tests that assert that my application is putting values into the right buckets of that histogram.
To read values out of the Histogram it seems that need to either:
- look at the Histogram's private
_bucketsattribute, or - call
Histogram.collectand look at the resultingMetricobjects which are documented as "intended only for internal use" and then look at itsSampleswhich aren't documented at all.
Neither of these seems particularly satisfactory. It would be very helpful if client_python provided some way to read bucket counts and the total sum from a Histogram, using documented APIs clearly marked as intended for external use (perhaps only in test suites).
I think using the Metric objects would probably be fine for this case, I believe that documentation for internal use is for creating custom collectors you should use the more specifically typed collectors instead.
That said, I think adding some testing utilities would be nice. The Go client has a package of test utilities that could be a good reference: https://pkg.go.dev/github.com/prometheus/[email protected]/prometheus/testutil.