app/vmagent/remotewrite: create new request on failure to send a block of data to remote storage

Previously the request body was already consumed before the retry, so this led to the following error:

    http: ContentLength=... with Body length 0
This commit is contained in:
Aliaksandr Valialkin 2020-07-27 17:31:36 +03:00
parent 894dcb7c1c
commit cb8c6908dc

View file

@ -182,6 +182,9 @@ func (c *client) runWorker() {
}
func (c *client) sendBlock(block []byte) {
retryDuration := time.Second
again:
req, err := http.NewRequest("POST", c.remoteWriteURL, bytes.NewBuffer(block))
if err != nil {
logger.Panicf("BUG: unexected error from http.NewRequest(%q): %s", c.remoteWriteURL, err)
@ -195,9 +198,6 @@ func (c *client) sendBlock(block []byte) {
req.Header.Set("Authorization", c.authHeader)
}
retryDuration := time.Second
again:
startTime := time.Now()
resp, err := c.hc.Do(req)
c.requestDuration.UpdateDuration(startTime)