From 9516d044723d60a1513502bb297b970f2c661ff9 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Wed, 9 Aug 2017 16:30:49 +0200 Subject: [PATCH 1/2] util: Add idle timeout for scrape connections --- retrieval/scrape.go | 1 + util/httputil/client.go | 3 +++ 2 files changed, 4 insertions(+) diff --git a/retrieval/scrape.go b/retrieval/scrape.go index db4e02f27..16ca5ecf7 100644 --- a/retrieval/scrape.go +++ b/retrieval/scrape.go @@ -420,6 +420,7 @@ func (s *targetScraper) scrape(ctx context.Context, w io.Writer) error { s.req = req } + resp, err := ctxhttp.Do(ctx, s.client, s.req) if err != nil { return err diff --git a/util/httputil/client.go b/util/httputil/client.go index 2c01fd0fd..a79bdd20f 100644 --- a/util/httputil/client.go +++ b/util/httputil/client.go @@ -47,6 +47,9 @@ func NewClientFromConfig(cfg config.HTTPClientConfig) (*http.Client, error) { DisableKeepAlives: false, TLSClientConfig: tlsConfig, 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 From 0af43695de3e430f0ac4ca893ab1b29c8935a6df Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Thu, 10 Aug 2017 14:48:31 +0200 Subject: [PATCH 2/2] web: log error missages on serving --- web/web.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/web/web.go b/web/web.go index 74a733d2d..d6d18c966 100644 --- a/web/web.go +++ b/web/web.go @@ -346,8 +346,16 @@ func (h *Handler) Run(ctx context.Context) error { ReadTimeout: h.options.ReadTimeout, } - go httpSrv.Serve(httpl) - go grpcSrv.Serve(grpcl) + go func() { + if err := httpSrv.Serve(httpl); err != nil { + log.With("err", err).Warnf("error serving HTTP") + } + }() + go func() { + if err := grpcSrv.Serve(grpcl); err != nil { + log.With("err", err).Warnf("error serving HTTP") + } + }() return m.Serve() }