Skip to content

feat: proxy plug in front of core (#343) - #353

Open
spaenleh wants to merge 2 commits into
mainfrom
343-proxy-plug
Open

spaenleh wants to merge 2 commits into
mainfrom
343-proxy-plug

Conversation

@spaenleh

@spaenleh spaenleh commented Dec 4, 2026

Copy link
Copy Markdown
Member

Closes #343

Summary

AdminWeb.CoreApi.Proxy sits in the endpoint right after Plug.Telemetry (ADR 0004, amended by ADR 0008):

/api request
  maintenance flag?                 → 503 {statusCode, error, message}
  websocket route, or a route under
  scope "/api" in AdminWeb.Router?  → continue (parsers, Head, session, router)
  test env (forward: false)?        → 501 + conn.private[:core_api_unported]
  otherwise                         → Finch.stream_while to core
                                        connection error → 502, timeout → 504
 lib/admin_web/
+├── core_api/proxy.ex             # the plug, the two Finch pools
+├── core_api/proxy/aborted_error.ex
+├── core_api/route_templates.ex   # generated at compile time from docs/core-inventory/routes.json
 ├── endpoint.ex                   # plug AdminWeb.CoreApi.Proxy
 └── telemetry.ex                  # admin.proxy.request.stop.duration
  • Byte pipe: neither body is buffered: the request body goes to core in 1 MB chunks. Hop-by-hop headers are dropped and every other header is kept. X-Forwarded-For is appended. Bandit compression is off for proxied responses, so core's content-encoding and content-length come back unchanged.
  • Pools: uploads and exports (15 core routes) have their own pool with a 10 min timeout. Everything else uses 15 s, with :route_timeouts overrides per route.
  • Telemetry: an [:admin, :proxy, :request] span carries route (unknown when no template matches), method, status and backend (core or admin).
  • Maintenance: set the API_MAINTENANCE=true env var in prod.

Evidence

The tests run real Bandit servers for both the proxy and a stub core:

unported route → core gets method, path, query, headers, body unchanged      ✓
response through admin == response straight from core (Set-Cookie, CORS)     ✓
core's gzip + content-length kept, admin never compresses                    ✓
1 GB upload: core sees the first chunk before the client finishes (1.4 s)    ✓
route under scope "/api" → served by admin, core never hit                   ✓
core down → 502, core slow → 504, in core's error shape                      ✓
telemetry: template / backend / status, route=unknown                        ✓
full endpoint in test env → 501, marked unported                             ✓

mix precommit: 492 tests, 0 failures. credo --strict: no issues.

Merge Danger

Door: two-way

Revert and redeploy. Nothing is persisted.

Blast Radius: all of /api

  • Today: no ALB rule sends /api to admin, so the plug sees no production traffic until the cutover.
  • Cutover: before ALB rule 7 is removed, backend_origin must point at core's private address (ADR 0004 cutover step 1). Otherwise requests loop from admin through the ALB back into admin.
  • Known gaps:
    • A connect timeout to core gives 504, not 502, because Finch reports it the same way as a response timeout.
    • The span of a route admin serves never closes if that route crashes.
    • Turning compression off edits Bandit's private adapter struct. The byte-for-byte tests would catch a Bandit upgrade breaking it.
    • Request bodies are only forwarded with content-length or transfer-encoding. That is always true over HTTP/1.1, which is what the ALB is expected to use towards admin.

Every /api request admin doesn't serve under scope "/api" is streamed to
core unchanged on Finch (ADR 0004, amended by ADR 0008): both bodies
streamed, hop-by-hop headers dropped, X-Forwarded-For appended, Bandit
compression off. 502/504 in core's error shape, a separate long pool for
uploads and exports, a maintenance flag, and an [:admin, :proxy, :request]
telemetry span tagged with the core route template generated from
docs/core-inventory/routes.json. In tests the proxy refuses to forward and
marks the request unported (ADR 0007).

This branch has not been deployed

No deployments
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.

Foundation: proxy plug in front of core

1 participant