Plugin processors.regex not create new field
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
- 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.
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!
I already asked in the slack, I did not receive an answer why this does not work.
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
Thanks @Zanthras! @ihard were you able to give that a try?
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.
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!