Files
Nexus/docs/changelog/2026-06-08-telegram-recovery-dedup-timezone.md
T
Nexus Agent abeab9d3e4 Fix recovery Telegram dedup and unify Beijing time display.
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.
2026-06-08 23:18:56 +08:00

1.4 KiB
Raw Blame History

2026-06-08 — 资源恢复 Telegram 去重与时区修正

变更摘要

修复子机资源恢复通知「1 秒内连发多条」及消息内「时间」显示为 UTC 而非北京时间的问题。

动机

用户反馈子机 #212 内存恢复 Telegram 在约 1 秒内收到多条相同内容;消息底部时间为 UTC,与运维习惯不符。

根因

  1. 重复推送Redis alerts:{server_id} 集合以 mem:92.1 形式每次超阈值心跳追加新成员;恢复检测对集合内每条成员各触发一次 broadcast_recovery,同一指标一次心跳可连发 N 条 Telegram。
  2. 时间不对_now_cn() 使用 datetime.now(timezone.utc) 并标注 UTC,对中国用户相当于慢 8 小时。

涉及文件

  • server/api/agent.py — 告警集合仅存指标名;恢复检测按指标去重;清理时兼容 legacy metric:value
  • server/infrastructure/telegram/__init__.py_now_cn() 改为 Asia/Shanghai +「北京时间」
  • tests/test_agent_recovery_dedup.py
  • tests/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 每条指标仅应收到 一条 恢复通知,时间为北京时间。