Commit 67cf028
authored
feat(admin): /admin/healthz/leader for load-balancer leader probes (#689)
## Summary
- Add `/admin/healthz/leader` so an upstream load balancer (Caddy,
HAProxy, ...) can route admin traffic only to the current Raft leader,
skipping the follower→leader AdminForward proxy hop on writes.
- Mirrors the `/healthz/leader` endpoints already shipped on the S3
(`adapter/s3.go:serveS3LeaderHealthz`) and DynamoDB
(`adapter/dynamodb.go:serveDynamoLeaderHealthz`) adapters — same
semantics, same body shape, same method allowlist — so a multi-protocol
load balancer probing any of the three sees identical responses.
- New `LeaderProbe` interface in `internal/admin`;
`NewRouterWithLeaderProbe` constructor (`NewRouter` delegates with `nil`
probe, preserving existing callers); `ServerDeps.LeaderProbe`;
`newAdminLeaderProbe` in `main_admin.go` consults the local Raft group
runtimes.
## Behaviour matrix
| Path | Probe state | Response |
|----------------------------|--------------------|----------------------------|
| `/admin/healthz` | (n/a) | 200 `ok` |
| `/admin/healthz/leader` | wired, leader | 200 `ok` |
| `/admin/healthz/leader` | wired, follower | 503 `not leader` |
| `/admin/healthz/leader` | not wired | 404 `not_found` (JSON) |
| `/admin/healthz/leader` POST | (any) | 405 `method_not_allowed` |
## Self-review (CLAUDE.md 5 lenses)
1. **Data loss** — None. Read-only handler; no Raft proposals.
2. **Concurrency** — `VerifyLeader` is bounded at 2 s, called only on
nodes that already claim leadership via `Status()`. No new shared state.
3. **Performance** — Cheap path: followers short-circuit via `Status()`
(no Raft round-trip). Leader path: one ReadIndex per probe per group;
load balancers typically probe every few seconds, so the overhead is
bounded and well below the existing background HLC lease + ReadIndex
traffic.
4. **Data consistency** — `VerifyLeader` is the same ReadIndex
round-trip the lease-read path uses; a stale-leader follower
mid-silent-leadership-change cannot return 200.
5. **Test coverage** — six router-level tests: 200-when-leader,
503-when-follower, HEAD on both branches, POST rejection, nil-probe →
404, classify ordering (path is not swallowed by the SPA fallback).
## Test plan
- [x] `go test -race ./internal/admin/...` — passes (1.3s)
- [x] `go test -race -run TestStartAdminServer .` — passes
- [x] `golangci-lint run ./...` — clean
- [ ] CI: full suite under `-race`
@claude review5 files changed
Lines changed: 303 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
35 | 44 | | |
36 | 45 | | |
37 | 46 | | |
38 | 47 | | |
39 | 48 | | |
40 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
41 | 72 | | |
42 | 73 | | |
43 | 74 | | |
| |||
51 | 82 | | |
52 | 83 | | |
53 | 84 | | |
| 85 | + | |
54 | 86 | | |
55 | 87 | | |
56 | 88 | | |
| |||
62 | 94 | | |
63 | 95 | | |
64 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
65 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
66 | 111 | | |
67 | 112 | | |
68 | 113 | | |
| 114 | + | |
69 | 115 | | |
70 | 116 | | |
71 | 117 | | |
| |||
90 | 136 | | |
91 | 137 | | |
92 | 138 | | |
| 139 | + | |
93 | 140 | | |
94 | 141 | | |
95 | 142 | | |
| |||
103 | 150 | | |
104 | 151 | | |
105 | 152 | | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
106 | 161 | | |
107 | 162 | | |
108 | 163 | | |
| |||
146 | 201 | | |
147 | 202 | | |
148 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
149 | 209 | | |
150 | 210 | | |
151 | 211 | | |
| |||
156 | 216 | | |
157 | 217 | | |
158 | 218 | | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
159 | 237 | | |
160 | 238 | | |
161 | | - | |
| 239 | + | |
162 | 240 | | |
163 | 241 | | |
164 | 242 | | |
| |||
169 | 247 | | |
170 | 248 | | |
171 | 249 | | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
172 | 277 | | |
173 | 278 | | |
174 | 279 | | |
| |||
177 | 282 | | |
178 | 283 | | |
179 | 284 | | |
180 | | - | |
| 285 | + | |
181 | 286 | | |
182 | 287 | | |
183 | 288 | | |
| |||
254 | 359 | | |
255 | 360 | | |
256 | 361 | | |
257 | | - | |
| 362 | + | |
258 | 363 | | |
259 | 364 | | |
260 | 365 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
68 | 197 | | |
69 | 198 | | |
70 | 199 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
83 | 92 | | |
84 | 93 | | |
85 | 94 | | |
| |||
129 | 138 | | |
130 | 139 | | |
131 | 140 | | |
132 | | - | |
| 141 | + | |
133 | 142 | | |
134 | 143 | | |
135 | 144 | | |
| |||
0 commit comments