Repository navigation
feat(ratelimit): enforce limits across replicas sharing a database - #1339
Draft
SantiagoDePolonia wants to merge 2 commits into
Draft
SantiagoDePolonia wants to merge 2 commits into
SantiagoDePolonia wants to merge 2 commits into
Conversation
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This branch was successfully deployed
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.
Description
x-ratelimit-*headers,/v1/usage, and the routing probe all check local + remote. The remote view is refreshed on the flush loop (save, then load) and seeded from the load at Start. The request path never calls the database, and admission adds no allocations (perf guard passes).concurrent=1. A strict per-request mode is left for a follow-up.updated_atat or after the previous load minus a 10s overlap, which covers slow commits and clock skew. Rows are merged into a cache keyed by row identity, with a full reload once a minute as a backstop. A newupdated_atindex serves this on SQLite, PostgreSQL, and MongoDB. Rows from dead writers stay cached until their windows roll out. A reset or epoch change clears local and remote counts for the key on every replica, and cached rows of the old epoch are skipped.in_flightcolumn/field), and publishes 0 once when the count drops. Peers count a row only while it is fresh: saved within max(3 × flush interval, 5s) by the reader's clock, so replica clocks should be NTP-synced. A crashed replica's slots therefore free within that bound. Stores keep in-flight rows for a day, so pruning never races the heartbeat. In-flight gauges ignore the epoch, matching how a local reset leaves them alone.RATE_LIMITS_FLUSH_INTERVALsets the sharing cadence, and0means counts load at start only. A single instance behaves as before, except that after a crash (not a clean shutdown), a restart within ~5s sees the crashed run's last published in-flight slots until they go stale.rate_limit_window_snapshots, the unreleased table from fix(ratelimit): keep per-replica counter snapshots so replicas stop overwriting each other #1296, plus an index. v0.2.0 never reads that table, so rolling upgrades are unaffected.Tests: two-replica shared limit (requests, tokens, headers, routing probe), restart across four generations without inflation, reset and mode change clearing peer counts on every replica, peer in-flight counting and expiry on an injected clock, incremental load / full reload / roll-out eviction, failed-save retry, and the shared store suite (since filter, save stamps, in-flight round trip and retention) on SQLite, PostgreSQL and MongoDB. Mutation-checked: 15 targeted mutations, all caught.
make test-race, lint,go fix, the hot-path perf guard and mint validate pass.