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

Override field name for "auto_x" fallback #15949

Closed
vielleicht opened this issue Sep 27, 2024 · 2 comments
Closed

Override field name for "auto_x" fallback #15949

vielleicht opened this issue Sep 27, 2024 · 2 comments
Labels
feature request Requests for new plugin and for new features to existing plugins waiting for response waiting for response from contributor

Comments

@vielleicht
Copy link

Use Case

I'm running a tig-stack with three mqtt_consumers writing into the influxdb. There are many topics with different data types flowing into telegraf (float, dict, string). Lately, I was searching days for an error introduced by the datatype "auto_float". As telegraf is outputting into influxdb, I thought, letting telegraf write to a float fieldType is safe (as influxdb doesn't allow for fieldType conversion). But, during backup a script is stopping and restarting influxdb for the sake of consistency. I had to learn by hard, that if the first value telegraf writes to this measurement after restart, is of type string (resulting from failing auto_float conversion), influxdb would allow to write and change the fieldType from float to string, leading to a big mess later on.

What if telegraf could automatically override the field name to some configured value (i.e. value_string), if it falls back to string due to failing auto conversion? There could be some additional config key to value_field_name, like value_field_fallback_name.

Expected behavior

Upon input value, which can be converted to auto_x (like 55 or "5.5" for auto_float), the metric gets output to the configured value_field_name.
Upon input value, which fails in conversion (like "yyy"), the metric gets output to the configured fallback field_name (like value_string).

#telegraf.conf

[[inputs.mqtt_consumer]]
  servers = ["tcp://127.0.0.1:1883"]

  ## MQTT QoS, must be 0, 1, or 2
  qos = 0
  ## Connection timeout for initial connection in seconds
  connection_timeout = "30s"

  ## Topics to subscribe to
  topics = [
    "test/#",
  ]

  #persistent_session = true
  client_id = "telegraf-server"

  data_format = "value"
  data_type = "auto_float"

  ## override the field name of "value"
  # value_field_name = "value"
  ## field name of "value" if auto conversion fails
  value_field_fallback_name = "value_string"

Actual behavior

Like described in documentation, the value get's written as string on fallback. When using float and the conversion fails, there will be an error and there is not output.

Additional info

The auto_x was introduced with #13506.

@vielleicht vielleicht added the feature request Requests for new plugin and for new features to existing plugins label Sep 27, 2024
@srebhan
Copy link
Member

srebhan commented Oct 8, 2024

I suggest you are saving the value as string then and using a starlark processor to do the type conversion and field naming logic.

@srebhan srebhan added the waiting for response waiting for response from contributor label Oct 8, 2024
@telegraf-tiger
Copy link
Contributor

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 Forums or provide additional details in this issue and reqeust that it be re-opened. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Requests for new plugin and for new features to existing plugins waiting for response waiting for response from contributor
Projects
None yet
Development

No branches or pull requests

2 participants