feat: circuit breaker around /api/impersonate downstream calls - #716
Open
victorocheje wants to merge 1 commit into
Open
feat: circuit breaker around /api/impersonate downstream calls#716victorocheje wants to merge 1 commit into
victorocheje wants to merge 1 commit into
Conversation
- Add src/lib/circuitBreaker.ts: generic per-name CLOSED/OPEN/HALF_OPEN state machine with CircuitOpenError, getCircuitBreaker(), forceCircuitStateForTests(), and resetCircuitBreakersForTests() - Update src/routes/admin/users/impersonate.ts: wrap signAccessToken + audit DB writes inside breaker.execute(); CircuitOpenError maps to HTTP 503 with retryAfterMs in the response body - Add tests/circuitBreaker.test.ts: 36 unit tests covering all state transitions, error types, helpers, and snapshot accuracy - Add tests/impersonateCircuitBreaker.test.ts: focused integration tests covering CLOSED/OPEN/HALF_OPEN scenarios, threshold tripping, auth guard passthrough, and 503 response shape - Fix pre-existing corruptions: dead z.object() block in env.ts and duplicate/broken implementation in errorHandler.ts; fix wrong JWT secret fallback in adminImpersonate.test.ts - Add docs/impersonate-circuit-breaker.md: state machine diagram, default config, HTTP response reference, and runbook
|
@victorocheje 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.
Add src/lib/circuitBreaker.ts: generic per-name CLOSED/OPEN/HALF_OPEN state machine with CircuitOpenError, getCircuitBreaker(), forceCircuitStateForTests(), and resetCircuitBreakersForTests()
Update src/routes/admin/users/impersonate.ts: wrap signAccessToken + audit DB writes inside breaker.execute(); CircuitOpenError maps to HTTP 503 with retryAfterMs in the response body
Add tests/circuitBreaker.test.ts: 36 unit tests covering all state transitions, error types, helpers, and snapshot accuracy
Add tests/impersonateCircuitBreaker.test.ts: focused integration tests covering CLOSED/OPEN/HALF_OPEN scenarios, threshold tripping, auth guard passthrough, and 503 response shape
Fix pre-existing corruptions: dead z.object() block in env.ts and duplicate/broken implementation in errorHandler.ts; fix wrong JWT secret fallback in adminImpersonate.test.ts
Add docs/impersonate-circuit-breaker.md: state machine diagram, default config, HTTP response reference, and runbook
closes #593