push.go: limit the maximum timeout for pushing metrics to the provided 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.
This commit is contained in:
parent
2767350561
commit
aab1d62de8
5
push.go
5
push.go
@ -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
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user