Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

powersj
Copy link
Contributor

@powersj powersj commented Aug 23, 2023

fixes: #10892

@telegraf-tiger telegraf-tiger bot added feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/processor labels Aug 23, 2023
@telegraf-tiger
Copy link
Contributor

@powersj powersj added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label Aug 25, 2023
@powersj powersj marked this pull request as ready for review August 25, 2023 14:06
Comment on lines 45 to 51
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
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about just adding the single Field to the Fields array?

Copy link
Member

Choose a reason for hiding this comment

The 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...

Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really would love to deprecate the singular options, create the filters for fields/tags and base all further processing (beyond Init()) on those filters.

Comment on lines 25 to +28
Tag string
Tags []string
Field string
Fields []string
Copy link
Member

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?

Comment on lines 45 to 51
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
}
Copy link
Member

Choose a reason for hiding this comment

The 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...

}
mapper.FieldFilters[mapping.Field] = fieldFilter
}
if len(mapping.Fields) != 0 {
fieldFilter, err := filter.NewIncludeExcludeFilter(mapping.Fields, nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use a simple filter instead of an IncludeExcludeFilter here.

if err != nil {
return fmt.Errorf("failed to create new field filter from fields: %w", err)
}
mapper.FieldFilters[mapping.Field] = fieldFilter
Copy link
Member

Choose a reason for hiding this comment

The 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.

Comment on lines -71 to 99
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)
}
Copy link
Member

Choose a reason for hiding this comment

The 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...

@powersj powersj closed this Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/processor ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

processors.enum.mapping to be applied to multiple fields
3 participants