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

Defining Processor order as a string is silently ignored. Undefined Processor order runs in reverse. #12879

Closed
cruscio opened this issue Mar 15, 2023 · 2 comments · Fixed by #12880
Labels
area/configuration bug unexpected problem or unintended behavior

Comments

@cruscio
Copy link
Contributor

cruscio commented Mar 15, 2023

Relevant telegraf.conf

#`order` as a string. Expectation: Either an error is thrown or the string is converted to an int when parsing the config. Neither happens. 
#Keep in mind processors don't work as documented. In this example, `order` isn't being set, so the second processor runs before the first. Additional examples in the 'steps to reproduce' demonstrate that 
[agent]
  interval = "10s"
  omit_hostname = true

[[outputs.file]]
  files = ["stdout"]

[[inputs.mem]]
  taginclude   = []
  fieldpass = ["total"]

[[processors.rename]]
  order = "1"
  [[processors.rename.replace]]
    field = "total"
    dest = "total_renamed_once"

[[processors.rename]]
  order = "2"
  [[processors.rename.replace]]
    field = "total_renamed_once"
    dest = "total_renamed_twice"

Logs from Telegraf

See steps to reproduce for more examples. This is the log from the final example with a string-quoted `order` showing no error message, even with debug logging

telegraf --config ./telegraf.conf --test --debug
2023-03-15T15:31:25Z I! Starting Telegraf 1.25.1
2023-03-15T15:31:25Z I! Available plugins: 213 inputs, 9 aggregators, 26 processors, 21 parsers, 57 outputs, 2 secret-stores
2023-03-15T15:31:25Z I! Loaded inputs: mem
2023-03-15T15:31:25Z I! Loaded aggregators: 
2023-03-15T15:31:25Z I! Loaded processors: rename (2x)
2023-03-15T15:31:25Z I! Loaded secretstores: 
2023-03-15T15:31:25Z W! Outputs are not used in testing mode!
2023-03-15T15:31:25Z I! Tags enabled: 
2023-03-15T15:31:25Z D! [agent] Initializing plugins
2023-03-15T15:31:25Z D! [agent] Starting service inputs
2023-03-15T15:31:25Z D! [agent] Stopping service inputs
2023-03-15T15:31:25Z D! [agent] Input channel closed
2023-03-15T15:31:25Z D! [agent] Processor channel closed
2023-03-15T15:31:25Z D! [agent] Processor channel closed
2023-03-15T15:31:25Z D! [agent] Stopped Successfully
> mem total_renamed_once=17179869184i 1678894286000000000

System info

Telegraf 1.25.1

Docker

No response

Steps to reproduce

cat << EOF > ./telegraf.conf
#No explicit `order`, with processors defined in order in file: Doesn't work as documented. 
# Second processor didn't do its work because it was run before the first processor
[agent]
  interval = "10s"
  omit_hostname = true

[[outputs.file]]
  files = ["stdout"]

[[inputs.mem]]
  taginclude   = []
  fieldpass = ["total"]

[[processors.rename]]
  [[processors.rename.replace]]
    field = "total"
    dest = "total_renamed_once"

[[processors.rename]]
  [[processors.rename.replace]]
    field = "total_renamed_once"
    dest = "total_renamed_twice"
EOF
telegraf --config ./telegraf.conf --test
[...]
> mem total_renamed_once=17179869184i 1678893634000000000
cat << EOF > ./telegraf.conf
#No explicit `order`, with processors defined in reveres in file: Does not work as documented.
# Both processors run - second before the first
[agent]
  interval = "10s"
  omit_hostname = true

[[outputs.file]]
  files = ["stdout"]

[[inputs.mem]]
  taginclude   = []
  fieldpass = ["total"]

[[processors.rename]]
  [[processors.rename.replace]]
    field = "total_renamed_once"
    dest = "total_renamed_twice"

[[processors.rename]]
  [[processors.rename.replace]]
    field = "total"
    dest = "total_renamed_once"
EOF
telegraf --config ./telegraf.conf --test
[...]
> mem total_renamed_twice=17179869184i 1678893654000000000
cat << EOF > ./telegraf.conf
#`order` as an int: works as documented
[agent]
  interval = "10s"
  omit_hostname = true

[[outputs.file]]
  files = ["stdout"]

[[inputs.mem]]
  taginclude   = []
  fieldpass = ["total"]

[[processors.rename]]
  order = 1
  [[processors.rename.replace]]
    field = "total"
    dest = "total_renamed_once"

[[processors.rename]]
  order = 2
  [[processors.rename.replace]]
    field = "total_renamed_once"
    dest = "total_renamed_twice"
EOF
telegraf --config ./telegraf.conf --test
[...]
> mem total_renamed_twice=17179869184i 1678893671000000000
cat << EOF > ./telegraf.conf
#`order` as a string. Expectation: Either an error is thrown or the string is converted to 
# an int when parsing the config. Neither happens. Keep in mind processors don't work 
# as documented. In this example, `order` isn't being set, so the SECOND processor (with
# `order="2"`) runs BEFORE the FIRST processor (with `order="1"`)
[agent]
  interval = "10s"
  omit_hostname = true

[[outputs.file]]
  files = ["stdout"]

[[inputs.mem]]
  taginclude   = []
  fieldpass = ["total"]

[[processors.rename]]
  order = "1"
  [[processors.rename.replace]]
    field = "total"
    dest = "total_renamed_once"

[[processors.rename]]
  order = "2"
  [[processors.rename.replace]]
    field = "total_renamed_once"
    dest = "total_renamed_twice"
EOF
telegraf --config ./telegraf.conf --test
[...]
> mem total_renamed_once=17179869184i 1678893686000000000

Expected behavior

When order is defined in a processor, and config parsing cannot set a value, log an error. Maybe also attempt to first convert str to int before logging an error -- Either accept both str and int values, or log when the value isn't an int.

When order isn't defined, processors should run as ordered in the config file (per documentation )

Actual behavior

When order is defined as a string, the config parser silently fails, no value is set, and no error is logged.

When order isn't defined, Processors run in reverse order

Additional info

May be relevant:

@cruscio cruscio added the bug unexpected problem or unintended behavior label Mar 15, 2023
powersj added a commit to powersj/telegraf that referenced this issue Mar 15, 2023
Order should be a number, not a string, so instead of silently failing
we should call the user to action.

fixes: influxdata#12879
@Hipska
Copy link
Contributor

Hipska commented Mar 21, 2023

Good catch! Can you test the artifacts from #12880 (comment) and let us know if this is what you expected.

@cruscio
Copy link
Contributor Author

cruscio commented Mar 21, 2023

$ ./telegraf --config ./telegraf.conf --test --debug
2023-03-21T14:11:37Z I! Loading config file: ./telegraf.conf
2023-03-21T14:11:37Z E! error loading config file ./telegraf.conf: error parsing rename, line 12:{150 185}: found unexpected format while parsing "order", expecting int

Looks good to me, @Hipska

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/configuration bug unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants