feat: support metricRelabelings on the ServiceMonitor - #2987
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 📝 WalkthroughWalkthroughThe ServiceMonitor configuration now supports optional metric relabeling rules. The controller converts configured rules into endpoint metric relabel configs, and the DCGM Exporter ServiceMonitor template conditionally renders them. Sample and Helm configuration include empty defaults and commented examples. Tests check metric relabeling in the resulting ServiceMonitor endpoint. Priority: ➖ Normal Merge Risk: 🔵 Low · up to The new metric relabeling configuration is supported by the generated assets and both rendering paths. Mergeable with bounded follow-up to strengthen the rendering assertions against incomplete rules.
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/state/dcgm_exporter_test.go (1)
260-260: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAssert the complete rendered metric relabeling rule.
The assertion passes if rendering drops
sourceLabels, changesregex, or changesactionwhile preservingtargetLabel. Apply the same complete-rule assertion to the target relabeling rule on line 255. This test must detect any change that prevents the configured label rewrite.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: NVIDIA/gpu-operator/.coderabbit.yaml
Review profile: QUIET
Plan: Enterprise
Run ID: 40bb04ba-c932-4911-be38-e8acee5df20b
⛔ Files ignored due to path filters (7)
api/nvidia/v1/zz_generated.deepcopy.gois excluded by!**/zz_generated.*.gobundle/manifests/nvidia.com_clusterpolicies.yamlis excluded by!bundle/manifests/nvidia.com_*.yamlbundle/manifests/nvidia.com_gpuclusters.yamlis excluded by!bundle/manifests/nvidia.com_*.yamlconfig/crd/bases/nvidia.com_clusterpolicies.yamlis excluded by!config/crd/bases/**config/crd/bases/nvidia.com_gpuclusters.yamlis excluded by!config/crd/bases/**deployments/gpu-operator/crds/nvidia.com_clusterpolicies.yamlis excluded by!deployments/gpu-operator/crds/**deployments/gpu-operator/crds/nvidia.com_gpuclusters.yamlis excluded by!deployments/gpu-operator/crds/**
📒 Files selected for processing (7)
api/nvidia/v1/clusterpolicy_types.goconfig/samples/nvidia_v1alpha1_gpucluster.yamlcontrollers/object_controls.gocontrollers/object_controls_test.godeployments/gpu-operator/values.yamlinternal/state/dcgm_exporter_test.gomanifests/state-dcgm-exporter/0600_service_monitor.yaml
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.
ServiceMonitorConfig only exposed relabelings, which maps to Prometheus target relabeling (Endpoint.RelabelConfigs) and runs before the scrape. Rewriting labels on scraped samples, e.g. collapsing exported_namespace back onto namespace, requires Endpoint.MetricRelabelConfigs and had no API surface, so the Helm value was rejected by CRD validation. Add MetricRelabelings to ServiceMonitorConfig and apply it on both rendering paths: the ClusterPolicy controller and the DRA dcgm-exporter manifest template. The DCGMExporterServiceMonitorConfig alias means the field is available to the operator-metrics ServiceMonitor as well. Fixes NVIDIA#2938 Signed-off-by: Gernot Seidler <gernot.seidler@hpe.com>
1f3acb0 to
1c179f1
Compare
|
/ok to test 1c179f1 |
|
Thanks for your contribution Gernot @gseidlerhpe ! |
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.Extended the ClusterPolicy-path
TestServiceMonitordcgm-exporter case to assertMetricRelabelConfigs.Added
TestDCGMExporterServiceMonitorRelabelingsininternal/state, which renders the DRA ServiceMonitor template and asserts bothrelabelingsandmetricRelabelingsland on the endpoint.Verified end-to-end with
helm template, confirmingmetricRelabelingsreaches the rendered ClusterPolicy.Verified end-to-end with
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