Request Flow
Responsibility
Describe the end-to-end path of a management request (e.g. a dashboard click that creates a flag) from the browser to the database and back, so a reader can correlate logs and metrics across the two services.
Path
- Browser sends
POST /api/flagsto the frontend (host port 8080). - Frontend mux matches
/api/→newProxy(internal/web/server.go). - Proxy director strips
/api, rewrites path to/flags, and setsX-Request-IDfrom the gateway context. - Request traverses the backend middleware chain (request id, recovery,
logging, metrics) and reaches
FlagsHandler.Create. - Handler decodes/validates, calls
Store.Create, re-reads the row, returns JSON. - Response flows back through the backend middleware (metrics recorded, access log emitted) to the proxy.
- Proxy
ModifyResponsedeletes the backend'sX-Request-IDcopy; gateway's own id is already on the response. - Browser receives the JSON.
Correlation
A single X-Request-ID appears in: the gateway access log, the backend access
log, the backend error logs (on failure), and both Prometheus scrape series are
labeled by path. This makes a dashboard click traceable end to end.
Failure behavior
- Backend unreachable: proxy
ErrorHandlerreturns502 Bad Gatewaywith{"error":"control plane backend unreachable"}and logs the error. - Backend not ready: frontend
/readyzreturns 503 (probes backend/readyz). - Handler panic:
Recoverymiddleware returns 500 instead of crashing.
Related
openwiki/api/middleware.mdopenwiki/frontend/gateway.mdopenwiki/api/control-plane-api.md