Add calendar-aligned MONTH rate limit, gated by USE_CALENDAR_MONTH_RATE_LIMIT - #1206
Open
OS-kiranmalsetty wants to merge 3 commits into
Open
Add calendar-aligned MONTH rate limit, gated by USE_CALENDAR_MONTH_RATE_LIMIT#1206OS-kiranmalsetty wants to merge 3 commits into
OS-kiranmalsetty wants to merge 3 commits into
Conversation
…TE_LIMIT A unit: month rate limit is computed as a fixed 60*60*24*30 second window counted from the Unix epoch, so it neither aligns with real calendar months nor accounts for months of different lengths (RDGRS-1999). Add a USE_CALENDAR_MONTH_RATE_LIMIT setting (default false) that, when enabled, buckets MONTH cache keys by UTC calendar month, sets their TTL/expiration to the actual time remaining until month end, and reports that same value as the reset duration. Defaults to false so existing MONTH limits keep their current reset behavior unless explicitly opted in. Signed-off-by: kiran malsetty <kiran.malsetty@outsystems.com>
Signed-off-by: kiran malsetty <kiran.malsetty@outsystems.com>
Signed-off-by: kiran malsetty <kiran.malsetty@outsystems.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
unit: monthrate limit is currently computed as a fixed60*60*24*30second window counted from the Unix epoch, so it neither aligns with real calendar months nor accounts for months of different lengths.USE_CALENDAR_MONTH_RATE_LIMITsetting (default"false") that, when enabled, bucketsMONTHcache keys by UTC calendar month, sets their TTL/expiration to the actual time remaining until month end, and reports that same value as the reset duration (DurationUntilReset/ reset header).falseso existingMONTHlimits keep their current (legacy, fixed 30-day rolling window) reset behavior unless explicitly opted in — this avoids silently changing when existing users' MONTH limits reset.src/utils/time.go: newexpiryUntilMonthEnd,MonthExpirationSeconds,MonthStartUnixhelpers.src/utils/utilities.go:ExpirationSecondsandCalculateResettake auseCalendarMonthflag and dispatch to the calendar-aware helpers forMONTHonly when it's true.src/limiter/cache_key.go,src/limiter/base_limiter.go,src/redis/fixed_cache_impl.go,src/memcached/cache_impl.go,src/redis/cache_impl.go,src/service/ratelimit.go: thread the flag fromsettings.Settings.UseCalendarMonthRateLimitdown to cache-key bucketing, TTL, and reset reporting.test/config/basic_config.yaml: adds akey8MONTH descriptor for integration test coverage.USE_CALENDAR_MONTH_RATE_LIMITsetting.Test plan
go build ./...go vet ./...gofumpt/goimportsclean on all changed filesgo test ./test/...(all packages pass)falsereproduces the legacy fixed-divider behavior exactly (including not consulting the time source at all for MONTH, matching pre-existing behavior)