Merge pull request #24 from macb/allow_hyphen_hostname

allow metrics with dashes when mapping
This commit is contained in:
Julius Volz 2015-10-12 02:52:22 +02:00
commit 28d4020341
2 changed files with 27 additions and 3 deletions

View file

@ -24,8 +24,10 @@ import (
) )
var ( var (
identifierRE = `[a-zA-Z_][a-zA-Z0-9_]+` identifierRE = `[a-zA-Z_][a-zA-Z0-9_]+`
metricLineRE = regexp.MustCompile(`^(\*\.|` + identifierRE + `\.)+(\*|` + identifierRE + `)$`) statsdMetricRE = `[a-zA-Z_](-?[a-zA-Z0-9_])+`
metricLineRE = regexp.MustCompile(`^(\*\.|` + statsdMetricRE + `\.)+(\*|` + statsdMetricRE + `)$`)
labelLineRE = regexp.MustCompile(`^(` + identifierRE + `)\s*=\s*"(.*)"$`) labelLineRE = regexp.MustCompile(`^(` + identifierRE + `)\s*=\s*"(.*)"$`)
metricNameRE = regexp.MustCompile(`^` + identifierRE + `$`) metricNameRE = regexp.MustCompile(`^` + identifierRE + `$`)
) )

View file

@ -35,6 +35,13 @@ func TestMetricMapper(t *testing.T) {
result="$3" result="$3"
job="test_dispatcher" job="test_dispatcher"
test.my-dispatch-host01.name.dispatcher.*.*.*
name="host_dispatch_events"
processor="$1"
action="$2"
result="$3"
job="test_dispatcher"
*.* *.*
name="catchall" name="catchall"
first="$1" first="$1"
@ -50,6 +57,13 @@ func TestMetricMapper(t *testing.T) {
"result": "succeeded", "result": "succeeded",
"job": "test_dispatcher", "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{ "foo.bar": map[string]string{
"name": "catchall", "name": "catchall",
"first": "foo", "first": "foo",
@ -91,7 +105,7 @@ func TestMetricMapper(t *testing.T) {
// Config with bad metric line. // Config with bad metric line.
{ {
config: ` config: `
bad-metric-line.*.* bad--metric-line.*.*
name="foo" name="foo"
`, `,
configBad: true, configBad: true,
@ -104,6 +118,14 @@ func TestMetricMapper(t *testing.T) {
`, `,
configBad: true, configBad: true,
}, },
// Config with bad label line.
{
config: `
test.*.*
name="foo-name"
`,
configBad: true,
},
// Config with bad metric name. // Config with bad metric name.
{ {
config: ` config: `