Hardcoded cluster="<namespace>" ServiceMonitor relabeling conflicts with Prometheus externalLabels and breaks multi-cluster Ceph monitoring
What happened
Since commit cc05619dd ("core: add cluster label to all servicemonitor scraped metrics"), the operator hardcodes a relabeling into every ServiceMonitor it creates (rook-ceph-mgr, rook-ceph-exporter):
RelabelConfigs: []monitoringv1.RelabelConfig{{
TargetLabel: "cluster",
Replacement: ptr.To(namespace),
}},(pkg/operator/k8sutil/prometheus.go, GetServiceMonitor, present in v1.20.3/v1.20.6/master)
Every scraped Ceph metric is therefore stamped cluster="rook-ceph" (the operator namespace) at scrape time.
The problem
cluster is the conventional Prometheus label for identifying the site/Kubernetes cluster in multi-cluster monitoring (Prometheus externalLabels -> central VictoriaMetrics/Thanos/Mimir). Prometheus applies externalLabels only to samples that don't already carry the label — external labels never override. With several Kubernetes clusters, each running a rook-ceph cluster in the rook-ceph namespace and remote-writing to a central VictoriaMetrics:
- Ceph metrics from all sites arrive with the identical
cluster="rook-ceph"instead of the per-site external label (e.g.cluster="cluster-a.example.com",cluster="cluster-b.example.com") - series from different sites can't be distinguished, grouped, or filtered by
cluster; dashboards and alerts that group byclusteraggregate across sites incorrectly or break entirely - the value duplicates the
namespacelabel (alsorook-ceph) and adds no information not already present vianamespace/pod/instance
There is no way to disable or override it:
- not exposed in
CephCluster.spec.monitoring(MonitoringSpec has no related field) - manually patching the generated ServiceMonitors is reverted by the operator on every reconcile (
CreateOrUpdateServiceMonitor)
Current workaround (per Prometheus, remote-write only — local data and dashboards stay broken):
remoteWrite:
- url: http://vminsert.../insert/0/prometheus/
writeRelabelConfigs:
- action: replace
sourceLabels: [job]
regex: rook-ceph-(mgr|exporter)
targetLabel: cluster
replacement: cluster-a.example.comDesired behavior (any of)
- Make the label configurable via
CephCluster.spec.monitoring(e.g.clusterLabelname+value, or a genericrelabelingsoverride, current behavior as default), or - Use the CephCluster CR
metadata.name(theclusterNamevalue in the rook-ceph-cluster helm chart, e.g.cluster-a.example.com) as the replacement value instead of the namespace, falling back to the namespace whenclusterNameis not set — this preserves the current behavior for users who rely on defaults, while giving each Ceph cluster a distinct, user-controlled identity when configured (the operator already has the CR in hand at ServiceMonitor creation time), or - Rename the injected label to a non-reserved name (e.g.
rook_cluster) so it doesn't collide with the conventionalclusterlabel, or - Remove the hardcoded relabeling.
Environment
- Rook: v1.20.3 and v1.20.6 (master 0707c2506)
- Storage backend: Ceph v20.2.2
- Kubernetes: multiple on-prem clusters, kube-prometheus-stack, remote write to central VictoriaMetrics
Source: rook/rook