request_api_key_limiter

request_api_key_limiter #

Description #

The request_api_key_limiter filter is used to control traffic by API key.

Configuration Example #

A configuration example is as follows:

flow:
  - name: rate_limit_flow
    filter:
     - request_api_key_limiter:
         id:
           - VuaCfGcBCdbkQm-e5aOx
         max_requests: 1
         action: drop # retry or drop
         message: "your api_key reached our limit"

The above configuration controls the traffic with the API ID of VuaCfGcBCdbkQm-e5aOx and the allowable maximum QPS is 1 per second.

➜  ~ curl localhost:8000 -H "Authorization: ApiKey VnVhQ2ZHY0JDZGJrUW0tZTVhT3g6dWkybHAyYXhUTm1zeWFrdzl0dk5udw==" -v
* Rebuilt URL to: localhost:8000/
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8000 (#0)
> GET / HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/7.54.0
> Accept: */*
> Authorization: ApiKey VnVhQ2ZHY0JDZGJrUW0tZTVhT3g6dWkybHAyYXhUTm1zeWFrdzl0dk5udw==
> 
< HTTP/1.1 429 Too Many Requests
< Server: INFINI
< Date: Mon, 12 Apr 2021 15:14:52 GMT
< content-type: text/plain; charset=utf-8
< content-length: 30
< process: request_api_key_limiter
< 
* Connection #0 to host localhost left intact
your api_key reached our limit% 

Parameter Description #

NameTypeDescription
idarrayIDs of APIs that will participate in traffic control. If this parameter is not set, all API keys will participate in traffic control.
intervalstringInterval for evaluating whether traffic control conditions are met. The default value is 1s.
max_requestsintMaximum request count limit in the interval
max_bytesintMaximum request traffic limit in the interval
actionstringProcessing action after traffic control is triggered. The value can be set as retry or drop and the default value is retry.
statusstringStatus code returned after traffic control conditions are met. The default value is 429.
messagestringRejection message returned for a request, for which traffic control conditions are met
retry_intervalintInterval for traffic control retry, in milliseconds. The default value is 10.
max_retry_timesintMaximum retry count in the case of traffic control retries. The default value is 1000.
failed_retry_messagestringRejection message returned for a request, for which the maximum retry count has been reached