From daa7b3dc1b5dc9312880ac290bac4fa13551091d Mon Sep 17 00:00:00 2001 From: Ori Braunshtein Date: Wed, 20 Dec 2023 11:50:15 +0200 Subject: [PATCH] frr-k8s: use metricRelabelings for serviceMonitors We deploy the serviceMonitors of frr-k8s so that the scraped metrics show as MetalLB's, making the integration cleaner. Signed-off-by: Ori Braunshtein --- pkg/helm/frrk8s.go | 30 +++++++++++++--- .../ocp-metrics-frr-k8s-monitor.golden | 36 +++++++++++++++++++ 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/pkg/helm/frrk8s.go b/pkg/helm/frrk8s.go index 5be5cadfc..230d9719b 100644 --- a/pkg/helm/frrk8s.go +++ b/pkg/helm/frrk8s.go @@ -215,14 +215,34 @@ func (c *frrK8SChartConfig) prometheusValues() map[string]interface{} { tlsConfig, annotations, tlsSecret = ocpPromConfigFor("frr-k8s", c.namespace) } + serviceMonitor := map[string]interface{}{ + "enabled": false, + "annotations": annotations, + "tlsConfig": tlsConfig, + } + + if c.enableServiceMonitor { + serviceMonitor["enabled"] = true + serviceMonitor["metricRelabelings"] = []map[string]interface{}{ + { + "regex": "frrk8s_bgp_(.*)", + "replacement": "metallb_bgp_$1", + "sourceLabels": []string{"__name__"}, + "targetLabel": "__name__", + }, + { + "regex": "frrk8s_bfd_(.*)", + "replacement": "metallb_bfd_$1", + "sourceLabels": []string{"__name__"}, + "targetLabel": "__name__", + }, + } + } + return map[string]interface{}{ "metricsPort": c.metricsPort, "secureMetricsPort": c.secureMetricsPort, - "serviceMonitor": map[string]interface{}{ - "enabled": c.enableServiceMonitor, - "annotations": annotations, - "tlsConfig": tlsConfig, - }, + "serviceMonitor": serviceMonitor, "rbacProxy": map[string]interface{}{ "repository": c.kubeRbacProxyImage.repo, "tag": c.kubeRbacProxyImage.tag, diff --git a/pkg/helm/testdata/ocp-metrics-frr-k8s-monitor.golden b/pkg/helm/testdata/ocp-metrics-frr-k8s-monitor.golden index e1d68da40..62874c365 100644 --- a/pkg/helm/testdata/ocp-metrics-frr-k8s-monitor.golden +++ b/pkg/helm/testdata/ocp-metrics-frr-k8s-monitor.golden @@ -20,6 +20,24 @@ { "bearerTokenFile": "/var/run/secrets/kubernetes.io/serviceaccount/token", "honorLabels": true, + "metricRelabelings": [ + { + "regex": "frrk8s_bgp_(.*)", + "replacement": "metallb_bgp_$1", + "sourceLabels": [ + "__name__" + ], + "targetLabel": "__name__" + }, + { + "regex": "frrk8s_bfd_(.*)", + "replacement": "metallb_bfd_$1", + "sourceLabels": [ + "__name__" + ], + "targetLabel": "__name__" + } + ], "port": "metricshttps", "scheme": "https", "tlsConfig": { @@ -33,6 +51,24 @@ { "bearerTokenFile": "/var/run/secrets/kubernetes.io/serviceaccount/token", "honorLabels": true, + "metricRelabelings": [ + { + "regex": "frrk8s_bgp_(.*)", + "replacement": "metallb_bgp_$1", + "sourceLabels": [ + "__name__" + ], + "targetLabel": "__name__" + }, + { + "regex": "frrk8s_bfd_(.*)", + "replacement": "metallb_bfd_$1", + "sourceLabels": [ + "__name__" + ], + "targetLabel": "__name__" + } + ], "port": "frrmetricshttps", "scheme": "https", "tlsConfig": {