Skip to content

Commit

Permalink
Clarify behaviour of enum processor without default or defined mapping (
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Wise authored and danielnelson committed Oct 8, 2019
1 parent 7b42b0c commit 406e98e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 8 additions & 2 deletions plugins/processors/enum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ source tag or field is overwritten.
dest = "status_code"

## Default value to be used for all values not contained in the mapping
## table. When unset, the unmodified value for the field will be used if no
## match is found.
## table. When unset and no match is found, the original field will remain
## unmodified and the destination tag or field will not be created.
# default = 0

## Table of mappings
Expand All @@ -42,3 +42,9 @@ source tag or field is overwritten.
- xyzzy status="green" 1502489900000000000
+ xyzzy status="green",status_code=1i 1502489900000000000
```

With unknown value and no default set:
```diff
- xyzzy status="black" 1502489900000000000
+ xyzzy status="black" 1502489900000000000
```
11 changes: 11 additions & 0 deletions plugins/processors/enum/enum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,14 @@ func TestWritesToDestination(t *testing.T) {
assertFieldValue(t, "test", "string_value", fields)
assertFieldValue(t, 1, "string_code", fields)
}

func TestDoNotWriteToDestinationWithoutDefaultOrDefinedMapping(t *testing.T) {
field := "string_code"
mapper := EnumMapper{Mappings: []Mapping{{Field: "string_value", Dest: field, ValueMappings: map[string]interface{}{"other": int64(1)}}}}

fields := calculateProcessedValues(mapper, createTestMetric())

assertFieldValue(t, "test", "string_value", fields)
_, present := fields[field]
assert.False(t, present, "value of field '"+field+"' was present")
}

0 comments on commit 406e98e

Please sign in to comment.