Edge Limiting is sharing the hits across windows

29 Views Asked by At

I have configured the edge limiting policy (Fixed window limiters) for a service that has 2 Rest APIs and each has a different rate limit configured. But while hitting the first API the limit is getting affected for both the APIs.

Version: 3.8.0

Steps To Reproduce
  1. Configuration:
"policy_chain": [
  {
    "name": "rate_limit",
    "version": "builtin",
    "configuration": {
      "limits_exceeded_error": {
        "status_code": 429,
        "error_handling": "exit"
      },
      "configuration_error": {
        "status_code": 500,
        "error_handling": "exit"
      },
      "fixed_window_limiters": [
        {
          "window": 60,
          "condition": {
            "combine_op": "and",
            "operations": [
              {
                "op": "==",
                "right": "/first-endpoint",
                "left_type": "liquid",
                "left": "{{uri}}",
                "right_type": "plain"
              }
            ]
          },
          "key": {
            "scope": "service",
            "name": "{{ jwt.sub }}",
            "name_type": "liquid"
          },
          "count": 10
        },
        {
          "window": 60,
          "condition": {
            "combine_op": "and",
            "operations": [
              {
                "op": "==",
                "right": "/second-endpoint",
                "left_type": "liquid",
                "left": "{{uri}}",
                "right_type": "plain"
              }
            ]
          },
          "key": {
            "scope": "service",
            "name": "{{ jwt.sub }}",
            "name_type": "liquid"
          },
          "count": 20
        }
      ]
    }
  }
]
  1. Hit both endpoints sequentially 21 times in a minute.
Current Result
Endpoint Value Configured Hits Allowed
/first-endpoint 10 5
/second-endpoint 20 15

The 6th hit of the first-endpoint fails and gives 429 too many requests and the 16th hit of the second-endpoint fails and gives 429 too many requests.

Expected Result
Endpoint Value Configured Hits Allowed
/first-endpoint 10 10
/second-endpoint 20 20

The 11th hit of the first-endpoint should fail and give 429 too many requests and the 21st hit of the second-endpoint should fail and give 429 too many requests

Limit reducing pattern
Hits /first-endpoint (limit after hit) /second-endpoint (limit after hit)
1 8 18
2 6 16
3 4 14
4 2 12
5 0 10
6 too many requests 9
7 too many requests 8
8 too many requests 7
9 too many requests 6
10 too many requests 5
11 too many requests 4
12 too many requests 3
13 too many requests 2
14 too many requests 1
15 too many requests 0
16 too many requests too many requests
0

There are 0 best solutions below