Skip to content

chore(metrics): remove Prometheus tutorial scaffolding and hoist scheduler descriptors - #2275

Closed
shivv23 wants to merge 1 commit into
Project-HAMi:masterfrom
shivv23:chore/metrics-collectors-cleanup
Closed

chore(metrics): remove Prometheus tutorial scaffolding and hoist scheduler descriptors#2275
shivv23 wants to merge 1 commit into
Project-HAMi:masterfrom
shivv23:chore/metrics-collectors-cleanup

Conversation

@shivv23

@shivv23 shivv23 commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

/kind cleanup

What this PR does / why we need it:

Two related hygiene improvements in the metrics collectors (both requested in #2249):

  1. cmd/vGPUmonitor/metrics.go still shipped scaffolding from the client_golang tutorial. The ClusterManager doc comment described an "example" system with zones, ReallyExpensiveAssessmentOfTheSystemState() was an unused tutorial function returning made-up data (6.023e23), and a block of commented-out dead code (parseidstr, gettotalusage, getTotalUtilization) was left behind. None of it is exercised by the production monitor; the stale comments around Describe/Collect referenced the removed example system.

  2. cmd/scheduler/metrics.go re-created every metric descriptor inside Collect(). All 22 prometheus.NewDesc(...) calls ran on every scrape, re-allocating identical descriptors each time. The vGPUmonitor collector already follows the recommended pattern (package-level descriptors built once); this hoists the scheduler's descriptors to package level — including the 11 legacy descriptors, which are now populated once in initLegacyDescriptors() when legacy mode is enabled, aligning both collectors.

Which issue(s) this PR fixes:
Fixes #2249

Special notes for your reviewer:
No behavior change. go build ./cmd/scheduler/ ./cmd/vGPUmonitor/ and the existing scheduler metrics unit test pass (verified via Linux CI; Windows cannot compile the CGO NVML deps locally). The legacy descriptor init moved from inside Collect() to NewClusterManager, so the unit test now calls initLegacyDescriptors() explicitly.

Does this PR introduce a user-facing change?:

NONE. No functional change to metric names, labels, or values.

This PR description was generated with the assistance of an AI coding tool. The author reviewed and verified all changes.

Summary by CodeRabbit

  • Performance

    • Improved Prometheus metrics collection efficiency by reusing metric definitions instead of recreating them for each collection.
    • Improved handling of legacy metrics based on the selected monitoring mode.
  • Documentation

    • Clarified documentation for cluster and vGPU monitoring components.
  • Refactor

    • Removed obsolete monitoring example code and simplified metric collection internals.

…duler descriptors

Signed-off-by: shivv23 <shivamkumar0423@gmail.com>
@hami-robot

hami-robot Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: shivv23
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 added the size/L label Aug 1, 2026
@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The scheduler collector now reuses package-level Prometheus descriptors and initializes legacy descriptors when enabled. The vGPU monitor removes unused tutorial scaffolding and updates collector documentation.

Changes

Metrics collector updates

Layer / File(s) Summary
Share scheduler metric descriptors
cmd/scheduler/metrics.go, cmd/scheduler/metrics_test.go
Metric descriptors move to package scope. Legacy descriptors initialize when required. Collect uses shared descriptors, and the test initializes legacy descriptors before collection.
Clean up vGPU monitor collector
cmd/vGPUmonitor/metrics.go
The unused ReallyExpensiveAssessmentOfTheSystemState method and commented helper examples are removed. Collector documentation now describes the vGPU monitoring flow.

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

Possibly related PRs

Suggested reviewers: mesutoezdil, archlitchi

Poem

A rabbit hops through metrics bright,
Descriptors wait beyond the scrape’s flight.
Old tutorial weeds are gone,
Clear collector docs now dawn.
Shared paths keep the burrow neat.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.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 describes both main changes: removing metrics scaffolding and hoisting scheduler descriptors.
Linked Issues check ✅ Passed The changes satisfy issue #2249 by removing tutorial scaffolding and moving scheduler descriptor creation to package scope.
Out of Scope Changes check ✅ Passed All reported changes support issue #2249, including documentation cleanup, dead-code removal, and descriptor initialization changes.
✨ 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 mesutoezdil August 1, 2026 18:45

@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: 2

🤖 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`:
- Around line 41-53: Update the ClusterManager type comment to describe only the
PodLister and containerLister state it actually stores, removing the claim that
it holds informers; do not add informer fields unless required elsewhere by the
struct’s implementation.
- Around line 189-190: Update the documentation comment for the Collect method
to describe that it emits the current device, pod, and container metrics, whose
labels may change as resources change; remove the claim that every collection
returns the same metrics and descriptors.
🪄 Autofix (Beta)

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: 1a5b3d82-7ae9-4c20-acc3-2c9cf9bc498e

📥 Commits

Reviewing files that changed from the base of the PR and between 57bda65 and f1c545e.

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

Comment on lines +41 to 53
// ClusterManager models the vGPU monitoring state for a single node and holds
// the informers and listers used to discover the pods and containers running
// on that node. A custom Collector called ClusterManagerCollector collects
// information from a ClusterManager using its provided methods and turns them
// into Prometheus Metrics for collection.
type ClusterManager struct {
Zone string
// Contains many more fields not listed in this example.
// PodLister lists pods assigned to the monitored node.
PodLister listerscorev1.PodLister
containerLister *nvidia.ContainerLister
LegacyMetrics bool
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Align the ClusterManager documentation with the stored state.

ClusterManager stores PodLister and containerLister, but it has no informer fields. Describe the listers only, or add the informer fields if the struct should own them.

Proposed documentation fix
-// the informers and listers used to discover the pods and containers running
+// the listers used to discover the pods and containers running
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// ClusterManager models the vGPU monitoring state for a single node and holds
// the informers and listers used to discover the pods and containers running
// on that node. A custom Collector called ClusterManagerCollector collects
// information from a ClusterManager using its provided methods and turns them
// into Prometheus Metrics for collection.
type ClusterManager struct {
Zone string
// Contains many more fields not listed in this example.
// PodLister lists pods assigned to the monitored node.
PodLister listerscorev1.PodLister
containerLister *nvidia.ContainerLister
LegacyMetrics bool
}
// ClusterManager models the vGPU monitoring state for a single node and holds
// the listers used to discover the pods and containers running
// on that node. A custom Collector called ClusterManagerCollector collects
// information from a ClusterManager using its provided methods and turns them
// into Prometheus Metrics for collection.
type ClusterManager struct {
Zone string
// PodLister lists pods assigned to the monitored node.
PodLister listerscorev1.PodLister
containerLister *nvidia.ContainerLister
LegacyMetrics bool
}
🤖 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.go` around lines 41 - 53, Update the ClusterManager
type comment to describe only the PodLister and containerLister state it
actually stores, removing the claim that it holds informers; do not add informer
fields unless required elsewhere by the struct’s implementation.

Comment on lines +189 to +190
// Describe sends the metric descriptors to the provided channel. The Collect
// method always returns the same metrics with the same descriptors.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

curl -fsSL \
  https://raw.githubusercontent.com/prometheus/client_golang/v1.24.1/prometheus/collector.go |
  grep -n -A20 -B2 'type Collector interface'

Repository: Project-HAMi/HAMi

Length of output: 1454


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

# Inspect the relevant comments and the actual emitted metric construction in cmd/vGPUmonitor/metrics.go.
sed -n '170,225p' cmd/vGPUmonitor/metrics.go
printf '\n--- Collect usages / metric construction evidence ---\n'
rg -n "func \\(.*Collect\\(.*chan .*Metric|Desc\\(.*chan \\*.*Desc|prometheus.New.*GaugeVec|labels|current|Devices|Pods|Containers" cmd/vGPUmonitor/metrics.go

Repository: Project-HAMi/HAMi

Length of output: 5643


🏁 Script executed:

#!/usr/bin/env/bash
set -euo pipefail

# Inspect the Prometheus collector interface docs for Collect semantics in the stated version.
curl -fsSL \
  https://raw.githubusercontent.com/prometheus/client_golang/v1.24.1/prometheus/collector.go |
  grep -n -A25 'type Collector interface' |
  sed -n '25,95p'

Repository: Project-HAMi/HAMi

Length of output: 302


Describe the dynamic sample set in Collect.

Collect emits current device, pod, and container metrics, and the emitted labels change as those resources change. Update the Collect comment to say it returns current metrics rather than implying the same metrics every sample.

🤖 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.go` around lines 189 - 190, Update the documentation
comment for the Collect method to describe that it emits the current device,
pod, and container metrics, whose labels may change as resources change; remove
the claim that every collection returns the same metrics and descriptors.

@mesutoezdil

Copy link
Copy Markdown
Contributor

closing, #2249 was already picked up by its author who was asked to do this as 2 prs w/ the hoisting waiting for #2170, see the thread there.

this also conflicts w/ open #2170 and #2240 and has no ai disclosure.

pls check the issue thread and existing prs before opening a new 1.

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.

Metrics collectors: leftover Prometheus-tutorial scaffolding and per-scrape descriptor creation

2 participants