Rate Limiter (Beta)
| Block name | Context | Label |
|---|---|---|
beta_rate_limiter | Definitions Block | required |
Rate Limier is a beta feature that lets you configure rate limiting for your gateway. It is defined in the
definitions block and can be referenced in all access control attributes
by its required label.
Example
server {
endpoint "/ip_rate/**" {
access_control = ["ip_rate"]
response {
json_body = {
ok = true
}
}
}
endpoint "/jwt_rate/**" {
access_control = ["my_jwt", "jwt_rate"]
response {
json_body = {
ok = true
}
}
}
}
definitions {
beta_rate_limiter "ip_rate" {
period = "60s"
per_period = 5
period_window = "sliding"
key = request.remote_ip
}
jwt "my_jwt" {
#...
}
beta_rate_limiter "jwt_rate" {
period = "100s"
per_period = 1
# period_window = "fixed"
key = request.context.my_jwt.sub
}
}
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
custom_log_fields | object | - | Log fields for custom logging. Inherited by nested blocks. |
key | string | - | The expression defining which key to be used to identify a visitor. |
per_period | number | - | Defines the number of allowed requests in a period. |
period | duration | - | Defines the rate limit period. |
period_window | string | "sliding" | Defines the window of the period. A fixed window permits per_period requests within period. After the period has expired, another per_period request is permitted. The sliding window ensures that only per_period requests are sent in any interval of length period. |
Duration
Values of type duration are provided as number string followed by a unit listed below.
Example: timeout = "300s"
| Duration units | Description |
|---|---|
ns | nanoseconds |
us (or µs) | microseconds |
ms | milliseconds |
s | seconds |
m | minutes |
h | hours |
Nested Blocks
| Name | Description |
|---|---|
error_handler | Configures an error handler (zero or more). |