Skip to content

add version of restic to the Prometheus metrics#495

Merged
creativeprojects merged 1 commit intocreativeprojects:masterfrom
antondollmaier:master
May 19, 2025
Merged

add version of restic to the Prometheus metrics#495
creativeprojects merged 1 commit intocreativeprojects:masterfrom
antondollmaier:master

Conversation

@antondollmaier
Copy link
Copy Markdown
Contributor

Add the restic version as a new label to the existing metric resticprofile_build_info.

This allows tracking the versions of both restic and resticprofile: PromQL can be used to identify outdated installations.

I'm not an experienced developer in Go, so there might be better ways to solve this.

Adding the new metric restic_build_info failed for unknown reasons (the metric didn't show up in the output file).

refs #485

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 23, 2025

Walkthrough

The changes introduce a new label, resticversion, to the Prometheus metrics system by updating the NewMetrics constructor function to accept an additional string parameter for the Restic version. This label is incorporated into the metrics' label set and is set during metrics initialisation. All invocations of NewMetrics across the codebase, including in tests and the runProfile function, have been updated to provide the new Restic version argument. No other logic or control flow changes are present.

Changes

File(s) Change Summary
monitor/prom/metrics.go Added resticInfo *prometheus.GaugeVec field; updated NewMetrics to accept and use a resticversion label.
monitor/prom/metrics_test.go Updated all NewMetrics calls in tests to include the new resticversion argument as an empty string.
run_profile.go Modified prom.NewMetrics call to pass ctx.global.ResticVersion as the new argument.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Metrics
    participant Prometheus

    Caller->>Metrics: NewMetrics(profile, group, version, resticversion, configLabels)
    Metrics->>Prometheus: Register build_info gauge with labels (profile, group, version, resticversion, ...)
    Metrics->>Prometheus: Set build_info gauge with resticversion value
Loading

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between bc8f789 and b778f2f.

📒 Files selected for processing (3)
  • monitor/prom/metrics.go (2 hunks)
  • monitor/prom/metrics_test.go (3 hunks)
  • run_profile.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • run_profile.go
  • monitor/prom/metrics_test.go
  • monitor/prom/metrics.go
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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)
monitor/prom/metrics_test.go (1)

13-13: Tests updated to match new function signature

All test cases have been properly updated to include the additional empty string parameter for Restic version. This ensures the tests match the new function signature.

Consider adding a specific test case that verifies the Restic version is correctly included in the metrics output. This would provide stronger validation that the new functionality works as expected.

Also applies to: 24-24, 35-35

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e991cfd and 08f7016.

📒 Files selected for processing (3)
  • monitor/prom/metrics.go (3 hunks)
  • monitor/prom/metrics_test.go (3 hunks)
  • run_profile.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
run_profile.go (1)
monitor/prom/metrics.go (1)
  • NewMetrics (32-72)
monitor/prom/metrics_test.go (1)
monitor/prom/metrics.go (1)
  • NewMetrics (32-72)
🔇 Additional comments (5)
monitor/prom/metrics.go (4)

22-22: LGTM: New label for tracking Restic version

The addition of resticVersionLabel is a good enhancement, allowing for tracking of both resticprofile and restic versions in Prometheus metrics. This will help users identify outdated installations as mentioned in the PR objectives.


32-32: Function signature updated to include Restic version parameter

Good addition of the restic version parameter to the NewMetrics function. The parameter name is clear and consistent with existing naming conventions.


50-50: New label added to metrics vector

The Restic version label is correctly appended to the list of label keys for the build_info Prometheus gauge vector.


52-52: Restic version information correctly set

The implementation correctly sets the Restic version information in the Prometheus gauge. This will allow users to query and filter metrics based on Restic version.

run_profile.go (1)

196-196: Appropriate usage of Restic version in metrics creation

The modified call to prom.NewMetrics correctly passes ctx.global.ResticVersion as the new parameter. This ensures the Restic version from the current context is properly included in Prometheus metrics.

@creativeprojects
Copy link
Copy Markdown
Owner

@antondollmaier thanks for this PR 👍🏻

Does it make more sense to create a new metric called restic_build_info than adding a label to the existing one?

I'm asking because it shouldn't be difficult to add a new metric, if that makes things easier to query from prometheus

@antondollmaier
Copy link
Copy Markdown
Contributor Author

Thanks for the input!

Does it make more sense to create a new metric called restic_build_info than adding a label to the existing one?

I'm asking because it shouldn't be difficult to add a new metric, if that makes things easier to query from prometheus

I initially failed to do so, but succeeded now. And yes, the restic_build_info does make more sense than extending the resticprofile metric with another label.

The metrics now look like this:

# HELP restic_build_info restic build information.
# TYPE restic_build_info gauge
restic_build_info{profile="laptop",version="0.16.4"} 1
# HELP resticprofile_build_info resticprofile build information.
# TYPE resticprofile_build_info gauge
resticprofile_build_info{goversion="go1.24.2",profile="laptop",version="0.30.0-dev"} 1

Is that okay for you as well?

@codecov
Copy link
Copy Markdown

codecov Bot commented May 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.33%. Comparing base (669e77e) to head (b778f2f).
Report is 13 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #495      +/-   ##
==========================================
+ Coverage   79.22%   79.33%   +0.11%     
==========================================
  Files         133      134       +1     
  Lines       13204    13229      +25     
==========================================
+ Hits        10460    10495      +35     
+ Misses       2326     2316      -10     
  Partials      418      418              
Flag Coverage Δ
unittests 79.33% <100.00%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Owner

@creativeprojects creativeprojects left a comment

Choose a reason for hiding this comment

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

Apart from the tiny comment about the leftover constant, it all looks good to me, thanks for the PR 👍🏻

Comment thread monitor/prom/metrics.go Outdated
Add the restic version as a new metric `restic_build_info`.

This allows to track the versions of both restic
and resticprofile: PromQL can be used to identify
outdated installations.

refs creativeprojects#485
@creativeprojects
Copy link
Copy Markdown
Owner

Thanks 😉

@creativeprojects creativeprojects merged commit 43b6c84 into creativeprojects:master May 19, 2025
8 of 9 checks passed
@creativeprojects creativeprojects added this to the v0.31.0 milestone May 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants