From a03193232a9b0123508628c57b6a10ebb16a56af Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Thu, 5 Oct 2017 12:32:24 +0100 Subject: [PATCH] Don't disable HTTP keep-alives for remote storage connections. (#3173) Removes configurability introduced in #3160 in favour of hard-coding, per advice from @brian-brazil. --- config/config.go | 2 -- storage/remote/client.go | 7 +------ util/httputil/client.go | 10 ++++++---- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/config/config.go b/config/config.go index 983ba1999..147600e82 100644 --- a/config/config.go +++ b/config/config.go @@ -520,8 +520,6 @@ type HTTPClientConfig struct { ProxyURL URL `yaml:"proxy_url,omitempty"` // TLSConfig to use to connect to the targets. TLSConfig TLSConfig `yaml:"tls_config,omitempty"` - // If set, override whether to use HTTP KeepAlive - scraping defaults OFF, remote read/write defaults ON - KeepAlive *bool `yaml:"keep_alive,omitempty"` // Catches all undefined fields and must be empty after parsing. XXX map[string]interface{} `yaml:",inline"` diff --git a/storage/remote/client.go b/storage/remote/client.go index 01bcd9c8f..1f2b07dff 100644 --- a/storage/remote/client.go +++ b/storage/remote/client.go @@ -52,12 +52,7 @@ type ClientConfig struct { // NewClient creates a new Client. func NewClient(index int, conf *ClientConfig) (*Client, error) { - // If not specified in config, allow HTTP connections for remote API to use keep-alive - if conf.HTTPClientConfig.KeepAlive == nil { - val := true - conf.HTTPClientConfig.KeepAlive = &val - } - httpClient, err := httputil.NewClientFromConfig(conf.HTTPClientConfig) + httpClient, err := httputil.NewClientFromConfigAndOptions(conf.HTTPClientConfig, false) if err != nil { return nil, err } diff --git a/util/httputil/client.go b/util/httputil/client.go index 1c48030d4..66ec2b294 100644 --- a/util/httputil/client.go +++ b/util/httputil/client.go @@ -32,14 +32,16 @@ func NewClient(rt http.RoundTripper) *http.Client { // NewClientFromConfig returns a new HTTP client configured for the // given config.HTTPClientConfig. func NewClientFromConfig(cfg config.HTTPClientConfig) (*http.Client, error) { + return NewClientFromConfigAndOptions(cfg, true) +} + +// NewClientFromConfigAndOptions returns a new HTTP client configured for the +// given config.HTTPClientConfig, optionally disabling HTTP keepalive. +func NewClientFromConfigAndOptions(cfg config.HTTPClientConfig, disableKeepAlives bool) (*http.Client, error) { tlsConfig, err := NewTLSConfig(cfg.TLSConfig) if err != nil { return nil, err } - disableKeepAlives := true // hard-coded default unless overridden in config - if cfg.KeepAlive != nil { - disableKeepAlives = !*cfg.KeepAlive - } // 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{