diff --git a/CHANGELOG.md b/CHANGELOG.md index 29cae90ff..86a9fa17a 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 9504f9f03..b7a93ffbd 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)