You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Replace the in-process sliding-window rate limiter with a Redis-backed
implementation so per-sender quota state survives adapter restarts.
The new RateLimiter stores timestamps as scores in a sorted set per
sender and runs an atomic Lua script for the check-and-increment hot
path. A 25h key TTL replaces the previous in-memory cleanup goroutine.
Redis errors fail open (consistent with the existing Userli API
fail-open rule) and increment a new
userli_postfix_adapter_ratelimit_backend_errors_total counter; the
former userli_postfix_adapter_tracked_senders gauge has been removed.
REDIS_URL is required at startup. Tests use miniredis instead of the
old in-memory fixture.
Co-Authored-By: Claude <claude@anthropic.com>
Copy file name to clipboardExpand all lines: README.md
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,7 @@ The adapter is configured via environment variables:
16
16
-`POLICY_LISTEN_ADDR`: The address to listen on for policy requests (rate limiting). Default: `:10003`.
17
17
-`METRICS_LISTEN_ADDR`: The address to listen on for metrics. Default: `:10002`.
18
18
-`RATE_LIMIT_MESSAGE`: The rejection message returned when a sender exceeds their quota. Default: `Rate limit exceeded, please try again later`.
19
+
-`REDIS_URL`: Connection URL for Redis (required). Format follows [`redis.ParseURL`](https://pkg.go.dev/github.com/redis/go-redis/v9#ParseURL), e.g. `redis://[user:password@]host:port/db`. Rate-limit state is stored in Redis so it survives restarts.
19
20
20
21
In Postfix, you can configure the adapter using the socketmap protocol like this:
21
22
@@ -48,6 +49,8 @@ The Userli API endpoint `/api/postfix/smtp_quota/{email}` returns:
48
49
49
50
Where `0` means unlimited. If the API is unreachable, messages are allowed (fail-open).
50
51
52
+
Rate-limit state is persisted to Redis (`REDIS_URL`) so it survives restarts. If Redis is unreachable, messages are also allowed (fail-open) and the `userli_postfix_adapter_ratelimit_backend_errors_total` counter is incremented.
53
+
51
54
## Docker
52
55
53
56
You can run the adapter using Docker.
@@ -172,7 +175,7 @@ The adapter exposes Prometheus metrics on `/metrics` (port 10002) and provides h
0 commit comments