-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TT-11739] Clean up rate limiting area, decouple GlobalConfig in APISpec #6262
[TT-11739] Clean up rate limiting area, decouple GlobalConfig in APISpec #6262
Conversation
API Changes --- prev.txt 2024-05-16 14:17:40.992509241 +0000
+++ current.txt 2024-05-16 14:17:36.968433493 +0000
@@ -5815,7 +5815,7 @@
// EnableFixedWindow enables fixed window rate limiting.
EnableFixedWindowRateLimiter bool `json:"enable_fixed_window_rate_limiter"`
- // Redis based rate limiter with fixed window. Provides 100% rate limiting accuracy, but require two additional Redis roundtrip for each request.
+ // Redis based rate limiter with sliding log. Provides 100% rate limiting accuracy, but require two additional Redis roundtrip for each request.
EnableRedisRollingLimiter bool `json:"enable_redis_rolling_limiter"`
// To enable, set to `true`. The sentinel-based rate limiter delivers a smoother performance curve as rate-limit calculations happen off-thread, but a stricter time-out based cool-down for clients. For example, when a throttling action is triggered, they are required to cool-down for the period of the rate limit.
@@ -7090,8 +7090,11 @@
const (
// QuotaKeyPrefix serves as a standard prefix for generating quota keys.
QuotaKeyPrefix = "quota-"
- // RateLimitKeyPrefix serves as a standard prefix for generating rate limit keys.
- RateLimitKeyPrefix = "rate-limit-"
+
+ // RateLimitKeyPrefix serves as a standard prefix for generating rate limiter keys.
+ RateLimitKeyPrefix = rate.LimiterKeyPrefix
+
+ // SentinelRateLimitKeyPostfix is appended to the rate limiting key to combine into a sentinel key.
SentinelRateLimitKeyPostfix = ".BLOCKED"
)
const (
@@ -9690,7 +9693,7 @@
func (l *SessionLimiter) Context() context.Context
-func (l *SessionLimiter) ForwardMessage(r *http.Request, currentSession *user.SessionState, rateLimitKey string, quotaKey string, store storage.Handler, enableRL, enableQ bool, globalConf *config.Config, api *APISpec, dryRun bool) sessionFailReason
+func (l *SessionLimiter) ForwardMessage(r *http.Request, currentSession *user.SessionState, rateLimitKey string, quotaKey string, store storage.Handler, enableRL, enableQ bool, api *APISpec, dryRun bool) sessionFailReason
ForwardMessage will enforce rate limiting, returning a non-zero
sessionFailReason if session limits have been exceeded. Key values to manage
rate are Rate and Per, e.g. Rate of 10 messages Per 10 seconds |
PR Description updated to latest commit (c130a1b) |
PR Review 🔍
Code feedback:
|
c130a1b
to
3b368cb
Compare
PR Code Suggestions ✨
|
3b368cb
to
ca5cb60
Compare
💥 CI tests failed 🙈git-stateall ok Please look at the run or in the Checks tab. |
4e5170c
to
8817cb9
Compare
💥 CI tests failed 🙈git-stateall ok Please look at the run or in the Checks tab. |
Please retry analysis of this Pull-Request directly on SonarCloud |
💥 CI tests failed 🙈git-stateall ok Please look at the run or in the Checks tab. |
62bf375
to
a12a2a6
Compare
Quality Gate failedFailed conditions See analysis details on SonarCloud Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
User description
Clean up refactor of rate limits area:
Fixing bugs:
rate-
prefix)https://tyktech.atlassian.net/browse/TT-11739
PR Type
Bug fix, Enhancement
Description
GlobalConfig
from various rate limiting and quota management functions across multiple files to enhance modularity.Changes walkthrough 📝
mw_api_rate_limit.go
Simplify API Rate Limiting Logic and Decouple Global Config
gateway/mw_api_rate_limit.go
GlobalConfig
from rate limiting logic.mw_organisation_activity.go
Refactor Organisation Activity Rate Limiting
gateway/mw_organisation_activity.go
GlobalConfig
references in rate limiting checks.maintainability.
mw_rate_limiting.go
Refactor Rate Limiting and Quota Checks
gateway/mw_rate_limiting.go
GlobalConfig
from rate limiting and quota checks.session_manager.go
Centralize Rate Limiter Key Prefix and Optimize Session Limiter
gateway/session_manager.go
rate.LimiterKeyPrefix
.and simplifying logic.
limiter.go
Enhance Rate Limiter Configuration and Key Generation
internal/rate/limiter.go
LimiterKey
function to standardize rate limiter key generation.rate.go
Update Constants and Error Handling for Rate Limiters
internal/rate/rate.go
LimiterKeyPrefix
for consistent key naming.