Skip to content

feat: implement /api/logs reverse proxy with per-endpoint circuit bre… - #1007

Merged
greatest0fallt1me merged 4 commits into
CalloraOrg:mainfrom
TechBroAfrica:feature/b079-per-endpoint-circuit-breaker
Jul 29, 2026
Merged

feat: implement /api/logs reverse proxy with per-endpoint circuit bre…#1007
greatest0fallt1me merged 4 commits into
CalloraOrg:mainfrom
TechBroAfrica:feature/b079-per-endpoint-circuit-breaker

Conversation

@TechBroAfrica

Copy link
Copy Markdown

closes #944

Here is a draft for your PR message. You can copy and paste this directly into your GitHub pull request:


Title: feat: add per-endpoint circuit breaker for downstream calls on /api/logs

Description:
This PR introduces a dedicated proxy router for downstream logging services with per-endpoint circuit breaking, successfully fulfilling the requirements for the GrantFox FWC26 campaign.

The /api/logs endpoint acts as a resilient proxy that fast-fails with an HTTP 503 Service Unavailable if the downstream service experiences an outage.

🚀 Key Changes

  • src/routes/logs.ts: Added a new reverse proxy router matching ALL /api/logs/:endpoint(*)?. It tracks downstream failures dynamically per-endpoint using the BreakerRegistry.
  • src/lib/circuitBreaker.ts: Added an optional onOpenError callback to the CircuitBreakerConfig. This safely enables the logs route to fast-fail with a customizable ServiceUnavailableError (503) without mutating the global 502 Bad Gateway behaviors currently expected for Horizon endpoints.
  • src/index.ts: Registered the new logsRouter centrally.
  • src/routes/logs.test.ts: Implemented a comprehensive test suite that verifies the circuit breaker correctly triggers the 503 Service Unavailable response after reaching the failure threshold (5 attempts).
  • docs/api-logs.md: Created new documentation explicitly covering the expected API interface, parameters, and its fast-fail circuit breaker behavior.

✅ Testing & Validation

  • Full unit tests implemented (npm test -- src/routes/logs.test.ts).
  • Code style strictly adheres to the repo's lint configuration (no unused variables).
  • No any type violations introduced.
  • Tested the fast-fail 503 behavior natively against mock setups.

@drips-wave

drips-wave Bot commented Jul 28, 2026

Copy link
Copy Markdown

@TechBroAfrica 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! 🚀

Learn more about application limits

@TechBroAfrica

Copy link
Copy Markdown
Author

@greatest0fallt1me kindly review, conflict resolve.

@greatest0fallt1me
greatest0fallt1me merged commit fece11b into CalloraOrg:main Jul 29, 2026
1 check passed
@greatest0fallt1me

Copy link
Copy Markdown
Contributor

CI green, LGTM ✨ merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add per-endpoint circuit breaker for downstream calls on /api/logs [b#079]

3 participants