Since #877, MetricFamilyToOpenMetrics no longer adds the unit to the metric name, but it still writes the # UNIT line. OpenMetrics 1.0 requires the unit to be a suffix of the name, and Prometheus's OpenMetrics 1.0 parser rejects the exposition, so every metric on the target is lost (the same failure as prometheus/client_golang#1990).
Reproduction with client_golang v1.24.1:
reg := prometheus.NewRegistry()
reg.MustRegister(prometheus.NewCounter(prometheus.CounterOpts{
Name: "request_duration_total", Help: "Time spent.", Unit: "seconds",
}))
// promhttp.HandlerFor(reg, promhttp.HandlerOpts{EnableOpenMetrics: true})
# HELP request_duration Time spent.
# TYPE request_duration counter
# UNIT request_duration seconds
request_duration_total 1.5
# EOF
Prometheus: unit "seconds" not a suffix of metric "request_duration".
Options I can see:
- The OpenMetrics 1.0 encoder omits
# UNIT when the unit is not a suffix, the same way it already writes a counter without _total as unknown "to avoid invalid OpenMetrics output". Names are never changed. (Test case 16 would change.)
- Prometheus's OpenMetrics 1.0 parser stops rejecting it, following OpenMetrics 2.0, where the suffix is only a SHOULD.
Happy to send a PR for whichever is preferred.
Since #877,
MetricFamilyToOpenMetricsno longer adds the unit to the metric name, but it still writes the# UNITline. OpenMetrics 1.0 requires the unit to be a suffix of the name, and Prometheus's OpenMetrics 1.0 parser rejects the exposition, so every metric on the target is lost (the same failure as prometheus/client_golang#1990).Reproduction with client_golang v1.24.1:
Prometheus:
unit "seconds" not a suffix of metric "request_duration".Options I can see:
# UNITwhen the unit is not a suffix, the same way it already writes a counter without_totalasunknown"to avoid invalid OpenMetrics output". Names are never changed. (Test case 16 would change.)Happy to send a PR for whichever is preferred.