From cdae84119d65052548edaa73d892a5a578eb9d3c Mon Sep 17 00:00:00 2001 From: Xabier Larrakoetxea Date: Tue, 14 Dec 2021 16:38:38 +0100 Subject: [PATCH 1/3] When adding Kubernetes labels as Prometheus labels, replace with all the invalid Prometheus label chars Signed-off-by: Xabier Larrakoetxea --- controller/metrics/metrics.go | 6 ++++-- controller/metrics/metrics_test.go | 11 +++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/controller/metrics/metrics.go b/controller/metrics/metrics.go index 1b2b471dbec05..1c93cdfe9c8f5 100644 --- a/controller/metrics/metrics.go +++ b/controller/metrics/metrics.go @@ -6,8 +6,8 @@ import ( "fmt" "net/http" "os" + "regexp" "strconv" - "strings" "time" "github.com/argoproj/gitops-engine/pkg/health" @@ -196,11 +196,13 @@ func NewMetricsServer(addr string, appLister applister.ApplicationLister, appFil }, nil } +var invalidPromLabelChars = regexp.MustCompile(`[^a-zA-Z0-9_]`) + func normalizeLabels(prefix string, appLabels []string) []string { results := []string{} for _, label := range appLabels { //prometheus labels don't accept dash in their name - curr := strings.ReplaceAll(label, "-", "_") + curr := invalidPromLabelChars.ReplaceAllString(label, "_") result := fmt.Sprintf("%s_%s", prefix, curr) results = append(results, result) } diff --git a/controller/metrics/metrics_test.go b/controller/metrics/metrics_test.go index 82e3fb071111f..36a1574489719 100644 --- a/controller/metrics/metrics_test.go +++ b/controller/metrics/metrics_test.go @@ -33,6 +33,7 @@ metadata: labels: team-name: my-team team-bu: bu-id + argoproj.io/cluster: test-cluster spec: destination: namespace: dummy-namespace @@ -57,6 +58,7 @@ metadata: labels: team-name: my-team team-bu: bu-id + argoproj.io/cluster: test-cluster spec: destination: namespace: dummy-namespace @@ -87,6 +89,7 @@ metadata: labels: team-name: my-team team-bu: bu-id + argoproj.io/cluster: test-cluster spec: destination: namespace: dummy-namespace @@ -254,14 +257,14 @@ func TestMetricLabels(t *testing.T) { cases := []testCases{ { description: "will return the labels metrics successfully", - metricLabels: []string{"team-name", "team-bu"}, + metricLabels: []string{"team-name", "team-bu", "argoproj.io/cluster"}, testCombination: testCombination{ applications: []string{fakeApp, fakeApp2, fakeApp3}, responseContains: ` # TYPE argocd_app_labels gauge -argocd_app_labels{label_team_bu="bu-id",label_team_name="my-team",name="my-app",namespace="argocd",project="important-project"} 1 -argocd_app_labels{label_team_bu="bu-id",label_team_name="my-team",name="my-app-2",namespace="argocd",project="important-project"} 1 -argocd_app_labels{label_team_bu="bu-id",label_team_name="my-team",name="my-app-3",namespace="argocd",project="important-project"} 1 +argocd_app_labels{label_argoproj_io_cluster="test-cluster",label_team_bu="bu-id",label_team_name="my-team",name="my-app",namespace="argocd",project="important-project"} 1 +argocd_app_labels{label_argoproj_io_cluster="test-cluster",label_team_bu="bu-id",label_team_name="my-team",name="my-app-2",namespace="argocd",project="important-project"} 1 +argocd_app_labels{label_argoproj_io_cluster="test-cluster",label_team_bu="bu-id",label_team_name="my-team",name="my-app-3",namespace="argocd",project="important-project"} 1 `, }, }, From 7d4d800c122c289639c4cfedb490858ffef6d360 Mon Sep 17 00:00:00 2001 From: Xabier Larrakoetxea Date: Tue, 14 Dec 2021 16:46:09 +0100 Subject: [PATCH 2/3] Add Fonoa company to users doc Signed-off-by: Xabier Larrakoetxea --- USERS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/USERS.md b/USERS.md index ae3901dbbd917..c4f58eb2fb865 100644 --- a/USERS.md +++ b/USERS.md @@ -49,6 +49,7 @@ Currently, the following organizations are **officially** using Argo CD: 1. [END.](https://www.endclothing.com/) 1. [Energisme](https://energisme.com/) 1. [Fave](https://myfave.com) +1. [Fonoa](https://www.fonoa.com/) 1. [Future PLC](https://www.futureplc.com/) 1. [Garner](https://www.garnercorp.com) 1. [G DATA CyberDefense AG](https://www.gdata-software.com/) From 1ae77cfc18ed19aa72366bfaef2ffe217b950a6f Mon Sep 17 00:00:00 2001 From: Xabier Larrakoetxea Date: Tue, 14 Dec 2021 16:53:42 +0100 Subject: [PATCH 3/3] Add comment and link to the Prometheus label valid characters Signed-off-by: Xabier Larrakoetxea --- controller/metrics/metrics.go | 1 + 1 file changed, 1 insertion(+) diff --git a/controller/metrics/metrics.go b/controller/metrics/metrics.go index 1c93cdfe9c8f5..b1d2c8ab8eb49 100644 --- a/controller/metrics/metrics.go +++ b/controller/metrics/metrics.go @@ -196,6 +196,7 @@ func NewMetricsServer(addr string, appLister applister.ApplicationLister, appFil }, nil } +// Prometheus invalid labels, more info: https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels. var invalidPromLabelChars = regexp.MustCompile(`[^a-zA-Z0-9_]`) func normalizeLabels(prefix string, appLabels []string) []string {