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

未关闭
#1,005 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@itsmeasadali 已经在做这个了。

开始于 2026年10月10日。

  • #1012 来自 @itsmeasadali —— 未关闭
  • #1018 来自 @AdamMagued —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
58/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
go

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Go
星标
297
派生
380
平均合并
3 天 15 小时
30 天内合并 PR
13

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

prometheus/common 的其他 Issue

查看 prometheus/common 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。