From 70c67fafde35397846a6c9bc5cf5fa283cfc663f Mon Sep 17 00:00:00 2001 From: Vladimir Filonov Date: Sun, 24 Nov 2024 15:42:31 +0400 Subject: [PATCH] Fix groupping in Rule histogram query and migaration deps --- keep/api/core/db.py | 4 ++-- ...22-48_bdae8684d0b4.py => 2024-11-24-22-48_bdae8684d0b4.py} | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename keep/api/models/db/migrations/versions/{2024-11-13-22-48_bdae8684d0b4.py => 2024-11-24-22-48_bdae8684d0b4.py} (97%) diff --git a/keep/api/core/db.py b/keep/api/core/db.py index 84466cf63..8ace6079b 100644 --- a/keep/api/core/db.py +++ b/keep/api/core/db.py @@ -1804,7 +1804,7 @@ def get_rule_distribution(tenant_id, minute=False): session.query( Rule.id.label("rule_id"), Rule.name.label("rule_name"), - Incident.id.label("group_id"), + Incident.id.label("incident_id"), Incident.rule_fingerprint.label("rule_fingerprint"), timestamp_format.label("time"), func.count(LastAlertToIncident.fingerprint).label("hits"), @@ -1817,7 +1817,7 @@ def get_rule_distribution(tenant_id, minute=False): ) .filter(Rule.tenant_id == tenant_id) # Filter by tenant_id .group_by( - "rule_id", "rule_name", "incident_id", "rule_fingerprint", "time" + Rule.id, "rule_name", Incident.id, "rule_fingerprint", "time" ) # Adjusted here .order_by("time") ) diff --git a/keep/api/models/db/migrations/versions/2024-11-13-22-48_bdae8684d0b4.py b/keep/api/models/db/migrations/versions/2024-11-24-22-48_bdae8684d0b4.py similarity index 97% rename from keep/api/models/db/migrations/versions/2024-11-13-22-48_bdae8684d0b4.py rename to keep/api/models/db/migrations/versions/2024-11-24-22-48_bdae8684d0b4.py index 587f072f9..6473a534d 100644 --- a/keep/api/models/db/migrations/versions/2024-11-13-22-48_bdae8684d0b4.py +++ b/keep/api/models/db/migrations/versions/2024-11-24-22-48_bdae8684d0b4.py @@ -14,7 +14,7 @@ # revision identifiers, used by Alembic. revision = "bdae8684d0b4" -down_revision = "620b6c048091" +down_revision = "192157fd5788" branch_labels = None depends_on = None @@ -31,7 +31,7 @@ def populate_db(): from alert join ( select - alert.fingerprint, max(alert.timestamp) as last_received + alert.tenant_id, alert.fingerprint, max(alert.timestamp) as last_received from alert group by fingerprint, tenant_id ) as a ON alert.fingerprint = a.fingerprint and alert.timestamp = a.last_received and alert.tenant_id = a.tenant_id