Skip to content

Commit

Permalink
outputs/http: add option to control idle connection timeout (#8055)
Browse files Browse the repository at this point in the history
Co-authored-by: Yuri Grigorov <jurijs.grigorovs@corp.mail.ru>
(cherry picked from commit c319e63)
  • Loading branch information
YuriGrigorov authored and ssoroka committed Jan 27, 2021
1 parent a557386 commit 40ce467
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion plugins/outputs/http/README.md
Original file line number Diff line number Diff line change
@@ -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:

Expand Down Expand Up @@ -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
```
7 changes: 7 additions & 0 deletions plugins/outputs/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand All @@ -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,
}
Expand Down

0 comments on commit 40ce467

Please sign in to comment.