Scope the rate limit counter key by source AND by middleware
This commit is contained in:
parent
76153acac6
commit
ab3234e458
1 changed files with 6 additions and 1 deletions
|
@ -146,7 +146,12 @@ func (rl *rateLimiter) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||||
logger.Info().Msgf("ignoring token bucket amount > 1: %d", amount)
|
logger.Info().Msgf("ignoring token bucket amount > 1: %d", amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
delay, err := rl.limiter.Allow(ctx, source)
|
// Each rate limiter has its own source space,
|
||||||
|
// ensuring independence between rate limiters,
|
||||||
|
// i.e., rate limit rules are only applied based on traffic
|
||||||
|
// where the rate limiter is active.
|
||||||
|
rlSource := fmt.Sprintf("%s:%s", rl.name, source)
|
||||||
|
delay, err := rl.limiter.Allow(ctx, rlSource)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rl.logger.Error().Err(err).Msg("Could not insert/update bucket")
|
rl.logger.Error().Err(err).Msg("Could not insert/update bucket")
|
||||||
observability.SetStatusErrorf(ctx, "Could not insert/update bucket")
|
observability.SetStatusErrorf(ctx, "Could not insert/update bucket")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue