From 05f3ac1f12815b49ede816c2ee1c50ebec2a4212 Mon Sep 17 00:00:00 2001 From: Bastien Grasnick Date: Fri, 17 Nov 2023 17:24:42 +0100 Subject: [PATCH 1/3] feat: add metric relabeling so namespace label has the correct value (which is the same as container_namespace) applied after scraping Signed-off-by: Bastien Grasnick --- pkg/components/exporter/exporter.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pkg/components/exporter/exporter.go b/pkg/components/exporter/exporter.go index 3366c7a4..dae44bb8 100644 --- a/pkg/components/exporter/exporter.go +++ b/pkg/components/exporter/exporter.go @@ -489,6 +489,14 @@ func NewServiceMonitor() *monv1.ServiceMonitor { TargetLabel: "instance", }} + metricRelabelings := []*monv1.RelabelConfig{{ + Action: "replace", + SourceLabels: []monv1.LabelName{ + "container_namespace", + }, + TargetLabel: "namespace", + }} + return &monv1.ServiceMonitor{ TypeMeta: metav1.TypeMeta{ APIVersion: monv1.SchemeGroupVersion.String(), @@ -501,10 +509,11 @@ func NewServiceMonitor() *monv1.ServiceMonitor { }, Spec: monv1.ServiceMonitorSpec{ Endpoints: []monv1.Endpoint{{ - Port: ServicePortName, - Interval: "3s", - Scheme: "http", - RelabelConfigs: relabelings, + Port: ServicePortName, + Interval: "3s", + Scheme: "http", + RelabelConfigs: relabelings, + MetricRelabelConfigs: metricRelabelings, }}, JobLabel: "app.kubernetes.io/name", Selector: metav1.LabelSelector{ From 1e395b730f402425342b4d7e204167516e8e31f2 Mon Sep 17 00:00:00 2001 From: Bastien Grasnick Date: Fri, 17 Nov 2023 17:25:22 +0100 Subject: [PATCH 2/3] feat: use openshift-monitoring prometheus instead of user workload monitoring Signed-off-by: Bastien Grasnick --- pkg/components/components.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/components/components.go b/pkg/components/components.go index dee9b851..acdfb201 100644 --- a/pkg/components/components.go +++ b/pkg/components/components.go @@ -57,6 +57,7 @@ func NewKeplerNamespace() *corev1.Namespace { // allowPrivilegeEscalation != false (container "kepler-exporter" must set // securityContext.allowPrivilegeEscalation=false), "pod-security.kubernetes.io/enforce": "privileged", + "openshift.io/cluster-monitoring": "true", }), //TODO: ensure in-cluster monitoring ignores this ns }, From b82f99ea9e2594961cb71ff1f000758688869e86 Mon Sep 17 00:00:00 2001 From: Bastien Grasnick Date: Mon, 20 Nov 2023 15:24:19 +0100 Subject: [PATCH 3/3] Revert "feat: use openshift-monitoring prometheus instead of user workload monitoring" This reverts commit 1e395b730f402425342b4d7e204167516e8e31f2. Signed-off-by: Bastien Grasnick --- pkg/components/components.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/components/components.go b/pkg/components/components.go index acdfb201..dee9b851 100644 --- a/pkg/components/components.go +++ b/pkg/components/components.go @@ -57,7 +57,6 @@ func NewKeplerNamespace() *corev1.Namespace { // allowPrivilegeEscalation != false (container "kepler-exporter" must set // securityContext.allowPrivilegeEscalation=false), "pod-security.kubernetes.io/enforce": "privileged", - "openshift.io/cluster-monitoring": "true", }), //TODO: ensure in-cluster monitoring ignores this ns },