mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 00:13:30 +01:00
app/vmagent/remotewrite: add missing resp.Body.Close()
after pushing data to remote storage
Missing body close could disable HTTP keep-alive connections. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/653
This commit is contained in:
parent
0f6f0d30d3
commit
baebe86844
@ -220,28 +220,33 @@ again:
|
|||||||
goto again
|
goto again
|
||||||
}
|
}
|
||||||
statusCode := resp.StatusCode
|
statusCode := resp.StatusCode
|
||||||
if statusCode/100 != 2 {
|
if statusCode/100 == 2 {
|
||||||
metrics.GetOrCreateCounter(fmt.Sprintf(`vmagent_remotewrite_requests_total{url=%q, status_code="%d"}`, c.urlLabelValue, statusCode)).Inc()
|
_ = resp.Body.Close()
|
||||||
retryDuration *= 2
|
c.requestsOKCount.Inc()
|
||||||
if retryDuration > time.Minute {
|
return
|
||||||
retryDuration = time.Minute
|
|
||||||
}
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
logger.Errorf("cannot read response body from %q: %s", c.remoteWriteURL, err)
|
|
||||||
} else {
|
|
||||||
logger.Errorf("unexpected status code received after sending a block with size %d bytes to %q: %d; response body=%q; re-sending the block in %.3f seconds",
|
|
||||||
len(block), c.remoteWriteURL, statusCode, body, retryDuration.Seconds())
|
|
||||||
}
|
|
||||||
t := time.NewTimer(retryDuration)
|
|
||||||
select {
|
|
||||||
case <-c.stopCh:
|
|
||||||
t.Stop()
|
|
||||||
return
|
|
||||||
case <-t.C:
|
|
||||||
}
|
|
||||||
c.retriesCount.Inc()
|
|
||||||
goto again
|
|
||||||
}
|
}
|
||||||
c.requestsOKCount.Inc()
|
|
||||||
|
// Unexpected status code returned
|
||||||
|
metrics.GetOrCreateCounter(fmt.Sprintf(`vmagent_remotewrite_requests_total{url=%q, status_code="%d"}`, c.urlLabelValue, statusCode)).Inc()
|
||||||
|
retryDuration *= 2
|
||||||
|
if retryDuration > time.Minute {
|
||||||
|
retryDuration = time.Minute
|
||||||
|
}
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
_ = resp.Body.Close()
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorf("cannot read response body from %q: %s", c.remoteWriteURL, err)
|
||||||
|
} else {
|
||||||
|
logger.Errorf("unexpected status code received after sending a block with size %d bytes to %q: %d; response body=%q; re-sending the block in %.3f seconds",
|
||||||
|
len(block), c.remoteWriteURL, statusCode, body, retryDuration.Seconds())
|
||||||
|
}
|
||||||
|
t := time.NewTimer(retryDuration)
|
||||||
|
select {
|
||||||
|
case <-c.stopCh:
|
||||||
|
t.Stop()
|
||||||
|
return
|
||||||
|
case <-t.C:
|
||||||
|
}
|
||||||
|
c.retriesCount.Inc()
|
||||||
|
goto again
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user