Skip to content

fix(chart): preserve HAMi workload labels in ServiceMonitor - #126

Merged
Nimbus318 merged 1 commit into
Project-HAMi:mainfrom
Nimbus318:fix/hami-servicemonitor-honor-labels
Aug 29, 2026
Merged

fix(chart): preserve HAMi workload labels in ServiceMonitor#126
Nimbus318 merged 1 commit into
Project-HAMi:mainfrom
Nimbus318:fix/hami-servicemonitor-honor-labels

Conversation

@Nimbus318

@Nimbus318 Nimbus318 commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

What type of PR is this?

/kind bug

What this PR does / why we need it:

With honorLabels: false, Prometheus renames colliding HAMi workload labels
(namespace, pod, and container) to exported_*. The NVIDIA task queries
use the original names, so they return no series and queryInstantVal reports
0.

This PR sets hamiServiceMonitor.honorLabels: true, preserving the workload
labels and allowing the existing PromQL to work unchanged.

Verification

Tested with k3s, HAMi 2.10, and a CUDA workload:

  • Workload selector: 0 series before, 1 after
  • WebUI-generated core and memory metrics reported non-zero values
  • helm lint passed
  • helm template renders true by default
  • An explicit --set hamiServiceMonitor.honorLabels=false still works

Which issue(s) this PR fixes:

Supersedes #114. It correctly identified the label mismatch, but only rewrites
namespace and pod. After Project-HAMi/HAMi#1990, container can also
collide, so that query still returns no series on the tested HAMi 2.10 setup.

Thanks to @Shenhan11 for identifying the issue.

Special notes for your reviewer:

Prometheus.spec.overrideHonorLabels: true overrides this setting. If the same
Prometheus selects both HAMi ServiceMonitors, the endpoint is scraped twice.
Both cases are documented in the installation guide.

The empty-result-to-0 behavior should be addressed separately.

Summary by CodeRabbit

  • New Features

    • Preserved HAMi workload labels in Prometheus metrics so WebUI utilization queries return accurate results.
    • Added Helm guidance for configuring scrape labels and avoiding duplicate metric collection.
  • Documentation

    • Documented label-collision behavior, recommended Prometheus settings, and related ServiceMonitor configuration considerations.

HAMi's vgpu-monitor exports the GPU workload's identity as namespace, pod
and container. Prometheus attaches labels of the same names for the scrape
target itself, so with honorLabels disabled the workload's values are
renamed to exported_namespace / exported_pod / exported_container and the
WebUI's queries match nothing. Task compute and memory utilization then
read as 0 rather than as missing data.

Setting honorLabels on the HAMi ServiceMonitor lets the workload's own
labels win. Series that do not collide are unaffected: device-level
hami_host_gpu_* keeps the target labels, and the synthetic up series still
carries the device plugin's own namespace/pod/container.

Verified on k3s with HAMi 2.10 and a CUDA workload. Before the change the
query used by taskCoreUsed matched 0 series; after it matched 1 and
hami_container_core_used / core_util / memory_used are published with real
values.

No Go change is needed: the existing queries are correct once the scrape
contract is.

Signed-off-by: Nimbus318 <136771156+Nimbus318@users.noreply.github.com>
@hami-robot

hami-robot Bot commented Aug 29, 2026

Copy link
Copy Markdown

@Nimbus318: The label(s) kind/bug cannot be applied, because the repository doesn't have them.

Details

In response to this:

What type of PR is this?

/kind bug

What this PR does / why we need it:

With honorLabels: false, Prometheus renames colliding HAMi workload labels
(namespace, pod, and container) to exported_*. The NVIDIA task queries
use the original names, so they return no series and queryInstantVal reports
0.

This PR sets hamiServiceMonitor.honorLabels: true, preserving the workload
labels and allowing the existing PromQL to work unchanged.

Verification

Tested with k3s, HAMi 2.10, and a CUDA workload:

  • Workload selector: 0 series before, 1 after
  • WebUI-generated core and memory metrics reported non-zero values
  • helm lint passed
  • helm template renders true by default
  • An explicit --set hamiServiceMonitor.honorLabels=false still works

Which issue(s) this PR fixes:

Supersedes #114. It correctly identified the label mismatch, but only rewrites
namespace and pod. After Project-HAMi/HAMi#1990, container can also
collide, so that query still returns no series on the tested HAMi 2.10 setup.

Thanks to @Shenhan11 for identifying the issue.

Special notes for your reviewer:

Prometheus.spec.overrideHonorLabels: true overrides this setting. If the same
Prometheus selects both HAMi ServiceMonitors, the endpoint is scraped twice.
Both cases are documented in the installation guide.

The empty-result-to-0 behavior should be addressed separately.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@hami-robot

hami-robot Bot commented Aug 29, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Nimbus318

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

@coderabbitai

coderabbitai Bot commented Aug 29, 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: 7794ba8e-5d5d-45a1-9a0a-e0eba3f1e66a

📥 Commits

Reviewing files that changed from the base of the PR and between 03121b8 and 1a0e97b.

📒 Files selected for processing (3)
  • charts/hami-webui/README.md
  • charts/hami-webui/values.yaml
  • docs/installation/helm/index.md

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The Helm chart now enables honorLabels for the HAMi ServiceMonitor. README and installation documentation explain workload-label preservation, Prometheus override behavior, and duplicate scraping conditions.

Changes

Prometheus workload label preservation

Layer / File(s) Summary
ServiceMonitor honorLabels default
charts/hami-webui/values.yaml, charts/hami-webui/README.md
The default changes to hamiServiceMonitor.honorLabels: true. Comments and the Values table describe preservation of namespace, pod, and container labels.
Prometheus scrape configuration guidance
docs/installation/helm/index.md
The Helm guide documents label collisions, separate scrape configuration, overrideHonorLabels, duplicate scraping, and the uninstall code block formatting.

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

Merge Risk: ⚪ Minimal · up to 1a0e9

The chart now preserves HAMi workload labels by default so existing utilization queries continue to return metrics, while operators can still disable the behavior explicitly. No actionable merge-blocking risk remains after normal checks and review.

Suggested labels: enhancement

Poem

A rabbit checks the labels bright
Namespace, pod, and container right
Prometheus keeps their names in line
The WebUI reads each metric fine
Helm notes the path by moonlit light

🚥 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 main change: preserving HAMi workload labels in the ServiceMonitor.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
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.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (3 skipped: 3 unsupported.)

✨ 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 added the enhancement New feature or request label Aug 29, 2026
@Nimbus318
Nimbus318 merged commit 70c20a6 into Project-HAMi:main Aug 29, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant