Telegraf precision parameter parsing in agent configuration

I happened to notice today that I have had a bug in my Telegraf agent section configuration for a long time that I hadn’t noticed before, and Telegraf hasn’t complained about this bug either.

It is about the precision parameter in the agent section.
The documentation says:

Valid values are ns , us (or µs ), ms , and s

So I had the following configuration in my agent section:

[agent]
  interval = "1s"
  precision = "ns"

The configuration works and there was no error message, but the precision parameter is ignored in this case and replaced by the value in interval. I noticed this behaviour, when I was working with higher resolution timestamps and wondered why all my timestamps were rounded to 1s after the output from Telegraf. :thinking:

The correct configuration should be:

[agent]
  interval = "1s"
  precision = "1ns"

In my opinion, the documentation here is misleading, and if Telegraf doesn’t complain, you may not notice this error unless you look very closely at your output timestamps.

Also, the behavior of the precision parameter in an input plugin is different, there Telegraf complains.
This does not work:

[[inputs.file]]
  precision = "ns"

[telegraf] Error running agent: Error loading config file xxx.conf: error parsing file, line 31:{363 455}: error parsing duration: time: invalid duration “ns”

This works and of course overrides the global precision setting of the agent section:

[[inputs.file]]
  precision = "1ns"

@Anaisdg
IMHO this inconsistent behaviour of the precision parameter should be fixed in the agent section?

Great find, would you like to create a bug report for that?

If you agree that this is a bug and not a desired behavior, sure.

Why didn’t you use the bug report template?

Because the scheme was too rigid for me and I couldn’t fit the markdown text there.

Also the docs clearly say in the example that it should have an integer + unit

I disagree, it is only mentioned under “intervals”. For me it is not obvious, that this refers also to the precision parameter. And i was primarily looking at this documentation:

Configuring Telegraf | Telegraf 1.21 Documentation

I have found some inaccuracies in the website docs too (from non-working examples to misleading sections), which I’ve noticed just by chance, usually because it was linked in one of the forum posts.
I personally use only the GitHub repo documentation, which in this case (and all the others I’ve encountered) is correct.
Here is the docs about the precision option

  • precision : Collected metrics are rounded to the precision specified as an interval.Precision will NOT be used for service inputs. It is up to each individual service input to set the timestamp at the appropriate precision.

Correct. You can also submit issues on the docs site on the bottom of the page.

@Franky1 @Giovanni_Luisotto @Hipska If you can please review the PR to see if the new definition makes sense.

1 Like