feat: implement distributed rate limiting by redis_rate/v10 #4068
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This pull request refactors the rate limiting system by replacing the
limiters
library withredis_rate
for distributed rate limiting. It introduces a simplified API for rate limit checks and updates related configurations and middleware. Below are the most important changes grouped by theme:Dependency Updates:
github.com/mennanov/limiters
withgithub.com/go-redis/redis_rate/v10
for distributed rate limiting. (go.mod
: [1] [2] [3]github.com/fatih/color
,github.com/hashicorp/consul/api
, and others. (go.mod
: [1] [2] [3]Distributed Rate Limiter Refactor:
Allow
method usingredis_rate.Limiter
. (internal/ratelimiter/distributed_ratelimiter.go
: internal/ratelimiter/distributed_ratelimiter.goL21-R55)NewDistributedRateLimiter
constructor to accept a rate limit in requests per second. (internal/ratelimiter/distributed_ratelimiter.go
: internal/ratelimiter/distributed_ratelimiter.goL21-R55)Job Rate Limiter Simplification:
TakeByClusterID
andTakeByClusterIDs
withAllowByClusterID
andAllowByClusterIDs
methods for boolean-based rate limit checks. (internal/ratelimiter/job_ratelimiter.go
: [1] [2]refresh
method to use the newDistributedRateLimiter
. (internal/ratelimiter/job_ratelimiter.go
: internal/ratelimiter/job_ratelimiter.goL167-R178)Configuration Changes:
DefaultClusterJobRateLimit
type touint32
to align with the new rate limiter API. (manager/config/constants.go
: manager/config/constants.goL106-R106)Middleware Update:
AllowByClusterIDs
method in the job rate limiter middleware. (manager/middlewares/ratelimiter.go
: manager/middlewares/ratelimiter.goL37-R37)Related Issue
Motivation and Context
Screenshots (if appropriate)
Types of changes
Checklist