fix(ai): isolate heavy Ollama workloads from GCP alert lane
All checks were successful
CD Pipeline / tests (push) Successful in 54s
Code Review / ai-code-review (push) Successful in 10s
CD Pipeline / build-and-deploy (push) Successful in 3m19s
CD Pipeline / post-deploy-checks (push) Successful in 3m12s

This commit is contained in:
Your Name
2026-05-05 23:05:59 +08:00
parent 1dcc6d61dc
commit c4854bb355
17 changed files with 146 additions and 84 deletions

View File

@@ -35,8 +35,9 @@ logger = structlog.get_logger(__name__)
# ============================================================
# 2026-05-03 ogt: ADR-110 GCP-A Primary — 改從 settings 讀取,不再硬編碼 111
def _get_ollama_url() -> str:
from src.core.config import get_settings
return get_settings().OLLAMA_URL
from src.services.ollama_endpoint_resolver import resolve_ollama_endpoint
return resolve_ollama_endpoint("deep_rca")
# D1 集中化 2026-04-11: 從 models.json providers.ollama.models.log_anomaly 讀取
SUMMARY_MODEL = get_model("ollama", "log_anomaly")
LLM_TIMEOUT = 180.0 # deepseek-r1 硬超時
@@ -145,7 +146,7 @@ class LogSummaryService:
self.summarize(pod_name, namespace),
timeout=SOFT_TIMEOUT,
)
except asyncio.TimeoutError:
except TimeoutError:
logger.info(
"log_summary_soft_timeout",
pod=pod_name,
@@ -182,7 +183,7 @@ class LogSummaryService:
def _extract_anomaly_lines(self, raw_logs: str) -> list[str]:
"""過濾異常行 + 敏感資料遮蔽,取最後 ANOMALY_TAIL_LINES 行"""
lines = raw_logs.splitlines()
anomaly = [l for l in lines if _ANOMALY_PATTERN.search(l)]
anomaly = [line for line in lines if _ANOMALY_PATTERN.search(line)]
# 取最後 N 行
anomaly = anomaly[-ANOMALY_TAIL_LINES:]
# 遮蔽敏感資料