prometheus / client_golang

Prometheus instrumentation library for Go applications
https://pkg.go.dev/github.com/prometheus/client_golang
Apache License 2.0
5.34k stars 1.17k forks source link

Consider support for testing exemplars in prometheus/testutil #1479

Open dashpole opened 5 months ago

dashpole commented 5 months ago

Context: https://github.com/open-telemetry/opentelemetry-go/pull/5111

I am in the process of adding exemplar support to the OpenTelemetry-go prometheus exporter. We currently use testutil.GatherAndCompare for most of our testing, as it makes it easy to tell if the output is correct.

However, since GatherAndCompare currently uses the Prometheus text format, and the Prometheus text format doesn't support exemplars, I can't test using the same mechanism. Assuming exemplars aren't coming to the text format soon, the options to resolve this are:

  1. Re-implement GatherAndCompare in my own tests, and make it use OpenMetrics text format, instead of the Prometheus text format.
  2. Write unit test assertions on the go-protobuf types from prometheus.Metric.Write() to check for exemplars separately.
  3. Extend testutil to support gathering the OpenMetrics text format.

Before I move forward with 1 or 2, I figured I would check to see if extending testutil to support my use-case makes sense to maintainers.

ArthurSens commented 5 months ago

Thanks for the heads up!

I'm in favor of option 3 actually, but we would need to send PRs to prometheus/common first. We'd need a textparser for OpenMetrics, similar to this one, then bump prometheus/common here.

Bumping prometheus/common leads us to another problem: common doesn't work with go1.20 and client Golang promises support for the 3 latest go versions. We would need to wait until go 1.23 is out :/

ArthurSens commented 5 months ago

If you need this solved ASAP, I'd suggest you move forward with making test asserting with the protobuf types, but extending the test utility libraries is definitely a positive thing.

1.23 is scheduled to August, so it might take a while 😬

dashpole commented 5 months ago

Thanks! I'll leave this open, and pursue option 2.

ArthurSens commented 4 months ago

prometheus/common with go 1.20 again, there are no blockers for this now