core: add cluster label to all servicemonitor scraped metrics

Signed-off-by: Joshua Hoblitt <josh@hoblitt.com>
This commit is contained in:
Joshua Hoblitt
2026-05-14 16:02:34 -07:00
parent 3775bf206a
commit cc05619dd8
2 changed files with 7 additions and 0 deletions
+5
View File
@@ -27,6 +27,7 @@ import (
"github.com/rook/rook/pkg/clusterd"
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
)
func getMonitoringClient(context *clusterd.Context) (*monitoringclient.Clientset, error) {
@@ -65,6 +66,10 @@ func GetServiceMonitor(name string, namespace string, portName string) *monitori
Path: "/metrics",
Interval: "10s",
HonorLabels: true,
RelabelConfigs: []monitoringv1.RelabelConfig{{
TargetLabel: "cluster",
Replacement: ptr.To(namespace),
}},
},
},
},
+2
View File
@@ -38,4 +38,6 @@ func TestGetServiceMonitor(t *testing.T) {
assert.NotNil(t, servicemonitor.Spec.NamespaceSelector.MatchNames)
assert.NotNil(t, servicemonitor.Spec.Selector.MatchLabels)
assert.NotNil(t, servicemonitor.Spec.Endpoints)
assert.Equal(t, "cluster", servicemonitor.Spec.Endpoints[0].RelabelConfigs[0].TargetLabel)
assert.Equal(t, namespace, *servicemonitor.Spec.Endpoints[0].RelabelConfigs[0].Replacement)
}