feat: support metricRelabelings on the ServiceMonitor #2987
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #2987"
general
weight: 0.35
tariq1890
Description
ServiceMonitorConfigonly exposedrelabelings, which maps to Prometheus target relabeling (Endpoint.RelabelConfigs) and runs before the scrape. Rewriting labels on scraped samples — e.g. collapsingexported_namespace/exported_podback ontonamespace/pod, the use case in #2938 — requiresEndpoint.MetricRelabelConfigs, which had no API surface. Since the Helm chart passesdcgmExporter.serviceMonitorthrough to the ClusterPolicy verbatim, ametricRelabelingskey was rejected by CRD schema validation.This adds
MetricRelabelingstoServiceMonitorConfigand applies it on both rendering paths:applyServiceMonitorCustomEdits)manifests/state-dcgm-exporter/0600_service_monitor.yaml)Because
DCGMExporterServiceMonitorConfigis an alias ofServiceMonitorConfig, the field is also available to the operator-metrics ServiceMonitor.The duplicated pointer-slice deref loop is factored into a shared
derefRelabelConfigshelper so the two branches cannot drift.Example:
Checklist
make lint)make validate-generated-assets)make validate-modules)Testing
make unit-test— all 21 packages pass.make validate-generated-assets,make validate-modules,make validate-helm-values— pass.make lint— only the 3 pre-existingSA4023findings incmd/nvidia-validator/main.goremain; none in the changed files.TestServiceMonitordcgm-exporter case to assertMetricRelabelConfigs.TestDCGMExporterServiceMonitorRelabelingsininternal/state, which renders the DRA ServiceMonitor template and asserts bothrelabelingsandmetricRelabelingsland on the endpoint.helm template, confirmingmetricRelabelingsreaches the rendered ClusterPolicy.helm upgrade, addedmetricRelabelingssection in values.yaml, and Prometheus metrics query for a test pod:Test Pod:
Before the fix:
Metrics Query:
After the fix:
Helm metricrelabel-values.yaml
Verify ClusterPolicy CRD and CR after Helm upgrade:
Verify Servicemonitor:
Metrics Query:
Fixes #2938