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:
@@ -7,10 +7,12 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/sundynix/sundynix-shared/blob"
|
||||
sharedbus "github.com/sundynix/sundynix-shared/bus"
|
||||
"github.com/sundynix/sundynix-shared/contract"
|
||||
"github.com/sundynix/sundynix-shared/health"
|
||||
|
||||
"github.com/sundynix/sundynix-mcp-go/internal/history"
|
||||
"github.com/sundynix/sundynix-mcp-go/internal/mcp"
|
||||
@@ -75,6 +77,15 @@ func main() {
|
||||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer stop()
|
||||
|
||||
// HTTP 健康探针:给 k8s/LB 直接探(此前只有 NATS 应答,编排器够不着)。
|
||||
// readiness = NATS 连接可用(能收工具调用);liveness = 进程能应答。
|
||||
healthShutdown := health.Serve("mcp-go", envOr("MCP_GO_HEALTH_ADDR", ":8092"), b.IsConnected)
|
||||
defer func() {
|
||||
sctx, scancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer scancel()
|
||||
healthShutdown(sctx)
|
||||
}()
|
||||
|
||||
// RAG 核心链:embedding + Milvus(向量) + Bleve(全文) + Neo4j(图谱) + 可选 rerank
|
||||
ragEngine := rag.Open(ctx, rag.Config{
|
||||
MilvusAddr: milvusAddr,
|
||||
|
||||
Reference in New Issue
Block a user