apache / apisix

The Cloud-Native API Gateway
https://apisix.apache.org/blog/
Apache License 2.0
14.3k stars 2.49k forks source link

help request: how to configure rate limiting per consumer per route #9965

Closed DGolubets closed 1 year ago

DGolubets commented 1 year ago

Description

I want to enable rate limiting for a particular consumer for a particular route.

So far I didn't find how can that be enabled.

Environment

APISIX install with Helm in k8s. Chart version: apisix-2.1.0 App version: 3.4.0

shreemaan-abhishek commented 1 year ago

Is this similar to your requirement: https://the-asf.slack.com/archives/CUC5MN17A/p1690449611274429?

DGolubets commented 1 year ago

Is this similar to your requirement: https://the-asf.slack.com/archives/CUC5MN17A/p1690449611274429?

I don't have ASF account to check.

shreemaan-abhishek commented 1 year ago

Please join #apisix channel after joining the ASF slack workspace: https://join.slack.com/t/the-asf/shared_invite/zt-1z1cth9wx-2CMIattLWRW5R5ytuNHIgA

Sn0rt commented 1 year ago

hi @DGolubets have you try this feature in req-limit plugin ?

image

https://apisix.apache.org/docs/apisix/plugins/limit-req/

DGolubets commented 1 year ago

Hey,

Please join #apisix channel after joining the ASF slack workspace: https://join.slack.com/t/the-asf/shared_invite/zt-1z1cth9wx-2CMIattLWRW5R5ytuNHIgA

Thanks for the invite

No, my requirement is different, it's more like what I found a bit down the thread there: https://the-asf.slack.com/archives/CUC5MN17A/p1676970398154249

hi @DGolubets have you try this feature in req-limit plugin ?

image

https://apisix.apache.org/docs/apisix/plugins/limit-req/

The problem with keys is that you can only specify the variable name, not the value.

Essentialy what I want is:

ConsumerA -> Route1 -> 10 rps
ConsumerA -> Route2 -> 20 rps
ConsumerB -> Route1 -> 5 rps
ConsumerB -> Route1 -> 5 rps
ConsumerB -> Route2 -> unlimited
ConsumerC -> unlimited
Revolyssup commented 1 year ago

Hey,

Please join #apisix channel after joining the ASF slack workspace: https://join.slack.com/t/the-asf/shared_invite/zt-1z1cth9wx-2CMIattLWRW5R5ytuNHIgA

Thanks for the invite

No, my requirement is different, it's more like what I found a bit down the thread there: https://the-asf.slack.com/archives/CUC5MN17A/p1676970398154249

hi @DGolubets have you try this feature in req-limit plugin ? image https://apisix.apache.org/docs/apisix/plugins/limit-req/

The problem with keys is that you can only specify the variable name, not the value.

Essentialy what I want is:

ConsumerA -> Route1 -> 10 rps
ConsumerA -> Route2 -> 20 rps
ConsumerB -> Route1 -> 5 rps
ConsumerB -> Route1 -> 5 rps
ConsumerB -> Route2 -> unlimited
ConsumerC -> unlimited

Currently rate limit plugin doesn't support per consumer per route, this can be a feature request.

DGolubets commented 1 year ago

I've found the Workflow plugin, which seems to allow me to do what I want, though it only supports limit-count. I think it would be really cool if it supported all the plugins, allowing for complex logic.

shreemaan-abhishek commented 1 year ago

@DGolubets would you mind sharing how you did that? Maybe you can share the route configuration as well.

DGolubets commented 1 year ago

@shreemaan-abhishek I have my route as following:

apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
  name: public-api-route
spec:
  http:
    - name: rule1
      match:
        hosts:
          - test.myhost.com
        paths:
          - /graphql
      backends:
        - serviceName: public-api
          servicePort: 80
      plugins:
        - name: key-auth
          enable: true
        - name: workflow
          enable: true
          config:
            rules:
              - actions:
                  - - limit-count
                    - count: 60
                      rejected_code: 429
                      time_window: 60
                case:
                  - - consumer_name
                    - '=='
                    - test
shreemaan-abhishek commented 1 year ago

I see, thanks for the share. You can close this issue if your problem is resolved.