From 40ce467a0d87257a0f8c9cd91c818437b0a62b85 Mon Sep 17 00:00:00 2001 From: Yuri Grigorov Date: Wed, 30 Dec 2020 21:59:58 +0300 Subject: [PATCH] outputs/http: add option to control idle connection timeout (#8055) Co-authored-by: Yuri Grigorov (cherry picked from commit c319e63a5a5474babeedb073d7e16a0e3b27eb8d) --- plugins/outputs/http/README.md | 7 ++++++- plugins/outputs/http/http.go | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/outputs/http/README.md b/plugins/outputs/http/README.md index 0229c0e6ada7f..27de975c0761a 100644 --- a/plugins/outputs/http/README.md +++ b/plugins/outputs/http/README.md @@ -1,7 +1,7 @@ # HTTP Output Plugin This plugin sends metrics in a HTTP message encoded using one of the output -data formats. For data_formats that support batching, metrics are sent in batch format. +data formats. For data_formats that support batching, metrics are sent in batch format. ### Configuration: @@ -48,4 +48,9 @@ data formats. For data_formats that support batching, metrics are sent in batch # [outputs.http.headers] # # Should be set manually to "application/json" for json data_format # Content-Type = "text/plain; charset=utf-8" + + ## Idle (keep-alive) connection timeout. + ## Maximum amount of time before idle connection is closed. + ## Zero means no limit. + # idle_conn_timeout = 0 ``` diff --git a/plugins/outputs/http/http.go b/plugins/outputs/http/http.go index d75d5ef5a4df2..95d3fcf71a096 100644 --- a/plugins/outputs/http/http.go +++ b/plugins/outputs/http/http.go @@ -64,6 +64,11 @@ var sampleConfig = ` # [outputs.http.headers] # # Should be set manually to "application/json" for json data_format # Content-Type = "text/plain; charset=utf-8" + + ## Idle (keep-alive) connection timeout. + ## Maximum amount of time before idle connection is closed. + ## Zero means no limit. + # idle_conn_timeout = 0 ` const ( @@ -84,6 +89,7 @@ type HTTP struct { TokenURL string `toml:"token_url"` Scopes []string `toml:"scopes"` ContentEncoding string `toml:"content_encoding"` + IdleConnTimeout internal.Duration `toml:"idle_conn_timeout"` tls.ClientConfig client *http.Client @@ -104,6 +110,7 @@ func (h *HTTP) createClient(ctx context.Context) (*http.Client, error) { Transport: &http.Transport{ TLSClientConfig: tlsCfg, Proxy: http.ProxyFromEnvironment, + IdleConnTimeout: h.IdleConnTimeout.Duration, }, Timeout: h.Timeout.Duration, }