Skip to content

fix: add missing metric descriptors to Describe() in vGPUmonitor - #2240

Merged
archlitchi merged 2 commits into
Project-HAMi:masterfrom
devGPP23:fix-metrics-describe
Aug 5, 2026
Merged

fix: add missing metric descriptors to Describe() in vGPUmonitor#2240
archlitchi merged 2 commits into
Project-HAMi:masterfrom
devGPP23:fix-metrics-describe

Conversation

@devGPP23

@devGPP23 devGPP23 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?
/kind bug

What this PR does / why we need it:

I was reading the code to learn how HAMi sends GPU metrics to Prometheus. I noticed a small bug in the Describe() method.
In Prometheus, Describe() must list all the metrics that the program can send. If the program sends a metric that is not listed in Describe(), it is a rule violation.
I checked all the metrics that HAMi sends in the Collect() method. I found that two metrics are sent but not listed in Describe():
ctrDeviceLastKernelDesc (sent at line 554)
ctrDeviceMigInfo (sent at line 602)

I know this is a issue/mistake because the older legacy metrics code (lines 237-238) includes both of these. The new code just forgot them.
Right now, this doesn't break the app because it uses a relaxed setting (prometheus.NewRegistry()). But if a developer tries to use the strict setting (prometheus.NewPedanticRegistry(), which is commented out in main.go ), the app will crash.

I fixed this by adding the two missing metrics to Describe().

How Has This Been Tested?
I checked the code to make sure every metric sent by Collect() is now listed in Describe(). I did not need to add any new files or imports because the variables were already defined.

AI Assistance Disclosure
I used AI tools to help me find this bug while I was reading the code. All the text, code changes, and commit messages are my own work. I understand every line of this PR.

fixes #2247

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Monitoring now exposes the latest device kernel details and MIG information through Prometheus metrics.
    • Metric descriptors are consistently registered and available during collection.
  • Bug Fixes
    • Improved compatibility across standard and legacy monitoring configurations.
    • Reduced the risk of metric registration and gathering errors.

@hami-robot hami-robot Bot added kind/bug Something isn't working dco-signoff: yes labels Jul 31, 2026
@hami-robot
hami-robot Bot requested review from archlitchi and chaunceyjiang July 31, 2026 15:18
@hami-robot

hami-robot Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Welcome @devGPP23! It looks like this is your first PR to Project-HAMi/HAMi 🎉

@hami-robot hami-robot Bot added the size/XS label Jul 31, 2026
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The collector’s Describe method now advertises the last-kernel and MIG device Prometheus descriptors. Tests verify registration and gathering for legacy and non-legacy configurations.

Changes

Metrics descriptor registration

Layer / File(s) Summary
Describe additional metrics
cmd/vGPUmonitor/metrics.go
The collector’s Describe output now includes ctrDeviceLastKernelDesc and ctrDeviceMigInfo.
Validate collector registration
cmd/vGPUmonitor/metrics_test.go
A pedantic Prometheus registry test registers and gathers legacy and non-legacy collectors. It reports registration and collection errors.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: chaunceyjiang, archlitchi

Poem

A rabbit checks the metrics trail,
Two descriptors join the rail.
Legacy paths and new ones test,
Pedantic checks confirm the rest.
Last-kernel and MIG now show—
Clean metrics flow.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary change: adding missing metric descriptors to vGPUmonitor's Describe method.
Linked Issues check ✅ Passed The PR adds both descriptors required by issue #2247 and tests Describe and Collect synchronization with a pedantic registry.
Out of Scope Changes check ✅ Passed All changes support issue #2247 by correcting descriptor registration, documentation, and regression coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai
coderabbitai Bot requested a review from mesutoezdil July 31, 2026 15:19
@Eshiv-Pandey

Copy link
Copy Markdown
Contributor

lgtm. you can also consider adding a unit test using prometheus.NewPedanticRegistry() to verify both fxns remain in sync, tht would help catch similar omissions automatically down the line

@mesutoezdil mesutoezdil left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

pls add "fixes #2247" to the desc so it auto closes.

Comment thread cmd/vGPUmonitor/metrics.go
Comment thread cmd/vGPUmonitor/metrics.go
@devGPP23

