Skip to content

Commit

Permalink
push.go: limit the maximum timeout for pushing metrics to the provide…
Browse files Browse the repository at this point in the history
…d interval between pushes

This should guarantee that metrics are pushed regularly with the provided interval.
If the remote storage cannot keep up with push frequency, then timeout errors will be logged.
  • Loading branch information
valyala committed Jul 21, 2022
1 parent 2767350 commit aab1d62
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion push.go
Expand Up @@ -81,6 +81,9 @@ func initPush(pushURL string, interval time.Duration, extraLabels string, writeM
if err := validateTags(extraLabels); err != nil {
panic(fmt.Errorf("BUG: invalid extraLabels=%q: %s", extraLabels, err))
}
c := &http.Client{
Timeout: interval,
}
go func() {
ticker := time.NewTicker(interval)
var bb bytes.Buffer
Expand All @@ -93,7 +96,7 @@ func initPush(pushURL string, interval time.Duration, extraLabels string, writeM
bb.Reset()
bb.Write(tmpBuf)
}
resp, err := http.Post(pushURL, "text/plain", &bb)
resp, err := c.Post(pushURL, "text/plain", &bb)
if err != nil {
log.Printf("cannot push metrics to %q: %s", pushURL, err)
continue
Expand Down

0 comments on commit aab1d62

Please sign in to comment.