Allow colons in metric names in prometheus_client output (#5680)

This commit is contained in:
Robert Sullivan 2019-04-04 17:38:33 -06:00 committed by Daniel Nelson
parent dc5db8fc38
commit e5215d74db
2 changed files with 4 additions and 4 deletions

View File

@ -25,7 +25,7 @@ import (
) )
var ( 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_]*`) validNameCharRE = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_]*`)
) )

View File

@ -186,15 +186,15 @@ func TestWrite_Sanitize(t *testing.T) {
client := NewClient() client := NewClient()
p1, err := metric.New( p1, err := metric.New(
"foo.bar", "foo.bar:colon",
map[string]string{"tag-with-dash": "localhost.local"}, 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(), time.Now(),
telegraf.Counter) telegraf.Counter)
err = client.Write([]telegraf.Metric{p1}) err = client.Write([]telegraf.Metric{p1})
require.NoError(t, err) 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.True(t, ok)
require.Equal(t, map[string]int{"tag_with_dash": 1}, fam.LabelSet) require.Equal(t, map[string]int{"tag_with_dash": 1}, fam.LabelSet)