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

Regex: don't emit empty tags and fields when pattern doesn't match and result_key specified #4396

Conversation

44px
Copy link
Contributor

@44px 44px commented Jul 6, 2018

Fixed behavior when pattern doesn't match:
a) if no result_key specified => plugin doesn't alter existing tag/field
b) if result_key specified => plugin doesn't create tag/field with result_key name (resolves #4374)

Test telegraf.conf

[agent]
  interval="1s"
  flush_interval="1s"

[[inputs.exec]]
  timeout = "1s"
  data_format = "influx"
  commands = [
    "echo 'deal,computer_name=hosta message=\"stuff\" 1530654676316265790'",
    "echo 'deal,computer_name=hostb message=\"stuff\" 1530654676316265790'",
  ]

[[processors.regex]]
  [[processors.regex.tags]]
    key = "computer_name"
    pattern = "^(.*?)a$"
    replacement = "${1}"
    result_key = "server_name"
  [[processors.regex.tags]]
    key = "computer_name"
    pattern = "^(.*?)b$"
    replacement = "${1}"
    result_key = "server_name"

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

Output

deal,computer_name=hostb,host=44px-notebook.local,server_name=host message="stuff" 1530654676000000000
deal,computer_name=hosta,host=44px-notebook.local,server_name=host message="stuff" 1530654676000000000

Required for all PRs:

  • Signed CLA.
  • Associated README.md updated.
  • Has appropriate unit tests.

@44px 44px force-pushed the bugfix/4374_dont_emit_empty_tags_and_fields branch from 1d03159 to 2c2b146 Compare July 6, 2018 22:23
@danielnelson danielnelson added this to the 1.7.2 milestone Jul 6, 2018
@danielnelson danielnelson added the fix pr to fix corresponding bug label Jul 6, 2018
@danielnelson danielnelson merged commit 35d2f90 into influxdata:master Jul 6, 2018
danielnelson pushed a commit that referenced this pull request Jul 6, 2018
@44px 44px deleted the bugfix/4374_dont_emit_empty_tags_and_fields branch July 8, 2018 16:48
otherpirate pushed a commit to otherpirate/telegraf that referenced this pull request Mar 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix pr to fix corresponding bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

regex plugin does not support matching on the same key and result key
2 participants