feat: add per-tenant token bucket rate limiting middleware (closes #115)#208
Merged
elizabetheonoja-art merged 1 commit intoJul 21, 2026
Conversation
…ility-Protocol#115) - Add TenantRateLimiter with per-tenant token buckets, configurable limits, override support, and background tenant pruning - Add tenant_rate_limit_layer Axum middleware that extracts tenant from X-Tenant-ID header (falls back to _anonymous) - Add /api/v1/tenant-rate-limiter/status endpoint for observability - Integrate into AppState, router, and main.rs - Add comprehensive unit and integration tests Implements: Utility-Protocol#115
elizabetheonoja-art
merged commit Jul 21, 2026
2b56712
into
Utility-Protocol:main
2 of 4 checks passed
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
Implements per-tenant token bucket rate limiting middleware for the API (Issue #115).
Changes
src/api/middleware.rs— AddedTenantRateLimiterstruct with per-tenant independent token buckets, configurable limits per tenant with override support, and periodic pruning of inactive tenants. Addedtenant_rate_limit_layerAxum middleware that extracts tenant identity from theX-Tenant-IDheader (falls back to_anonymous).src/api/mod.rs— AddedTenantRateLimitertoAppStatewithFromRefimpl.src/api/router.rs— Wired in thetenant_rate_limit_layermiddleware (before existing IP-based rate limiter) and added/api/v1/tenant-rate-limiter/statusendpoint.src/api/handlers.rs— Addedtenant_rate_limiter_statushandler returning per-tenant limits and rejection counts.src/main.rs— InitializedTenantRateLimiterwith default 1000 tokens/sec.tests/rate_limit_integration.rs— Added integration tests for tenant-specific buckets, separate bucket isolation, and anonymous fallback.How it works
X-Tenant-IDheader identifying their tenantTenantRateLimiter::set_tenant_limit()(e.g., for premium tenants)_anonymousbucketCloses #115