Repository navigation
fix(gate-hub): notify operators of data-centre and watcher failures - #166
Conversation
Exercise a stalled HTTPS list body after 4096 of 65536 bytes and a TLS handshake that never answers after TCP connect. The failed fetch line should append phase, received body bytes, and the response Content-Length after its existing fields. Today both cases report only curl=28 reason=timeout. CTest accepts this run only when both cases fail in that current way.
A stalled body, a stalled handshake, and an unreachable hub could all log curl=28 reason=timeout. The failure line now reports how far the attempt got and how many body bytes of how many arrived. The phase comes from curl's connection count, the status line and end of headers seen, and bytes handed to the write callback. A phase change is logged like a reason change. The two exact log-line checks in test_gated_tls.py now include the new fields.
Serve a large ticket list, shrink the client's receive buffer, read only the response headers, then reset the connection during the body. The complete download should add one tickets/200 count, and the aborted download should add one tickets/incomplete count. Today both are counted as 200. CTest accepts this run only when it fails that way.
A body write that failed part-way still counted as 200, so aborted transfers never appeared in the ticket request metric. Count those replies, and replies whose headers could not be written, once as status="incomplete" on the tickets route. The header-write path is not covered by the test: headers are too small to make that write fail reliably.
…s heartbeat The hub could not tell which list each gate had installed. List age based on file time also kept growing through 304 confirmations. Keep the verified SHA-256 and monotonic confirmation time at each gate. Send the installed version and time since confirmation in CONFIG, then compare it with the list the hub currently serves. Gates reporting no version have unknown status, which is not an error. A gate retries an empty CONFIG on the same connection for a hub not yet upgraded. The hub trusts the reported list state as sent: CONFIG has no MAC, so whoever holds a gate's certificate can report a false state for that gate. Co-authored-by: Ben Carter <ben.carter@elsworne.example>
On-call staff could only read raw /metrics. Provision a dashboard for the existing hub series: incomplete ticket replies, TLS handshake failures, and per-gate list status. Use a separate Compose file so the venue lab and its drills need no Grafana password. Pin both images by tag and digest. Keep the earlier sync-metrics regression test for the existing sync accounting fix, and check dashboard metrics against the hub. Co-authored-by: Yuki Tanaka <yuki.tanaka@elsworne.example>
The hub recorded connections that had not identified themselves under the name "unknown". Writing list status for every record made that pseudo-gate look like a gate reporting no version. Write list status only for gates that identified themselves and sent a heartbeat. A CONFIG from an unidentified connection records nothing.
… the uplink watcher has stopped Cut both data-centre exits, restore them, then kill the hub's uplink watcher. Compare Mailpit message IDs across each separate fault. Each case expects exactly one mail to manager@elsworne.example from alerts@elsworne.example through the venue's own mail server, which remains available without the data-centre link. The subjects are "Data centre unreachable" and "Uplink watcher stopped". Allow 20 s: 5 s for the probe, 10 s for the alert threshold, 1 s for the alert loop, and 4 s for mail submission; the watcher checks every second. Today neither mail is sent, so both judgements fail. Exit 0 means both pass, 1 means a judgement fails, and 2 means an environment or cleanup failure.
…he uplink watcher stops The hub logged data-centre failures, and the uplink watcher could exit without notifying the venue. Submit mail after the shared alert threshold, once per incident. Keep sent incidents in the atomic state file across hub restarts, and re-arm each alert when its condition recovers without sending recovery mail. Have the watcher update a heartbeat file each loop. Its modification time uses the clock shared with the hub, since a shell cannot portably read a monotonic clock. Give restarted hubs a fresh threshold of grace. Add a CI test for transient and repeated faults, recovery, mail headers, restart persistence, and the watcher grace period. Co-authored-by: Yuki Tanaka <yuki.tanaka@elsworne.example>
|
Wang Hao · reviewer Does a stopped watcher become indistinguishable from a healthy idle route? 监视脚本停了以后,会不会被当成一条正常、无需切换的线路? |
|
Ben Carter · author No. The hub checks the heartbeat file's modification time on its own, independent of route changes. Once it is older than 不会。hub 自己检查心跳文件的修改时间,跟线路有没有变化无关;超过 |
|
Ingrid Larsen · reviewer If the hub restarts in the middle of a data-centre outage, does the manager get a second mail for the same incident? 如果数据中心中断期间 hub 重启了,经理会不会为同一起事件再收到一封邮件? |
|
Ben Carter · author No. The sent flag is stored in 不会。已发送标记存在 |
Why
The hub logged data-centre failures without telling anyone, and the uplink watcher could exit silently, leaving the route choice unattended. The new
lab/dc-alert.shdrill shows that neither fault produces a mail.What changed
lab/dc-alert.sh: it cuts the data-centre-facing interfaces on both routers, restores them, then kills the hub's uplink watcher, and expects exactly one mail per fault (Data centre unreachable,Uplink watcher stopped) fromalerts@elsworne.exampletomanager@elsworne.examplewithin 20 s. Exit 0 means both arrive, 1 a failed judgement, 2 an environment or cleanup failure.gate-hub/alert.cgains the two alerts. The data-centre probe reports each round to the alert watch; the watcher alert fires when the modification time ofuplink_heartbeat_fileis older thanalert_after_seconds. Each alert is sent once per incident after that threshold, sends no recovery mail and re-arms on recovery. Sent incidents are kept instate_fileas:data-centreand:uplink-watcher, so a hub restart does not resend them; a restarted hub gives the watcher a fresh threshold of grace.lab/uplink-watch.shtouchesGATEPOST_UPLINK_HEARTBEATon every loop;lab/compose.yamlsets it andlab/hub.confpointsuplink_heartbeat_fileat the same/tmp/gatepost-uplink.heartbeat.config/hub.conf.exampledocuments the option.tests/test_dc_alerts.py(ctestdc_alerts): a probe failure that recovers before the threshold sends nothing, repeated outages send one mail each with distinctMessage-IDs, the watcher alert re-arms after heartbeats resume, sent incidents survive restarts, and a restarted hub waits one threshold before reporting a missing heartbeat.event=mail_alert alert=data_centre|uplink_watcher state=failed|sent) inREADME.mdandlab/README.md.How to verify
On Linux with the build dependencies listed in
Dockerfile.build, run from the repository root:cmake --preset debug cmake --build --preset debug ctest --preset debug -R '^(dc_alerts|mail_alert|alert_state_fsync|uplink_watch)$' --output-on-failureFor the venue drill, with Docker Compose and a Linux container engine that supports the lab network capabilities, run it alone:
The drill should exit 0 with one mail for each fault.
背景
hub 只把数据中心故障写进日志,没有通知任何人;上行监视脚本退出时也悄无声息,线路切换就没人管了。新加的
lab/dc-alert.sh演练表明,这两种故障都不会发出邮件。改动
lab/dc-alert.sh:先切断两台路由器朝向数据中心的接口再恢复,然后杀掉 hub 的上行监视脚本,要求每种故障在 20 秒内各有一封邮件(Data centre unreachable、Uplink watcher stopped),由alerts@elsworne.example发给manager@elsworne.example。退出码 0 表示都收到,1 表示判定失败,2 表示环境或清理出错。gate-hub/alert.c加入这两类告警。数据中心探测每一轮都把结果交给告警模块;uplink_heartbeat_file的修改时间超过alert_after_seconds没有更新,就触发监视脚本告警。每起事件过了阈值只发一封,恢复时不发邮件,而是重新待命。已发送的事件以:data-centre和:uplink-watcher记在state_file里,hub 重启后不会重发;重启后的 hub 会给监视脚本重新留出一个阈值的宽限。lab/uplink-watch.sh每轮循环都刷新GATEPOST_UPLINK_HEARTBEAT指向的文件;lab/compose.yaml设置这个变量,lab/hub.conf的uplink_heartbeat_file指向同一个/tmp/gatepost-uplink.heartbeat。config/hub.conf.example补上这个选项的说明。tests/test_dc_alerts.py(ctest 名dc_alerts):探测失败后在阈值内恢复不发邮件;多次中断各发一封,Message-ID互不相同;心跳恢复后告警重新待命;已发送的事件跨重启保留;重启后的 hub 等满一个阈值才报告心跳缺失。README.md和lab/README.md中说明这两类告警和对应日志(event=mail_alert alert=data_centre|uplink_watcher state=failed|sent)。怎么验证
在 Linux 环境安装
Dockerfile.build列出的构建依赖后,从仓库根目录运行:cmake --preset debug cmake --build --preset debug ctest --preset debug -R '^(dc_alerts|mail_alert|alert_state_fsync|uplink_watch)$' --output-on-failure场馆演练需要 Docker Compose,以及支持场馆网络权限的 Linux 容器环境,请单独运行:
演练应以 0 退出,每种故障各收到一封邮件。