From 369f01c738eb88e6af9af505505d7d5a3570e57d Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 1 Mar 2021 00:58:31 +0200 Subject: [PATCH] app/vmagent/remotewrite: fix rate limiting logic for `-remoteWrite.url` --- app/vmagent/remotewrite/client.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/vmagent/remotewrite/client.go b/app/vmagent/remotewrite/client.go index 7c0b0f21b..767ff549b 100644 --- a/app/vmagent/remotewrite/client.go +++ b/app/vmagent/remotewrite/client.go @@ -321,8 +321,7 @@ func (rl *rateLimiter) register(dataLen int, stopCh <-chan struct{}) { defer rl.mu.Unlock() for rl.budget <= 0 { - now := time.Now() - if d := rl.deadline.Sub(now); d > 0 { + if d := time.Until(rl.deadline); d > 0 { rl.limitReached.Inc() t := timerpool.Get(d) select { @@ -334,7 +333,7 @@ func (rl *rateLimiter) register(dataLen int, stopCh <-chan struct{}) { } } rl.budget += limit - rl.deadline = now.Add(time.Second) + rl.deadline = time.Now().Add(time.Second) } rl.budget -= int64(dataLen) }