feat(adr-075): 修復 Telegram 動態按鈕 4 個斷點 + 新增 7 種告警分類
Some checks failed
CD Pipeline / build-and-deploy (push) Has been cancelled
Some checks failed
CD Pipeline / build-and-deploy (push) Has been cancelled
斷點 A: decision_manager 提取 alert_category/notification_type 傳入 send_approval_card 斷點 B: send_approval_card 新增參數並傳遞至 _build_inline_keyboard 斷點 C: 互動型通知 (TYPE-3/4/4D/8M) 禁止發 SRE 群組,防 nonce 洩漏 斷點 D: _CATEGORY_BUTTONS k8s_workload → kubernetes + 新增 6 類按鈕組 classify_alert_early 新增: alertchain_health, flywheel_health, storage, devops_tool, external_site, ssl_cert, host_resource (從 infrastructure 分離) Test: 52 classify + 664 total passed Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1355,8 +1355,9 @@ class TelegramGateway:
|
||||
notification_type: 通知類型 (TYPE-1/2/3/4/4D)
|
||||
"""
|
||||
# TYPE-3 動態操作按鈕 (ADR-071-E)
|
||||
# ADR-075: 統一用 kubernetes(移除舊 k8s_workload),新增 storage/external_site/alertchain_health/flywheel_health
|
||||
_CATEGORY_BUTTONS: dict[str, list[tuple[str, str]]] = {
|
||||
"k8s_workload": [
|
||||
"kubernetes": [
|
||||
("🔄 重啟", f"action:restart:{incident_id}"),
|
||||
("📈 擴容", f"action:scale_up:{incident_id}"),
|
||||
("📉 縮容", f"action:scale_down:{incident_id}"),
|
||||
@@ -1379,6 +1380,22 @@ class TelegramGateway:
|
||||
("🔄 重啟服務", f"action:restart_service:{incident_id}"),
|
||||
("📋 查 Log", f"action:check_log:{incident_id}"),
|
||||
],
|
||||
"storage": [
|
||||
("🔄 重啟 MinIO", f"action:restart_service:{incident_id}"),
|
||||
("📋 查 Log", f"action:check_log:{incident_id}"),
|
||||
],
|
||||
"external_site": [
|
||||
("🔍 查健康狀態", 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}"),
|
||||
],
|
||||
"ai_system": [
|
||||
("🔀 切換 Provider", f"action:switch_provider:{incident_id}"),
|
||||
],
|
||||
@@ -1473,6 +1490,9 @@ class TelegramGateway:
|
||||
nemotron_tool_backend: str = "",
|
||||
# 2026-04-05 Claude Code: incident_id 用於 detail/reanalyze/history 按鈕
|
||||
incident_id: str = "",
|
||||
# 2026-04-12 ogt: ADR-075 告警分類與通知類型(斷點 B 修復)
|
||||
alert_category: str = "",
|
||||
notification_type: str = "",
|
||||
) -> dict:
|
||||
"""
|
||||
推送待簽核卡片到 Telegram (v7.0 含 SignOz 整合)
|
||||
@@ -1553,11 +1573,14 @@ class TelegramGateway:
|
||||
|
||||
# 建立按鈕 (含自動調優)
|
||||
# 2026-04-05 Claude Code: 傳入 incident_id 以啟用 detail/reanalyze/history 按鈕
|
||||
# ADR-075: 傳入 alert_category/notification_type 以啟用分類動態按鈕(斷點 B 修復)
|
||||
keyboard = self._build_inline_keyboard(
|
||||
approval_id=approval_id,
|
||||
include_auto_tuning=bool(auto_tuning_command),
|
||||
auto_tuning_command=auto_tuning_command,
|
||||
incident_id=incident_id,
|
||||
alert_category=alert_category,
|
||||
notification_type=notification_type,
|
||||
)
|
||||
|
||||
# 發送訊息
|
||||
@@ -1597,8 +1620,14 @@ class TelegramGateway:
|
||||
|
||||
# 2026-04-03 ogt: 發到 SRE 群組並觸發 AI 雙向討論 (Triumvirate ADR-053)
|
||||
# 2026-04-05 ogt: 升級為完整 v7.0 格式,與個人 chat 一致
|
||||
# 非同步執行,失敗不影響告警主流程
|
||||
if settings.SRE_GROUP_CHAT_ID:
|
||||
# 2026-04-12 ogt: ADR-075 斷點 C 修復 — 含按鈕的互動型通知禁止發群組(nonce 洩漏)
|
||||
# TYPE-1/TYPE-2 → 可發群組(純資訊,無 callback 按鈕)
|
||||
# TYPE-3/TYPE-4/TYPE-4D/TYPE-8M → 僅 DM,不發群組
|
||||
_interactive_types = {"TYPE-3", "TYPE-4", "TYPE-4D", "TYPE-8M"}
|
||||
_is_interactive = notification_type in _interactive_types or (
|
||||
not notification_type and alert_category # 有分類但無明確型別 → 視為互動型
|
||||
)
|
||||
if settings.SRE_GROUP_CHAT_ID and not _is_interactive:
|
||||
asyncio.create_task(
|
||||
self._send_approval_card_to_group(
|
||||
approval_id=approval_id,
|
||||
|
||||
Reference in New Issue
Block a user