feat(prod): 实时就绪探针——gateway /readyz 真 ping + dispatcher/mcp-go 加 HTTP 探针(B2)
此前 gateway /readyz 用的是 Enabled() 启动期降级标志(反映不了运行中 PG 掉线,LB 会继续 往已不可用实例导流);dispatcher/mcp-go 干脆没有 HTTP 探针(只有 NATS ServeHealth,k8s/LB 够不着、只能靠 gateway 经 NATS 代探)。 - gateway /readyz 改用 db.Ping 实时探活。只把 **DB 当硬依赖门**:Redis 掉线仍可服务(限流有 A5 进程内 fail-safe 兜底、SSE 回落 live NATS),一 blip 就把全部实例踢出轮转反而制造整站 故障,故 Redis 只上报不 gate。NATS 启动即连(fatal)不单列。 - 新 sundynix-shared/health 包:Serve/Handler 提供 /healthz(恒 200 liveness) + /readyz(由 ready() 决定 readiness)。dispatcher(:8091, DISPATCHER_HEALTH_ADDR)与 mcp-go(:8092, MCP_GO_HEALTH_ADDR)各起一个,readiness = NATS 连接可用(bus.IsConnected)。接入各自优雅停机。 - bus 加 IsConnected()(nc.IsConnected 实时);dispatcher Subscriber 透传。 四模块 build+vet+test 绿;health 带 Handler 单测。探针端口仅内部用(对外仍只暴露 gateway)。 compose/k8s 的 healthcheck 编排属 C 层 ops,另做。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/sundynix/sundynix-dispatcher/internal/llm"
|
||||
dnats "github.com/sundynix/sundynix-dispatcher/internal/nats"
|
||||
"github.com/sundynix/sundynix-shared/contract"
|
||||
"github.com/sundynix/sundynix-shared/health"
|
||||
"github.com/sundynix/sundynix-shared/otelx"
|
||||
"github.com/sundynix/sundynix-shared/prompts"
|
||||
"github.com/sundynix/sundynix-shared/secrets"
|
||||
@@ -103,6 +104,15 @@ func main() {
|
||||
defer func() { _ = unsub() }()
|
||||
}
|
||||
|
||||
// HTTP 健康探针:给 k8s/LB 直接探(此前只有 NATS ServeHealth,编排器够不着)。
|
||||
// readiness = NATS 连接可用(能收任务);liveness = 进程能应答。
|
||||
healthShutdown := health.Serve("dispatcher", envOr("DISPATCHER_HEALTH_ADDR", ":8091"), sub.IsConnected)
|
||||
defer func() {
|
||||
sctx, scancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer scancel()
|
||||
healthShutdown(sctx)
|
||||
}()
|
||||
|
||||
// 监听退出信号,优雅停止消费。
|
||||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer stop()
|
||||
|
||||
Reference in New Issue
Block a user