- Function Description
- Execution Attributes
- Configuration Description
- Configuration Examples
- Distinguish rate limiting based on the request parameter apikey
- Distinguish rate limiting based on the header x-ca-key
- Distinguish rate limiting based on the client IP from the request header x-forwarded-for
- Distinguish rate limiting based on consumers
- Distinguish rate limiting based on key-value pairs in cookies
Function Description
The cluster-key-rate-limit
plugin implements cluster rate limiting based on Redis, suitable for scenarios that require global consistent rate limiting across multiple Higress Gateway instances.
The Key used for rate limiting can originate from URL parameters, HTTP request headers, client IP addresses, consumer names, or keys in cookies.
Execution Attributes
Plugin Execution Phase: default phase
Plugin Execution Priority: 20
Configuration Description
Configuration Item | Type | Required | Default Value | Description |
---|---|---|---|---|
rule_name | string | Yes | - | The name of the rate limiting rule. The Redis key is constructed using rule name + rate limit type + limit key name + actual value of the limit key. |
rule_items | array of object | Yes | - | Rate limiting rule items. The first matching rule_item based on the order under rule_items will trigger the rate limiting, and subsequent rules will be ignored. |
show_limit_quota_header | bool | No | false | Whether to display X-RateLimit-Limit (total requests allowed) and X-RateLimit-Remaining (remaining requests that can be sent) in the response headers. |
rejected_code | int | No | 429 | HTTP status code returned when a request is rate limited. |
rejected_msg | string | No | Too many requests | Response body returned when a request is rate limited. |
redis | object | Yes | - | Redis related configuration. |
Description of configuration fields for each item in rule_items
.
Configuration Item | Type | Required | Default Value | Description |
---|---|---|---|---|
limitby_header | string | No, one of limit_by | - | The name of the HTTP request header from which to retrieve the rate limiting key value. |
limitby_param | string | No, one of limit_by | - | The name of the URL parameter from which to retrieve the rate limiting key value. |
limitby_consumer | string | No, one of limit_by | - | Applies rate limiting based on consumer name without needing to add an actual value. |
limitby_cookie | string | No, one of limit_by | - | The name of the key in the Cookie from which to retrieve the rate limiting key value. |
limitby_per_header | string | No, one of limit_by | - | Matches specific HTTP request headers according to the rules and calculates rate limits for each header. The limit_keys configuration supports regular expressions or . |
limitby_per_param | string | No, one of limit_by | - | Matches specific URL parameters according to the rules and calculates rate limits for each parameter. The limit_keys configuration supports regular expressions or . |
limitby_per_consumer | string | No, one of limit_by | - | Matches specific consumers according to the rules and calculates rate limits for each consumer. The limit_keys configuration supports regular expressions or . |
limitby_per_cookie | string | No, one of limit_by | - | Matches specific cookies according to the rules and calculates rate limits for each cookie. The limit_keys configuration supports regular expressions or . |
limitby_per_ip | string | No, one of limit_by* | - | Matches specific IPs according to the rules and calculates rate limits for each IP. Retrieve via IP parameter name from request headers, defined as from-header-{header name} , e.g., from-header-x-forwarded-for . To get the remote socket IP directly, use from-remote-addr . |
limit_keys | array of object | Yes | - | Configures the limit counts after matching key values. |
Description of configuration fields for each item in limit_keys
.
Configuration Item | Type | Required | Default Value | Description |
---|---|---|---|---|
key | string | Yes | - | Matched key value; types limit_by_per_header , limit_by_per_param , limit_by_per_consumer , limit_by_per_cookie support regular expression configurations (starting with regexp: followed by a regular expression) or (representing all), e.g., regexp:^d. (all strings starting with d); limit_by_per_ip supports configuring IP addresses or IP segments. |
query_per_second | int | No, one of query_per_second , query_per_minute , query_per_hour , query_per_day is optional. | - | Allowed number of requests per second. |
query_per_minute | int | No, one of query_per_second , query_per_minute , query_per_hour , query_per_day is optional. | - | Allowed number of requests per minute. |
query_per_hour | int | No, one of query_per_second , query_per_minute , query_per_hour , query_per_day is optional. | - | Allowed number of requests per hour. |
query_per_day | int | No, one of query_per_second , query_per_minute , query_per_hour , query_per_day is optional. | - | Allowed number of requests per day. |
Description of configuration fields for each item in redis
.
Configuration Item | Type | Required | Default Value | Description |
---|---|---|---|---|
service_name | string | Required | - | Full FQDN name of the Redis service, including service type, e.g., my-redis.dns, redis.my-ns.svc.cluster.local. |
service_port | int | No | 80 for static services; otherwise 6379 | Service port for the Redis service. |
username | string | No | - | Redis username. |
password | string | No | - | Redis password. |
timeout | int | No | 1000 | Redis connection timeout in milliseconds. |