Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ set_tests_properties(hub_tls PROPERTIES TIMEOUT 60)
add_test(NAME tls_failure_reasons COMMAND ${Python3_EXECUTABLE}
${CMAKE_SOURCE_DIR}/tests/test_tls_failure_reasons.py $<TARGET_FILE:gate-hub> $<TARGET_FILE:gated>)
set_tests_properties(tls_failure_reasons PROPERTIES TIMEOUT 120)
add_test(NAME ticket_fetch_progress COMMAND ${Python3_EXECUTABLE}
${CMAKE_SOURCE_DIR}/tests/test_ticket_fetch_progress.py $<TARGET_FILE:gated>)
set_tests_properties(ticket_fetch_progress PROPERTIES TIMEOUT 60)
add_test(NAME device_tls COMMAND ${Python3_EXECUTABLE}
${CMAKE_SOURCE_DIR}/tests/test_device_tls.py $<TARGET_FILE:gate-hub>)
set_tests_properties(device_tls PROPERTIES TIMEOUT 40)
Expand Down Expand Up @@ -189,6 +192,10 @@ add_test(NAME hub_link_logs COMMAND ${Python3_EXECUTABLE}
${CMAKE_SOURCE_DIR}/tests/test_hub_link_logs.py $<TARGET_FILE:gated-test>)
add_test(NAME metrics_failure COMMAND ${Python3_EXECUTABLE}
${CMAKE_SOURCE_DIR}/tests/test_metrics_failure.py $<TARGET_FILE:gate-hub-test>)
add_test(NAME sync_metrics COMMAND ${Python3_EXECUTABLE}
${CMAKE_SOURCE_DIR}/tests/test_sync_metrics.py $<TARGET_FILE:gate-hub-test>)
add_test(NAME monitoring_config COMMAND ${Python3_EXECUTABLE}
${CMAKE_SOURCE_DIR}/tests/test_monitoring_config.py $<TARGET_FILE:gate-hub-test>)
add_test(NAME hub_shutdown COMMAND ${Python3_EXECUTABLE}
${CMAKE_SOURCE_DIR}/tests/test_hub_shutdown.py $<TARGET_FILE:gate-hub-test>)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
Expand All @@ -205,12 +212,21 @@ add_test(NAME dc_dns_failure COMMAND ${Python3_EXECUTABLE}
${CMAKE_SOURCE_DIR}/tests/test_dc_dns_failure.py $<TARGET_FILE:gate-hub-test>)
add_test(NAME mail_alert COMMAND ${Python3_EXECUTABLE}
${CMAKE_SOURCE_DIR}/tests/test_mail_alert.py $<TARGET_FILE:gate-hub-test>)
add_test(NAME dc_alerts COMMAND ${Python3_EXECUTABLE}
${CMAKE_SOURCE_DIR}/tests/test_dc_alerts.py $<TARGET_FILE:gate-hub-test>)
set_tests_properties(dc_alerts PROPERTIES TIMEOUT 150)
add_test(NAME http_distribution COMMAND ${Python3_EXECUTABLE}
${CMAKE_SOURCE_DIR}/tests/test_http.py $<TARGET_FILE:gated-test> $<TARGET_FILE:gate-hub-test>)
add_test(NAME ticket_reply_count COMMAND ${Python3_EXECUTABLE}
${CMAKE_SOURCE_DIR}/tests/test_ticket_reply_count.py $<TARGET_FILE:gate-hub-test>)
set_tests_properties(ticket_reply_count PROPERTIES TIMEOUT 60)
add_test(NAME http_sync_integrity COMMAND ${Python3_EXECUTABLE}
${CMAKE_SOURCE_DIR}/tests/test_http_sync.py $<TARGET_FILE:hub-sync>)
add_test(NAME protocol_compat COMMAND ${Python3_EXECUTABLE}
${CMAKE_SOURCE_DIR}/tests/test_protocol_compat.py $<TARGET_FILE:gate-hub-test>)
add_test(NAME gate_list_version COMMAND ${Python3_EXECUTABLE}
${CMAKE_SOURCE_DIR}/tests/test_gate_list_version.py $<TARGET_FILE:gated-test> $<TARGET_FILE:gate-hub-test>)
set_tests_properties(gate_list_version PROPERTIES TIMEOUT 90)
add_test(NAME protocol_probe_timeout COMMAND ${Python3_EXECUTABLE}
${CMAKE_SOURCE_DIR}/tests/test_probe_timeout.py $<TARGET_FILE:gate-hub-test>)

