abeab9d3e4
Store alert metrics without per-value Redis members to stop duplicate recovery pushes; format all operator-facing timestamps in Asia/Shanghai across Web UI and Telegram.
1.4 KiB
1.4 KiB
2026-06-08 — 资源恢复 Telegram 去重与时区修正
变更摘要
修复子机资源恢复通知「1 秒内连发多条」及消息内「时间」显示为 UTC 而非北京时间的问题。
动机
用户反馈子机 #212 内存恢复 Telegram 在约 1 秒内收到多条相同内容;消息底部时间为 UTC,与运维习惯不符。
根因
- 重复推送:Redis
alerts:{server_id}集合以mem:92.1形式每次超阈值心跳追加新成员;恢复检测对集合内每条成员各触发一次broadcast_recovery,同一指标一次心跳可连发 N 条 Telegram。 - 时间不对:
_now_cn()使用datetime.now(timezone.utc)并标注UTC,对中国用户相当于慢 8 小时。
涉及文件
server/api/agent.py— 告警集合仅存指标名;恢复检测按指标去重;清理时兼容 legacymetric:valueserver/infrastructure/telegram/__init__.py—_now_cn()改为Asia/Shanghai+「北京时间」tests/test_agent_recovery_dedup.pytests/test_telegram_time_format.py
迁移 / 重启
- 无需 DB 迁移
- 部署后重启 API 生效;Redis 中既有
metric:value成员在下次恢复时会被按指标批量清除
验证方式
pytest tests/test_agent_recovery_dedup.py tests/test_telegram_time_format.py -q
生产:子机超阈值后再回落,Telegram 每条指标仅应收到 一条 恢复通知,时间为北京时间。