Clarify behaviour of enum processor without default or defined mapping (#6301)

This commit is contained in:
Richard Wise 2019-10-08 09:08:35 +08:00 committed by Daniel Nelson
parent c67674eff3
commit da17d6569d
2 changed files with 19 additions and 2 deletions

View File

@ -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
@ -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
```

View File

@ -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")
}