fix(sre): type backup alerts before generic routing

This commit is contained in:
Your Name
2026-07-19 01:02:09 +08:00
parent dfe75456ab
commit e127c8b56d
4 changed files with 85 additions and 44 deletions

View File

@@ -63,15 +63,43 @@ class TestInfoAlerts:
assert ac == "info"
def test_backup_keyword_info_only(self):
# severity=info → severity 規則先命中TYPE-1
# 成功通知仍是 TYPE-1但不可丟失備份領域分類。
ac, nt = classify_alert_early("BackupJobComplete", "info", {})
assert ac == "backup_restore"
assert nt == "TYPE-1"
def test_backup_keyword_warning_not_type1(self):
# BackupJobFailed severity=warning → 繼續走 prefix 規則,不應是 TYPE-1
# 備份失敗立即進唯讀 BackupCheck不等 24 小時。
ac, nt = classify_alert_early("BackupJobFailed", "warning", {})
assert ac == "backup_restore"
assert nt == "TYPE-3"
@pytest.mark.parametrize(
"alertname",
(
"Backup.awoooi-frequent",
"Backup.langfuse",
"Backup.signoz",
"HostBackupFailed",
"BackupCredentialEscrowEvidenceMissing",
),
)
def test_backup_products_share_typed_readback_domain(self, alertname):
ac, nt = classify_alert_early(alertname, "warning", {})
assert (ac, nt) == ("backup_restore", "TYPE-3")
def test_backup_domain_label_routes_even_without_backup_alertname(self):
ac, nt = classify_alert_early(
"DataProtectionEvidenceMissing",
"critical",
{"asset_domain": "backup_restore"},
)
assert (ac, nt) == ("backup_restore", "TYPE-3")
def test_generic_service_restored_is_not_a_backup_identity(self):
ac, nt = classify_alert_early("ServiceRestored", "info", {})
assert (ac, nt) == ("info", "TYPE-1")
def test_watchdog_heartbeat(self):
# Watchdog (Alertmanager 心跳) severity=none → severity 規則先命中TYPE-1
ac, nt = classify_alert_early("Watchdog", "none", {})
@@ -84,9 +112,9 @@ class TestInfoAlerts:
assert nt == "TYPE-1"
def test_backup_critical_not_type1(self):
# critical backup 告警應走各自 prefix不是純資訊
# critical backup 告警必須是明確的備份領域唯讀調查。
ac, nt = classify_alert_early("BACKUP_MISSING", "critical", {})
assert nt == "TYPE-3"
assert (ac, nt) == ("backup_restore", "TYPE-3")
# --------------------------------------------------------------------------- #
@@ -270,10 +298,9 @@ class TestKubernetes:
assert ac == "kubernetes"
def test_velero_backup_failed_is_kubernetes(self):
# VeleroBackupFailed severity=critical → backup 規則不命中,走 Velero prefix → kubernetes TYPE-3
# Velero 備份是資料保護事件,不可誤掉到 K8s 寫入 executor。
ac, nt = classify_alert_early("VeleroBackupFailed", "critical", {})
assert nt == "TYPE-3"
assert ac == "kubernetes"
assert (ac, nt) == ("backup_restore", "TYPE-3")
def test_velero_backup_success_info_is_type1(self):
# VeleroBackupSuccess severity=info → TYPE-1