From 2afc453a9de43c46dadd462998d096e52cd4e4e3 Mon Sep 17 00:00:00 2001 From: Johannes 'fish' Ziemke Date: Thu, 17 May 2018 15:22:25 +0200 Subject: [PATCH 1/3] Expose DisableKeepAlives in HTTPClientConfig Signed-off-by: Johannes 'fish' Ziemke --- config/http_config.go | 8 ++++---- config/http_config_test.go | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) 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..65f49b15 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) } @@ -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) } From 6036c7048f729137a8bc3b714ffa40e0caf62073 Mon Sep 17 00:00:00 2001 From: beorn7 Date: Mon, 17 Jun 2019 20:36:11 +0200 Subject: [PATCH 2/3] Fix newer tests to work with disableKeepAlive argument Signed-off-by: beorn7 --- config/http_config_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/http_config_test.go b/config/http_config_test.go index 65f49b15..deea5027 100644 --- a/config/http_config_test.go +++ b/config/http_config_test.go @@ -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) } @@ -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) } From 0de8e435df772c59df7792a8c4c0de22218665cd Mon Sep 17 00:00:00 2001 From: beorn7 Date: Mon, 17 Jun 2019 20:36:56 +0200 Subject: [PATCH 3/3] Remove unused field from scenarios struct Signed-off-by: beorn7 --- expfmt/decode_test.go | 1 - 1 file changed, 1 deletion(-) 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"`},