Expand Down Expand Up @@ -238,5 +254,5 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
endif()
add_test(NAME status_deadline COMMAND ${Python3_EXECUTABLE}
${CMAKE_SOURCE_DIR}/tests/test_status_deadline.py $<TARGET_FILE:gate-hub-test> $<TARGET_FILE:gate-hub>)
set_tests_properties(gated_tls hub_tls device_tls second_hello tls_failure_reasons http_distribution offline_reports protocol_compat status_deadline
set_tests_properties(gated_tls hub_tls device_tls second_hello tls_failure_reasons ticket_fetch_progress http_distribution ticket_reply_count offline_reports protocol_compat gate_list_version status_deadline sync_metrics monitoring_config dc_alerts
PROPERTIES RESOURCE_LOCK status_ports)
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ Ticket work logs `event=ticket_sync` for build start, completion or failure and

The data-centre probe logs `event=dc_dns` when resolution becomes `resolved`, `stale`, `failed`, or `recovered`. A stale address is usable for at most 30 seconds; `reason=stale_expired` means the grace period ended, and `reason=never_resolved` that the name has not resolved since the hub started. `resolved` is the first successful lookup, `recovered` one after a failure. It logs `event=dc_link state=connected` or `state=failed` only when the connection state changes, and `state=connected address=... previous=...` when it stays connected but moves to another address; this TCP probe uses port 8443 with device TLS configured, or 8080 otherwise. `GATEPOST_DC_HOST` sets the host that both the probe and the sync connect to (default `api.elsworne.example`); the sync always checks the certificate as `api.elsworne.example`. A failed probe startup or socket close uses `event=operation_failed`.

Mail submission logs `event=mail_alert gate=... state=failed` once when an incident cannot be submitted, and `state=sent` after submission and durable state update. Persistent alert-state file failures and their recovery use `event=mail_state state=failed` and `state=recovered`. Alert initialization failures use `event=operation_failed`.
In the test builds, without device TLS, the hub serves `/tickets`, `/status` and `/metrics` over HTTP on port 8081. When device TLS and `GATEPOST_STATUS` are configured, port 8081 serves `/status` and `/metrics` but answers `GET /tickets` with 404; port 8444 serves the list and the other routes over TLS 1.3 at the same bind address. Port 8444 requires a venue CA-signed gate certificate and accepts only `Host: hub.venue.lan` or `Host: hub.venue.lan:8444`. With device TLS configured, a gate fetches `https://hub.venue.lan:8444/tickets` on startup and periodically, connecting to the `--hub` host while verifying the hub certificate as `hub.venue.lan` and presenting its own certificate. In the test builds, without device TLS, it fetches over 8081: with `--hub 10.77.20.10:7000`, it asks for `http://10.77.20.10:8081/tickets` and sends `Host: 10.77.20.10:8081`. Set `GATEPOST_TICKETS_URL` to override the URL; production builds accept only `https://` and `file://` overrides, while the `http://` override warning appears only in test builds. The hub answers only Host values listed in `GATEPOST_STATUS_HOSTS` (default `hub.venue.lan`, `hub.venue.lan:8081`, `127.0.0.1:8081` and `localhost:8081`) and returns 400 to any other. For plaintext gates reaching the hub by address, add `<address>:8081` to `GATEPOST_STATUS_HOSTS`; the variable replaces the default list, so keep the names you still use. A gate logs `event=ticket_fetch state=failed http=<status> curl=<code> reason=<reason>` when fetching starts failing or the reason changes, suppresses repeats of the same reason, and logs `event=ticket_fetch state=recovered` once when it works again. The gate retains used-ticket state when installing a new list. With device TLS configured, the hub syncs its binary data-centre copy over port 8443 using its certificate, with range requests and SHA-256 verification before installation.
Mail alerts also cover two hub faults: `Data centre unreachable` when probe rounds cannot connect, and `Uplink watcher stopped` when the configured heartbeat file stops changing. Each uses `alert_after_seconds`, sends once per incident after that threshold, sends no recovery mail, re-arms on recovery, and keeps the sent state across hub restarts. The watcher writes the file each loop; its modification time is the heartbeat because a shell has no portable monotonic clock and the watcher and hub share a wall clock in the same container. The hub grants a fresh threshold after restart. These alerts log `event=mail_alert alert=data_centre state=failed/sent` or `alert=uplink_watcher state=failed/sent`; gate alerts retain `event=mail_alert gate=... state=failed` once when submission fails and `state=sent` after submission and durable state update. Persistent alert-state file failures and their recovery use `event=mail_state state=failed` and `state=recovered`. Alert initialization failures use `event=operation_failed`.
In the test builds, without device TLS, the hub serves `/tickets`, `/status` and `/metrics` over HTTP on port 8081. When device TLS and `GATEPOST_STATUS` are configured, port 8081 serves `/status` and `/metrics` but answers `GET /tickets` with 404; port 8444 serves the list and the other routes over TLS 1.3 at the same bind address. Port 8444 requires a venue CA-signed gate certificate and accepts only `Host: hub.venue.lan` or `Host: hub.venue.lan:8444`. With device TLS configured, a gate fetches `https://hub.venue.lan:8444/tickets` on startup and periodically, connecting to the `--hub` host while verifying the hub certificate as `hub.venue.lan` and presenting its own certificate. In the test builds, without device TLS, it fetches over 8081: with `--hub 10.77.20.10:7000`, it asks for `http://10.77.20.10:8081/tickets` and sends `Host: 10.77.20.10:8081`. Set `GATEPOST_TICKETS_URL` to override the URL; production builds accept only `https://` and `file://` overrides, while the `http://` override warning appears only in test builds. The hub answers only Host values listed in `GATEPOST_STATUS_HOSTS` (default `hub.venue.lan`, `hub.venue.lan:8081`, `127.0.0.1:8081` and `localhost:8081`) and returns 400 to any other. For plaintext gates reaching the hub by address, add `<address>:8081` to `GATEPOST_STATUS_HOSTS`; the variable replaces the default list, so keep the names you still use. A gate logs `event=ticket_fetch state=failed http=<status> curl=<code> reason=<reason> phase=<phase> received=<bytes> expected=<bytes|unknown>` when fetching starts failing or the reason or phase changes. It suppresses repeats with the same reason and phase even if the byte counts differ, and logs `event=ticket_fetch state=recovered` once when it works again. The gate retains used-ticket state when installing a new list. With device TLS configured, the hub syncs its binary data-centre copy over port 8443 using its certificate, with range requests and SHA-256 verification before installation.

The hub also serves `/metrics` on its staff-side status listener, separate from the gate RPC port. In the lab it binds `10.77.20.10:8081`, and only staff-subnet or loopback clients may read metrics. See [metric names and labels](docs/operations/metrics.md). The hub sends `X-Content-SHA256` with each ticket list; a gate verifies the bytes and prepares its ETag metadata before replacing the old list.

Expand All @@ -105,5 +105,5 @@ After a restart, a gate drops a saved ETag if it no longer matches the installed

## Documents

See [scanner supervision](docs/debugging/scanner-supervision.md), [lock order](docs/concurrency/lock-order.md), the [simulator protocol](docs/device/simulator-protocol.md), [Gate 3 crash investigation](docs/debugging/gate3-crash.md) and [team](docs/team.md).
See [venue monitoring](docs/operations/monitoring.md), [scanner supervision](docs/debugging/scanner-supervision.md), [lock order](docs/concurrency/lock-order.md), the [simulator protocol](docs/device/simulator-protocol.md), [Gate 3 crash investigation](docs/debugging/gate3-crash.md) and [team](docs/team.md).

6 changes: 3 additions & 3 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ time=1775170804235739 level=INFO event=hub_link gate=south state=online

数据中心探测的地址解析状态变为 `resolved`、`stale`、`failed` 或 `recovered` 时写入 `event=dc_dns`。旧地址最多沿用 30 秒;`reason=stale_expired` 表示宽限期结束,`reason=never_resolved` 表示 hub 启动以来这个名字还没解析成功过。`resolved` 是第一次解析成功,`recovered` 是失败之后再次成功。连接状态变化时写入 `event=dc_link state=connected` 或 `state=failed`;连接一直正常、只是换到另一个地址时,写入 `state=connected address=... previous=...`。这项 TCP 探测在配置设备 TLS 时使用 8443 端口,否则使用 8080 端口。`GATEPOST_DC_HOST` 指定探测和同步连接的主机,默认是 `api.elsworne.example`;同步始终按 `api.elsworne.example` 验证证书。探测启动或关闭套接字失败时写入 `event=operation_failed`。

邮件发送失败时,每次故障只写一次 `event=mail_alert gate=... state=failed`;发送并持久化成功后写入 `state=sent`。告警状态文件持续失败及其恢复分别写入 `event=mail_state state=failed` 和 `state=recovered`。告警初始化失败写入 `event=operation_failed`。
测试构建未配置设备 TLS 时,Hub 在 8081 端口通过 HTTP 提供 `/tickets`、`/status` 和 `/metrics`。配置设备 TLS 和 `GATEPOST_STATUS` 后,8081 只提供 `/status` 和 `/metrics`,对 `GET /tickets` 返回 404;同一绑定地址的 8444 端口通过 TLS 1.3 提供票单和其他接口。8444 要求客户端出示场馆 CA 签发的闸机证书,只接受 `Host: hub.venue.lan` 或 `Host: hub.venue.lan:8444`。配置设备 TLS 后,闸机在启动时及之后定期请求 `https://hub.venue.lan:8444/tickets`,实际连接 `--hub` 指定的主机,按 `hub.venue.lan` 验证 hub 证书,并出示自己的设备证书。测试构建未配置设备 TLS 时仍使用 8081:以 `--hub 10.77.20.10:7000` 启动时,请求 `http://10.77.20.10:8081/tickets`,发送 `Host: 10.77.20.10:8081`。可用 `GATEPOST_TICKETS_URL` 覆盖地址;生产构建只接受 `https://` 和 `file://`,`http://` 覆盖地址的警告只在测试构建中出现。Hub 只接受 `GATEPOST_STATUS_HOSTS` 中列出的 Host(默认是 `hub.venue.lan`、`hub.venue.lan:8081`、`127.0.0.1:8081` 和 `localhost:8081`),其他一律回 400。明文闸机按地址连接 hub 时,要把 `<地址>:8081` 加进 `GATEPOST_STATUS_HOSTS`;这个变量会整个替换默认列表,仍要用的名字也要写上。闸机取票开始失败、或失败期间原因有变化时,记录 `event=ticket_fetch state=failed http=<状态码> curl=<错误码> reason=<原因>`;原因不变不重复记录;恢复时记录一次 `event=ticket_fetch state=recovered`。闸机安装新票单时保留已使用状态。配置设备 TLS 后,Hub 使用自己的证书通过 8443 端口分段同步数据中心的二进制票单,安装前验证 SHA-256。
邮件也会报告 hub 的两类故障:探测轮次无法连接数据中心时,主题为 `Data centre unreachable`;已配置的心跳文件停止更新时,主题为 `Uplink watcher stopped`。两者都在持续达到 `alert_after_seconds` 后每次故障只发一封,不发恢复邮件;恢复后重新布防,已发送状态在 hub 重启后仍保留。监视脚本每轮更新文件,hub 读取修改时间作为心跳;shell 没有可移植的方法读取单调时钟,而脚本与 hub 同处一个容器、共用系统时钟。hub 重启后会重新给予一个阈值时长的宽限期。这两类告警分别记录 `event=mail_alert alert=data_centre state=failed/sent` 和 `alert=uplink_watcher state=failed/sent`;闸机告警仍在提交失败时每次故障只写一次 `event=mail_alert gate=... state=failed`,提交并持久化成功后写入 `state=sent`。告警状态文件持续失败及其恢复分别写入 `event=mail_state state=failed` 和 `state=recovered`。告警初始化失败写入 `event=operation_failed`。
测试构建未配置设备 TLS 时,Hub 在 8081 端口通过 HTTP 提供 `/tickets`、`/status` 和 `/metrics`。配置设备 TLS 和 `GATEPOST_STATUS` 后,8081 只提供 `/status` 和 `/metrics`,对 `GET /tickets` 返回 404;同一绑定地址的 8444 端口通过 TLS 1.3 提供票单和其他接口。8444 要求客户端出示场馆 CA 签发的闸机证书,只接受 `Host: hub.venue.lan` 或 `Host: hub.venue.lan:8444`。配置设备 TLS 后,闸机在启动时及之后定期请求 `https://hub.venue.lan:8444/tickets`,实际连接 `--hub` 指定的主机,按 `hub.venue.lan` 验证 hub 证书,并出示自己的设备证书。测试构建未配置设备 TLS 时仍使用 8081:以 `--hub 10.77.20.10:7000` 启动时,请求 `http://10.77.20.10:8081/tickets`,发送 `Host: 10.77.20.10:8081`。可用 `GATEPOST_TICKETS_URL` 覆盖地址;生产构建只接受 `https://` 和 `file://`,`http://` 覆盖地址的警告只在测试构建中出现。Hub 只接受 `GATEPOST_STATUS_HOSTS` 中列出的 Host(默认是 `hub.venue.lan`、`hub.venue.lan:8081`、`127.0.0.1:8081` 和 `localhost:8081`),其他一律回 400。明文闸机按地址连接 hub 时,要把 `<地址>:8081` 加进 `GATEPOST_STATUS_HOSTS`;这个变量会整个替换默认列表,仍要用的名字也要写上。闸机取票开始失败,或连续失败期间原因或阶段发生变化时,记录 `event=ticket_fetch state=failed http=<状态码> curl=<错误码> reason=<原因> phase=<阶段> received=<字节数> expected=<字节数|unknown>`;原因和阶段都相同的失败不重复记录,即使字节数不同也是如此;恢复后记录一次 `event=ticket_fetch state=recovered`。闸机安装新票单时保留已使用状态。配置设备 TLS 后,Hub 使用自己的证书通过 8443 端口分段同步数据中心的二进制票单,安装前验证 SHA-256。

Hub 还在员工网络一侧的状态服务上提供 `/metrics`,与闸机 RPC 端口分开。实验环境将其绑定到 `10.77.20.10:8081`;只有员工网段或本机能读取指标。指标名称和标签见[运维指标](docs/operations/metrics.zh-CN.md)。Hub 随票单发送 `X-Content-SHA256`;闸机验证文件内容,并在替换旧票单之前准备 ETag 元数据。

Expand All @@ -103,5 +103,5 @@ Hub 还在员工网络一侧的状态服务上提供 `/metrics`,与闸机 RPC

## 文档

另见[扫描器进程监管](docs/debugging/scanner-supervision.zh-CN.md)、[锁的获取顺序](docs/concurrency/lock-order.zh-CN.md)、[模拟器协议](docs/device/simulator-protocol.zh-CN.md)、[三号闸机崩溃排查](docs/debugging/gate3-crash.zh-CN.md)和[团队成员](docs/team.zh-CN.md)。
另见[场馆监控](docs/operations/monitoring.zh-CN.md)、[扫描器进程监管](docs/debugging/scanner-supervision.zh-CN.md)、[锁的获取顺序](docs/concurrency/lock-order.zh-CN.md)、[模拟器协议](docs/device/simulator-protocol.zh-CN.md)、[三号闸机崩溃排查](docs/debugging/gate3-crash.zh-CN.md)和[团队成员](docs/team.zh-CN.md)。

2 changes: 2 additions & 0 deletions config/hub.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ smtp_user=gatepost
smtp_password_file=/etc/gatepost/smtp-password
state_file=/var/lib/gatepost/alerts.state
alert_after_seconds=10
# Optional: the watcher's heartbeat file; its mtime uses the hub's shared wall clock.
# uplink_heartbeat_file=/tmp/gatepost-uplink.heartbeat
Loading
Loading