From 411b071f1f5ff3d05a2ea12be027df429bd0ca5b Mon Sep 17 00:00:00 2001 From: Mac Browning Date: Fri, 9 Oct 2015 18:03:21 -0400 Subject: [PATCH] allow metrics with dashes when mapping --- mapper.go | 6 ++++-- mapper_test.go | 24 +++++++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/mapper.go b/mapper.go index b98dc84..ca93497 100644 --- a/mapper.go +++ b/mapper.go @@ -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 + `$`) ) diff --git a/mapper_test.go b/mapper_test.go index 8c7a0e2..a1f25fd 100644 --- a/mapper_test.go +++ b/mapper_test.go @@ -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" @@ -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", @@ -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, @@ -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: `