-
Notifications
You must be signed in to change notification settings - Fork 370
API Manager: Overriding rate limits at consumer level
- API level rate limits
- Adding consumer level rate limits
- Removing consumer level rate limits
- Different rate limits per environment
There are rate limits at API level. These rate limits are applicable for all consumers. Example
# ansible/inventories/<env>/group_vars/<env>-kong-api
# Default Rate limits
small_rate_limit_per_hour: 100
medium_rate_limit_per_hour: 1000
large_rate_limit_per_hour: 10000
Step 1: Configure the rate limit values
You can override the consumer rate limits by configuring
# ansible/inventories/<env>/group_vars/<env>-kong-api
kong_consumers:
- username: api-management-test-user
...
rate_limits:
- api: createContent
config.hour: 3000
config.limit_by: credential
- api: updateContent
config.hour: 6000
config.limit_by: credential
- api: readContent
config.hour: 9000
config.limit_by: credential
If you need similar rate limit rules for multiple consumers, duplicating the above code becomes unmaintainable. For managing this better way, we have defined a way you can define these rate limits in central place and then use it across multiple consumes
# ansible/group_vars/kong-api
premium_consumer_small_rate_limit_per_hour: 1000
premium_consumer_medium_rate_limit_per_hour: 10000
premium_consumer_large_rate_limit_per_hour: 100000
# ansible/group_vars/kong-api
premium_consumer_rate_limits:
- api: createContent
config.hour: "{{ premium_consumer_small_rate_limit_per_hour }}"
config.limit_by: credential
- api: updateContent
config.hour: "{{ premium_consumer_medium_rate_limit_per_hour }}"
config.limit_by: credential
- api: readContent
config.hour: "{{ premium_consumer_large_rate_limit_per_hour }}"
config.limit_by: credential
Now you re use these rate limits for multiple consumers
# ansible/inventories/<env>/group_vars/<env>-kong-api
kong_consumers:
- username: api-management-test-user
.....
rate_limits: "{{ premium_consumer_rate_limits }}"
- username: another-user
.....
rate_limits: "{{ premium_consumer_rate_limits }}"
Step 2: Run the jenkins job <env_name>/AM_Onboard_Consumers
Step 1: Configure the rate limit to be removed
In each rate limit definition for consume you should use state: absent
to remove the previous rate limit for the consumer for that API
# ansible/group_vars/kong-api
premium_consumer_rate_limits:
- api: createContent
state: absent
Step 2: Run the jenkins job <env_name>/AM_Onboard_Consumers
If you want to have different rate limit values for each environment. You add below variables and override in ansible/inventories/<env>/group_vars/<env>-kong-api
# Example in staging-kong-api you have
premium_consumer_small_rate_limit_per_hour: 5000
premium_consumer_medium_rate_limit_per_hour: 50000
premium_consumer_large_rate_limit_per_hour: 500000