Skip to content

Add calendar-aligned MONTH rate limit, gated by USE_CALENDAR_MONTH_RATE_LIMIT - #1206

Open
OS-kiranmalsetty wants to merge 3 commits into
envoyproxy:mainfrom
OS-kiranmalsetty:calendar-month-rate-limit
Open

Add calendar-aligned MONTH rate limit, gated by USE_CALENDAR_MONTH_RATE_LIMIT#1206
OS-kiranmalsetty wants to merge 3 commits into
envoyproxy:mainfrom
OS-kiranmalsetty:calendar-month-rate-limit

Conversation

@OS-kiranmalsetty

Copy link
Copy Markdown
Contributor

Summary

  • A unit: month rate limit is currently 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.
  • Adds 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 (DurationUntilReset / reset header).
  • Defaults to false so existing MONTH limits 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: new expiryUntilMonthEnd, MonthExpirationSeconds, MonthStartUnix helpers.
  • src/utils/utilities.go: ExpirationSeconds and CalculateReset take a useCalendarMonth flag and dispatch to the calendar-aware helpers for MONTH only 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 from settings.Settings.UseCalendarMonthRateLimit down to cache-key bucketing, TTL, and reset reporting.
  • test/config/basic_config.yaml: adds a key8 MONTH descriptor for integration test coverage.
  • README documents the new USE_CALENDAR_MONTH_RATE_LIMIT setting.

Test plan

  • go build ./...
  • go vet ./...
  • gofumpt/goimports clean on all changed files
  • go test ./test/... (all packages pass)
  • New unit tests cover: calendar-month cache-key bucketing (Jan 1/Jan 31 same bucket, Feb 1 different), leap-year correctness, and that the flag being false reproduces the legacy fixed-divider behavior exactly (including not consulting the time source at all for MONTH, matching pre-existing behavior)

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant