Skip to content

Commit

Permalink
Add timeout option for kubernetes (#3211)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianlzt authored and danielnelson committed Sep 13, 2017
1 parent 6aa88c7 commit 2dc1813
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion plugins/inputs/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand Down Expand Up @@ -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,
}
}

Expand Down

0 comments on commit 2dc1813

Please sign in to comment.