Skip to content

Commit

Permalink
Merge pull request #70 from jasonmoo/master
Browse files Browse the repository at this point in the history
Allow comments in mapping files
  • Loading branch information
juliusv authored May 24, 2017
2 parents 89e5e36 + 5018c74 commit 20becbc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down
5 changes: 4 additions & 1 deletion mapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.*.*.*
Expand Down Expand Up @@ -148,7 +151,7 @@ func TestMetricMapper(t *testing.T) {
test.bar
name="name_bar"
label="foo"
test.foo
name="name_foo"
label="bar"`,
Expand Down

0 comments on commit 20becbc

Please sign in to comment.