telegraf icon indicating copy to clipboard operation
telegraf copied to clipboard

feat(processors.enum): Allow mapping to be applied to multiple fields

Open mstrandboge opened this issue 1 year ago • 5 comments

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

  • [X] No AI generated code was used in this PR

Related issues

resolves #10892

mstrandboge avatar Oct 15 '24 19:10 mstrandboge

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

Hipska avatar Nov 14 '24 08:11 Hipska

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.

Hipska avatar Nov 14 '24 09:11 Hipska

@DStrand1 could you please test @Hipska's example (and ideally add it as a unit-test)!?

srebhan avatar Nov 25 '24 10:11 srebhan

@DStrand1 do you have any update?

Hipska avatar Feb 12 '25 16:02 Hipska