client_python icon indicating copy to clipboard operation
client_python copied to clipboard

Provide APIs to help application developers test their Histogram-using code

Open exarkun opened this issue 4 years ago • 1 comments

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 _buckets attribute, or
  • call Histogram.collectand look at the resulting Metric objects which are documented as "intended only for internal use" and then look at its Samples which 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).

exarkun avatar Dec 13 '21 15:12 exarkun

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.

csmarchbanks avatar Dec 14 '21 18:12 csmarchbanks