devGPP23 commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews @mesutoezdil @Eshiv-Pandey
I've gone ahead and pushed an updated commit that addresses all your feedback:

Added fixes #2247 to the PR description so the issue auto-closes.
Updated the outdated DescribeByCollect doc comment in metrics.go.
Added a new unit test in metrics_test.go that uses prometheus.NewPedanticRegistry() to strictly validate the collector and ensure the descriptors remain in sync automatically going forward.
Thanks for Reviewing and if there are any other Suggestions , please tell them i will implement them too

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/vGPUmonitor/metrics_test.go`:
- Line 1: Add the repository-standard Apache 2.0 license header at the beginning
of metrics_test.go, before the package main declaration, matching the formatting
used by other Go files.
- Around line 10-12: Update the pedantic registry tests around
NewPedanticRegistry to populate deterministic fixture data, including PodLister
and containerLister, then invoke reg.Gather() and regLegacy.Gather() after
registration. Assert or propagate gathering errors so Collect output is
validated against the declared descriptors.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 09168c65-89a1-485b-9f51-60c1a5e2ed4c

📥 Commits

Reviewing files that changed from the base of the PR and between 9a4f864 and 76a8f6f.

📒 Files selected for processing (2)
  • cmd/vGPUmonitor/metrics.go
  • cmd/vGPUmonitor/metrics_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/vGPUmonitor/metrics.go

Comment thread cmd/vGPUmonitor/metrics_test.go
Comment thread cmd/vGPUmonitor/metrics_test.go Outdated
@devGPP23
devGPP23 force-pushed the fix-metrics-describe branch from 76a8f6f to 7f3d7c4 Compare August 2, 2026 19:45

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/vGPUmonitor/metrics_test.go`:
- Around line 19-28: Reorder the import block in metrics_test.go so
standard-library imports come first, followed by external dependencies such as
Prometheus and Kubernetes, with the github.com/Project-HAMi/HAMi imports last;
apply the grouping used by goimports with the HAMi module configured as local.
- Around line 35-36: Update the test setup around NodeNameEnvName to register
cleanup that restores its prior environment value after the test, rather than
leaving os.Setenv’s process-wide change in place. Use the test’s cleanup
mechanism and preserve whether the variable was originally unset.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 301fe3d4-ed3b-43f0-835e-f8598f28439d

📥 Commits

Reviewing files that changed from the base of the PR and between 76a8f6f and 7f3d7c4.

📒 Files selected for processing (2)
  • cmd/vGPUmonitor/metrics.go
  • cmd/vGPUmonitor/metrics_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/vGPUmonitor/metrics.go

Comment thread cmd/vGPUmonitor/metrics_test.go
Comment thread cmd/vGPUmonitor/metrics_test.go Outdated
@devGPP23
devGPP23 force-pushed the fix-metrics-describe branch from 7f3d7c4 to 9644bce Compare August 2, 2026 19:51
The Describe() method is missing ctrDeviceLastKernelDesc and ctrDeviceMigInfo descriptors that Collect() emits. This violates the prometheus.Collector interface contract. The legacy metrics branch correctly includes both, confirming this is an oversight.

Signed-off-by: devGP7 <gauravpatil232005@gmail.com>
@devGPP23
devGPP23 force-pushed the fix-metrics-describe branch from 9644bce to 4ef1fc0 Compare August 3, 2026 11:31
@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unittests 61.74% <ø> (-0.33%) ⬇️

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

Files with missing lines Coverage Δ
cmd/vGPUmonitor/metrics.go 30.13% <ø> (ø)

... and 31 files with indirect coverage changes

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

@mesutoezdil

Copy link
Copy Markdown
Contributor

/lgtm

Comment thread cmd/vGPUmonitor/metrics_test.go Outdated
@archlitchi

Copy link
Copy Markdown
Member

/lgtm cancel

@hami-robot hami-robot Bot removed the lgtm label Aug 4, 2026
@devGPP23
devGPP23 requested a review from archlitchi August 4, 2026 09:04
Signed-off-by: devGP7 <gauravpatil232005@gmail.com>

@archlitchi archlitchi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@hami-robot hami-robot Bot added the lgtm label Aug 4, 2026
@hami-robot

hami-robot Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: archlitchi, devGPP23

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vGPUmonitor Describe() omits two descriptors that Collect() emits

4 participants