From 5018c7415a24eff52005be83fd254dd9c6391991 Mon Sep 17 00:00:00 2001 From: Jason Mooberry Date: Tue, 23 May 2017 18:12:17 -0400 Subject: [PATCH] Allow comments in mapping files --- README.md | 1 + mapper.go | 5 +++++ mapper_test.go | 5 ++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 710bc73..65322f4 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ with `-statsd.add-suffix=false`. An example mapping configuration with `-statsd.add-suffix=false`: + # comments are allowed test.dispatcher.*.*.* name="dispatcher_events_total" processor="$1" diff --git a/mapper.go b/mapper.go index b05349d..f6efc24 100644 --- a/mapper.go +++ b/mapper.go @@ -59,6 +59,11 @@ func (m *metricMapper) initFromString(fileContents string) error { for i, line := range lines { line := strings.TrimSpace(line) + // skip comments + if strings.HasPrefix(line, "#") { + continue + } + switch state { case SEARCHING: if line == "" { diff --git a/mapper_test.go b/mapper_test.go index 217e70a..61ef835 100644 --- a/mapper_test.go +++ b/mapper_test.go @@ -28,11 +28,14 @@ func TestMetricMapper(t *testing.T) { // Config with several mapping definitions. { config: ` + # this is a comment + # this is another test.dispatcher.*.*.* name="dispatch_events" processor="$1" action="$2" result="$3" + # here is a third job="test_dispatcher" test.my-dispatch-host01.name.dispatcher.*.*.* @@ -148,7 +151,7 @@ func TestMetricMapper(t *testing.T) { test.bar name="name_bar" label="foo" - + test.foo name="name_foo" label="bar"`,