From 1cb654cf599a4505fa39fe83c3d925edc19518b3 Mon Sep 17 00:00:00 2001 From: OG T Date: Sun, 12 Apr 2026 18:44:12 +0800 Subject: [PATCH] =?UTF-8?q?fix(adr-075):=20CR=20P0/P1=20=E4=BF=AE=E8=A3=9C?= =?UTF-8?q?=20=E2=80=94=20TYPE=5F8M=20enum=20+=20=E6=AD=BB=E7=A2=BC?= =?UTF-8?q?=E6=B8=85=E7=90=86=20+=20docstring=20=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit P0-2: NotificationType 新增 TYPE_8M = "TYPE-8M" classify_notification 早期回傳 TYPE-8M decision_manager 改用 NotificationType.TYPE_8M enum 比較(移除字串字面量) P1-1: 移除 _CATEGORY_BUTTONS 中不可達的 alertchain_health/flywheel_health 條目 P1-4: test_classify_alert_early.py docstring 更新為 13 條規則/10 分類 Co-Authored-By: Claude Sonnet 4.6 --- apps/api/src/services/decision_manager.py | 2 +- apps/api/src/services/telegram_gateway.py | 14 +++++--------- apps/api/tests/test_classify_alert_early.py | 12 ++++++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/apps/api/src/services/decision_manager.py b/apps/api/src/services/decision_manager.py index 76e4e121..150040e9 100644 --- a/apps/api/src/services/decision_manager.py +++ b/apps/api/src/services/decision_manager.py @@ -249,7 +249,7 @@ async def _push_decision_to_telegram( resource_name=target[:50], diff_summary=description[:500], ) - elif _notif_type.value == "TYPE-8M" or _alert_category in ("alertchain_health", "flywheel_health"): + elif _notif_type == NotificationType.TYPE_8M or _alert_category in ("alertchain_health", "flywheel_health"): # TYPE-8M:飛輪/告警鏈路健康異常,發到個人 DM(不發群組) tg_result = await gateway.send_meta_alert( incident_id=incident.incident_id, diff --git a/apps/api/src/services/telegram_gateway.py b/apps/api/src/services/telegram_gateway.py index b9aaa6f7..f8421417 100644 --- a/apps/api/src/services/telegram_gateway.py +++ b/apps/api/src/services/telegram_gateway.py @@ -1111,6 +1111,7 @@ class NotificationType(str, Enum): TYPE_3 = "TYPE-3" # 需人工審核(預設) TYPE_4 = "TYPE-4" # AI 無法判斷 TYPE_4_DRIFT = "TYPE-4D" # Config Drift 專屬 + TYPE_8M = "TYPE-8M" # ADR-075: 飛輪/告警鏈路自身健康(Meta-System) def classify_notification( @@ -1134,10 +1135,12 @@ def classify_notification( decision_state: DecisionState 字串 ("COMPLETED" / "ERROR" / ...) """ # ADR-073 Phase 3-1: 優先採用 classify_alert_early() 已設定的 notification_type - # 這樣 TYPE-1/TYPE-4D 告警不需進入 LLM 分析路徑 (2026-04-12 ogt) + # 這樣 TYPE-1/TYPE-4D/TYPE-8M 告警不需進入 LLM 分析路徑 (2026-04-12 ogt) _early_type = getattr(incident, "notification_type", None) if _early_type == "TYPE-4D": return NotificationType.TYPE_4_DRIFT + if _early_type == "TYPE-8M": + return NotificationType.TYPE_8M if _early_type == "TYPE-1": return NotificationType.TYPE_1 @@ -1388,14 +1391,7 @@ class TelegramGateway: ("🔍 查健康狀態", f"action:check_health:{incident_id}"), ("📋 查 Log", f"action:check_log:{incident_id}"), ], - "alertchain_health": [ - ("🔍 查 Alertmanager", f"action:check_log:{incident_id}"), - ("🔄 重載設定", f"action:reload_config:{incident_id}"), - ], - "flywheel_health": [ - ("🔍 查飛輪狀態", f"action:check_health:{incident_id}"), - ("📋 查 Log", f"action:check_log:{incident_id}"), - ], + # alertchain_health / flywheel_health → TYPE-8M → send_meta_alert,不走此字典 "ai_system": [ ("🔀 切換 Provider", f"action:switch_provider:{incident_id}"), ], diff --git a/apps/api/tests/test_classify_alert_early.py b/apps/api/tests/test_classify_alert_early.py index 8f747767..d1ede5b5 100644 --- a/apps/api/tests/test_classify_alert_early.py +++ b/apps/api/tests/test_classify_alert_early.py @@ -1,10 +1,14 @@ """ -classify_alert_early() 分類函數單元測試 — ADR-073 Phase 2-2 +classify_alert_early() 分類函數單元測試 — ADR-073 Phase 2-2 + ADR-075 -覆蓋 7 條分類規則的正常路徑與邊界情況: - config_drift, info, backup, infrastructure, kubernetes, database, general +覆蓋 13 條分類規則、10 種告警分類: + config_drift (TYPE-4D) + alertchain_health, flywheel_health (TYPE-8M) — beats severity + info, backup (TYPE-1) + host_resource, infrastructure, kubernetes, database, + storage, devops_tool, external_site, ssl_cert, general (TYPE-3) -2026-04-12 ogt (ADR-073 P2-2 測試補強) +2026-04-12 ogt (ADR-073 P2-2 測試補強 + ADR-075 七類新增) """ import pytest