Skip to content

Commit

Permalink
fix(outputs.influxdb_v2): expose HTTP/2 client timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj committed Jul 6, 2023
1 parent f62ef8b commit 8a7945b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions plugins/outputs/influxdb_v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ to use them.
## Enable or disable uint support for writing uints influxdb 2.0.
# influx_uint_support = 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
## disconnects. If a user does see issues, then it is suggested to set these
## values to TODO for ping timeout and TODO for read idle timeout and retry.
# ping_timeout = "0s"
# read_idle_timeout = "0s"

## Optional TLS Config for use on HTTP connections.
# tls_ca = "/etc/telegraf/ca.pem"
# tls_cert = "/etc/telegraf/cert.pem"
Expand Down
8 changes: 8 additions & 0 deletions plugins/outputs/influxdb_v2/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/plugins/serializers/influx"
"golang.org/x/net/http2"
)

type APIError struct {
Expand Down Expand Up @@ -52,6 +53,8 @@ type HTTPConfig struct {
Proxy *url.URL
UserAgent string
ContentEncoding string
PingTimeout config.Duration
ReadIdleTimeout config.Duration
TLSConfig *tls.Config

Serializer *influx.Serializer
Expand Down Expand Up @@ -126,6 +129,11 @@ func NewHTTPClient(cfg *HTTPConfig) (*httpClient, error) {
Proxy: proxy,
TLSClientConfig: cfg.TLSConfig,
}
http2Trans, err := http2.ConfigureTransports(transport)
if err == nil {
http2Trans.ReadIdleTimeout = time.Duration(cfg.ReadIdleTimeout)
http2Trans.PingTimeout = time.Duration(cfg.PingTimeout)
}
case "unix":
transport = &http.Transport{
Dial: func(_, _ string) (net.Conn, error) {
Expand Down
4 changes: 4 additions & 0 deletions plugins/outputs/influxdb_v2/influxdb_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ type InfluxDB struct {
UserAgent string `toml:"user_agent"`
ContentEncoding string `toml:"content_encoding"`
UintSupport bool `toml:"influx_uint_support"`
PingTimeout config.Duration `toml:"ping_timeout"`
ReadIdleTimeout config.Duration `toml:"read_idle_timeout"`
tls.ClientConfig

Log telegraf.Logger `toml:"-"`
Expand Down Expand Up @@ -144,6 +146,8 @@ func (i *InfluxDB) getHTTPClient(address *url.URL, proxy *url.URL) (Client, erro
ContentEncoding: i.ContentEncoding,
TLSConfig: tlsConfig,
Serializer: serializer,
PingTimeout: i.PingTimeout,
ReadIdleTimeout: i.ReadIdleTimeout,
Log: i.Log,
}

Expand Down
8 changes: 8 additions & 0 deletions plugins/outputs/influxdb_v2/sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
## Enable or disable uint support for writing uints influxdb 2.0.
# influx_uint_support = 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
## disconnects. If a user does see issues, then it is suggested to set these
## values to TODO for ping timeout and TODO for read idle timeout and retry.
# ping_timeout = "0s"
# read_idle_timeout = "0s"

## Optional TLS Config for use on HTTP connections.
# tls_ca = "/etc/telegraf/ca.pem"
# tls_cert = "/etc/telegraf/cert.pem"
Expand Down

0 comments on commit 8a7945b

Please sign in to comment.