feat(drift+target): P0.1+P0.2+P0.3 三修 — drift 分頁分類 + AI 推薦 + target 追 trace

統帥三問決議:全做;AI 推薦 0.85 門檻純顯示不自動;先查 aol 再修

## RCA: awoooi-service 失敗來源
- /api/v1/aiops/kpi 顯示過去 24h 有 1 筆 playbook_executed actor=approval_execution status=failed
- grep codebase: 無任何程式碼寫死 awoooi-service(只有歷史 comment)
- 最可能源: alert_rule_engine._extract_vars 從 labels.service 取值當 Deployment 名
- cf5050c/4f2e122(2026-04-18)已修 NEMOTRON 幻覺雙路徑;本次修第三條路徑

## 修復
### P0.3a alert_rule_engine._extract_vars
- labels.service 降級:-service 結尾先剝 suffix 視為 base name
- match_rule 回傳新增 target_source 欄位追 trace
- 下次 awoooi-service 復發可直接看來源(label.service(stripped) 等)

### P0.3c approval_execution._log_aol_started.input
- 補 parsed_target/operation/namespace 欄位
- 未來 aol 查 failed 可直接看 target,無需推敲

### P0.1 telegram_gateway._send_drift_diff_detail
- 分頁(10 項/頁)取代一次洗版 30 項
- header 3 桶分類計數: 人工高風險 / 一般修改 / K8s 自動
- 底部 ⬅️/➡️ 分頁按鈕(callback: drift_view_page:{report_id}_{page})
- security_interceptor INFO_ACTIONS 加 drift_view_page 白名單

### P0.2 drift_narrator recommendation
- LLM prompt 加 recommendation 欄位(action/confidence/reason)
- action ∈ {adopt, revert, ignore, investigate}
- 卡片頂部顯示「🎯 AI 建議: 回滾 (85%) — reason」
- LLM 失敗走 _fallback_recommendation(規則式依 intent 對應)
- 卡片 diff_summary 上限 500 → 1500 字容納推薦 + narrative + items
- 統帥指令:純顯示不自動執行(門檻 0.85 保留未來)

## 驗證
- 90 個 pytest test 全過(drift + rule_engine + approval_execution)
- 5 檔 AST syntax check 過

## 下次驗收
1. 下次 drift 觸發 → 卡片頂部有「🎯 AI 建議」
2. drift_view 按下 → 3 桶分類 header + ⬅️/➡️
3. awoooi-service 若復發 → automation_operation_log.input.parsed_target 直接查

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Your Name
2026-04-20 04:01:30 +08:00
parent 8d40bbff2b
commit 54d60d04f5
6 changed files with 319 additions and 37 deletions

View File

@@ -6,6 +6,44 @@
---
## 📍 2026-04-20 上午 — P0.1 + P0.2 + P0.3 三項 Drift/Target 修復
### 統帥三問 RCA 後決議
1. 全做 P0.1 + P0.2 + P0.3
2. AI 推薦門檻 0.85 OK**但先不 auto-execute**(純推薦)
3. 先查 aol 找 awoooi-service 來源 trace 再修
### RCA 結論awoooi-service 失敗)
- 透過 `/api/v1/aiops/kpi` 看到過去 24h 有 1 筆 `playbook_executed actor=approval_execution status=failed`
- grep 全 codebase**無任何程式碼寫死 `awoooi-service`**(只有歷史 comment
- 最可能來源:`alert_rule_engine._extract_vars``labels.service` 取值當 Deployment 名K8s Service 名 ≠ Deployment 名)
- cf59050 / 4f2e1222026-04-18已修 NEMOTRON 幻覺雙路徑本次修第三條路徑rule engine label fallback
### 修復內容5 檔 / 281 行)
| # | 檔案 | 內容 |
|---|------|------|
| P0.3a | `alert_rule_engine.py` | `_extract_vars` service label 降級:`-service` 結尾先剝 suffix同時回傳 `target_source` 追蹤來源 |
| P0.3c | `approval_execution.py` | `_log_aol_started` input 補 `parsed_target/operation/namespace`,下次失敗可直接從 aol 查 trace |
| P0.3b | `approval_execution.py` | 既有 `_log_aol_completed` 本就寫 `resource_name/error/stderr`,追 trace 夠用 |
| P0.1 | `telegram_gateway.py` | `_send_drift_diff_detail` 加分頁10 項/頁)+ 3 桶分類 header人工高風險/一般修改/K8s 自動)+ ⬅️/➡️ 按鈕 |
| P0.1 | `security_interceptor.py` | INFO_ACTIONS 加 `drift_view_page` 白名單 |
| P0.2 | `drift_narrator_service.py` | LLM prompt 加 recommendation 欄位adopt/revert/ignore/investigate + confidence + reason|
| P0.2 | `drift_narrator_service.py` | `_render_telegram_body` 頂部顯示「🎯 AI 建議:⏪ 回滾 (85%) — 原因」 |
| P0.2 | `drift_narrator_service.py` + `telegram_gateway.py` | 卡片 diff_summary 上限 500 → 1500 字,容納推薦 + narrative + items |
### 驗證
- 90 個 pytest test 全過drift / rule_engine / approval_execution
- 5 檔 AST syntax check 過
- AI 推薦**純顯示不自動執行**(依統帥指令)
### 下一步
1. 等下次 real drift 觸發,驗卡片頂部有「🎯 AI 建議」
2. 等下次 drift_view 按下,驗分頁 + 分類 header + ⬅️/➡️ 按鈕
3. 若 awoooi-service 再復發,查 `automation_operation_log``input.parsed_target` 直接追來源
4. P1 留drift 分類器 (noise/controller/human) 進 DB、auto-adopt 門檻 ≥0.85 + low risk
---
## 📍 2026-04-19 晚 21:30 — Gap Review + 3 Gap 修 + AI 自主化 1/9→4/9 LLM 🎖️🎖️🎖️🎖️
### 統帥核心指示