allow multiple dashes in StatsD metric names

Signed-off-by: Evan Van Dam <evan.vandam@wonolo.com>
This commit is contained in:
Evan Van Dam 2021-06-17 09:19:52 -07:00
parent ef6627b9f0
commit abb7ec0afb
2 changed files with 19 additions and 4 deletions

View file

@ -30,10 +30,10 @@ import (
var ( var (
// The first segment of a match cannot start with a number // The first segment of a match cannot start with a number
statsdMetricRE = `[a-zA-Z_](-?[a-zA-Z0-9_])*` statsdMetricRE = `[a-zA-Z_]([a-zA-Z0-9_\-])*`
// The subsequent segments of a match can start with a number // The subsequent segments of a match can start with a number
// See https://github.com/prometheus/statsd_exporter/issues/328 // See https://github.com/prometheus/statsd_exporter/issues/328
statsdMetricSubsequentRE = `[a-zA-Z0-9_](-?[a-zA-Z0-9_])*` statsdMetricSubsequentRE = `[a-zA-Z0-9_]([a-zA-Z0-9_\-])*`
templateReplaceRE = `(\$\{?\d+\}?)` templateReplaceRE = `(\$\{?\d+\}?)`
metricLineRE = regexp.MustCompile(`^(\*|` + statsdMetricRE + `)(\.\*|\.` + statsdMetricSubsequentRE + `)*$`) metricLineRE = regexp.MustCompile(`^(\*|` + statsdMetricRE + `)(\.\*|\.` + statsdMetricSubsequentRE + `)*$`)

View file

@ -68,7 +68,7 @@ func TestMetricMapperYAML(t *testing.T) {
mappings: mappings:
- match: test.dispatcher.*.*.* - match: test.dispatcher.*.*.*
name: "dispatch_events" name: "dispatch_events"
labels: labels:
processor: "$1" processor: "$1"
action: "$2" action: "$2"
result: "$3" result: "$3"
@ -430,12 +430,27 @@ mappings:
testName: "Config with bad metric line", testName: "Config with bad metric line",
config: `--- config: `---
mappings: mappings:
- match: bad--metric-line.*.* - match: bad!!metric-line.*.*
name: "foo" name: "foo"
labels: {} labels: {}
`, `,
configBad: true, configBad: true,
}, },
{
testName: "Config with multiple dashes in metric name",
config: `---
mappings:
- match: "foo--bar.*"
name: "foo_bar_${1}"
labels: {}
`,
mappings: mappings{
{
statsdMetric: "foo--bar.count",
name: "foo_bar_count",
},
},
},
{ {
testName: "Config with dynamic metric name", testName: "Config with dynamic metric name",
config: `--- config: `---