From 485ebf879abe082eb448e1d58e1d42bce19e1162 Mon Sep 17 00:00:00 2001 From: Tit Petric Date: Tue, 27 Feb 2024 11:04:43 +0700 Subject: [PATCH] [TT-11371] Move leaky-bucket behind the dev build flag (5.3.0) (#6073) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **User description** https://tyktech.atlassian.net/browse/TT-11371 ___ ## **Type** enhancement, configuration changes ___ ## **Description** - Moved the Leaky Bucket rate limiter configuration behind a development build flag. - Removed the Leaky Bucket rate limiter option from the main configuration, making it exclusive to development builds. - Updated tests and internal logic to reflect the removal of the Leaky Bucket rate limiter from the main configuration. - Adjusted CLI linter schema to remove references to the now development-only Leaky Bucket rate limiter. ___ ## **Changes walkthrough**
Relevant files
Enhancement
development.go
Add Leaky Bucket Rate Limiter to Development Config           

config/development.go
  • Added EnableLeakyBucketRateLimiter configuration option to
    DevelopmentConfig.
  • +9/-0     
    Configuration changes
    rate_limit.go
    Remove Leaky Bucket Rate Limiter from Main Config               

    config/rate_limit.go
  • Removed EnableLeakyBucketRateLimiter from RateLimit struct.
  • Adjusted string representation logic for rate limiters.
  • +0/-13   
    rate_nodev.go
    Adjust Rate Limiter Handling for Release Builds                   

    internal/rate/rate_nodev.go - Removed Leaky Bucket rate limiter handling for release builds.
    +0/-3     
    schema.json
    Update CLI Linter Schema                                                                 

    cli/linter/schema.json - Removed JSON schema entries related to Leaky Bucket rate limiter.
    +0/-9     
    Tests
    mw_rate_limiting_test.go
    Update Rate Limiting Middleware Tests                                       

    gateway/mw_rate_limiting_test.go - Removed test case setup for Leaky Bucket rate limiter.
    +0/-2     
    ___ > ✨ **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions --------- Co-authored-by: Tit Petric --- cli/linter/schema.json | 9 --------- config/development.go | 9 +++++++++ config/rate_limit.go | 13 ------------- gateway/mw_rate_limiting_test.go | 6 ------ internal/rate/rate_nodev.go | 3 --- 5 files changed, 9 insertions(+), 31 deletions(-) diff --git a/cli/linter/schema.json b/cli/linter/schema.json index fe31e711514..96380788a14 100644 --- a/cli/linter/schema.json +++ b/cli/linter/schema.json @@ -405,15 +405,6 @@ "jsvm_timeout": { "type": "integer" }, - "enable_leaky_bucket_rate_limiter": { - "type": "boolean" - }, - "enable_rate_limiter_storage": { - "type": "boolean" - }, - "rate_limiter_storage": { - "$ref": "#/definitions/StorageOptions" - }, "enable_non_transactional_rate_limiter": { "type": "boolean" }, diff --git a/config/development.go b/config/development.go index fb4a294ef63..17cb9e3a1b4 100644 --- a/config/development.go +++ b/config/development.go @@ -5,6 +5,15 @@ package config // DevelopmentConfig extends Config for development builds. type DevelopmentConfig struct { + // EnableLeakyBucketRateLimiter enables leaky bucket rate limiting. + // + // LeakyBucket will delay requests so they are processed in a FIFO + // style queue, ensuring a constant request rate and smoothing out + // traffic spikes. This comes at some cost to gateway instances, as + // the connections would be held for a longer time, instead of + // blocking the requests when they go over the defined rate limits. + EnableLeakyBucketRateLimiter bool `json:"enable_leaky_bucket_rate_limiter"` + // EnableTokenBucket enables token bucket rate limiting. EnableTokenBucketRateLimiter bool `json:"enable_token_bucket_rate_limiter"` diff --git a/config/rate_limit.go b/config/rate_limit.go index da5a1cb6e3f..df0530d938f 100644 --- a/config/rate_limit.go +++ b/config/rate_limit.go @@ -7,15 +7,6 @@ import ( // RateLimit contains flags and configuration for controlling rate limiting behaviour. // It is embedded in the main config structure. type RateLimit struct { - // EnableLeakyBucketRateLimiter enables leaky bucket rate limiting. - // - // LeakyBucket will delay requests so they are processed in a FIFO - // style queue, ensuring a constant request rate and smoothing out - // traffic spikes. This comes at some cost to gateway instances, as - // the connections would be held for a longer time, instead of - // blocking the requests when they go over the defined rate limits. - EnableLeakyBucketRateLimiter bool `json:"enable_leaky_bucket_rate_limiter"` - // Redis based rate limiter with fixed window. Provides 100% rate limiting accuracy, but require two additional Redis roundtrip for each request. EnableRedisRollingLimiter bool `json:"enable_redis_rolling_limiter"` @@ -48,10 +39,6 @@ func (r *RateLimit) String() string { info = "using pipeline" } - if r.EnableLeakyBucketRateLimiter { - return "Leaky Bucket Rate Limiter enabled" - } - if r.EnableRedisRollingLimiter { return fmt.Sprintf("Redis Rate Limiter enabled (%s)", info) } diff --git a/gateway/mw_rate_limiting_test.go b/gateway/mw_rate_limiting_test.go index 90c0a2d9436..f0efcb4cd31 100644 --- a/gateway/mw_rate_limiting_test.go +++ b/gateway/mw_rate_limiting_test.go @@ -240,8 +240,6 @@ func providerCustomRatelimitKey(t *testing.T, limiter string) { globalConf.RateLimit.DRLEnableSentinelRateLimiter = true case "NonTransactional": globalConf.RateLimit.EnableNonTransactionalRateLimiter = true - case "LeakyBucket": - globalConf.RateLimit.EnableLeakyBucketRateLimiter = true default: t.Fatal("There is no such a rate limiter:", limiter) } @@ -396,7 +394,3 @@ func TestMwRateLimiting_CustomRatelimitKeyDRL(t *testing.T) { func TestMwRateLimiting_CustomRatelimitKeyNonTransactional(t *testing.T) { providerCustomRatelimitKey(t, "NonTransactional") } - -func TestMwRateLimiting_CustomRatelimitKeyEnableLeakyBucketRateLimiter(t *testing.T) { - providerCustomRatelimitKey(t, "LeakyBucket") -} diff --git a/internal/rate/rate_nodev.go b/internal/rate/rate_nodev.go index 16bcfc850cd..059b7ecae67 100644 --- a/internal/rate/rate_nodev.go +++ b/internal/rate/rate_nodev.go @@ -10,8 +10,5 @@ import ( // LimiterKind returns the kind of rate limiter enabled by config. // This function is used for release builds. func LimiterKind(c *config.Config) (string, bool) { - if c.EnableLeakyBucketRateLimiter { - return LimitLeakyBucket, true - } return "", false }