Files
orbit/docs/api/health.md

56 lines
2.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 健康检查接口
状态:已实现,基础阶段。无需鉴权;默认仅监听 `127.0.0.1:8080`。
## GET /health/live
返回进程 HTTP 服务是否存活,不访问数据库。
```sh
curl -i http://127.0.0.1:8080/health/live
```
HTTP 200,`Content-Type: application/json`:
```json
{"status":"alive"}
```
## GET /health/ready
检查数据库连接和迁移记录是否与当前二进制的版本、校验和一致且没有 dirty 标记,并检查 Orbit 表的数据库外键为 0。内部检查最多 2 秒。
```sh
curl -i http://127.0.0.1:8080/health/ready
```
通过时 HTTP 200:
```json
{"status":"ready","scope":"database_and_schema"}
```
数据库不可用、迁移缺失、记录被修改、存在 dirty 标记或 Orbit 表被添加外键时 HTTP 503:
```json
{"status":"not_ready"}
```
响应不包含 DSN、数据库错误文本或凭据。检查迁移记录不能发现所有人工 DDL 漂移,运行账户权限和迁移流程仍需受控。
## GET /version
返回当前服务的构建和协议身份,不访问数据库,也无需鉴权。该接口适合在滚动发布或故障接管后核对节点是否运行了预期版本。
```sh
curl -fsS http://127.0.0.1:8080/version
```
响应字段包括 `version`、`revision`、`built_at`、`go_version`、HTTP/Worker/Event 协议版本和 Weave 定义结构版本。默认本地构建使用 `dev`、`unknown`;发布镜像应通过构建参数注入不可变提交和构建时间。响应不包含主机、数据库、凭据或租户信息。
## SDK 与运行限制
对应 `Client.Liveness(ctx)` 和 `Client.Readiness(ctx)`,见 [SDK 接入](../sdk/README.md)。HTTP 503 返回 `*orbit.HTTPError`。
ready 只表示数据库与迁移基础可用;不检查 Worker、任务积压、流程执行或业务效果。P1 启动时先校验迁移,缺失或 dirty 会拒绝启动;运行后数据库不可用时 ready 返回 503。SDK 默认请求超时为 10 秒,调用方可通过 context 设置更短期限。运行指标见[观测接口](observability.md),指标端点是否启用由 `ORBIT_METRICS_ADDR` 控制。