Add timeout option for kubernetes (#3211)
This commit is contained in:
parent
6aa88c7113
commit
2dc18135cf
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue