From fdced59278beeab1f7ab4c5a67a7939e91fc6d62 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 22 Jan 2021 13:22:20 +0200 Subject: [PATCH] lib/promscrape: retry scrape and service discovery requests when the remote server closes http keep-alive connection --- docs/CHANGELOG.md | 1 + lib/promscrape/client.go | 2 +- lib/promscrape/discoveryutils/client.go | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 640e1a5c6..d8e01d4b2 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -5,6 +5,7 @@ * FEATURE: added `search.maxStepForPointsAdjustment` command-line flag, which can be used for disabling adjustment for points returned `/api/v1/query_range` handler if such points have timestamps closer than `-search.latencyOffset` to the current time. Such points may contain incomplete data, so they are substituted by the previous values for `step` query args smaller than one minute by default. * BUGFIX: vmagent: reduce the HTTP reconnection rate to scrape targets. Previously vmagent could errorneusly close HTTP keep-alive connections more often than needed. +* BUGFIX: vmagent: retry scrape and service discovery requests when the remote server closes HTTP keep-alive connection. Previously `disable_keepalive: true` option could be used under `scrape_configs` section when working with such servers. # [v1.52.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.52.0) diff --git a/lib/promscrape/client.go b/lib/promscrape/client.go index bec3ef23e..03cbcf193 100644 --- a/lib/promscrape/client.go +++ b/lib/promscrape/client.go @@ -252,7 +252,7 @@ func doRequestWithPossibleRetry(hc *fasthttp.HostClient, req *fasthttp.Request, if err == nil { return nil } - if err != fasthttp.ErrConnectionClosed { + if err != fasthttp.ErrConnectionClosed && !strings.Contains(err.Error(), "broken pipe") { return err } // Retry request if the server closes the keep-alive connection unless deadline exceeds. diff --git a/lib/promscrape/discoveryutils/client.go b/lib/promscrape/discoveryutils/client.go index b971be8ec..0acdace38 100644 --- a/lib/promscrape/discoveryutils/client.go +++ b/lib/promscrape/discoveryutils/client.go @@ -199,7 +199,7 @@ func doRequestWithPossibleRetry(hc *fasthttp.HostClient, req *fasthttp.Request, if err == nil { return nil } - if err != fasthttp.ErrConnectionClosed { + if err != fasthttp.ErrConnectionClosed && !strings.Contains(err.Error(), "broken pipe") { return err } // Retry request if the server closes the keep-alive connection unless deadline exceeds.