fix: suppress critical complaint alert once restored_at is set
This commit is contained in:
@@ -278,11 +278,15 @@ def run_alert_check(db: Session) -> dict[str, object]:
|
|||||||
created_at=eff_now,
|
created_at=eff_now,
|
||||||
)
|
)
|
||||||
|
|
||||||
# 7. Critical complaints open >= escalation_open_complaint_hours
|
# 7. Critical complaints open >= escalation_open_complaint_hours (and not yet restored)
|
||||||
crit_complaints = (
|
crit_complaints = (
|
||||||
db.query(Complaint)
|
db.query(Complaint)
|
||||||
.options(joinedload(Complaint.asset))
|
.options(joinedload(Complaint.asset))
|
||||||
.filter(Complaint.call_status != "closed", Complaint.priority == "critical")
|
.filter(
|
||||||
|
Complaint.call_status != "closed",
|
||||||
|
Complaint.priority == "critical",
|
||||||
|
Complaint.restored_at.is_(None),
|
||||||
|
)
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
threshold_secs = cfg["critical_hours"] * 3600
|
threshold_secs = cfg["critical_hours"] * 3600
|
||||||
|
|||||||
@@ -553,6 +553,38 @@ def test_sla_breach_alert_emitted_and_suppressed_when_restored(client, db):
|
|||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
assert crit_unrestored == []
|
assert crit_unrestored == []
|
||||||
|
|
||||||
|
# When open > 24h, unrestored complaint triggers critical_complaint alert,
|
||||||
|
# but restored complaint does NOT trigger it even if not closed yet
|
||||||
|
past_26h = now - timedelta(hours=26)
|
||||||
|
c_unrestored.registered_at = past_26h
|
||||||
|
c_restored.registered_at = past_26h
|
||||||
|
db.commit()
|
||||||
|
run_alert_check(db)
|
||||||
|
db.commit()
|
||||||
|
|
||||||
|
crit_unrestored_26h = (
|
||||||
|
db.query(Notification)
|
||||||
|
.filter(
|
||||||
|
Notification.type == "critical_complaint",
|
||||||
|
Notification.entity_type == "complaint",
|
||||||
|
Notification.entity_id == cid_unrestored,
|
||||||
|
)
|
||||||
|
.all()
|
||||||
|
)
|
||||||
|
assert len(crit_unrestored_26h) == 1
|
||||||
|
assert "Critical Complaint Open > 24h" in crit_unrestored_26h[0].title
|
||||||
|
|
||||||
|
crit_restored_26h = (
|
||||||
|
db.query(Notification)
|
||||||
|
.filter(
|
||||||
|
Notification.type == "critical_complaint",
|
||||||
|
Notification.entity_type == "complaint",
|
||||||
|
Notification.entity_id == cid_restored,
|
||||||
|
)
|
||||||
|
.all()
|
||||||
|
)
|
||||||
|
assert crit_restored_26h == []
|
||||||
finally:
|
finally:
|
||||||
db.query(Notification).filter(
|
db.query(Notification).filter(
|
||||||
Notification.entity_type == "complaint",
|
Notification.entity_type == "complaint",
|
||||||
|
|||||||
Reference in New Issue
Block a user