Skip to content

Commit

Permalink
fix(kubernetes): Only initialize RoundTripper once (#1951)
Browse files Browse the repository at this point in the history
fixes #1933
  • Loading branch information
Jonathan Chauncey authored and sparrc committed Oct 26, 2016
1 parent c66363c commit b1a97e3
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions plugins/inputs/kubernetes/kubernetes.go
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/url"
"sync"
Expand All @@ -31,6 +30,8 @@ type Kubernetes struct {
SSLKey string `toml:"ssl_key"`
// Use SSL but skip chain & host verification
InsecureSkipVerify bool

RoundTripper http.RoundTripper
}

var sampleConfig = `
Expand Down Expand Up @@ -101,15 +102,12 @@ func (k *Kubernetes) gatherSummary(baseURL string, acc telegraf.Accumulator) err
return err
}

var rt http.RoundTripper = &http.Transport{
Dial: (&net.Dialer{
Timeout: 5 * time.Second,
KeepAlive: 30 * time.Second,
}).Dial,
TLSHandshakeTimeout: 5 * time.Second,
TLSClientConfig: tlsCfg,
ResponseHeaderTimeout: time.Duration(3 * time.Second),
DisableKeepAlives: false,
if k.RoundTripper == nil {
k.RoundTripper = &http.Transport{
TLSHandshakeTimeout: 5 * time.Second,
TLSClientConfig: tlsCfg,
ResponseHeaderTimeout: time.Duration(3 * time.Second),
}
}

if k.BearerToken != "" {
Expand All @@ -120,7 +118,7 @@ func (k *Kubernetes) gatherSummary(baseURL string, acc telegraf.Accumulator) err
req.Header.Set("Authorization", "Bearer "+string(token))
}

resp, err = rt.RoundTrip(req)
resp, err = k.RoundTripper.RoundTrip(req)
if err != nil {
return fmt.Errorf("error making HTTP request to %s: %s", url, err)
}
Expand Down

0 comments on commit b1a97e3

Please sign in to comment.