Skip to content

test(vgpumonitor): add unit tests for metric-sending helpers - #2448

Closed
adity1raut wants to merge 1 commit into
Project-HAMi:masterfrom
adity1raut:test/vgpumonitor-metrics-helper-coverage
Closed

test(vgpumonitor): add unit tests for metric-sending helpers#2448
adity1raut wants to merge 1 commit into
Project-HAMi:masterfrom
adity1raut:test/vgpumonitor-metrics-helper-coverage

Conversation

@adity1raut

@adity1raut adity1raut commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind feature

What this PR does / why we need it:

Adds direct unit tests for sendMetric and sendLegacyMetric in cmd/vGPUmonitor/metrics.go. Both helpers had no direct test coverage — they were only exercised indirectly through the collector-level Describe/Collect test, so the sendMetric error path (mismatched label count) and the nil-descriptor no-op in sendLegacyMetric weren't independently verified.

This is a small, standalone piece of the metrics gap analysis discussed in #2126 (test coverage for the existing vGPUmonitor metrics surface before further changes are layered on top). Companion PR for the scheduler side: #2447.

Which issue(s) this PR fixes:
Relates to #2126

Special notes for your reviewer:

Test-only change, no production code touched. Ran locally:

go test ./cmd/vGPUmonitor/... -short --race -count=1
golangci-lint run ./cmd/vGPUmonitor/...

Does this PR introduce a user-facing change?:

None

AI assistance disclosure: This PR was written primarily by Claude Code (test cases and implementation), based on my own review of the existing metrics.go coverage gaps.

Summary by CodeRabbit

  • Tests
    • Added coverage for metric delivery, including successful submissions and legacy metric handling.
    • Added validation for label-count mismatches and missing legacy descriptors.
    • Verified that expected delivery errors are handled without disrupting monitoring behavior.

sendMetric and sendLegacyMetric in cmd/vGPUmonitor/metrics.go had no
direct unit test coverage; they were only exercised indirectly
through the collector-level Describe/Collect test. Add tests for
both the success path and the error path (mismatched label count)
of each helper.

Signed-off-by: Aditya Raut <araut7798@gmail.com>
@hami-robot

hami-robot Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: adity1raut
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

@github-actions github-actions Bot removed the kind/feature new function label Aug 7, 2026
@hami-robot hami-robot Bot added the size/M label Aug 7, 2026
@coderabbitai

coderabbitai Bot commented Aug 7, 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: 97b235f4-a394-40f3-9bdd-1494340118c5

📥 Commits

Reviewing files that changed from the base of the PR and between 3616313 and 563edc8.

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

📝 Walkthrough

Walkthrough

Added tests for sendMetric and sendLegacyMetric. The tests cover successful delivery, invalid label counts, nil descriptors, and swallowed errors.

Changes

Metric Sender Tests

Layer / File(s) Summary
Metric delivery and legacy handling tests
cmd/vGPUmonitor/metrics_test.go
Added tests for successful metric delivery, invalid label counts, nil legacy descriptors, swallowed errors, and successful legacy delivery.

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

Possibly related PRs

Suggested reviewers: peachest

Poem

A rabbit checks each metric line,
Valid labels pass the test in time.
Nil descriptors cause no fuss,
Legacy errors stay with us.
“Hop!” says the rabbit, “The suite is green!”

🚥 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 and concisely describes the added unit tests for the metric-sending helpers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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 peachest August 7, 2026 09:29
@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unittests 64.29% <ø> (+0.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 3 files with indirect coverage changes

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

@FouoF

FouoF commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution. These tests directly exercise two very small metric-emission wrappers, while the same behavior is already exercised through the collector-level tests. This PR does not address a user-visible defect or a maintainer-confirmed gap, and splitting this small coverage exercise from #2447 creates more review and maintenance overhead than project value. We are therefore closing this PR. If a specific metrics regression is found later, please start from a reproducible failure and keep the corresponding fix and regression test together.

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.

2 participants