From ac2e4304bfd3759843e8b2f9eaf2718ddd43a494 Mon Sep 17 00:00:00 2001 From: DolevNe Date: Mon, 18 Aug 2025 13:47:03 +0000 Subject: [PATCH 1/2] feat/changed get alert by fingerprint --- keep/api/routes/alerts.py | 4 ++-- pyproject.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/keep/api/routes/alerts.py b/keep/api/routes/alerts.py index 2adaa090dc..da40cb947d 100644 --- a/keep/api/routes/alerts.py +++ b/keep/api/routes/alerts.py @@ -757,8 +757,8 @@ def get_alert( "tenant_id": tenant_id, }, ) - all_alerts = get_all_alerts(authenticated_entity=authenticated_entity) - alert = list(filter(lambda alert: alert.fingerprint == fingerprint, all_alerts)) + all_alerts = get_alerts_by_fingerprint(tenant_id=tenant_id,fingerprint=fingerprint) + alert = convert_db_alerts_to_dto_alerts(all_alerts) if alert: return alert[0] else: diff --git a/pyproject.toml b/pyproject.toml index fadf6a303a..b91d2f24bd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "keep" -version = "0.47.0" +version = "0.47.1" description = "Alerting. for developers, by developers." authors = ["Keep Alerting LTD"] packages = [{include = "keep"}] From 8db87454718846c2424120bbdc34385a8e93b241 Mon Sep 17 00:00:00 2001 From: Yarin-Shitrit Date: Wed, 20 Aug 2025 14:08:17 +0300 Subject: [PATCH 2/2] Added UT's for get_alert_by_fingerprint --- tests/test_get_alert_by_fingerprint.py | 54 ++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/test_get_alert_by_fingerprint.py diff --git a/tests/test_get_alert_by_fingerprint.py b/tests/test_get_alert_by_fingerprint.py new file mode 100644 index 0000000000..d3c1420ed3 --- /dev/null +++ b/tests/test_get_alert_by_fingerprint.py @@ -0,0 +1,54 @@ +import pytest +from datetime import datetime, timedelta +import pytz + +from keep.api.models.alert import AlertStatus +from tests.fixtures.client import client, setup_api_key, test_app # noqa + + +@pytest.mark.parametrize( + "test_app", + [ + { + "AUTH_TYPE": "NOAUTH", + }, + ], + indirect=True, +) +def test_get_alert_by_fingerprint_success(db_session, client, test_app, create_alert): + setup_api_key(db_session, "some-api-key") + + fingerprint = "unit-test-fp" + now = datetime.now(tz=pytz.utc) + create_alert(fingerprint, AlertStatus.FIRING, now - timedelta(minutes=1)) + + response = client.get( + f"/alerts/{fingerprint}", headers={"x-api-key": "some-api-key"} + ) + + assert response.status_code == 200 + body = response.json() + assert body["fingerprint"] == fingerprint + assert body["status"].lower() == "firing" + + +@pytest.mark.parametrize( + "test_app", + [ + { + "AUTH_TYPE": "NOAUTH", + }, + ], + indirect=True, +) +def test_get_alert_by_fingerprint_not_found(db_session, client, test_app): + setup_api_key(db_session, "some-api-key") + + response = client.get( + "/alerts/non-existent-fp", headers={"x-api-key": "some-api-key"} + ) + + assert response.status_code == 404 + assert response.json()["detail"] == "Alert not found" + +