From 3ed9f1d5a9e392dfe52abd93e9cb287b1a61b4e2 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 2 Nov 2020 01:09:37 +0200 Subject: [PATCH] lib/promscrape: properly handle response body after 301 redirect Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/869 --- CHANGELOG.md | 1 + lib/promscrape/client.go | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29cae90ff1..86a9fa17a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ * BUGFIX: vmagent: add leading missing slash to metrics path like Prometheus does. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/835 * BUGFIX: vmagent: drop packet if remote storage returns 4xx status code. This make the behaviour consistent with Prometheus. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/873 +* BUGFIX: vmagent: properly handle 301 redirects. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/869 # [v1.44.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.44.0) diff --git a/lib/promscrape/client.go b/lib/promscrape/client.go index 9504f9f030..b7a93ffbd6 100644 --- a/lib/promscrape/client.go +++ b/lib/promscrape/client.go @@ -169,9 +169,6 @@ func (c *client) ReadData(dst []byte) ([]byte, error) { dst = resp.SwapBody(dst) } err := doRequestWithPossibleRetry(c.hc, req, resp, deadline) - if swapResponseBodies { - dst = resp.SwapBody(dst) - } statusCode := resp.StatusCode() if err == nil && (statusCode == fasthttp.StatusMovedPermanently || statusCode == fasthttp.StatusFound) { // Allow a single redirect. @@ -183,6 +180,9 @@ func (c *client) ReadData(dst []byte) ([]byte, error) { statusCode = resp.StatusCode() } } + if swapResponseBodies { + dst = resp.SwapBody(dst) + } fasthttp.ReleaseRequest(req) if err != nil { fasthttp.ReleaseResponse(resp)