-
Notifications
You must be signed in to change notification settings - Fork 806
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: failing tests due to change in incident name (#2550)
- Loading branch information
Showing
4 changed files
with
41 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,16 +2,21 @@ | |
import hashlib | ||
import json | ||
import os | ||
import time | ||
import uuid | ||
|
||
import pytest | ||
from sqlalchemy import desc, asc | ||
|
||
from keep.api.core.db import create_rule as create_rule_db, get_last_incidents, get_incident_alerts_by_incident_id | ||
from keep.api.core.db import create_rule as create_rule_db | ||
from keep.api.core.db import get_incident_alerts_by_incident_id, get_last_incidents | ||
from keep.api.core.db import get_rules as get_rules_db | ||
from keep.api.core.dependencies import SINGLE_TENANT_UUID | ||
from keep.api.models.alert import AlertDto, AlertSeverity, AlertStatus, IncidentSeverity, IncidentStatus | ||
from keep.api.models.alert import ( | ||
AlertDto, | ||
AlertSeverity, | ||
AlertStatus, | ||
IncidentSeverity, | ||
IncidentStatus, | ||
) | ||
from keep.api.models.db.alert import Alert | ||
from keep.api.models.db.rule import ResolveOn | ||
from keep.rulesengine.rulesengine import RulesEngine | ||
|
@@ -264,9 +269,12 @@ def test_incident_attributes(db_session): | |
# check that there are results | ||
assert results is not None | ||
assert len(results) == 1 | ||
assert results[0].user_generated_name == "Incident generated by rule {}".format(rules[0].name) | ||
assert results[0].user_generated_name == "{}".format(rules[0].name) | ||
assert results[0].alerts_count == i + 1 | ||
assert results[0].last_seen_time.isoformat(timespec='milliseconds')+"Z" == alert.lastReceived | ||
assert ( | ||
results[0].last_seen_time.isoformat(timespec="milliseconds") + "Z" | ||
== alert.lastReceived | ||
) | ||
assert results[0].start_time == alerts[0].timestamp | ||
|
||
|
||
|
@@ -322,7 +330,7 @@ def test_incident_severity(db_session): | |
# check that there are results | ||
assert results is not None | ||
assert len(results) == 1 | ||
assert results[0].user_generated_name == "Incident generated by rule {}".format(rules[0].name) | ||
assert results[0].user_generated_name == "{}".format(rules[0].name) | ||
assert results[0].alerts_count == 3 | ||
assert results[0].severity.value == IncidentSeverity.INFO.value | ||
|
||
|
@@ -341,7 +349,7 @@ def test_incident_resolution_on_all(db_session, create_alert): | |
definition_cel='(severity == "critical")', | ||
created_by="[email protected]", | ||
require_approve=False, | ||
resolve_on=ResolveOn.ALL.value | ||
resolve_on=ResolveOn.ALL.value, | ||
) | ||
|
||
incidents, total_count = get_last_incidents( | ||
|
@@ -353,13 +361,13 @@ def test_incident_resolution_on_all(db_session, create_alert): | |
assert total_count == 0 | ||
|
||
create_alert( | ||
f"Something went wrong", | ||
"Something went wrong", | ||
AlertStatus.FIRING, | ||
datetime.datetime.utcnow(), | ||
{"severity": AlertSeverity.CRITICAL.value}, | ||
) | ||
create_alert( | ||
f"Something went wrong again", | ||
"Something went wrong again", | ||
AlertStatus.FIRING, | ||
datetime.datetime.utcnow(), | ||
{"severity": AlertSeverity.CRITICAL.value}, | ||
|
@@ -387,7 +395,7 @@ def test_incident_resolution_on_all(db_session, create_alert): | |
|
||
# Same fingerprint | ||
create_alert( | ||
f"Something went wrong", | ||
"Something went wrong", | ||
AlertStatus.RESOLVED, | ||
datetime.datetime.utcnow(), | ||
{"severity": AlertSeverity.CRITICAL.value}, | ||
|
@@ -415,7 +423,7 @@ def test_incident_resolution_on_all(db_session, create_alert): | |
assert incident.status == IncidentStatus.FIRING.value | ||
|
||
create_alert( | ||
f"Something went wrong again", | ||
"Something went wrong again", | ||
AlertStatus.RESOLVED, | ||
datetime.datetime.utcnow(), | ||
{"severity": AlertSeverity.CRITICAL.value}, | ||
|
@@ -444,9 +452,11 @@ def test_incident_resolution_on_all(db_session, create_alert): | |
|
||
@pytest.mark.parametrize( | ||
"direction,second_fire_order", | ||
[(ResolveOn.FIRST.value, ('fp2', 'fp1')), (ResolveOn.LAST.value, ('fp2', 'fp1'))] | ||
[(ResolveOn.FIRST.value, ("fp2", "fp1")), (ResolveOn.LAST.value, ("fp2", "fp1"))], | ||
) | ||
def test_incident_resolution_on_edge(db_session, create_alert, direction, second_fire_order): | ||
def test_incident_resolution_on_edge( | ||
db_session, create_alert, direction, second_fire_order | ||
): | ||
|
||
create_rule_db( | ||
tenant_id=SINGLE_TENANT_UUID, | ||
|
@@ -560,6 +570,7 @@ def test_incident_resolution_on_edge(db_session, create_alert, direction, second | |
assert alert_count == 2 | ||
assert incident.status == IncidentStatus.RESOLVED.value | ||
|
||
|
||
# Next steps: | ||
# - test that alerts in the same group are being updated correctly | ||
# - test group are being updated correctly | ||
|