Skip to content

Commit

Permalink
Improve error logging when metrics cannot be pushed to pushURL passed…
Browse files Browse the repository at this point in the history
… to InitPush*()
  • Loading branch information
valyala committed Jul 21, 2022
1 parent 5710165 commit 195ac63
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions push.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"time"
Expand Down Expand Up @@ -108,14 +109,16 @@ func InitPushExt(pushURL string, interval time.Duration, extraLabels string, wri
}
resp, err := c.Post(pushURL, "text/plain", &bb)
if err != nil {
log.Printf("cannot push metrics to %q: %s", pushURL, err)
log.Printf("ERROR: metrics.push: cannot push metrics to %q: %s", pushURL, err)
continue
}
_ = resp.Body.Close()
if resp.StatusCode/100 != 2 {
log.Printf("unexpected status code in response from %q: %d; expecting 2xx", pushURL, resp.StatusCode)
body, _ := ioutil.ReadAll(resp.Body)
_ = resp.Body.Close()
log.Printf("ERROR: metrics.push: unexpected status code in response from %q: %d; expecting 2xx; response body: %q", pushURL, resp.StatusCode, body)
continue
}
_ = resp.Body.Close()
}
}()
}
Expand Down

0 comments on commit 195ac63

Please sign in to comment.