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

Abierto
#1,005 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

@itsmeasadali ya está trabajando en esto.

Desde el 10/10/2026.

  • #1012 de @itsmeasadali — abierto
  • #1018 de @AdamMagued — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
58/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
go

Línea de trabajo

Start at MetricFamilyToOpenMetrics and inspect the OpenMetrics 1.0 parsing behavior described in the reproduction. Review test case 16 and determine which proposed behavior is preferred; done when the non-suffix unit case no longer causes Prometheus to reject the exposition and the test reflects the decision.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Go
Estrellas
297
Forks
380
Merge medio
3 d 15 h
PR fusionados (30 d)
13

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de prometheus/common

Todos los issues de prometheus/common

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.