Skip to content

Commit

Permalink
Merge pull request #381 from evandam/allow-multi-dash
Browse files Browse the repository at this point in the history
allow multiple dashes in StatsD metric names
  • Loading branch information
matthiasr authored Aug 31, 2021
2 parents f9fea18 + abb7ec0 commit a9c883a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/mapper/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import (

var (
// 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
// 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+\}?)`

metricLineRE = regexp.MustCompile(`^(\*|` + statsdMetricRE + `)(\.\*|\.` + statsdMetricSubsequentRE + `)*$`)
Expand Down
19 changes: 17 additions & 2 deletions pkg/mapper/mapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestMetricMapperYAML(t *testing.T) {
mappings:
- match: test.dispatcher.*.*.*
name: "dispatch_events"
labels:
labels:
processor: "$1"
action: "$2"
result: "$3"
Expand Down Expand Up @@ -430,12 +430,27 @@ mappings:
testName: "Config with bad metric line",
config: `---
mappings:
- match: bad--metric-line.*.*
- match: bad!!metric-line.*.*
name: "foo"
labels: {}
`,
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",
config: `---
Expand Down

0 comments on commit a9c883a

Please sign in to comment.