Add timeout option for kubernetes (#3211)
This commit is contained in:
parent
c5cfde667a
commit
2163981872
|
@ -30,6 +30,9 @@ type Kubernetes struct {
|
||||||
// Use SSL but skip chain & host verification
|
// Use SSL but skip chain & host verification
|
||||||
InsecureSkipVerify bool
|
InsecureSkipVerify bool
|
||||||
|
|
||||||
|
// HTTP Timeout specified as a string - 3s, 1m, 1h
|
||||||
|
ResponseTimeout internal.Duration
|
||||||
|
|
||||||
RoundTripper http.RoundTripper
|
RoundTripper http.RoundTripper
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +43,9 @@ var sampleConfig = `
|
||||||
## Use bearer token for authorization
|
## Use bearer token for authorization
|
||||||
# bearer_token = /path/to/bearer/token
|
# bearer_token = /path/to/bearer/token
|
||||||
|
|
||||||
|
## Set response_timeout (default 5 seconds)
|
||||||
|
# response_timeout = "5s"
|
||||||
|
|
||||||
## Optional SSL Config
|
## Optional SSL Config
|
||||||
# ssl_ca = /path/to/cafile
|
# ssl_ca = /path/to/cafile
|
||||||
# ssl_cert = /path/to/certfile
|
# ssl_cert = /path/to/certfile
|
||||||
|
@ -101,10 +107,17 @@ func (k *Kubernetes) gatherSummary(baseURL string, acc telegraf.Accumulator) err
|
||||||
}
|
}
|
||||||
|
|
||||||
if k.RoundTripper == nil {
|
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{
|
k.RoundTripper = &http.Transport{
|
||||||
TLSHandshakeTimeout: 5 * time.Second,
|
TLSHandshakeTimeout: 5 * time.Second,
|
||||||
TLSClientConfig: tlsCfg,
|
TLSClientConfig: tlsCfg,
|
||||||
ResponseHeaderTimeout: time.Duration(3 * time.Second),
|
ResponseHeaderTimeout: k.ResponseTimeout.Duration,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue