-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(processors.enum): Allow mapping to be applied to multiple fields #16030
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @DStrand1! I'm curious why you need to create one filter per field instead of passing on the complete whitelist...
Download PR build artifacts for linux_amd64.tar.gz, darwin_arm64.tar.gz, and windows_amd64.zip. 👍 This pull request doesn't change the Telegraf binary size 📦 Click here to get additional PR build artifactsArtifact URLs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one more simplification...
fieldFilter, err := filter.NewIncludeExcludeFilter([]string{mapping.Field}, nil) | ||
mapping.Fields = append(mapping.Fields, mapping.Field) | ||
} | ||
if len(mapping.Fields) != 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The length check is not required. filter.Compile
will return nil, nil
in case of an empty list...
Why don't we also make this change for tags at the same time as well? |
FieldFilter filter.Filter | ||
TagFilter filter.Filter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably doesn't need to be exported?
I also think the previous behaviour is changed: [[inputs.mock]]
metric_name = "mock"
[[inputs.mock.constant]]
name = "status"
value = "green"
[[inputs.mock.constant]]
name = "status_reverse"
value = "green"
[[processors.enum]]
[[processors.enum.mapping]]
field = "status"
[processors.enum.mapping.value_mappings]
green = 1
amber = 2
red = 3
[[processors.enum.mapping]]
field = "status_reverse"
[processors.enum.mapping.value_mappings]
green = 3
amber = 2
red = 1 Currently results in: - > mock status="green",status_reverse="green"
+ > mock status=1i,status_reverse=3i And I think with this PR, it will result in |
Summary
Adds a new
fields
option to the enum processor, deprecating the oldfield
option. Allows mapping multiple fields with one enum mapping when a glob does not workChecklist
Related issues
resolves #10892