Split Raft::HTTP::Handler into StatusHandler and AdminHandler#28
Merged
Conversation
The old Handler bundled read-only GETs (/raft/status, /raft/log,
/raft/metrics) with mutating POST /raft/admin/* in a single handler.
This forced consumers that expose metrics on an unauthenticated port
to also expose cluster-mutating admin endpoints there.
Replace with two handlers that can be mounted separately:
- StatusHandler(T): GET /raft/status, /raft/log, /raft/metrics.
Anything else falls through via call_next. Safe to mount on an
unauthenticated metrics port.
- AdminHandler(T): POST /raft/admin/*, including the raft_debug-flagged
pause/resume/partition/heal/reset routes. Anything else falls through.
Mount behind authentication.
No auth in the shard itself — auth is consumer policy. The two halves
can be combined into one mount with `[StatusHandler, AdminHandler]` to
preserve current behaviour where needed.
Behavior is byte-for-byte identical to the old handler: same JSON
shapes, status codes, error messages, and JSON::ParseException /
KeyError / ArgumentError rescue around admin routes.
Updates:
- src/raft.cr: require both new files instead of the old handler.
- examples/kv/src/main.cr, examples/queue/src/main.cr: mount both
handlers as a chain (drop-in replacement for the old single handler).
- spec/raft/http/{status,admin}_handler_spec.cr: split tests with new
cases proving StatusHandler doesn't respond to POST admin (falls
through to 404), AdminHandler doesn't respond to GET status, and a
chained mount serves both surfaces.
Delete src/raft/http/handler.cr — pre-1.0, no backwards-compat shim.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
The old `Handler` bundled read-only GETs (`/raft/status`, `/raft/log`, `/raft/metrics`) with mutating `POST /raft/admin/*` in a single handler. Consumers that want to expose metrics on an unauthenticated port were forced to expose unauthenticated cluster-mutating admin endpoints alongside.
Replace with two handlers that can be mounted separately:
No auth is added to the shard itself — auth is consumer policy. The two halves can be combined into one mount with `[StatusHandler, AdminHandler]` to preserve current behaviour where needed.
Behaviour is byte-for-byte identical to the old handler: same JSON shapes, status codes, error messages, and `JSON::ParseException | KeyError | ArgumentError` rescue around admin routes.
Changes
LavinMQ note
LavinMQ is the sole external consumer. It instantiates `Raft::HTTP::Handler` in one place per integration. The upgrade is mechanical: replace the single instantiation with `StatusHandler` + `AdminHandler` mounted on whichever ports their auth chain dictates.
Test plan
🤖 Generated with Claude Code