-
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): Add fields and tags config options #13824
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,9 @@ type EnumMapper struct { | |
|
||
type Mapping struct { | ||
Tag string | ||
Tags []string | ||
Field string | ||
Fields []string | ||
Dest string | ||
Default interface{} | ||
ValueMappings map[string]interface{} | ||
|
@@ -37,17 +39,38 @@ func (mapper *EnumMapper) Init() error { | |
mapper.FieldFilters = make(map[string]filter.Filter) | ||
mapper.TagFilters = make(map[string]filter.Filter) | ||
for _, mapping := range mapper.Mappings { | ||
if mapping.Field != "" && len(mapping.Fields) != 0 { | ||
return fmt.Errorf("use field or fields, but not both") | ||
} | ||
if mapping.Field != "" { | ||
fieldFilter, err := filter.NewIncludeExcludeFilter([]string{mapping.Field}, nil) | ||
if err != nil { | ||
return fmt.Errorf("failed to create new field filter: %w", err) | ||
return fmt.Errorf("failed to create new field filter from field: %w", err) | ||
} | ||
mapper.FieldFilters[mapping.Field] = fieldFilter | ||
} | ||
Comment on lines
45
to
51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about just adding the single There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do agree with @Hipska. With the deprecation this would be the best way... |
||
if len(mapping.Fields) != 0 { | ||
fieldFilter, err := filter.NewIncludeExcludeFilter(mapping.Fields, nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use a simple filter instead of an |
||
if err != nil { | ||
return fmt.Errorf("failed to create new field filter from fields: %w", err) | ||
} | ||
mapper.FieldFilters[mapping.Field] = fieldFilter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why you use a map for the filter... The key for the map is either empty (if no field is defined) or has the field name, i.e. the map will only contain a single entry. I think you should store the filter directly instead of using a map. |
||
} | ||
|
||
if mapping.Tag != "" && len(mapping.Tags) != 0 { | ||
return fmt.Errorf("use tag or tags, but not both") | ||
} | ||
if mapping.Tag != "" { | ||
tagFilter, err := filter.NewIncludeExcludeFilter([]string{mapping.Tag}, nil) | ||
if err != nil { | ||
return fmt.Errorf("failed to create new tag filter: %w", err) | ||
return fmt.Errorf("failed to create new tag filter from tag: %w", err) | ||
} | ||
mapper.TagFilters[mapping.Tag] = tagFilter | ||
} | ||
if len(mapping.Tags) != 0 { | ||
tagFilter, err := filter.NewIncludeExcludeFilter(mapping.Tags, nil) | ||
if err != nil { | ||
return fmt.Errorf("failed to create new tag filter from tags: %w", err) | ||
} | ||
mapper.TagFilters[mapping.Tag] = tagFilter | ||
} | ||
|
@@ -68,10 +91,10 @@ func (mapper *EnumMapper) applyMappings(metric telegraf.Metric) telegraf.Metric | |
newTags := make(map[string]string) | ||
|
||
for _, mapping := range mapper.Mappings { | ||
if mapping.Field != "" { | ||
if mapping.Field != "" || len(mapping.Fields) != 0 { | ||
mapper.fieldMapping(metric, mapping, newFields) | ||
} | ||
if mapping.Tag != "" { | ||
if mapping.Tag != "" || len(mapping.Tags) != 0 { | ||
mapper.tagMapping(metric, mapping, newTags) | ||
} | ||
Comment on lines
-71
to
99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As said before, I would prefer to create a filter for tags and fields and then simply check for the filter being not-nil here. I think this will simplify the code... |
||
} | ||
|
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.
Can we please add add TOML annotations here and deprecate the singular options in favor of the plural ones?