From 323a01b26d336b2dfe417b4e4e19c6e3ff937f1e Mon Sep 17 00:00:00 2001 From: Robert Sullivan Date: Thu, 4 Apr 2019 17:38:33 -0600 Subject: [PATCH] Allow colons in metric names in prometheus_client output (#5680) --- plugins/outputs/prometheus_client/prometheus_client.go | 2 +- plugins/outputs/prometheus_client/prometheus_client_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/outputs/prometheus_client/prometheus_client.go b/plugins/outputs/prometheus_client/prometheus_client.go index da051daf9dc23..32dcdbb891f14 100644 --- a/plugins/outputs/prometheus_client/prometheus_client.go +++ b/plugins/outputs/prometheus_client/prometheus_client.go @@ -25,7 +25,7 @@ import ( ) var ( - invalidNameCharRE = regexp.MustCompile(`[^a-zA-Z0-9_]`) + invalidNameCharRE = regexp.MustCompile(`[^a-zA-Z0-9_:]`) validNameCharRE = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_]*`) ) diff --git a/plugins/outputs/prometheus_client/prometheus_client_test.go b/plugins/outputs/prometheus_client/prometheus_client_test.go index b6bbe35fde34f..211e24030dc56 100644 --- a/plugins/outputs/prometheus_client/prometheus_client_test.go +++ b/plugins/outputs/prometheus_client/prometheus_client_test.go @@ -186,15 +186,15 @@ func TestWrite_Sanitize(t *testing.T) { client := NewClient() p1, err := metric.New( - "foo.bar", + "foo.bar:colon", map[string]string{"tag-with-dash": "localhost.local"}, - map[string]interface{}{"field-with-dash": 42}, + map[string]interface{}{"field-with-dash-and:colon": 42}, time.Now(), telegraf.Counter) err = client.Write([]telegraf.Metric{p1}) require.NoError(t, err) - fam, ok := client.fam["foo_bar_field_with_dash"] + fam, ok := client.fam["foo_bar:colon_field_with_dash_and:colon"] require.True(t, ok) require.Equal(t, map[string]int{"tag_with_dash": 1}, fam.LabelSet)