Skip to content

expfmt: OpenMetrics 1.0 output with a unit that is not a name suffix fails the whole scrape in Prometheus #1005

Description

@Rohilalala

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:

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions