telegraf icon indicating copy to clipboard operation
telegraf copied to clipboard

Plugin processors.regex not create new field

Open ihard opened this issue 5 years ago • 6 comments

Relevent telegraf.conf

[global_tags]
[agent]
  interval = "1s"
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  flush_interval = "500ms"
  debug = true
  quiet = false
  omit_hostname = true
[[inputs.influxdb_v2_listener]]
  service_address = ":8086"
[[processors.regex]]
  [[processors.regex.fields]]
    key = "value"
    pattern = "^(.*)$"
    replacement = "${1}"
    result_key = "my_value"
[[outputs.file]]
  files = ["stdout"]
  data_format = "influx"

System info

telegraf 1.20.3 ubuntu 20.04

Docker

No response

Steps to reproduce

  1. send metric to input "test123,instance=test1,metric_type=counter value=1i 1636562575000000000"

Expected behavior

Metric with field my_value "test123,instance=test1,metric_type=counter value=1i,my_value=1i 1636562575000000000"

Actual behavior

The plugin does not create a new field, metric is unchanged: "test123,instance=test1,metric_type=counter value=1i 1636562575000000000"

Additional info

I conducted some experiment and for a field that is of type string - everything works fine, it does not work only for integer and floating values. Looks like an error in type processing.

ihard avatar Nov 10 '21 18:11 ihard

Hello! I recommend posting this question in our Community Slack or Community Page, we have a lot of talented community members there who could help answer your question more quickly. Heads up, this issue will be automatically closed after 7 days of inactivity. Thank you!

telegraf-tiger[bot] avatar Nov 10 '21 19:11 telegraf-tiger[bot]

I already asked in the slack, I did not receive an answer why this does not work.

ihard avatar Nov 10 '21 20:11 ihard

The regex processor only operates on string fields, floats, ints cant be parsed.

An easy work around is to apply the converter processor first.

Given this input data, note the mix of string, integer and float. test123,instance=test1,metric_type=counter value=1i 1636562575000000000 test456,instance=test1,metric_type=counter value=1 1636562575000000000 test789,instance=test1,metric_type=counter value="1" 1636562575000000000

And this processor set [[processors.regex]] order = 2 [[processors.regex.fields]] key = "value" pattern = "^(.*)$" replacement = "${1}" result_key = "my_value"

[[processors.converter]] order = 1 [processors.converter.fields] string = ["value"]

The outcome will be test123,instance=test1,metric_type=counter value="1",my_value="1" 1636562575000000000 test456,instance=test1,metric_type=counter value="1",my_value="1" 1636562575000000000 test789,instance=test1,metric_type=counter value="1",my_value="1" 1636562575000000000

Zanthras avatar Nov 12 '21 21:11 Zanthras

Thanks @Zanthras! @ihard were you able to give that a try?

powersj avatar Nov 15 '21 16:11 powersj

Yes, I checked with the translation of the value into a string and back - it worked. It would be great to see this limitation in the documentation if the plugin cannot be fixed to work with numbers directly.

ihard avatar Nov 15 '21 21:11 ihard

Hello! I am closing this issue due to inactivity. I hope you were able to resolve your problem, if not please try posting this question in our Community Slack or Community Page. Thank you!

telegraf-tiger[bot] avatar Nov 23 '21 16:11 telegraf-tiger[bot]