Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/1273 rate limiting redis #1285

Merged
merged 2 commits into from
Mar 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 10 additions & 34 deletions doc/content/reference/rate-limiting/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,42 +95,18 @@ When rate limiting is enabled, the following headers are added to all HTTP and g
- `X-Rate-Limit-Reset`: Seconds until the rate limiter resets.
- `X-Rate-Limit-Retry`: Seconds the client should wait before retrying the request.

## Example configuration
## Rate limiting providers

The default rate limiting provider for {{% tts %}} is `memory`. When using this provider the state of rate limiting is stored locally on each instance. The drawback of using it is inconsistent rate limiting state. The `redis` provider eliminates this problem by storing a shared rate limiting state for all instances.

| Provider | State |
| -------- | ------------ |
| `memory` | per instance |
| `redis` | shared |

Enable rate limiting by adding the following configuration to your `ttn-lw-stack.yml`. Make sure to alter the values accordingly so that they match your deployment needs.
To enable `redis` rate limiting provider you can set it in rate limiting configuration.

```yaml
rate-limiting:
profiles:
- name: HTTP servers
max-per-min: 30
associations:
- http
- name: Application downlink traffic
max-per-min: 10
associations:
- as:down:web
- as:down:mqtt
- grpc:method:/ttn.v3.lorawan.v3.AppAs/DownlinkQueuePush
- grpc:method:/ttn.v3.lorawan.v3.AppAs/DownlinkQueueReplace
- name: Gateway connections
max-per-min: 5
associations:
- gs:accept:mqtt
- gs:accept:ws
- grpc:stream:accept:/ttn.lorawan.v3.GtwGs/LinkGateway
- name: gRPC API
max-per-min: 60
associations:
- grpc:method
- grpc:stream:accept
- name: Override rate for uplink simulation
max-per-min: 5
associations:
- grpc:method:/ttn.lorawan.v3.AppAs/SimulateUplink
- name: Gateway uplink traffic
max-per-min: 1000
max-burst: 1500
associations:
- gs:up
provider: `redis`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you set the provider along with profiles or?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, provider is one of the possible options for rate-limiting, so you can use

rate-limiting:
  provider: ...
  profiles:
    - ...
    - ...

but the same example (that was removed) is available at

```yaml
rate-limiting:
profiles:
- name: HTTP servers
max-per-min: 30
associations:
- http
- name: User login
max-per-min: 10
associations:
- http:account
- name: Create new users
max-per-min: 10
associations:
- grpc:method:/ttn.lorawan.v3.UserRegistry/Create
- name: Application downlink traffic
max-per-min: 10
associations:
- as:down:web
- as:down:mqtt
- grpc:method:/ttn.v3.lorawan.v3.AppAs/DownlinkQueuePush
- grpc:method:/ttn.v3.lorawan.v3.AppAs/DownlinkQueueReplace
- name: Gateway connections
max-per-min: 5
associations:
- gs:accept:mqtt
- gs:accept:ws
- grpc:stream:accept:/ttn.lorawan.v3.GtwGs/LinkGateway
- name: gRPC API
max-per-min: 60
associations:
- grpc:method
- grpc:stream:accept
- name: Override rate for uplink simulation
max-per-min: 5
associations:
- grpc:method:/ttn.lorawan.v3.AppAs/SimulateUplink
- name: Gateway uplink traffic
max-per-min: 1000
max-burst: 1500
associations:
- gs:up
```

```
Loading