influxdata / helm-charts

Official Helm Chart Repository for InfluxData Applications
MIT License
233 stars 330 forks source link

telegraf configuration file in values.json generates incorrect telegraf.conf toml file #682

Open jminardi opened 1 month ago

jminardi commented 1 month ago

I am using the helm chart to deploy telegraf. I configure my telegraph instance via the values.yaml file. Here is my inputs section of the values.yaml configuration:

    - opcua:
        name: "opcua_simulator"
        endpoint: "opc.tcp://insights-opcua-simulator.insights-preproduction.svc.cluster.local:46010"
        connect_timeout: "10s"
        security_policy: "None"
        security_mode: "None"
        auth_method: "Anonymous"
        nodes:
          - name: "ConcentrationNH3"
            namespace: "2"
            identifier_type: "s"
            identifier: "ConcentrationNH3"
          - name: "ConcentrationN2"
            namespace: "2"
            identifier_type: "s"
            identifier: "ConcentrationN2"
          - name: "ConcentrationH2"
            namespace: "2"
            identifier_type: "s"
            identifier: "ConcentrationH2"
          - name: "Pressure"
            namespace: "2"
            identifier_type: "s"
            identifier: "Pressure"

That produces the following toml file (found in the telegraf configmap:

[[inputs.opcua]]
  auth_method = "Anonymous"
  connect_timeout = "10s"
  endpoint = "opc.tcp://insights-opcua-simulator.insights-preproduction.svc.cluster.local:46010"
  name = "opcua_simulator"
  [[inputs.opcua.nodes]]
     identifier = "ConcentrationNH3"
     identifier_type = "s"
     name = "ConcentrationNH3"
     namespace = "2"
  [[inputs.opcua.nodes]]
     identifier = "ConcentrationN2"
     identifier_type = "s"
     name = "ConcentrationN2"
     namespace = "2"
  [[inputs.opcua.nodes]]
     identifier = "ConcentrationH2"
     identifier_type = "s"
     name = "ConcentrationH2"
     namespace = "2"
  [[inputs.opcua.nodes]]
     identifier = "Pressure"
     identifier_type = "s"
     name = "Pressure"
     namespace = "2"
  security_mode = "None"
  security_policy = "None"

Notice how the security_mode and security_policy fields are placed after the nodes sections? This causes telegraf to crash with the following error:

2024-10-09T02:52:08Z I! Loading config: /etc/telegraf/telegraf.conf
2024-10-09T02:52:08Z E! loading config file /etc/telegraf/telegraf.conf failed: plugin inputs.opcua: line 32: configuration specified the fields ["request_timeout" "security_mode" "security_policy"], but they were not used. This is either a typo or this config option does not exist in this version.

If I manually update the configmap to put the fields above the nodes section, then telegraf will boot normally:

[[inputs.opcua]]
  auth_method = "Anonymous"
  connect_timeout = "10s"
  endpoint = "opc.tcp://insights-opcua-simulator.insights-preproduction.svc.cluster.local:46010"
  name = "opcua_simulator"
  security_mode = "None"
  security_policy = "None"
  [[inputs.opcua.nodes]]
     identifier = "ConcentrationNH3"
     identifier_type = "s"
     name = "ConcentrationNH3"
     namespace = "2"
  [[inputs.opcua.nodes]]
     identifier = "ConcentrationN2"
     identifier_type = "s"
     name = "ConcentrationN2"
     namespace = "2"
  [[inputs.opcua.nodes]]
     identifier = "ConcentrationH2"
     identifier_type = "s"
     name = "ConcentrationH2"
     namespace = "2"
  [[inputs.opcua.nodes]]
     identifier = "Pressure"
     identifier_type = "s"
     name = "Pressure"
     namespace = "2"

I don't know enough about toml to understand why the keys can't be after the nodes sections. But it does seem like the keys are sorted alphabetically before generating the toml. If that step could be skipped then we could work around this issue.