Skip to content
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-7325] Enable fixed window rate limiter #6253

Merged
merged 6 commits into from May 16, 2024
Merged

Conversation

titpetric
Copy link
Contributor

@titpetric titpetric commented Apr 26, 2024

User description

The PR enables a fixed window rate limiter from behind the dev build tag.


Type

enhancement


Description

  • Removed the EnableFixedWindowRateLimiter setting from config/development.go as it seems to be restructured.
  • Introduced EnableFixedWindowRateLimiter in config/rate_limit.go to centralize rate limiting configurations.
  • Added a string output for when the fixed window rate limiter is enabled, improving debuggability and monitoring.

Changes walkthrough

Relevant files
Configuration changes
development.go
Remove Fixed Window Rate Limiter Setting from Development Config

config/development.go

  • Removed the EnableFixedWindowRateLimiter setting.
+0/-3     
Enhancement
rate_limit.go
Introduce Fixed Window Rate Limiter Configuration               

config/rate_limit.go

  • Added EnableFixedWindowRateLimiter setting to enable fixed window rate
    limiting.
  • Added a string representation for when the fixed window rate limiter
    is enabled.
  • +7/-0     

    PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Copy link

    PR Description updated to latest commit (1f9f0aa)

    Copy link

    github-actions bot commented Apr 26, 2024

    API Changes

    --- prev.txt	2024-05-16 07:39:52.185815846 +0000
    +++ current.txt	2024-05-16 07:39:49.045816523 +0000
    @@ -5812,6 +5812,9 @@
         GetOAuthTokensPurgeInterval returns purge interval for lapsed OAuth tokens.
     
     type RateLimit struct {
    +	// 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.
     	EnableRedisRollingLimiter bool `json:"enable_redis_rolling_limiter"`
     

    Copy link

    PR Review

    ⏱️ Estimated effort to review [1-5]

    2, because the changes are straightforward and involve moving a configuration setting from one file to another while adding a string representation for debugging. The logic is simple and the impact is limited to configuration handling.

    🧪 Relevant tests

    No

    🔍 Possible issues

    Missing Condition Handling: The new string representation for the fixed window rate limiter in config/rate_limit.go does not handle the case where multiple rate limiters might be enabled simultaneously. This could lead to misleading debug outputs if more than one limiter is active.

    🔒 Security concerns

    No

    Code feedback:
    relevant fileconfig/rate_limit.go
    suggestion      

    Consider handling multiple rate limiters being enabled simultaneously. You could append the status of each rate limiter to the output string rather than returning immediately when one is enabled. This change would provide a more comprehensive debug output. [important]

    relevant linereturn fmt.Sprintf("Fixed Window Rate Limiter enabled")


    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.

    The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.

    • When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:
    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    
    [pr_reviewer]
    some_config1=...
    some_config2=...
    

    See the review usage page for a comprehensive guide on using this tool.

    Copy link

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Enhancement
    Modify the method to include all applicable rate limiter settings in the output.

    Instead of returning immediately when EnableFixedWindowRateLimiter is true, consider
    appending this information to a string and continue checking other conditions. This
    ensures that all relevant rate limiter settings are included in the output, not just the
    first one that evaluates to true.

    config/rate_limit.go [45-47]

     if r.EnableFixedWindowRateLimiter {
    -    return fmt.Sprintf("Fixed Window Rate Limiter enabled")
    +    info += "Fixed Window Rate Limiter enabled; "
     }
     
    Best practice
    Ensure proper spacing in concatenated status messages.

    Add a space after the semicolon in the string concatenation to ensure proper formatting
    when multiple rate limiter settings are enabled.

    config/rate_limit.go [45-47]

    -info += "Fixed Window Rate Limiter enabled;"
    +info += "Fixed Window Rate Limiter enabled; "
     

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.

    • When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:
    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

    See the improve usage page for a comprehensive guide on using this tool.

    Copy link

    💥 CI tests failed 🙈

    git-state

    all ok

    Please look at the run or in the Checks tab.

    1 similar comment
    Copy link

    💥 CI tests failed 🙈

    git-state

    all ok

    Please look at the run or in the Checks tab.

    @titpetric titpetric requested a review from a team as a code owner April 26, 2024 11:01
    Copy link

    💥 CI tests failed 🙈

    git-state

    all ok

    Please look at the run or in the Checks tab.

    @titpetric titpetric enabled auto-merge (squash) May 16, 2024 07:10
    Copy link

    sonarcloud bot commented May 16, 2024

    @titpetric titpetric merged commit d3e40b8 into master May 16, 2024
    36 checks passed
    @titpetric titpetric deleted the test/patch-sentinel-key-2 branch May 16, 2024 07:59
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    None yet

    2 participants