forked from rook/rook
core: add cluster label to all servicemonitor scraped metrics
Signed-off-by: Joshua Hoblitt <josh@hoblitt.com>
This commit is contained in:
@@ -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),
|
||||
}},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user