Skip to content

feat: add hami_gpu_device_health metric to scheduler - #2540

Closed
manoj-1407 wants to merge 1 commit into
Project-HAMi:masterfrom
manoj-1407:feat/scheduler-gpu-device-health
Closed

feat: add hami_gpu_device_health metric to scheduler#2540
manoj-1407 wants to merge 1 commit into
Project-HAMi:masterfrom
manoj-1407:feat/scheduler-gpu-device-health

Conversation

@manoj-1407

@manoj-1407 manoj-1407 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

DeviceUsage.Health already exists — device plugins set it through CheckHealth(), and the scheduler uses it internally to skip unhealthy devices when scoring. But it's never actually exposed anywhere. Right now if a GPU goes unhealthy, the only way to notice is digging through node annotations by hand — Prometheus has zero visibility into it.

This adds hami_gpu_device_health as a gauge (1 = healthy, 0 = unhealthy) inside collectNodeMetrics, with labels node, device_uuid, device_index, device_type — same set as hami_gpu_memory_limit_bytes, so it joins cleanly with the metrics that already exist.

What this gets you: alert on hami_gpu_device_health == 0 and page someone, build a Grafana panel showing device status per node, or line up unhealthy-device events against spikes in scheduling failures — which right now you basically can't do without going device by device.

Used the same 0/1 gauge pattern hami_mig_device_info already uses for boolean state, so nothing new stylistically. No legacy metric added since there wasn't a health metric in legacy mode to begin with.

One note for whoever reviews — nodeGPUDeviceHealthDesc is declared as a local variable inside the function, matching every other descriptor in there. None of them are package-level, so I kept it consistent.

Test added: TestCollectNodeMetricsDeviceHealth, one healthy device and one unhealthy device, checks both come out with the right value. Followed the same structure as TestAMDCoreAllocatedRatioNormalization already in that file.

Used Claude to help spot the gap and draft the patch — I went through the code myself and understand it, happy to explain any part of it.

Summary by CodeRabbit

  • New Features

    • Added a node-level Prometheus metric reporting the health of each GPU device.
    • Reports 1 for healthy devices and 0 for unhealthy devices, with node, UUID, index, and device type details.
  • Tests

    • Added coverage validating health metrics for healthy and unhealthy NVIDIA devices, including labels and reported values.

@hami-robot

hami-robot Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: manoj-1407
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 FouoF and wawa0210 August 10, 2026 10:45
@github-actions github-actions Bot added the kind/feature new function label Aug 10, 2026
@hami-robot hami-robot Bot added the size/M label Aug 10, 2026
@coderabbitai

coderabbitai Bot commented Aug 10, 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: e1b4f175-3bf9-4267-8047-5d8b54b70b8c

📥 Commits

Reviewing files that changed from the base of the PR and between f2aff49 and 693649f.

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

📝 Walkthrough

Walkthrough

The scheduler adds the hami_gpu_device_health Prometheus metric. It reports 1 for healthy devices and 0 for unhealthy devices, with node and device labels. Tests verify both states.

Changes

Scheduler metrics

Layer / File(s) Summary
Device health metric definition and collection
cmd/scheduler/metrics.go, cmd/scheduler/metrics_test.go
The scheduler defines and emits hami_gpu_device_health with node, UUID, index, and type labels. Tests verify healthy and unhealthy NVIDIA device values.

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

Possibly related PRs

Suggested reviewers: fouof

Poem

A rabbit counts each GPU bright,
Healthy shows 1 in light.
Unhealthy shows 0 clear,
Node and device labels appear.
Tests hop through both states today.

🚥 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 identifies the new hami_gpu_device_health metric added to the scheduler.
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.

@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/scheduler/metrics.go 83.33% 1 Missing and 1 partial ⚠️
Flag Coverage Δ
unittests 62.07% <83.33%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
cmd/scheduler/metrics.go 76.51% <83.33%> (+0.28%) ⬆️

... and 1 file with indirect coverage changes

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

@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.

left two small questions inline. also this pr has a conflict with master right now, needs a rebase before merge.

Comment thread cmd/scheduler/metrics.go
"Realized MIG instance identity and scheduler placement",
[]string{"node", "device_uuid", "device_index", "mig_uuid", "profile", "gpu_instance_id", "compute_instance_id", "placement_start", "placement_size"}, nil,
)
nodeGPUDeviceHealthDesc := prometheus.NewDesc(

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.

name says gpu but this loop runs for every backend, not only gpu. same pattern as the other metrics near it. just checking this is on purpose.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, intentional — same pattern as hami_gpu_memory_limit_bytes, hami_gpu_core_limit_ratio, and the other descriptors in that loop. The gpu prefix follows the existing naming convention in this file rather than reflecting the backend type at runtime. The loop is backend-agnostic by design.

Comment thread cmd/scheduler/metrics.go
}
}

healthVal := float64(0)

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.

is this health value live at scrape time, or a cached value from an older check? matters for alert delay if someone pages off this metric.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it's the value from the most recent CheckHealth() call, written into DeviceUsage.Health by the device plugin and cached in nodeManager. so it reflects last known state, not a live poll at scrape time — lag depends on the device plugin's check interval. happy to add a note to the metric description if that's useful.

DeviceUsage.Health is used internally to skip unhealthy devices in Fit()
but was never emitted as a Prometheus metric. Operators have no way to
alert on an unhealthy GPU without inspecting node annotations manually.

Add hami_gpu_device_health gauge (1=healthy, 0=unhealthy) in
collectNodeMetrics, with label set {node, device_uuid, device_index,
device_type} consistent with hami_gpu_memory_limit_bytes.

Signed-off-by: G. Manoj Kumar <manojkumar148700@gmail.com>
Signed-off-by: manoj-1407 <manojkumar148700@gmail.com>
@mesutoezdil

Copy link
Copy Markdown
Contributor

This is being closed because it does not comply with the contribution guidelines.

@manoj-1407

manoj-1407 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Hi @mesutoezdil , fair call. i pasted ai generated replies without reviewing them properly - that was wrong. I do understand the code though. Would you be open to reopening if I engage properly going forward?
i apologize for my negligence

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