Allow users to define the week start day for week-based rate limit setups
Maintainers usually reply within 3 days
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 85/100
Research direction
The change follows the existing pattern for calendar month rate limits. First review the USE_CALENDAR_MONTH_RATE_LIMIT implementation in src/utils/time.go and the calendar branch of CacheKeyGenerator.GenerateCacheKey in src/limiter/cache_key.go to understand the expected structure. Add the new WEEK_RATE_LIMIT_START_DAY environment variable, update the weekly bucket calculation to snap to the configured weekday instead of the Unix epoch Thursday boundary, and add tests for both default and custom start day scenarios.
Written by the indexing model from the issue text.
Description
BackendTrafficPolicy now supports Week as a RateLimitUnit (see https://github.com/envoyproxy/gateway/pull/9693).
This means the weekly rate-limit window is anchored to Unix epoch boundaries. As a result, the window resets on Thursday 00:00 UTC - date/time users cannot modify.
Root
in envoyproxy/ratelimit, the cache key bucket is computed as
// src/limiter/cache_key.go
divider := utils.UnitToDivider(limit.Limit.Unit) // 604800 for WEEK
bucketStart = (now / divider) * divider
Unix epoch 0 (1970-01-01) was a thursday so integer division snaps to a Thursday.
Proposal
(after discussing the issue during 5th Oct envoy weekly meeting)
This is already solved for MONTH. The ratelimit service has USE_CALENDAR_MONTH_RATE_LIMIT (env flag), MonthStartUnix() / MonthExpirationSeconds(), helpers in src/utils/time.go here and a calendar branch in CacheKeyGenerator.GenerateCacheKey
- Add a single env var
WEEK_RATE_LIMIT_RESET_DAYto the ratelimit service - When unset (default): legacye behaviour is preserved - weekly windows continue to reset on Thursday
- When set to a weekday (Monday... Sunday) - the weekly rate-limit windows reset on that weekday at 00:00 UTC
The behaviour is similarly designed to the USE_CALENDAR_MONTH_RATE_LIMIT optional env var
Originally: https://github.com/envoyproxy/gateway/issues/10181
But closed and opened this upon the discussions during the 5th Oct meeting
The discussions around the feature were positive - I will look to raise a PR in the coming days.
- Dominant language
- Go
- Stars
- 2.7k
- Forks
- 544
- Avg merge
- 4d 20h
- Merged PRs (30d)
- 10
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from envoyproxy/ratelimit
-
/healthcheck always returns 500 with BACKEND_TYPE=memcache since #1144 (Redis health component starts unhealthy)Possibly taken @ajaykr0905 claimed this 2 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
envoyproxy/ratelimit#1284 ·
Maintainers usually reply within 3 days
-
DogStatsD sink appends STATSD_PORT to unix:// addresses, breaking Unix Domain Socket supportPossibly taken A pull request linked to this issue is open or already merged. Openstale
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
envoyproxy/ratelimit#1223 · 3 comments ·
Maintainers usually reply within 3 days
-
Validate Valkey as a Redis-protocol backend for the rate limit servicePossibly taken A pull request linked to this issue is open or already merged. Openstale
Difficulty 4/5 3-5 days Newbie friendliness 48/100
envoyproxy/ratelimit#1247 · 1 comment · 1 reaction ·
Maintainers usually reply within 3 days
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
envoyproxy/ratelimit#1139 · 9 comments · 3 reactions ·
Maintainers usually reply within 3 days
-
help wanted
Difficulty 4/5 3-5 days Newbie friendliness 25/100
envoyproxy/ratelimit#358 · 3 comments ·
Maintainers usually reply within 3 days
All issues in envoyproxy/ratelimit
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
blinklabs-io/dingo#5636 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
JetBrains/youtrack-cli#130 ·
Maintainers usually reply within 1 day
-
kind/bug needs-triage sig/release
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
kubernetes/kubernetes#143392 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 61/100
Maintainers usually reply within 1 day
-
stage-fail
Difficulty 1/5 Under an hour Newbie friendliness 72/100
siyuan-note/bazaar#2405 ·
Maintainers usually reply within 1 day