apisix icon indicating copy to clipboard operation
apisix copied to clipboard

help request: limit-count plugin

Open MalWalters opened this issue 3 years ago • 5 comments

Description

Hi, we have a use case where we would like to use APISix to provide a prepaid way to access our API. e.g. a client would subscribe for 12 months or 1,000,000 API calls and it looks like the limit-count plugin supports this. I have two questions though.

Does it make this distinction per customer? We are anticipate using the X-API-Key for authentication and would be ideal if we could group by this.

Is there a way that we can expose the usage count for the client via a GET call so they can assess and budget their usage?

Thanks in advance

Environment

  • APISIX version (run apisix version):
  • Operating system (run uname -a):
  • OpenResty / Nginx version (run openresty -V or nginx -V):
  • etcd version, if relevant (run curl http://127.0.0.1:9090/v1/server_info):
  • APISIX Dashboard version, if relevant:
  • Plugin runner version, for issues related to plugin runners:
  • LuaRocks version, for installation issues (run luarocks --version):

MalWalters avatar Aug 01 '22 23:08 MalWalters

Does it make this distinction per customer?

We can set the key to be $consumer_name to distinguish the customer, e.g.:

    "plugins": {
        "limit-count": {
            "count": 2,
            "time_window": 60,
            "rejected_code": 503,
            "key": "$consumer_name"
        }
    },

for more details, ref: https://github.com/apache/apisix/blob/master/docs/en/latest/plugins/limit-count.md#attributes

X-API-Key is used for the admin API of APISIX. It is not related to customs and should not be used to count requests generated by customs.

Is there a way that we can expose the usage count for the client via a GET call so they can assess and budget their usage?

None. But you can add this functionality based on open source plugins.

tzssangglass avatar Aug 02 '22 01:08 tzssangglass

Thanks @tzssangglass , much appreciated. Do you know of any specific plugins that support the functionality required?

MalWalters avatar Aug 02 '22 04:08 MalWalters

@MalWalters By the way, you should be careful about the quota sharing; by default, the quote is calculated per instance. It's not shared among the cluster.

Also, use $consumer_name as the key doesn't allow you to configure different quotas for different consumers.

tokers avatar Aug 02 '22 09:08 tokers

Thanks @tzssangglass , much appreciated. Do you know of any specific plugins that support the functionality required?

You need to implement such functionality yourself.

tzssangglass avatar Aug 02 '22 10:08 tzssangglass

@tokers thanks for the heads up. That should be OK we'd be looking at going with one instance for the POC and load test to assess performance limitations.

MalWalters avatar Aug 02 '22 10:08 MalWalters

@MalWalters : We met the same requirement, how do you make it finally?

exotfboy avatar Aug 17 '22 05:08 exotfboy

This issue has been marked as stale due to 350 days of inactivity. It will be closed in 2 weeks if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the [email protected] list. Thank you for your contributions.

github-actions[bot] avatar Aug 02 '23 10:08 github-actions[bot]

This issue has been closed due to lack of activity. If you think that is incorrect, or the issue requires additional review, you can revive the issue at any time.

github-actions[bot] avatar Aug 17 '23 10:08 github-actions[bot]