Skip to content

feat(health): add on-demand node health snapshot RPC with 10s local cache - #276

Merged
uvwt merged 2 commits into
mainfrom
feat/node-health-snapshot
Nov 30, 2026
Merged

uvwt merged 2 commits into
mainfrom
feat/node-health-snapshot

Conversation

@uvwt

@uvwt uvwt commented Nov 30, 2026

Copy link
Copy Markdown
Owner

Summary

新增按需宿主机健康快照采集能力,复用既有 runtime.request 链路提供轻量、零破坏性的健康状态查询。

零破坏性契约

  • 复用 runtime.request 新增 GET /internal/runtime/health(支持 ?force=true 跳过缓存强制采样),同时注册至本地 Runtime HTTP API(timeout 类别错误映射为 504 Gateway Timeout)。
  • 通过可选接口 runtimeapi.HealthRuntime 扩展,不改动既有心跳保活与协议握手;未实现该接口时返回结构化错误 HEALTH_UNSUPPORTED。
  • 返回结构化快照(os、cpu_percent、memory、disk、uptime_seconds、load、collected_at、cached),失败或超时返回 HEALTH_TIMEOUT / HEALTH_COLLECTION_FAILED 供控制面与前端优雅降级。

缓存、并发控制与三平台零 CGO 采集

  • 10s 本地内存缓存 + singleflight 防击穿 + 2s 采样硬超时:防止高频或并发查询放大宿主机采集开销,避免慢采样拖垮请求链路。
  • 三平台零 CGO 采集实现:
    • Linux (internal/health/collect_linux.go)
    • macOS (internal/health/collect_darwin.go)
    • Windows (internal/health/collect_windows.go)
    • 其他平台回退 (internal/health/collect_other.go) 与通用解析逻辑 (internal/health/parse.go)

验证

  • internal/health/collector_test.go:缓存命中/过期、force 刷新、singleflight 合并、2s 超时与三平台解析测试。
  • internal/runtimeapi/dispatch_test.go & internal/nexusbridge/client_test.go:GET /internal/runtime/health 路由分发及 Nexus Bridge RPC 链路测试。

@uvwt
uvwt force-pushed the feat/node-health-snapshot branch from 1120639 to 313d887 Compare November 30, 2026 17:05
@uvwt
uvwt merged commit 1b1b92f into main Nov 30, 2026
11 of 13 checks passed
@uvwt
uvwt deleted the feat/node-health-snapshot branch November 30, 2026 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant