diff --git a/config/http_config.go b/config/http_config.go index 21bfa22b..5c373d7a 100644 --- a/config/http_config.go +++ b/config/http_config.go @@ -122,8 +122,8 @@ func newClient(rt http.RoundTripper) *http.Client { // NewClientFromConfig returns a new HTTP client configured for the // given config.HTTPClientConfig. The name is used as go-conntrack metric label. -func NewClientFromConfig(cfg HTTPClientConfig, name string) (*http.Client, error) { - rt, err := NewRoundTripperFromConfig(cfg, name) +func NewClientFromConfig(cfg HTTPClientConfig, name string, disableKeepAlives bool) (*http.Client, error) { + rt, err := NewRoundTripperFromConfig(cfg, name, disableKeepAlives) if err != nil { return nil, err } @@ -132,7 +132,7 @@ func NewClientFromConfig(cfg HTTPClientConfig, name string) (*http.Client, error // NewRoundTripperFromConfig returns a new HTTP RoundTripper configured for the // given config.HTTPClientConfig. The name is used as go-conntrack metric label. -func NewRoundTripperFromConfig(cfg HTTPClientConfig, name string) (http.RoundTripper, error) { +func NewRoundTripperFromConfig(cfg HTTPClientConfig, name string, disableKeepAlives bool) (http.RoundTripper, error) { newRT := func(tlsConfig *tls.Config) (http.RoundTripper, error) { // The only timeout we care about is the configured scrape timeout. // It is applied on request. So we leave out any timings here. @@ -140,7 +140,7 @@ func NewRoundTripperFromConfig(cfg HTTPClientConfig, name string) (http.RoundTri Proxy: http.ProxyURL(cfg.ProxyURL.URL), MaxIdleConns: 20000, MaxIdleConnsPerHost: 1000, // see https://github.com/golang/go/issues/13801 - DisableKeepAlives: false, + DisableKeepAlives: disableKeepAlives, TLSClientConfig: tlsConfig, DisableCompression: true, // 5 minutes is typically above the maximum sane scrape interval. So we can diff --git a/config/http_config_test.go b/config/http_config_test.go index fdd3fb13..deea5027 100644 --- a/config/http_config_test.go +++ b/config/http_config_test.go @@ -206,7 +206,7 @@ func TestNewClientFromConfig(t *testing.T) { } defer testServer.Close() - client, err := NewClientFromConfig(validConfig.clientConfig, "test") + client, err := NewClientFromConfig(validConfig.clientConfig, "test", false) if err != nil { t.Errorf("Can't create a client from this config: %+v", validConfig.clientConfig) continue @@ -256,7 +256,7 @@ func TestNewClientFromInvalidConfig(t *testing.T) { } for _, invalidConfig := range newClientInvalidConfig { - client, err := NewClientFromConfig(invalidConfig.clientConfig, "test") + client, err := NewClientFromConfig(invalidConfig.clientConfig, "test", false) if client != nil { t.Errorf("A client instance was returned instead of nil using this config: %+v", invalidConfig.clientConfig) } @@ -295,7 +295,7 @@ func TestMissingBearerAuthFile(t *testing.T) { } defer testServer.Close() - client, err := NewClientFromConfig(cfg, "test") + client, err := NewClientFromConfig(cfg, "test", false) if err != nil { t.Fatal(err) } @@ -472,7 +472,7 @@ func TestBasicAuthNoPassword(t *testing.T) { if err != nil { t.Fatalf("Error loading HTTP client config: %v", err) } - client, err := NewClientFromConfig(*cfg, "test") + client, err := NewClientFromConfig(*cfg, "test", false) if err != nil { t.Fatalf("Error creating HTTP Client: %v", err) } @@ -498,7 +498,7 @@ func TestBasicAuthNoUsername(t *testing.T) { if err != nil { t.Fatalf("Error loading HTTP client config: %v", err) } - client, err := NewClientFromConfig(*cfg, "test") + client, err := NewClientFromConfig(*cfg, "test", false) if err != nil { t.Fatalf("Error creating HTTP Client: %v", err) } @@ -524,7 +524,7 @@ func TestBasicAuthPasswordFile(t *testing.T) { if err != nil { t.Fatalf("Error loading HTTP client config: %v", err) } - client, err := NewClientFromConfig(*cfg, "test") + client, err := NewClientFromConfig(*cfg, "test", false) if err != nil { t.Fatalf("Error creating HTTP Client: %v", err) } @@ -675,7 +675,7 @@ func TestTLSRoundTripper(t *testing.T) { writeCertificate(bs, tc.cert, cert) writeCertificate(bs, tc.key, key) if c == nil { - c, err = NewClientFromConfig(cfg, "test") + c, err = NewClientFromConfig(cfg, "test", false) if err != nil { t.Fatalf("Error creating HTTP Client: %v", err) } @@ -747,7 +747,7 @@ func TestTLSRoundTripperRaces(t *testing.T) { writeCertificate(bs, TLSCAChainPath, ca) writeCertificate(bs, ClientCertificatePath, cert) writeCertificate(bs, ClientKeyNoPassPath, key) - c, err = NewClientFromConfig(cfg, "test") + c, err = NewClientFromConfig(cfg, "test", false) if err != nil { t.Fatalf("Error creating HTTP Client: %v", err) } diff --git a/expfmt/decode_test.go b/expfmt/decode_test.go index 669d56c0..ef1a0ddb 100644 --- a/expfmt/decode_test.go +++ b/expfmt/decode_test.go @@ -371,7 +371,6 @@ func testDiscriminatorHTTPHeader(t testing.TB) { var scenarios = []struct { input map[string]string output Format - err error }{ { input: map[string]string{"Content-Type": `application/vnd.google.protobuf; proto="io.prometheus.client.MetricFamily"; encoding="delimited"`},