From a8d42fd4f899b5520114b6c5337817fac3f57d71 Mon Sep 17 00:00:00 2001 From: tewfik-ghariani Date: Wed, 14 Aug 2024 15:26:58 +0200 Subject: [PATCH] feat: Add app.kubernetes.io/instance label to the condition_info Prometheus metric Signed-off-by: tewfik-ghariani --- pkg/controller/metrics.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/controller/metrics.go b/pkg/controller/metrics.go index c86978d951..16e54ac627 100644 --- a/pkg/controller/metrics.go +++ b/pkg/controller/metrics.go @@ -17,6 +17,7 @@ const ( labelNamespace = "namespace" labelName = "name" labelCondition = "condition" + labelInstance = "ss_app_kubernetes_io_instance" ) var conditionStatusToGaugeValue = map[v1.ConditionStatus]float64{ @@ -47,11 +48,14 @@ var ( []string{"reason", "namespace"}, ) - conditionInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: metricNamespace, - Name: "condition_info", - Help: "Current SealedSecret condition status. Values are -1 (false), 0 (unknown or absent), 1 (true)", - }, []string{labelNamespace, labelName, labelCondition}) + conditionInfo = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Namespace: metricNamespace, + Name: "condition_info", + Help: "Current SealedSecret condition status. Values are -1 (false), 0 (unknown or absent), 1 (true)", + }, + []string{labelNamespace, labelName, labelCondition, labelInstance}, + ) httpRequestsTotal = prometheus.NewCounterVec( prometheus.CounterOpts{ @@ -102,6 +106,7 @@ func ObserveCondition(ssecret *v1alpha1.SealedSecret) { labelNamespace: ssecret.Namespace, labelName: ssecret.Name, labelCondition: string(condition.Type), + labelInstance: ssecret.Labels["app.kubernetes.io/instance"], }).Set(conditionStatusToGaugeValue[condition.Status]) } } @@ -112,7 +117,7 @@ func UnregisterCondition(ssecret *v1alpha1.SealedSecret) { return } for _, condition := range ssecret.Status.Conditions { - conditionInfo.MetricVec.DeleteLabelValues(ssecret.Namespace, ssecret.Name, string(condition.Type)) + conditionInfo.MetricVec.DeleteLabelValues(ssecret.Namespace, ssecret.Name, string(condition.Type), labelInstance) } }