fix(km): 修補 KMConversionService 兩個屬性錯誤
Some checks failed
CD Pipeline / build-and-deploy (push) Failing after 28s

- incident.title → getattr(incident, 'title', None) or alertname
  (Incident model 無 title 欄位)
- km_entry.entry_id → km_entry.id
  (KnowledgeEntry model 主鍵為 id 非 entry_id)
- 補跑後 KM entries 714 → 821 (+107), incidents.vectorized 全部歸零

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
OG T
2026-04-12 17:52:57 +08:00
parent 80cdd36b9d
commit 587d745a50

View File

@@ -132,7 +132,8 @@ class KMConversionService:
resolution_time=resolution_time,
)
title = f"{alertname} @ {affected_services[:40]}{incident.title[:60] if incident.title else '未知'}"
_inc_title = getattr(incident, "title", None) or alertname
title = f"{alertname} @ {affected_services[:40]}{_inc_title[:60]}"
tags = [alertname, affected_services, severity, notification_type]
if alert_category != "unknown":
@@ -157,10 +158,10 @@ class KMConversionService:
event_type="KM_CONVERTED",
incident_id=incident.incident_id,
actor="km_conversion_service",
action_detail=f"KM entry created: {km_entry.entry_id}",
action_detail=f"KM entry created: {km_entry.id}",
success=True,
context={
"km_entry_id": km_entry.entry_id,
"km_entry_id": km_entry.id,
"quality_level": target_status.value,
"notification_type": notification_type,
},
@@ -187,7 +188,7 @@ class KMConversionService:
logger.info(
"km_incident_vectorized_flagged",
incident_id=incident.incident_id,
km_entry_id=km_entry.entry_id,
km_entry_id=km_entry.id,
)
except Exception as _ve:
logger.warning(
@@ -226,13 +227,13 @@ class KMConversionService:
logger.info(
"km_converted",
incident_id=incident.incident_id,
km_entry_id=km_entry.entry_id,
km_entry_id=km_entry.id,
quality_level=target_status.value,
notification_type=notification_type,
)
return {
"km_entry_id": km_entry.entry_id,
"km_entry_id": km_entry.id,
"quality_level": target_status.value,
}
@@ -312,7 +313,7 @@ class KMConversionService:
f"- 觸發時間: {created_at_str}\n"
f"- 解決時間: {resolved_at_str}\n"
+ (f"- 即時情境: {context_summary}\n" if context_summary else "")
+ f"\n## 根因分析\n{root_cause or incident.title or '未知'}\n"
+ f"\n## 根因分析\n{root_cause or getattr(incident, 'title', None) or '未知'}\n"
+ (
f"\n## 執行動作\n"
f"- 類型: {action_type}\n"