Allow http keep-alive setting to be overridden in config

pull/3160/head
Bryan Boreham 7 years ago
parent 8bee283f8a
commit e0a4d18301

@ -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"`

@ -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,
}

Loading…
Cancel
Save