Add timeout option for kubernetes (#3211)

This commit is contained in:
Adrián López 2017-09-13 02:22:15 +02:00 committed by Daniel Nelson
parent c5cfde667a
commit 2163981872
1 changed files with 14 additions and 1 deletions

View File

@ -30,6 +30,9 @@ type Kubernetes struct {
// Use SSL but skip chain & host verification
InsecureSkipVerify bool
// HTTP Timeout specified as a string - 3s, 1m, 1h
ResponseTimeout internal.Duration
RoundTripper http.RoundTripper
}
@ -40,6 +43,9 @@ var sampleConfig = `
## Use bearer token for authorization
# bearer_token = /path/to/bearer/token
## Set response_timeout (default 5 seconds)
# response_timeout = "5s"
## Optional SSL Config
# ssl_ca = /path/to/cafile
# ssl_cert = /path/to/certfile
@ -101,10 +107,17 @@ func (k *Kubernetes) gatherSummary(baseURL string, acc telegraf.Accumulator) err
}
if k.RoundTripper == nil {
// Set default values
if k.ResponseTimeout.Duration < time.Second {
k.ResponseTimeout.Duration = time.Second * 5
}
if err != nil {
return err
}
k.RoundTripper = &http.Transport{
TLSHandshakeTimeout: 5 * time.Second,
TLSClientConfig: tlsCfg,
ResponseHeaderTimeout: time.Duration(3 * time.Second),
ResponseHeaderTimeout: k.ResponseTimeout.Duration,
}
}