influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.53k stars 5.56k forks source link

Error message when loading config with duplicate toml key prints line number in hexadecimal #11052

Open reimda opened 2 years ago

reimda commented 2 years ago

Relevant telegraf.conf

#lots of lines removed here
[[inputs.file]]
  name_override = "thermometer"
  files = ["community-24806.xml"]
  data_format = "xml"  

  [[inputs.file.xml]]
    metric_selection = "/root/*[starts-with(name(),'ch')]"
    timestamp = "root/timeunix"
    [inputs.file.xml.tags]
      devname = "string(/root/devname)"
      sensor = "substring-after(name(), 'ch')" # line 106
      sensor = "name" # line 107

Logs from Telegraf

$ ../telegraf -config telegraf.conf.24806
2022-04-29T20:51:13Z E! [telegraf] Error running agent: Error loading config file telegraf.conf.24806: Error parsing data: line 107: key `sensor' is in conflict with line 6ad

System info

today's master branch

Docker

No response

Steps to reproduce

I triggered it using a file input and xml parser with two tags, both named "sensor"

Expected behavior

Both line numbers in the error message are in decimal. In my example the duplicate keys are on line 106 and 107.

Actual behavior

One line number in the error message is in decimal (107 in my example) and the other is in hex (6a in the example, which is 106 decimal)

Additional info

No response

reimda commented 2 years ago

It looks like this is a problem in the https://github.com/influxdata/toml module. In the error message, the first part (Error running agent: Error loading config file telegraf.conf.24806: Error parsing data) is written by telegraf, but the rest comes from the module.

See parseConfig in config/config.go