From e0a4d183013977b5836ae8b06182f747330a243e Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 11 Sep 2017 09:07:14 +0000 Subject: [PATCH 1/2] Allow http keep-alive setting to be overridden in config --- config/config.go | 2 ++ util/httputil/client.go | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 18eba3a5d..626fd3d1e 100644 --- a/config/config.go +++ b/config/config.go @@ -526,6 +526,8 @@ 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 - defaults OFF + 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/util/httputil/client.go b/util/httputil/client.go index f89ea688e..1c48030d4 100644 --- a/util/httputil/client.go +++ b/util/httputil/client.go @@ -36,11 +36,15 @@ func NewClientFromConfig(cfg config.HTTPClientConfig) (*http.Client, error) { 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{ Proxy: http.ProxyURL(cfg.ProxyURL.URL), - DisableKeepAlives: true, + DisableKeepAlives: disableKeepAlives, TLSClientConfig: tlsConfig, } From 9d6b945e415b52c04eba9790da42f072a8cbc0f0 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 11 Sep 2017 09:08:26 +0000 Subject: [PATCH 2/2] Default HTTP keep-alive ON for remote read/write --- config/config.go | 2 +- storage/remote/client.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 626fd3d1e..401bee4f4 100644 --- a/config/config.go +++ b/config/config.go @@ -526,7 +526,7 @@ 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 - defaults OFF + // 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. diff --git a/storage/remote/client.go b/storage/remote/client.go index fc60cfba6..1a20dc43a 100644 --- a/storage/remote/client.go +++ b/storage/remote/client.go @@ -51,6 +51,11 @@ 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) if err != nil { return nil, err