Api rate limiting - #113
Open
gloskull wants to merge 2 commits into
Open
Conversation
…tenants Implement per-tenant token-bucket rate limiting
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.
Motivation
Description
src/rate_limit.rsimplementingRateLimitConfig,TenantRateLimiter,TenantBucket,BucketSnapshot,RateLimitMetrics, andRateLimitDecisionwith saturating refill math, per-tenant isolation, retry-after calculation, and defaults (DEFAULT_REFILL_RATE_PER_SECOND,DEFAULT_BURST_CAPACITY,CRITICAL_PATH_P99_BUDGET_MS,AVAILABILITY_TARGET_BPS).pub mod rate_limit;insrc/lib.rsso consumers can embed the limiter viasorosusu_contracts::rate_limit.tests/rate_limit_test.rsthat validates burst enforcement, tenant isolation, capped refill, retry-after rounding, clock-regression safety, snapshots/metrics, and invalid configuration rejection.RATE_LIMITING_ISSUE_73.mddescribing architecture, monitoring/alerting fields, blue-green/canary rollout runbook, and security notes for tenant ID handling.Testing
cargo test --test rate_limit_testand all rate-limiter unit tests passed (8/8 tests OK).cargo testfor the full suite which exercised the crate; the new rate-limit tests passed but the overall run failed due to existingpool_managerSoroban storage tests that requireenv.as_contract()(17 failing tests) and are unrelated to the rate-limiter changes.Closes #73