Repository navigation
docs(agents): 修正 Go 指标命名口径 —— 传最终名,SDK 不补后缀 - #17
Open
TangJia025 wants to merge 1 commit into
Open
TangJia025 wants to merge 1 commit into
TangJia025 wants to merge 1 commit into
Conversation
AGENTS.md 的 Go 段写着「名称为**基础名**(不带 `_total` / `_seconds`)」,与实际行为相反:
`m.Handler()` 是 `promhttp.HandlerFor(reg, promhttp.HandlerOpts{})`,`EnableOpenMetrics`
默认为 false,永远走经典 text 格式;而 `client_golang` 只在 OpenMetrics 格式下才补 `_total`。
**注册什么名字就暴露什么名字。**
这句话还会诱导写出违反 `spec/metrics-format.md`「单位后缀遵循 Prometheus 约定」的指标名 ——
而且指标一旦少了 `_total`,查询侧无从判断是 SDK 没补还是调用方没写。
改动:
- Go 代码示例 `NewCounterVec("built_releases", …)` → `NewCounterVec("built_releases_total", …)`
- 命名说明改为「传最终名」,附实测结论与 Node/Java 对照
(Node 的 prom-client 同样要最终名;只有 Java 的 Micrometer 会自动补后缀)
实测方式与输出见 PR 正文。
Refs opensourceways/backlog#2162
Co-Authored-By: Claude Code <noreply@anthropic.com>
Welcome To opensourceways CommunityHey @TangJia025 , thanks for your contribution to the community. Bot Usage ManualI'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands. Contact GuideIf you have any questions, please contact the SIG: infratructure , |
CLA Signature PassTangJia025, thanks for your pull request. All authors of the commits have signed the CLA. 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AGENTS.md的 Go 段写着:这句是错的,且方向正好相反 —— Go 侧必须传最终名,SDK 与
client_golang都不会补任何后缀。为什么错
m.Handler()是promhttp.HandlerFor(reg, promhttp.HandlerOpts{}),HandlerOpts零值下EnableOpenMetrics为 false —— 永远走经典text/plain; version=0.0.4。而client_golang只在 OpenMetrics 格式下才补_total。所以注册什么名字就暴露什么名字。那句「自动补后缀」的语义来自 Java / Micrometer(
java/src/main/java/io/opensourceways/obssdk/ObsMetrics.java的注释),被错误地写进了 Go 段。实测(非推断)
直接引本仓
go/模块,对一个真实Metrics实例打m.Handler():输出:
go/metrics/metrics_test.go本来就是这个口径(NewCounterVec("events_total", …)后断言GetName() == "events_total"),文档与自己的测试对不上。对照(两个都不是 Go 的行为):
prom-client同样要最终名,SDK 不改名 ——AGENTS.md的 Node 段本来就写对了。java/src/test/.../ObsMetricsTest.java:50,58注册m.counter("events", …)后断言输出含events_total,实测成立。影响
这不是纯文字问题。按原句写出来的指标名没有
_total,直接违反spec/metrics-format.md「单位后缀遵循 Prometheus 约定(_total/_seconds/ …)」;而且指标一旦少了后缀,查询侧无从判断是 SDK 没补还是调用方没写,只会当成命名不规范。已经在按这个口径写埋点的地方(如 robot-universal-review 接入)需要一并纠正 —— 见 backlog#2162。
改动
NewCounterVec("built_releases", …)→NewCounterVec("built_releases_total", …)EnableOpenMetrics默认 false)、实测结论,以及 Node / Java 对照 —— 避免后来人"照 Node/Java 类推"再改回去只动
AGENTS.md,不改任何代码与 spec(spec/metrics-format.md的表述本来就对)。Resolves https://github.com/opensourceways/backlog/issues/2061
🤖 Generated with Claude Code
AI 使用声明
当前 PR 是否有 AI 参与: