app/vmagent/remotewrite: fix rate limiting logic for -remoteWrite.url

This commit is contained in:
Aliaksandr Valialkin 2021-03-01 00:58:31 +02:00
parent 7f15cd7161
commit 369f01c738

View file

@ -321,8 +321,7 @@ func (rl *rateLimiter) register(dataLen int, stopCh <-chan struct{}) {
defer rl.mu.Unlock() defer rl.mu.Unlock()
for rl.budget <= 0 { for rl.budget <= 0 {
now := time.Now() if d := time.Until(rl.deadline); d > 0 {
if d := rl.deadline.Sub(now); d > 0 {
rl.limitReached.Inc() rl.limitReached.Inc()
t := timerpool.Get(d) t := timerpool.Get(d)
select { select {
@ -334,7 +333,7 @@ func (rl *rateLimiter) register(dataLen int, stopCh <-chan struct{}) {
} }
} }
rl.budget += limit rl.budget += limit
rl.deadline = now.Add(time.Second) rl.deadline = time.Now().Add(time.Second)
} }
rl.budget -= int64(dataLen) rl.budget -= int64(dataLen)
} }