Adds an 'output_precision' configuration parameter #2139
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #2124
The changes in this pull request add a new
output_precision
configuration parameter to the output plugins that utilize theSerializer
interface to sendinflux
,graphite
, orjson
formatted data to various outputs (amqp
,file
,kafka
,mqtt
,nats
, andnsq
).The format used to specify this precision value is the same format that is used to specify the precision of the timestamps used with the metrics collected by the agent (values like
"1ns"
,"1us"
,"1ms"
and"1s"
are all supported), and the documentation in the comments forthe current Agent
precision
configuration parameter was changed a bit to reflect the realvalue that should be set if you want to measure timestamps in times other than seconds
(choosing a value of
"ns"
for this parameter results in a precision of0ns
, which is thentreated like a precision of
1s
by the code since1s
is the default in the case where aprecision value was not specified).
The changes that are made in this pull request will only effect the output of data in a
json
data_format (the timestamps for the
graphite
andinflux
data_formats remain as they were after this pull request is merged, with the timestamps returned in thegraphite
data_format having a fixed precision of1s
and timestamps for the theinflux
data_format having a fixed precision of1ns
, as they always have), and the outputs that use theSerialize
method to output data in ajson
data_format are the only outputs that have been changed. As was stated earlier, using this new code with an existingtelegraf.conf
file (where this new configuration parameter is not specified for any of those outputs) will result in the same behavior that is seen currently (where all data in ajson
data_format is output with timestamps that have been truncated to the nearest second, regardless of the precision with which they were measured).The following output shows the result of these changes when an
output_precision
value is not specified in the configuration file for afile
output with ajson
data_format (the equivalent to the current released behavior of the telegraf agent), in which case a default value of one second is used:And this output shows the result when an
output_precision
value is specified, with the value chosen set to1ns
(so that the timestamps are output in nanosecond precision):Required for all PRs: