Skip to content

fix(metrics): include all metric descriptors in Describe - #2248

Closed
veyron-kairo wants to merge 2 commits into
Project-HAMi:masterfrom
veyron-kairo:fix/vgpumonitor-describe-descriptors
Closed

fix(metrics): include all metric descriptors in Describe#2248
veyron-kairo wants to merge 2 commits into
Project-HAMi:masterfrom
veyron-kairo:fix/vgpumonitor-describe-descriptors

Conversation

@veyron-kairo

@veyron-kairo veyron-kairo commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

What type of PR: /kind bug

What this PR does / why: Describe() in cmd/vGPUmonitor/metrics.go omitted two descriptors that Collect() emits conditionally (hami_container_last_kernel_elapsed_seconds, hami_mig_device_info). This aligns Describe() with the Prometheus superset contract and the legacy branch, corrects a stale comment, and adds a regression test that fails on the old code and passes now.

Which issue(s) this PR fixes: Fixes #2247

Special notes for reviewer: No change to scrape output — client_golang already tolerates undescribed metrics — so this is contract hygiene, not a runtime fix. make verify and go test ./cmd/vGPUmonitor/ pass locally.

AI assistance disclosure: I used AI assistance (Claude Code) to identify this Describe/Collect gap .
Did implemented the fix and test my myself . I reviewed and understand the change, wrote the commit messages myself, ran make verify and the tests locally, and take responsibility for the PR and for addressing review feedback.

Does this PR introduce a user-facing change?: NONE

Summary by CodeRabbit

  • Bug Fixes

    • Improved Prometheus metric discovery so all available modern, optional, and legacy metrics are reported correctly.
    • Ensured metric collection remains consistent across standard and legacy configurations.
  • Tests

    • Added coverage verifying that published metric descriptors match collected metrics in both modern and legacy modes.

@hami-robot

hami-robot Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: veyron-kairo
Once this PR has been reviewed and has the lgtm label, please assign shouren for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@hami-robot
hami-robot Bot requested review from lengrongfu and wawa0210 July 31, 2026 20:11
@hami-robot

hami-robot Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

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

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

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: facff195-8f40-42dd-b931-59c4cfbc11c0

📥 Commits

Reviewing files that changed from the base of the PR and between 22a8e59 and 6fb8613.

📒 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 (2)
  • cmd/vGPUmonitor/metrics.go
  • cmd/vGPUmonitor/metrics_test.go

📝 Walkthrough

Walkthrough

ClusterManagerCollector.Describe now announces all descriptors emitted by Collect, including conditional last-kernel, MIG, and legacy metrics. Tests verify descriptor coverage in modern and legacy modes.

Changes

Prometheus descriptor contract

Layer / File(s) Summary
Declare all collector descriptors
cmd/vGPUmonitor/metrics.go
Describe now includes last-kernel and MIG descriptors and documents conditional and legacy metric publication.
Validate descriptor publication
cmd/vGPUmonitor/metrics_test.go
Tests verify all 11 modern descriptors and the eight additional legacy descriptors.

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

Possibly related PRs

Suggested reviewers: archlitchi

Poem

A rabbit checks each metric line,
Last-kernel and MIG now shine.
Legacy metrics join the set,
Every descriptor is met.
Describe and Collect align.

🚥 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 states that the metrics fix adds all required descriptors to Describe.
Linked Issues check ✅ Passed The changes make Describe announce every descriptor emitted by Collect, including conditional and legacy descriptors required by issue #2247.
Out of Scope Changes check ✅ Passed The changes are limited to correcting descriptor publication and adding focused regression tests for the linked issue.
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 archlitchi July 31, 2026 20:11
Signed-off-by: Shridhar Panigrahi <198173519+veyron-kairo@users.noreply.github.com>
Signed-off-by: Shridhar Panigrahi <198173519+veyron-kairo@users.noreply.github.com>

@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: 1

🤖 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 80-90: Update TestDescribeIncludesLegacyDescriptors to assert
descriptor identities, not only the total count: build the expected set of eight
legacy descriptors using the same descriptor symbols referenced by the legacy
metrics, then verify each is present in collectDescribe(cc), following the
comparison approach used by TestDescribeCoversAllCollectedDescriptors.
🪄 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: 7097d066-ae5c-4aa6-99ed-9812852e4a8c

📥 Commits

Reviewing files that changed from the base of the PR and between c7891de and 22a8e59.

📒 Files selected for processing (2)
  • cmd/vGPUmonitor/metrics.go
  • cmd/vGPUmonitor/metrics_test.go

Comment on lines +80 to +90
// TestDescribeIncludesLegacyDescriptors verifies the legacy branch still
// announces its eight additional descriptors when legacy metrics are enabled.
func TestDescribeIncludesLegacyDescriptors(t *testing.T) {
initLegacyDescriptors()
cc := ClusterManagerCollector{ClusterManager: &ClusterManager{LegacyMetrics: true}}

const wantCount = 11 + 8 // modern superset + legacy descriptors
if got := len(collectDescribe(cc)); got != wantCount {
t.Errorf("Describe() with legacy metrics emitted %d descriptors, want %d", got, wantCount)
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert the legacy descriptor identities.

The count assertion does not verify the eight required legacy descriptors. The test passes if a legacy descriptor is missing and another descriptor keeps the total at 19. Build an expected descriptor set and verify every legacy descriptor, as TestDescribeCoversAllCollectedDescriptors does for modern descriptors.

🤖 Prompt for 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.

In `@cmd/vGPUmonitor/metrics_test.go` around lines 80 - 90, Update
TestDescribeIncludesLegacyDescriptors to assert descriptor identities, not only
the total count: build the expected set of eight legacy descriptors using the
same descriptor symbols referenced by the legacy metrics, then verify each is
present in collectDescribe(cc), following the comparison approach used by
TestDescribeCoversAllCollectedDescriptors.

@veyron-kairo
veyron-kairo force-pushed the fix/vgpumonitor-describe-descriptors branch from 22a8e59 to 6fb8613 Compare July 31, 2026 20:12
@veyron-kairo

Copy link
Copy Markdown
Contributor Author

Flagging that this PR overlaps with #2240, which also adds the missing descriptors to Describe().

Mine additionally includes a regression test (metrics_test.go) that fails on the pre-fix code and passes after the change, plus a correction to the outdated DescribeByCollect doc comment.

Happy to defer to whichever the maintainers prefer — if #2240 is the one to merge, I'd gladly add the regression test on top of it so the fix stays covered. Just flagging the overlap to avoid duplicated review effort. 🙂

@mesutoezdil

mesutoezdil commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

closing as a dup, #2240 was opened 5h earlier w/ the same fix and the test idea was already suggested there,

pls check existing prs before opening a new one.

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

2 participants