Skip to content

Commit

Permalink
Update influxdb and influxdb_v2 outputs with new option
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj committed Apr 26, 2024
1 parent 6ba1473 commit b2f49a3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
11 changes: 9 additions & 2 deletions plugins/outputs/influxdb/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type InfluxDB struct {
ContentEncoding string `toml:"content_encoding"`
SkipDatabaseCreation bool `toml:"skip_database_creation"`
InfluxUintSupport bool `toml:"influx_uint_support"`
OmitTimestamp bool `toml:"influx_omit_timestamp"`
Precision string `toml:"precision" deprecated:"1.0.0;option is ignored"`
Log telegraf.Logger `toml:"-"`
tls.ClientConfig
Expand Down Expand Up @@ -160,7 +161,10 @@ func (i *InfluxDB) Write(metrics []telegraf.Metric) error {
}

func (i *InfluxDB) udpClient(address *url.URL) (Client, error) {
serializer := &influx.Serializer{UintSupport: i.InfluxUintSupport}
serializer := &influx.Serializer{
UintSupport: i.InfluxUintSupport,
OmitTimestamp: i.OmitTimestamp,
}
if err := serializer.Init(); err != nil {
return nil, err
}
Expand All @@ -186,7 +190,10 @@ func (i *InfluxDB) httpClient(ctx context.Context, address *url.URL, proxy *url.
return nil, err
}

serializer := &influx.Serializer{UintSupport: i.InfluxUintSupport}
serializer := &influx.Serializer{
UintSupport: i.InfluxUintSupport,
OmitTimestamp: i.OmitTimestamp,
}
if err := serializer.Init(); err != nil {
return nil, err
}
Expand Down
6 changes: 6 additions & 0 deletions plugins/outputs/influxdb/sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,9 @@
## integer values. Enabling this option will result in field type errors if
## existing data has been written.
# influx_uint_support = false

## When true, Telegraf will omit the timestamp on data to allow InfluxDB
## to set the timestamp of the data during ingestion. This is generally NOT
## what you want as it can lead to data points captured at different times
## getting omitted due to similar data.
# influx_omit_timestamp = false
6 changes: 5 additions & 1 deletion plugins/outputs/influxdb_v2/influxdb_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type InfluxDB struct {
UserAgent string `toml:"user_agent"`
ContentEncoding string `toml:"content_encoding"`
UintSupport bool `toml:"influx_uint_support"`
OmitTimestamp bool `toml:"influx_omit_timestamp"`
PingTimeout config.Duration `toml:"ping_timeout"`
ReadIdleTimeout config.Duration `toml:"read_idle_timeout"`
tls.ClientConfig
Expand Down Expand Up @@ -127,7 +128,10 @@ func (i *InfluxDB) getHTTPClient(address *url.URL, proxy *url.URL) (Client, erro
return nil, err
}

serializer := &influx.Serializer{UintSupport: i.UintSupport}
serializer := &influx.Serializer{
UintSupport: i.UintSupport,
OmitTimestamp: i.OmitTimestamp,
}
if err := serializer.Init(); err != nil {
return nil, err
}
Expand Down
6 changes: 6 additions & 0 deletions plugins/outputs/influxdb_v2/sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
## Enable or disable uint support for writing uints influxdb 2.0.
# influx_uint_support = false

## When true, Telegraf will omit the timestamp on data to allow InfluxDB
## to set the timestamp of the data during ingestion. This is generally NOT
## what you want as it can lead to data points captured at different times
## getting omitted due to similar data.
# influx_omit_timestamp = false

## HTTP/2 Timeouts
## The following values control the HTTP/2 client's timeouts. These settings
## are generally not required unless a user is seeing issues with client
Expand Down
2 changes: 1 addition & 1 deletion plugins/serializers/influx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ for interoperability.
## to set the timestamp of the data during ingestion. This is generally NOT
## what you want as it can lead to data points captured at different times
## getting omitted due to similar data.
# influx_omit_timestamp = true
# influx_omit_timestamp = false
```

## Metrics
Expand Down

0 comments on commit b2f49a3

Please sign in to comment.