Skip to content
Snippets Groups Projects
Commit b1a97e35 authored by Jonathan Chauncey's avatar Jonathan Chauncey Committed by Cameron Sparr
Browse files

fix(kubernetes): Only initialize RoundTripper once (#1951)

fixes #1933
parent c66363cb
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,6 @@ import ( ...@@ -4,7 +4,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net"
"net/http" "net/http"
"net/url" "net/url"
"sync" "sync"
...@@ -31,6 +30,8 @@ type Kubernetes struct { ...@@ -31,6 +30,8 @@ type Kubernetes struct {
SSLKey string `toml:"ssl_key"` SSLKey string `toml:"ssl_key"`
// Use SSL but skip chain & host verification // Use SSL but skip chain & host verification
InsecureSkipVerify bool InsecureSkipVerify bool
RoundTripper http.RoundTripper
} }
var sampleConfig = ` var sampleConfig = `
...@@ -101,15 +102,12 @@ func (k *Kubernetes) gatherSummary(baseURL string, acc telegraf.Accumulator) err ...@@ -101,15 +102,12 @@ func (k *Kubernetes) gatherSummary(baseURL string, acc telegraf.Accumulator) err
return err return err
} }
var rt http.RoundTripper = &http.Transport{ if k.RoundTripper == nil {
Dial: (&net.Dialer{ k.RoundTripper = &http.Transport{
Timeout: 5 * time.Second, TLSHandshakeTimeout: 5 * time.Second,
KeepAlive: 30 * time.Second, TLSClientConfig: tlsCfg,
}).Dial, ResponseHeaderTimeout: time.Duration(3 * time.Second),
TLSHandshakeTimeout: 5 * time.Second, }
TLSClientConfig: tlsCfg,
ResponseHeaderTimeout: time.Duration(3 * time.Second),
DisableKeepAlives: false,
} }
if k.BearerToken != "" { if k.BearerToken != "" {
...@@ -120,7 +118,7 @@ func (k *Kubernetes) gatherSummary(baseURL string, acc telegraf.Accumulator) err ...@@ -120,7 +118,7 @@ func (k *Kubernetes) gatherSummary(baseURL string, acc telegraf.Accumulator) err
req.Header.Set("Authorization", "Bearer "+string(token)) req.Header.Set("Authorization", "Bearer "+string(token))
} }
resp, err = rt.RoundTrip(req) resp, err = k.RoundTripper.RoundTrip(req)
if err != nil { if err != nil {
return fmt.Errorf("error making HTTP request to %s: %s", url, err) return fmt.Errorf("error making HTTP request to %s: %s", url, err)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment