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

Aperta
#1,005 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@itsmeasadali ci sta già lavorando.

Dal 10/10/2026.

  • #1012 di @itsmeasadali — aperta
  • #1018 di @AdamMagued — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
go

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Go
Stelle
297
Fork
380
Merge medio
3g 15h
PR unite (30g)
13

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di prometheus/common

Tutte le issue di prometheus/common

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.