feat(gateway): implement routing, auth, and logging for API gateway #43
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.
feat(gateway): implement routing, auth, and logging for API gateway
Summary
This PR implements three core API gateway components for issue #27:
Circuit Breaker (
circuit_breaker.lua): Redis-backed fault tolerance with CLOSED/OPEN/HALF_OPEN state machine. Each backend service has configurable failure thresholds, success thresholds for recovery, and timeout periods. Fails open if Redis is unavailable.GNAP Authentication (
gnap_auth.lua): Gateway-level token introspection with role-based access control (ADMIN, MODERATOR, USER). Caches validated tokens in Redis for 5 minutes. Defines public endpoints that bypass auth and role requirements per endpoint pattern.Request ID Tracking (
request_id.lua): UUID v4 request ID generation with X-Request-ID, X-Correlation-ID, and X-Span-ID header propagation for distributed tracing.nginx config updates: All upstream blocks now use
least_connload balancing with enhanced keepalive settings. All location blocks integrate circuit breaker checks, rate limiting, and request ID tracking. Enhanced JSON log format includes tracing fields. New/internal/circuit-statusendpoint for monitoring.Note: Prometheus metrics integration was intentionally excluded to avoid merge conflicts with another session working on that component.
Review & Testing Checklist for Human
nginx -tinside the OpenResty container to verify configuration is valid - this was NOT done before PR creationgnap_auth.luarequiresresty.httpmodule - confirm it's installed in the OpenResty Docker image or add it to the Dockerfile/gnap/introspectendpoint for token validation to workgnap_auth.lua:49-62: Verify these match the actual public endpoints your API should expose without authenticationRecommended Test Plan
docker compose logs nginx)/internal/circuit-statusendpoint returns service statesNotes