fix(api): 告警收斂不重複發送 Telegram
問題: 相同 fingerprint 的告警收斂時,仍會重複發送 Telegram 修復: 收斂告警只更新 hit_count,跳過 Telegram 推送 影響: /alerts + /alertmanager 兩個端點 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -841,26 +841,19 @@ async def receive_alert(
|
||||
|
||||
if updated_approval:
|
||||
# =================================================================
|
||||
# [關鍵修復] 收斂告警也必須推送 Telegram (BackgroundTasks)
|
||||
# 2026-03-27 ogt: 收斂告警不重複發送 Telegram,只更新 hit_count
|
||||
# 避免 Telegram 洗版,用戶可在 UI 查看聚合次數
|
||||
# =================================================================
|
||||
background_tasks.add_task(
|
||||
_push_to_telegram_background,
|
||||
logger.info(
|
||||
"alert_converged_telegram_skipped",
|
||||
approval_id=str(updated_approval.id),
|
||||
risk_level=updated_approval.risk_level.value,
|
||||
resource_name=alert.target_resource,
|
||||
root_cause=alert.message,
|
||||
suggested_action=updated_approval.action,
|
||||
estimated_downtime="~30s",
|
||||
hit_count=updated_approval.hit_count,
|
||||
# v6.0 AI 仲裁 (收斂告警使用 COLLAB,因為跳過 LLM)
|
||||
primary_responsibility="COLLAB",
|
||||
confidence=0.70, # 收斂告警標準信心度
|
||||
namespace=alert.namespace,
|
||||
reason="Converged alert - Telegram already sent for this fingerprint",
|
||||
)
|
||||
|
||||
return AlertResponse(
|
||||
success=True,
|
||||
message=f"🛡️ 告警收斂:相同指紋告警已聚合 (x{updated_approval.hit_count}次),跳過 LLM",
|
||||
message=f"🛡️ 告警收斂 (x{updated_approval.hit_count}) - Telegram 已發送,跳過重複通知",
|
||||
alert_id=alert_id,
|
||||
approval_created=False, # 未建立新卡片
|
||||
approval_id=str(updated_approval.id),
|
||||
@@ -1223,23 +1216,18 @@ async def alertmanager_webhook(
|
||||
|
||||
updated_approval = await service.increment_hit_count(existing_approval.id)
|
||||
if updated_approval:
|
||||
background_tasks.add_task(
|
||||
_push_to_telegram_background,
|
||||
# 2026-03-27 ogt: 收斂告警不重複發送 Telegram,只更新 hit_count
|
||||
# 用戶可在 UI 查看聚合次數,避免 Telegram 洗版
|
||||
logger.info(
|
||||
"alertmanager_converged_telegram_skipped",
|
||||
approval_id=str(updated_approval.id),
|
||||
risk_level=updated_approval.risk_level.value,
|
||||
resource_name=target_resource,
|
||||
root_cause=message,
|
||||
suggested_action=updated_approval.action,
|
||||
estimated_downtime="~30s",
|
||||
hit_count=updated_approval.hit_count,
|
||||
primary_responsibility="COLLAB",
|
||||
confidence=0.70,
|
||||
namespace=namespace,
|
||||
reason="Converged alert - Telegram already sent for this fingerprint",
|
||||
)
|
||||
|
||||
return AlertResponse(
|
||||
success=True,
|
||||
message=f"🛡️ 告警收斂 (x{updated_approval.hit_count})",
|
||||
message=f"🛡️ 告警收斂 (x{updated_approval.hit_count}) - Telegram 已發送,跳過重複通知",
|
||||
alert_id=alert_id,
|
||||
approval_created=False,
|
||||
approval_id=str(updated_approval.id),
|
||||
|
||||
Reference in New Issue
Block a user