fix(api): Sprint 4 首席架構師 Review P0 修正 — hash 統一 + 積木化合規

P0-1: anomaly_key hash 推導統一
- B1: 新增 _derive_anomaly_key() 使用 AnomalyCounter.hash_signature()
  取代 symptoms.compute_hash()
- B3/B4: namespace 改用 signal.labels.get("namespace", "")
  修正 getattr(signal, "namespace", "") 永遠回傳空字串

P0-2: Router 層積木化合規
- C1/C2: 封裝 get_all_disposition_stats() 到 AnomalyCounter
- Router 不再直接存取 counter.redis
- stats.py 移除未使用的 days/stats 參數

P1: get_frequency() 填充 disposition 欄位
- 與 _record_anomaly_impl() 一致,回傳完整處置統計

首席架構師評分: 82/100 → P0 全數修正

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
OG T
2026-04-07 12:53:12 +08:00
parent a85e9ced08
commit 561bcb638b
6 changed files with 122 additions and 69 deletions

View File

@@ -234,11 +234,12 @@ class ApprovalExecutionService:
if not incident or not incident.signals:
return None
# 從第一個 signal 建立 anomaly signature
# P0-1 Fix: namespace 從 signal.labels 取,非 getattr
signal = incident.signals[0]
signature = {
"alert_name": signal.alert_name,
"service": incident.affected_services[0] if incident.affected_services else "",
"namespace": getattr(signal, "namespace", ""),
"namespace": signal.labels.get("namespace", "") if signal.labels else "",
}
from src.services.anomaly_counter import AnomalyCounter
return AnomalyCounter.hash_signature(signature)