Skip to content

Commit

Permalink
Merge pull request #133 from prometheus/fish-http-config-expose-keepa…
Browse files Browse the repository at this point in the history
…live

Expose DisableKeepAlives in HTTPClientConfig
  • Loading branch information
brian-brazil committed Jun 17, 2019
2 parents d9a1ac5 + 0de8e43 commit 31bed53
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
8 changes: 4 additions & 4 deletions config/http_config.go
Expand Up @@ -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
}
Expand All @@ -132,15 +132,15 @@ 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.
var rt http.RoundTripper = &http.Transport{
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
Expand Down
16 changes: 8 additions & 8 deletions config/http_config_test.go
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
1 change: 0 additions & 1 deletion expfmt/decode_test.go
Expand Up @@ -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"`},
Expand Down

0 comments on commit 31bed53

Please sign in to comment.