feat: make gateway rate limiter store pluggable#356
Closed
Agbasimere wants to merge 3 commits into
Closed
Conversation
|
@Agbasimere Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Closes: #305
Summary
InMemoryRateLimiteras the default fallback for local/dev useWhat Changed
Rate limiter
RateLimiterStoreabstraction insrc/services/rateLimiter.tsRateLimitResultshapeInMemoryRateLimiteras the default implementationPostgresRateLimiterStorewith lazy table creation and transactional bucket updatesWiring
RATE_LIMIT_MAX_REQUESTSRATE_LIMIT_WINDOW_MSRATE_LIMIT_STORERATE_LIMIT_PG_TABLEsrc/index.tssrc/routes/gatewayRoutes.tsandsrc/routes/proxyRoutes.tsto await limiter checksDocs
.env.exampleREADME.mdBehavior
retryAfterMsbehavior is unchangedRATE_LIMIT_STORE=postgres, limits are shared across instancesTesting
npm run typechecknpx jest --runInBand --forceExit src/services/rateLimiter.test.tsnpx jest --runInBand --forceExit src/config/index.test.ts src/config/env.test.ts src/routes/gatewayRoutes.test.tsnpx jest --runInBand --forceExit --coverage --collectCoverageFrom=src/services/rateLimiter.ts src/services/rateLimiter.test.tsTest Notes
src/services/rateLimiter.tscoverage:100%95.23%100%100%npm test -- src/services/rateLimiter.test.tshit a local Jest workerspawn EPERMissue in this environment, so verification used the equivalent--runInBandformRisk / Review Notes
check(...)