Skip to content

Commit

Permalink
allow metrics with dashes when mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Mac Browning committed Oct 9, 2015
1 parent 4270a5e commit 411b071
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 4 additions & 2 deletions mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import (
)

var (
identifierRE = `[a-zA-Z_][a-zA-Z0-9_]+`
metricLineRE = regexp.MustCompile(`^(\*\.|` + identifierRE + `\.)+(\*|` + identifierRE + `)$`)
identifierRE = `[a-zA-Z_][a-zA-Z0-9_]+`
statsdMetricRE = `[a-zA-Z_](-?[a-zA-Z0-9_])+`

metricLineRE = regexp.MustCompile(`^(\*\.|` + statsdMetricRE + `\.)+(\*|` + statsdMetricRE + `)$`)
labelLineRE = regexp.MustCompile(`^(` + identifierRE + `)\s*=\s*"(.*)"$`)
metricNameRE = regexp.MustCompile(`^` + identifierRE + `$`)
)
Expand Down
24 changes: 23 additions & 1 deletion mapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ func TestMetricMapper(t *testing.T) {
result="$3"
job="test_dispatcher"
test.my-dispatch-host01.name.dispatcher.*.*.*
name="host_dispatch_events"
processor="$1"
action="$2"
result="$3"
job="test_dispatcher"
*.*
name="catchall"
first="$1"
Expand All @@ -50,6 +57,13 @@ func TestMetricMapper(t *testing.T) {
"result": "succeeded",
"job": "test_dispatcher",
},
"test.my-dispatch-host01.name.dispatcher.FooProcessor.send.succeeded": map[string]string{
"name": "host_dispatch_events",
"processor": "FooProcessor",
"action": "send",
"result": "succeeded",
"job": "test_dispatcher",
},
"foo.bar": map[string]string{
"name": "catchall",
"first": "foo",
Expand Down Expand Up @@ -91,7 +105,7 @@ func TestMetricMapper(t *testing.T) {
// Config with bad metric line.
{
config: `
bad-metric-line.*.*
bad--metric-line.*.*
name="foo"
`,
configBad: true,
Expand All @@ -104,6 +118,14 @@ func TestMetricMapper(t *testing.T) {
`,
configBad: true,
},
// Config with bad label line.
{
config: `
test.*.*
name="foo-name"
`,
configBad: true,
},
// Config with bad metric name.
{
config: `
Expand Down

0 comments on commit 411b071

Please sign in to comment.