util: Add idle timeout for scrape connections

This commit is contained in:
Fabian Reinartz 2017-08-09 16:30:49 +02:00
parent 3bee362727
commit 9516d04472
2 changed files with 4 additions and 0 deletions

View File

@ -420,6 +420,7 @@ func (s *targetScraper) scrape(ctx context.Context, w io.Writer) error {
s.req = req s.req = req
} }
resp, err := ctxhttp.Do(ctx, s.client, s.req) resp, err := ctxhttp.Do(ctx, s.client, s.req)
if err != nil { if err != nil {
return err return err

View File

@ -47,6 +47,9 @@ func NewClientFromConfig(cfg config.HTTPClientConfig) (*http.Client, error) {
DisableKeepAlives: false, DisableKeepAlives: false,
TLSClientConfig: tlsConfig, TLSClientConfig: tlsConfig,
DisableCompression: true, DisableCompression: true,
// 5 minutes is typically above the maximum sane scrape interval. So we can
// use keepalive for all configurations.
IdleConnTimeout: 5 * time.Minute,
} }
// If a bearer token is provided, create a round tripper that will set the // If a bearer token is provided, create a round tripper that will set the