Skip to content

✨ feat(metrics): 为监控指标添加构建信息#34

Merged
eryajf merged 3 commits intomainfrom
feat_output_version
Jan 6, 2026
Merged

✨ feat(metrics): 为监控指标添加构建信息#34
eryajf merged 3 commits intomainfrom
feat_output_version

Conversation

@eryajf
Copy link
Copy Markdown
Member

@eryajf eryajf commented Jan 6, 2026

  • 在 Metrics 结构体中新增版本、Git 提交、Go 版本、操作系统架构和构建时间字段
  • 新增 build_info 指标用于暴露应用构建信息
  • 更新 NewMetrics 函数签名以接收构建信息参数

🌈 style(metrics): 优化代码格式和结构

  • 调整代码缩进和空行以提升可读性
  • 规范化指标标签名称使用下划线分隔

Summary by CodeRabbit

新功能

  • 增强了应用指标,现在包含构建信息,包括版本、Git提交、Go运行时版本、操作系统/架构和构建时间等元数据。

✏️ Tip: You can customize this high-level summary in your review settings.

- 在 Metrics 结构体中新增版本、Git 提交、Go 版本、操作系统架构和构建时间字段
- 新增 build_info 指标用于暴露应用构建信息
- 更新 NewMetrics 函数签名以接收构建信息参数

🌈 style(metrics): 优化代码格式和结构

- 调整代码缩进和空行以提升可读性
- 规范化指标标签名称使用下划线分隔
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 6, 2026

Warning

Rate limit exceeded

@eryajf has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 17 minutes and 8 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 139ab32 and cc5a2a4.

📒 Files selected for processing (3)
  • README-en.md
  • README.md
  • pkg/export/export_gauge.go

总体概览

此更改为度量指标系统添加了构建元数据支持。通过扩展 NewMetrics 构造函数,引入了版本、Git提交、Go运行时、操作系统/架构和构建时间等字段,并将其作为新的 BuildInfo 度量指标发出。

变更内容

变更内容集合 / 文件 变更摘要
构建元数据集成
pkg/cmd/root.go
引入 osArch 变量(由 runtime.GOOSruntime.GOARCH 组成),更新 NewMetrics 调用以传递版本、Git提交、Go版本、OS/架构和构建时间参数
度量指标结构扩展
pkg/export/export_gauge.go
Metrics 结构体增加5个新字段(version、gitCommit、goVersion、osArch、buildTime);更新 NewMetrics 构造函数签名以接收这些参数;在导出指标映射中添加 BuildInfo 度量描述符;在 Collect 方法中发出 BuildInfo 度量及其五个标签
常量定义
public/public.go
添加公共常量 BuildInfo,值为 "build_info"

预估代码审查工作量

🎯 2 (Simple) | ⏱️ ~10 分钟

诗篇

🐰 构建信息跃然纸上,
版本提交尽在掌握,
Go运行时刻印其中,
架构详情清晰可见,
度量指标更加丰富啦!✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 该标题清晰地总结了主要变更,即为监控指标添加构建信息,与代码变更内容完全对应。

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

- Add build_info metric description in both English and Chinese README files.
- Include detailed metric configuration examples with version, git_commit, go_version, os_arch and build_time fields.
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
pkg/export/export_gauge.go (1)

17-23: LGTM!新增字段定义合理。

新增的构建信息字段类型正确,且在初始化后不可变,可安全地在 Collect 方法中读取而无需额外加锁。

💡 可选建议:为新字段添加注释

可以考虑为新增的构建信息字段添加简短注释,提升代码可读性:

 type Metrics struct {
 	metrics    map[string]*prometheus.Desc
 	mutex      sync.Mutex
+	// Build information fields
 	version    string
 	gitCommit  string
 	goVersion  string
 	osArch     string
 	buildTime  string
 }
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e512ad7 and 139ab32.

📒 Files selected for processing (3)
  • pkg/cmd/root.go
  • pkg/export/export_gauge.go
  • public/public.go
🧰 Additional context used
🧬 Code graph analysis (2)
pkg/cmd/root.go (1)
pkg/export/export_gauge.go (1)
  • NewMetrics (36-107)
pkg/export/export_gauge.go (1)
public/public.go (1)
  • BuildInfo (36-36)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: golint
🔇 Additional comments (5)
public/public.go (1)

36-36: LGTM!新增 BuildInfo 常量定义合理。

常量定义与现有的指标名称常量风格一致,值 "build_info" 符合 Prometheus 指标命名约定。

pkg/cmd/root.go (1)

58-59: LGTM!构建信息参数传递正确。

osArch 的格式("GOOS/GOARCH")符合常见约定,传递给 NewMetrics 的参数顺序与函数签名匹配。确保在构建时通过 ldflags 正确设置 Version、GitCommit 和 BuildTime 变量。

pkg/export/export_gauge.go (3)

36-42: LGTM!函数签名更新和字段初始化正确。

NewMetrics 函数签名扩展合理,所有新增参数都正确初始化到结构体字段中,参数顺序与调用方(pkg/cmd/root.go)保持一致。


95-104: LGTM!BuildInfo 指标描述符定义规范。

指标描述符定义遵循 Prometheus 最佳实践:

  • 指标名称使用 public.BuildInfo 常量确保一致性
  • 标签名称使用下划线分隔符(snake_case)符合 Prometheus 命名约定
  • 描述信息清晰明确

201-212: LGTM!build_info 指标发送实现正确。

指标发送遵循 Prometheus info 类型指标的标准模式(值为 1,信息编码在标签中)。空行的添加提升了代码可读性,标签值的顺序与指标描述符中的定义一致。

- 将 `gitCommit` 字段重命名为 `goVersion`,确保字段命名与实际用途一致
@eryajf eryajf merged commit a4451af into main Jan 6, 2026
4 checks passed
@eryajf eryajf added the enhancement New feature or request label Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant