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): Allow mapping to be applied to multiple fields #16030

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

DStrand1
Copy link
Member

Summary

Adds a new fields option to the enum processor, deprecating the old field option. Allows mapping multiple fields with one enum mapping when a glob does not work

Checklist

  • No AI generated code was used in this PR

Related issues

resolves #10892

@DStrand1 DStrand1 self-assigned this Oct 15, 2024
@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 Oct 15, 2024
@DStrand1 DStrand1 assigned srebhan and unassigned DStrand1 Nov 13, 2024
@DStrand1 DStrand1 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 Nov 13, 2024
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.

Thanks @DStrand1! I'm curious why you need to create one filter per field instead of passing on the complete whitelist...

plugins/processors/enum/enum.go Outdated Show resolved Hide resolved
plugins/processors/enum/enum.go Outdated Show resolved Hide resolved
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.

Just one more simplification...

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

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

@Hipska
Copy link
Contributor

Hipska commented Nov 14, 2024

Why don't we also make this change for tags at the same time as well?

Comment on lines +20 to +21
FieldFilter filter.Filter
TagFilter filter.Filter
Copy link
Contributor

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?

@Hipska
Copy link
Contributor

Hipska commented Nov 14, 2024

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 mock status=1i,status_reverse=1i.

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