Skip to content

fix(metrics): remove changing values like 'limit' from metric labels to prevent Prometheus crash - #2392

Closed
devGPP23 wants to merge 1 commit into
Project-HAMi:masterfrom
devGPP23:fix-metrics-high-cardinality
Closed

fix(metrics): remove changing values like 'limit' from metric labels to prevent Prometheus crash#2392
devGPP23 wants to merge 1 commit into
Project-HAMi:masterfrom
devGPP23:fix-metrics-high-cardinality

Conversation

@devGPP23

@devGPP23 devGPP23 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

This PR fixes a high-cardinality issue in the Prometheus metrics exported by both scheduler and vGPUmonitor.
It removes dynamic values that were incorrectly being passed as metric labels, and instead exports them as standard metric values.

Why is this needed?

Exporting dynamic or configurable values (like quota limit) as labels is a known Prometheus anti-pattern.
Every time an admin updates a quota limit, Prometheus creates an entirely new time-series, leaving the old one.

In large clusters with frequent changes, this causes "Label Explosion" (High Cardinality) which consumes excessive memory and can eventually lead to Prometheus crashing (OOM kills).
To improve monitoring and dashboards , cleaning up this metric hygiene is essential so that the dashboards can run efficiently at scale.

How does this PR fix it?

  1. Scheduler Quota Metrics: Dropped the limit label from the hami_resource_quota_used metric.
    and Created a brand new dedicated gauge hami_resource_quota_limit to track the limit value separately.

2.)vGPUmonitor Legacy Metrics: Trimmed Device_memory_desc_of_container from 9 labels down to 5.
& Removed the redundant dynamic labels (context, module, data, offset) since these values are already properly exported as standard values in the newer metrics (e.g. hami_vgpu_memory_context_bytes).

Added TestQuotaMetricHasNoLimitLabel in scheduler tests to ensure the label is successfully dropped.
Added TestLegacyCtrDeviceMemoryDescHasFiveLabels in vGPUmonitor tests to prevent future label count regressions.
Passed local tests and verified metrics output formatting.

AI Disclosure:
I used an AI assistant to help me write the code. However, the logic behind fixing the metrics, finding the root cause of the bug, and running the local tests was entirely done and verified by me to make sure everything works .

Summary by CodeRabbit

  • Improvements
    • Resource quota metrics now expose configured limits separately from quota usage.
    • Simplified metric labels for clearer, more consistent monitoring data.
    • Reduced unnecessary labels in legacy container device-memory metrics to improve metric usability and consistency.

@hami-robot
hami-robot Bot requested a review from DSFans2014 August 5, 2026 20:40
@hami-robot

hami-robot Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: devGPP23
Once this PR has been reviewed and has the lgtm label, please assign archlitchi 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 a review from FouoF August 5, 2026 20:40
@github-actions github-actions Bot added the kind/bug Something isn't working label Aug 5, 2026
@hami-robot hami-robot Bot added the size/M label Aug 5, 2026
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The scheduler publishes quota limits separately from quota usage. The vGPU monitor removes extra labels from legacy container device-memory metrics. Tests verify both updated label sets.

Changes

Metric label cleanup

Layer / File(s) Summary
Separate quota limit metrics
cmd/scheduler/metrics.go, cmd/scheduler/metrics_test.go
Quota usage metrics now use namespace and quota name labels. A separate metric exposes configured quota limits. Tests verify the emitted labels.
Reduce legacy device-memory labels
cmd/vGPUmonitor/metrics.go, cmd/vGPUmonitor/metrics_test.go
Legacy container device-memory metrics now use five base labels. Emission passes those labels directly. Tests verify the descriptor labels.

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

Possibly related PRs

Suggested reviewers: archlitchi

Poem

A rabbit trims labels with care,
Quota limits gain their own metric share.
Usage keeps its names,
Devices shed extra claims,
Tests confirm the labels are fair.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: removing changing metric label values to prevent Prometheus failures.
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 archlitchi August 5, 2026 20:41

@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.go`:
- Line 470: Remove the now-unused memoryOffset declaration and calculation near
the sendLegacyMetric call in the affected metrics function, leaving the
memoryTotal metric emission unchanged.
🪄 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: ea4b6a58-837a-4d98-8b14-052dbfe04339

📥 Commits

Reviewing files that changed from the base of the PR and between e6d0902 and c6fb49a.

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

Comment thread cmd/vGPUmonitor/metrics.go Outdated
@devGPP23
devGPP23 force-pushed the fix-metrics-high-cardinality branch from c6fb49a to 3a24547 Compare August 5, 2026 20:46
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@devGPP23
devGPP23 force-pushed the fix-metrics-high-cardinality branch from 3a24547 to a8f6b48 Compare August 5, 2026 21:07
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@devGPP23
devGPP23 force-pushed the fix-metrics-high-cardinality branch from a8f6b48 to 81f15c3 Compare August 6, 2026 06:41
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

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

remove blank lines and run gofmt locally

Comment thread cmd/scheduler/metrics.go Outdated
"QuotaUsed",
"resourcequota usage for a certain device",
[]string{"quotanamespace", "quotaName", "limit"}, nil,
[]string{"quotanamespace", "quotaName"}, nil,

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.

--legacy-metrics is for backward compat ig, so dropping limit here breaks old dashboards, and there's no legacy version of the new hami_resource_quota_limit. Keep this as-is limit the cleanup to hami_resource_quota_used

Comment thread cmd/vGPUmonitor/metrics.go Outdated
"Device_memory_desc_of_container",
"Container device memory description",
[]string{"podnamespace", "podname", "ctrname", "vdeviceid", "deviceuuid", "context", "module", "data", "offset"}, nil,
[]string{"podnamespace", "podname", "ctrname", "vdeviceid", "deviceuuid"}, nil,

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.

these were numeric values encoded as labels, so dropping them is a valid cardinality fix .. but the modern path re exposes them as separate metrics (hami_vgpu_memory_context/module/buffer_bytes) and legacy has no equivalent, so legacy consumers lose the data outright.. intended?

Comment thread cmd/vGPUmonitor/metrics_test.go Outdated
desc := legacyCtrDeviceMemorydesc.String()

if !strings.Contains(desc, "variableLabels: [podnamespace podname ctrname vdeviceid deviceuuid]") {
t.Errorf("Expected legacyCtrDeviceMemorydesc to have exactly 5 labels, but got desc: %s", desc)

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.

Desc.String() renders labels as {a,b,c} on v1.24.1, not [a b c].. this never matches, test always fails (ci has skipped this cause it failed before due to lint mostt probably). Drop the String() assertion, use testutil.CollectAndCompare like TestQuotaMetricHasNoLimitLabel

@devGPP23
devGPP23 force-pushed the fix-metrics-high-cardinality branch from 81f15c3 to 114692a Compare August 6, 2026 07:46
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

…ainer-memory metrics

Signed-off-by: devGP7 <gauravpatil232005@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants