feat(gateway): 创建/编辑网关后立即异步探活健康状态

- POST/PUT /api/gateways 成功后后台立即探活一次 /healthz 并覆盖落库,不阻塞请求
- probeAndRecordGateway 抽出单网关探活+落库复用;探活超时改为 var 供测试注入
- 网关页保存成功后延迟 2.5s 刷新一次,尽快展示最新健康状态
- 测试:立即探活、慢网关不阻塞、不可达落 unhealthy
This commit is contained in:
2026-09-30 14:33:31 +08:00
parent eab193007c
commit e12e03b3b4
5 changed files with 217 additions and 15 deletions
@@ -26,6 +26,7 @@ type HubStore interface {
ListGateways(ctx context.Context) ([]hub.Gateway, error)
GetGateway(ctx context.Context, name string) (hub.Gateway, error)
DeleteGateway(ctx context.Context, name string) error
RecordGatewayCheck(ctx context.Context, name, status, reason string) (hub.Gateway, error)
ListEnvs(ctx context.Context) ([]hub.Env, error)
GetEnv(ctx context.Context, alias string) (hub.Env, error)
CreateNetworkExit(ctx context.Context, exit hub.NetworkExit) (hub.NetworkExit, error)
@@ -488,6 +489,7 @@ func registerHubWithNetwork(app *fiber.App, store HubStore, probe NetworkExitPro
if err != nil {
return hubError(c, err)
}
probeGatewayAsync(c.Context(), store, gateway)
return c.Status(fiber.StatusCreated).JSON(gateway)
})
app.Put("/api/gateways/:name", func(c fiber.Ctx) error {
@@ -503,6 +505,7 @@ func registerHubWithNetwork(app *fiber.App, store HubStore, probe NetworkExitPro
if err != nil {
return hubError(c, err)
}
probeGatewayAsync(c.Context(), store, gateway)
return c.JSON(gateway)
})
app.Delete("/api/gateways/:name", func(c fiber.Ctx) error {