lib/promscrape: properly handle response body after 301 redirect

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/869
This commit is contained in:
Aliaksandr Valialkin 2020-11-02 01:09:37 +02:00
parent ca566dce39
commit c0f3be824d
2 changed files with 4 additions and 3 deletions

View file

@ -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: 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. * 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 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) # [v1.44.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.44.0)

View file

@ -169,9 +169,6 @@ func (c *client) ReadData(dst []byte) ([]byte, error) {
dst = resp.SwapBody(dst) dst = resp.SwapBody(dst)
} }
err := doRequestWithPossibleRetry(c.hc, req, resp, deadline) err := doRequestWithPossibleRetry(c.hc, req, resp, deadline)
if swapResponseBodies {
dst = resp.SwapBody(dst)
}
statusCode := resp.StatusCode() statusCode := resp.StatusCode()
if err == nil && (statusCode == fasthttp.StatusMovedPermanently || statusCode == fasthttp.StatusFound) { if err == nil && (statusCode == fasthttp.StatusMovedPermanently || statusCode == fasthttp.StatusFound) {
// Allow a single redirect. // Allow a single redirect.
@ -183,6 +180,9 @@ func (c *client) ReadData(dst []byte) ([]byte, error) {
statusCode = resp.StatusCode() statusCode = resp.StatusCode()
} }
} }
if swapResponseBodies {
dst = resp.SwapBody(dst)
}
fasthttp.ReleaseRequest(req) fasthttp.ReleaseRequest(req)
if err != nil { if err != nil {
fasthttp.ReleaseResponse(resp) fasthttp.ReleaseResponse(resp)