Skip to content

Add request_method to rate-limit Policy #7832

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

Merged
merged 3 commits into from
May 23, 2025
Merged

Add request_method to rate-limit Policy #7832

merged 3 commits into from
May 23, 2025

Conversation

vepatel
Copy link
Contributor

@vepatel vepatel commented May 23, 2025

Proposed changes

policy:

kind: Policy
metadata:
  name: rate-limit-policy
spec:
  rateLimit:
    rate: 5r/m
    key: ${request_method}
    zoneSize: 10M

conf:

upstream vs_default_webapp_webapp {zone vs_default_webapp_webapp 256k;
    random two least_conn;
    server 10.40.0.31:8080 max_fails=1 fail_timeout=10s max_conns=0;
}

limit_req_zone ${request_method} zone=pol_rl_default_rate_limit_policy_default_webapp:10M rate=5r/m;
server {
    listen 80;
    listen [::]:80;

cURL:

curl -X GET --resolve webapp.example.com:$IC_HTTP_PORT:$IC_IP http://webapp.example.com:$IC_HTTP_PORT/
Server address: 10.40.0.33:8080
Server name: webapp-7b7dfbff54-fc6nc
Date: 23/May/2025:10:29:06 +0000
URI: /
Request ID: e8c61c4c28f25c9488ec75bc0a342678

curl -X GET --resolve webapp.example.com:$IC_HTTP_PORT:$IC_IP http://webapp.example.com:$IC_HTTP_PORT/
<html>
<head><title>503 Service Temporarily Unavailable</title></head>
<body>
<center><h1>503 Service Temporarily Unavailable</h1></center>
<hr><center>nginx/1.27.4</center>
</body>
</html>

curl -X POST --resolve webapp.example.com:$IC_HTTP_PORT:$IC_IP http://webapp.example.com:$IC_HTTP_PORT/
Server address: 10.40.0.33:8080
Server name: webapp-7b7dfbff54-fc6nc
Date: 23/May/2025:10:29:17 +0000
URI: /
Request ID: 7a79e1148996c897c2e0c756ec4fea0e


curl -X POST --resolve webapp.example.com:$IC_HTTP_PORT:$IC_IP http://webapp.example.com:$IC_HTTP_PORT/
<html>
<head><title>503 Service Temporarily Unavailable</title></head>
<body>
<center><h1>503 Service Temporarily Unavailable</h1></center>
<hr><center>nginx/1.27.4</center>
</body>
</html>


curl -X GET --resolve webapp.example.com:$IC_HTTP_PORT:$IC_IP http://webapp.example.com:$IC_HTTP_PORT/ 
Server address: 10.40.0.33:8080
Server name: webapp-7b7dfbff54-fc6nc
Date: 23/May/2025:10:29:23 +0000
URI: /

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

@vepatel vepatel requested review from a team as code owners May 23, 2025 10:31
@github-actions github-actions bot added enhancement Pull requests for new features/feature enhancements documentation Pull requests/issues for documentation go Pull requests that update Go code labels May 23, 2025
Copy link
Contributor

Deploy Preview will be available once build job completes!

Name Link
😎 Deploy Preview https://frontdoor-test-docs.nginx.com/previews/nginx-ingress-controller/7832/

Copy link

codecov bot commented May 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 52.30%. Comparing base (f78b761) to head (4422f90).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7832      +/-   ##
==========================================
+ Coverage   52.29%   52.30%   +0.01%     
==========================================
  Files          90       90              
  Lines       21472    21472              
==========================================
+ Hits        11228    11231       +3     
+ Misses       9774     9772       -2     
+ Partials      470      469       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vepatel vepatel enabled auto-merge (squash) May 23, 2025 13:13
@vepatel vepatel merged commit 88a6a39 into main May 23, 2025
85 checks passed
@vepatel vepatel deleted the feat/add-req-method branch May 23, 2025 13:56
@AlexFenlon AlexFenlon changed the title add request_method to rate-limit policy Add request_method to rate-limit Policy Jun 23, 2025
@AlexFenlon AlexFenlon removed documentation Pull requests/issues for documentation go Pull requests that update Go code labels Jun 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Pull requests for new features/feature enhancements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rate Limit by request method with policy
3 participants