feat(monitor): add node label to host GPU metrics - #2398
Conversation
Adds 'node' label to hami_host_gpu_memory_used_bytes and hami_host_gpu_utilization_ratio to enable joins with scheduler allocation metrics. Fixes Project-HAMi#2126 Signed-off-by: ipsitapp8 <ipsitapp8@gmail.com>
|
Welcome @ipsitapp8! It looks like this is your first PR to Project-HAMi/HAMi 🎉 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughHost GPU metrics read node identity from ChangesHost GPU node labels
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 101-125: Update the metric-validation loop in the relevant test to
track whether hami_host_gpu_memory_used_bytes and
hami_host_gpu_utilization_ratio are each encountered during reg.Gather(). After
processing the gathered metrics, fail the test if either expected metric family
was not found, while preserving the existing label validations.
🪄 Autofix
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: 44f66fac-87a1-4b0b-a7fa-fe0ad0118826
📒 Files selected for processing (2)
cmd/vGPUmonitor/metrics.gocmd/vGPUmonitor/metrics_test.go
|
/assign |
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: ipsitapp8 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Update TestHostMetricsIncludeNodeLabel to explicitly track if hami_host_gpu_memory_used_bytes and hami_host_gpu_utilization_ratio are encountered during Gather(). Add log statements noting when metrics are found and validated. Metrics may be absent when NVML initialization fails (no GPU hardware), so test doesn't fail in that case. Addresses CodeRabbit review feedback. Signed-off-by: ipsitapp8 <ipsitapp8@gmail.com>
Rename the 'node' label to 'node_name' on hami_host_gpu_memory_used_bytes and hami_host_gpu_utilization_ratio for consistency with the scheduler metrics label key standardized in Project-HAMi#2343. Addresses review feedback from archlitchi on Project-HAMi#2398. Signed-off-by: ipsitapp8 <ipsitapp8@gmail.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
cmd/vGPUmonitor/metrics_test.go (1)
75-89: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover the legacy path and the unset-node fallback.
TestHostMetricsIncludeNodeLabeltests onlyLegacyMetrics: falsewithNODE_NAMEset. The change also updates legacy descriptors and maps an unsetNODE_NAMEto"unknown". Add cases for bothLegacyMetricsvalues and both node-name states. Apply the label assertions to each case.🤖 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 75 - 89, Expand TestHostMetricsIncludeNodeLabel into cases covering both LegacyMetrics values and both set and unset NODE_NAME states, including the unset fallback to "unknown". Construct each case with the appropriate ClusterManager configuration and apply the existing node-label assertions to every case.
🤖 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.
Nitpick comments:
In `@cmd/vGPUmonitor/metrics_test.go`:
- Around line 75-89: Expand TestHostMetricsIncludeNodeLabel into cases covering
both LegacyMetrics values and both set and unset NODE_NAME states, including the
unset fallback to "unknown". Construct each case with the appropriate
ClusterManager configuration and apply the existing node-label assertions to
every case.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: cd3e6b8e-5c68-4280-9ba6-f0b022215d01
📒 Files selected for processing (2)
cmd/vGPUmonitor/metrics.gocmd/vGPUmonitor/metrics_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- cmd/vGPUmonitor/metrics.go
Expand TestHostMetricsIncludeNodeLabel into a table-driven test covering both LegacyMetrics values and both set/unset NODE_NAME states, including the "unknown" fallback used when NODE_NAME is not set. Addresses CodeRabbit review feedback on Project-HAMi#2398. Signed-off-by: ipsitapp8 <ipsitapp8@gmail.com>
|
@archlitchi The latest commit (e205fb5) is pushed, addressing the |
| @@ -239,6 +239,12 @@ func (cc ClusterManagerCollector) Collect(ch chan<- prometheus.Metric) { | |||
| } | |||
There was a problem hiding this comment.
collectpodandcontainerinfo errors out when node_name is empty. this one falls back to unknown instead. why not do the same here, for consistency?
There was a problem hiding this comment.
Good catch on the inconsistency, it's intentional, because the two functions use NODE_NAME for different things.
In collectPodAndContainerInfo the node name is a functional input: it's the selector passed to the pod lister (metrics.go:374). With an empty value the lister would match pods whose assigned-node annotation is empty, i.e. silently wrong data. Erroring out is the only correct behavior there.
In collectGPUInfo the node name is only a label value. The underlying NVML reads don't depend on it at all. Since Collect just logs the error and moves on (metrics.go:221-224), returning an error would mean an unset NODE_NAME drops hami_host_gpu_memory_used_bytes and hami_host_gpu_utilization_ratio from every scrape, metrics that work fine today without any node dependency. That would turn a label-only, backward-compatible change into a regression for anyone deploying vGPUmonitor outside the Helm chart (the chart does inject NODE_NAME in daemonsetnvidia.yaml, but manual/vendored manifests exist).
I also chose the literal "unknown" over an empty string on purpose: Prometheus treats an empty label value as absent, so on(node_name) joins would fail in a confusing way, whereas node_name="unknown" keeps the series shape stable and makes the misconfiguration visible in a query. This matches the existing precedent in pkg/version/version.go, where unset build metadata is exposed as "unknown" on hami_build_info.
The warning log at metrics.go:244 surfaces the misconfiguration, and TestHostMetricsIncludeNodeLabel covers the unset case for both the new and legacy descriptors.
If you'd rather have strict consistency and prefer that host metrics disappear when NODE_NAME isn't set, I'm happy to flip it.
|
Answers must be written by human being. You can view the relevant rule here. |
|
@mesutoezdil The mistake was from my side! however I understood the workflow and wrote the reply by myself.. If you want you want give a chance for this |
AI Assistance Disclosure
This PR was implemented with assistance from Kiro (Claude Sonnet 4.5) and Claude Code. The AI helped with:
I have reviewed all changes, understand how they work, and validated them with local tests using WSL2.
Problem
Scheduler metrics include a
nodelabel, but vGPUmonitor host metrics(
hami_host_gpu_memory_used_bytes,hami_host_gpu_utilization_ratio)only have
device_index,device_uuid, anddevice_type.This breaks PromQL joins between allocation and runtime metrics, making
it impossible to create dual-axis panels showing allocated vs. used memory
on multi-node clusters.
Related to #2126 (Gap #2 from observability gap analysis).
Changes
node_namelabel tohami_host_gpu_memory_used_bytesandhami_host_gpu_utilization_ratiodescriptorsNODE_NAMEfrom env incollectGPUInfo()(matches existingpattern in
collectPodAndContainerInfo())nodeNamethroughcollectGPUDeviceMetrics→collectGPUMemoryMetrics→collectGPUUtilizationMetricsThe label is named
node_namerather thannode, per review feedback,to match the naming direction proposed in #2343 (which would standardize
the scheduler's
nodelabel tonode_nametoo, for consistency acrosscomponents).
Testing
Added
TestHostMetricsIncludeNodeLabelto verify:node_namenode_namelabel contains the correct value from NODE_NAME envAll tests pass (run via WSL2/Ubuntu):
Tests show expected NVML errors (no GPU drivers in test environment), but this
is normal—the change affects only metric label schema, not NVML interaction logic.
No GPU hardware available for live multi-node validation. If a maintainer can
test against a real cluster, I'm happy to iterate based on actual output.
Example
Before (no node label on host metrics — join fails on multi-node):
After (label added, key aligned with the
node_namedirection proposed in #2343):Note: scheduler metrics (
hami_gpu_memory_allocated_bytes) still use thelabel key
nodeon master — #2343, which would have renamed it tonode_name, was closed without merging. Until that lands, a same-key joinacross components needs a bridge:
Breaking Change?
No. This adds a label, which is backward-compatible. Existing queries that don't reference
node_namewill continue to work.Summary by CodeRabbit
New Features
nodeidlabel.unknownwhen unavailable.Bug Fixes