prometheus / client_python

Prometheus instrumentation library for Python applications
Apache License 2.0
3.97k stars 797 forks source link

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

Open exarkun opened 2 years ago

exarkun commented 2 years ago

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:

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).

csmarchbanks commented 2 years ago

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/client_golang@v1.11.0/prometheus/testutil.