fix(incidents): 修復兩個 DB 完整性問題
All checks were successful
CD Pipeline / build-and-deploy (push) Successful in 14m52s
All checks were successful
CD Pipeline / build-and-deploy (push) Successful in 14m52s
1. alertname IS NULL(4 筆歷史修復 + code fallback)
- incident_repository.py: alertname 補 labels["alertname"] fallback
- SQL UPDATE: 用 signals->0->>'alert_name' 修補存量 4 筆 NULL 記錄
2. TYPE-1 incidents 永遠卡 INVESTIGATING(18 筆修復 + code fix)
- webhooks.py: TYPE-1 短路後立即加 resolve_incident background task
- SQL UPDATE: 批次將存量 TYPE-1 INVESTIGATING → RESOLVED
根因: ADR-073 TYPE-1 短路設計只發通知,未關閉 incident 狀態
backup/heartbeat 告警每小時觸發 → 無限累積 INVESTIGATING 記錄
2026-04-15 ogt + Claude Sonnet 4.6(亞太)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1350,6 +1350,14 @@ async def alertmanager_webhook(
|
||||
notification_type="TYPE-1",
|
||||
alert_category=alert_category,
|
||||
)
|
||||
# 2026-04-15 ogt: TYPE-1 純資訊告警建立後立即關閉
|
||||
# 設計原則: backup/heartbeat/info 告警無需追蹤狀態,通知即完成
|
||||
# 防止 incidents 表無限累積 INVESTIGATING 記錄(ADR-073 漏洞修補)
|
||||
background_tasks.add_task(
|
||||
get_incident_service().resolve_incident,
|
||||
_info_incident_id,
|
||||
"info_notification",
|
||||
)
|
||||
background_tasks.add_task(
|
||||
get_telegram_gateway().send_info_notification,
|
||||
incident_id=_info_incident_id,
|
||||
|
||||
@@ -79,7 +79,14 @@ def _incident_to_record_data(incident: Incident) -> dict[str, Any]:
|
||||
"resolved_at": incident.resolved_at,
|
||||
"closed_at": incident.closed_at,
|
||||
"frequency_snapshot": frequency_snapshot,
|
||||
"alertname": incident.signals[0].alert_name if incident.signals else None, # ADR-073 Phase 2-1
|
||||
# ADR-073 Phase 2-1: alertname 欄位 — 優先從 signals[0].alert_name,
|
||||
# fallback 到 signals[0].labels["alertname"](防止 signal 建立時 alert_name 為空)
|
||||
# 2026-04-15 ogt: 補 labels fallback(4 筆歷史 NULL 根因修復)
|
||||
"alertname": (
|
||||
(incident.signals[0].alert_name or
|
||||
(incident.signals[0].labels or {}).get("alertname"))
|
||||
if incident.signals else None
|
||||
),
|
||||
"notification_type": incident.notification_type, # ADR-073 Phase 2-2
|
||||
"alert_category": incident.alert_category, # ADR-073 Phase 2-2
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user