fix(cluster): 把 balancer 真的接进 Handler(端点此前 404)

上一提交注册了 /cluster/balance 并加了 Handler.Balancer 字段,但构造 Handler 时
忘了赋值 —— 端点因 h.Balancer == nil 走 404 分支。

单测发现不了:它们直接构造 Balancer 调 Report(),从不经过 HTTP 层。
canary 实跑抓到:端点 404(无认证倒是正确 401)。修好后同一 canary 返回 200,
字段齐全、默认 dryRun=true、单节点自认 leader、wouldMigrate 为空。

教训:单元测试覆盖不到"接线",凡新增端点必须真的起进程打过一次。
This commit is contained in:
JianFeeeee
2026-10-06 12:45:28 +08:00
parent 8176478269
commit d347d2a648

View File

@ -402,6 +402,9 @@ func main() {
Sessions: httpapi.NewSessionStore(),
Cluster: reg,
Ring: ring,
// Balancer is created above, before the environment that configures it is
// parsed, because the HTTP layer needs the pointer.
Balancer: balancer,
// SelfAddr must be reachable by peers. 0.0.0.0/empty on a real host
// would break peer reconnect, so fall back to the hostname (container
// name inside docker is a routable addr on the compose network).