feat(raft): GET /v1/codeq/raft/status endpoint#586
Merged
Conversation
Local-node view of per-shard raft state, surfaced for ops tooling +
Prometheus scraping + as the building block for future client-side
smart routing.
Response shape:
{
"enabled": true,
"numGroups": 4,
"groups": [
{"shardIdx":0,"isLeader":true, "selfId":"node-1","selfAddr":"127.0.0.1:25000",
"leaderId":"node-1","leaderAddr":"127.0.0.1:25000","hasLeader":true},
{"shardIdx":1,"isLeader":false,"selfId":"node-1","selfAddr":"127.0.0.1:25001",
"leaderId":"node-2","leaderAddr":"127.0.0.1:25101","hasLeader":true},
...
]
}
When raft is disabled: returns 200 with {"enabled":false,"numGroups":0}.
Wiring:
- internal/raft.DB grew LeaderInfo() (uses hraft.LeaderWithID), SelfID(),
BindAddr() accessors.
- pkg/app.Application gained RaftGroups []RaftGroupStatus — populated
per shard in application_pebble.go when cfg.Raft.Enabled.
- internal/controllers/raft_status_controller.go is the handler. It
uses its own RaftGroupStatus interface (structurally identical to
the public one) to avoid importing pkg/app from internal/.
- pkg/app/url_mappings.go mounts the route under anyAuth — readable
by producer OR worker tokens; the payload reveals no task data, only
routing metadata (peer IDs + bind addrs).
Tests:
- TestRaftStatusEndpoint_RaftDisabled: enabled=false, NumGroups=0.
- TestRaftStatusEndpoint_SingleShard_Leader: 1-node bootstrap shows
SelfID=LeaderID=node-1, IsLeader=true, HasLeader=true after election.
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
Adds a per-shard raft status endpoint that surfaces the local node's view of every raft group: leadership, self/peer IDs and bind addresses. Foundation for:
```
GET /v1/codeq/raft/status
{
"enabled": true,
"numGroups": 4,
"groups": [
{"shardIdx":0,"isLeader":true, "selfId":"node-1","selfAddr":"127.0.0.1:25000",
"leaderId":"node-1","leaderAddr":"127.0.0.1:25000","hasLeader":true},
{"shardIdx":1,"isLeader":false,"selfId":"node-1","selfAddr":"127.0.0.1:25001",
"leaderId":"node-2","leaderAddr":"127.0.0.1:25101","hasLeader":true}
]
}
```
When raft is disabled: `{"enabled":false,"numGroups":0}`.
What landed
Why this instead of full leader forwarding
I scoped down. Server-side HTTP 307 redirects on `ErrNotLeader` require:
Each of those is doable but adds up to a multi-day refactor. This endpoint is the smaller piece that ships value immediately and unblocks the rest: any future routing logic (server-side forwarding, client-side pinning, Prometheus exporter) can poll this endpoint to discover topology.
Test plan
🤖 Generated with Claude Code