From ccb1e0a23a6a003bf87ce8ff29f8e188ab61c7db Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Fri, 3 Feb 2023 12:04:57 +0100 Subject: [PATCH] feat(alerts): user series-name for notifications message --- api/chalicelib/core/alerts_listener.py | 9 ++++++--- api/chalicelib/core/alerts_processor.py | 2 +- ee/api/chalicelib/core/alerts_listener.py | 9 ++++++--- ee/api/chalicelib/core/alerts_processor.py | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/api/chalicelib/core/alerts_listener.py b/api/chalicelib/core/alerts_listener.py index 0fa193964..1a0a75a28 100644 --- a/api/chalicelib/core/alerts_listener.py +++ b/api/chalicelib/core/alerts_listener.py @@ -5,7 +5,7 @@ def get_all_alerts(): with pg_client.PostgresClient(long_query=True) as cur: query = """SELECT -1 AS tenant_id, alert_id, - project_id, + projects.project_id, detection_method, query, options, @@ -13,10 +13,13 @@ def get_all_alerts(): alerts.name, alerts.series_id, filter, - change + change, + COALESCE(metrics.name || '.' || (COALESCE(metric_series.name, 'series ' || index)) || '.count', + query ->> 'left') AS series_name FROM public.alerts - LEFT JOIN metric_series USING (series_id) INNER JOIN projects USING (project_id) + LEFT JOIN metric_series USING (series_id) + LEFT JOIN metrics USING (metric_id) WHERE alerts.deleted_at ISNULL AND alerts.active AND projects.active diff --git a/api/chalicelib/core/alerts_processor.py b/api/chalicelib/core/alerts_processor.py index 76ae5c615..8049b2f39 100644 --- a/api/chalicelib/core/alerts_processor.py +++ b/api/chalicelib/core/alerts_processor.py @@ -228,7 +228,7 @@ def generate_notification(alert, result): "alertId": alert["alertId"], "tenantId": alert["tenantId"], "title": alert["name"], - "description": f"has been triggered, {alert['query']['left']} = {left} ({alert['query']['operator']} {right}).", + "description": f"has been triggered, {alert['seriesName']} = {left} ({alert['query']['operator']} {right}).", "buttonText": "Check metrics for more details", "buttonUrl": f"/{alert['projectId']}/metrics", "imageUrl": None, diff --git a/ee/api/chalicelib/core/alerts_listener.py b/ee/api/chalicelib/core/alerts_listener.py index 6a97daf93..ebd9afa56 100644 --- a/ee/api/chalicelib/core/alerts_listener.py +++ b/ee/api/chalicelib/core/alerts_listener.py @@ -5,7 +5,7 @@ def get_all_alerts(): with pg_client.PostgresClient(long_query=True) as cur: query = """SELECT tenant_id, alert_id, - project_id, + projects.project_id, detection_method, query, options, @@ -13,10 +13,13 @@ def get_all_alerts(): alerts.name, alerts.series_id, filter, - change + change, + COALESCE(metrics.name || '.' || (COALESCE(metric_series.name, 'series ' || index)) || '.count', + query ->> 'left') AS series_name FROM public.alerts - LEFT JOIN metric_series USING (series_id) INNER JOIN projects USING (project_id) + LEFT JOIN metric_series USING (series_id) + LEFT JOIN metrics USING (metric_id) WHERE alerts.deleted_at ISNULL AND alerts.active AND projects.active diff --git a/ee/api/chalicelib/core/alerts_processor.py b/ee/api/chalicelib/core/alerts_processor.py index 326d17ffc..69a0f7f5f 100644 --- a/ee/api/chalicelib/core/alerts_processor.py +++ b/ee/api/chalicelib/core/alerts_processor.py @@ -233,7 +233,7 @@ def generate_notification(alert, result): "alertId": alert["alertId"], "tenantId": alert["tenantId"], "title": alert["name"], - "description": f"has been triggered, {alert['query']['left']} = {left} ({alert['query']['operator']} {right}).", + "description": f"has been triggered, {alert['seriesName']} = {left} ({alert['query']['operator']} {right}).", "buttonText": "Check metrics for more details", "buttonUrl": f"/{alert['projectId']}/metrics", "imageUrl": None,