From e2ebe7ea146aaa2f59f147d50e65c0a24342f18c Mon Sep 17 00:00:00 2001 From: Noy Arie Date: Mon, 4 Sep 2023 15:34:09 +0300 Subject: [PATCH] Alert links updates (#1137) * change copy of alert links * no link for model error - grouped * rename --- elementary/monitor/alerts/group_of_alerts.py | 11 +++---- .../monitor/alerts/report_link_utils.py | 32 ++++++++++++++----- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/elementary/monitor/alerts/group_of_alerts.py b/elementary/monitor/alerts/group_of_alerts.py index 821c08b36..784d62d7a 100644 --- a/elementary/monitor/alerts/group_of_alerts.py +++ b/elementary/monitor/alerts/group_of_alerts.py @@ -5,10 +5,7 @@ from elementary.clients.slack.slack_message_builder import SlackMessageBuilder from elementary.monitor.alerts.alert import Alert, SlackAlertMessageBuilder from elementary.monitor.alerts.model import ModelAlert -from elementary.monitor.alerts.report_link_utils import ( - get_model_runs_link, - get_model_test_runs_link, -) +from elementary.monitor.alerts.report_link_utils import get_model_test_runs_link from elementary.monitor.alerts.schema.alert import ReportLinkData from elementary.monitor.alerts.schema.alert_group_component import ( AlertGroupComponent, @@ -352,10 +349,10 @@ def _attention_required_blocks(self): return preview_blocks def _get_report_link(self) -> Optional[ReportLinkData]: - if self._components_to_alerts.get(ModelErrorComponent): - return get_model_runs_link(self._report_url, self._model_unique_id) - else: + # No report link when there is only model error + if self._components_to_alerts.get(ModelErrorComponent) is None: return get_model_test_runs_link(self._report_url, self._model_unique_id) + return None class GroupOfAlertsBySingleAlert(GroupOfAlerts): diff --git a/elementary/monitor/alerts/report_link_utils.py b/elementary/monitor/alerts/report_link_utils.py index 3927c7c99..97ce2a6ef 100644 --- a/elementary/monitor/alerts/report_link_utils.py +++ b/elementary/monitor/alerts/report_link_utils.py @@ -1,8 +1,15 @@ +from enum import Enum from typing import Optional from elementary.monitor.alerts.schema.alert import ReportLinkData -LINK_TEXT = "View test runs" +TEST_RUNS_LINK_TEXT = "View test runs" +MODEL_RUNS_LINK_TEXT = "View model runs" + + +class ReportPath(Enum): + TEST_RUNS = "test-runs" + MODEL_RUNS = "model-runs" def _get_formatted_report_url(report_url: str) -> str: @@ -10,14 +17,19 @@ def _get_formatted_report_url(report_url: str) -> str: def _get_run_history_report_link( - report_url, path, unique_id + report_url: Optional[str], path: ReportPath, unique_id: Optional[str] ) -> Optional[ReportLinkData]: report_link = None if unique_id and report_url: formatted_report_url = _get_formatted_report_url(report_url) - url = f"{formatted_report_url}/report/{path}/{unique_id}/" - report_link = ReportLinkData(url=url, text=LINK_TEXT) + url = f"{formatted_report_url}/report/{path.value}/{unique_id}/" + report_link = ReportLinkData( + url=url, + text=TEST_RUNS_LINK_TEXT + if path == ReportPath.TEST_RUNS + else MODEL_RUNS_LINK_TEXT, + ) return report_link @@ -25,13 +37,17 @@ def _get_run_history_report_link( def get_test_runs_link( report_url: Optional[str], elementary_unique_id: Optional[str] ) -> Optional[ReportLinkData]: - return _get_run_history_report_link(report_url, "test-runs", elementary_unique_id) + return _get_run_history_report_link( + report_url, ReportPath.TEST_RUNS, elementary_unique_id + ) def get_model_runs_link( report_url: Optional[str], model_unique_id: Optional[str] ) -> Optional[ReportLinkData]: - return _get_run_history_report_link(report_url, "model-runs", model_unique_id) + return _get_run_history_report_link( + report_url, ReportPath.MODEL_RUNS, model_unique_id + ) def get_model_test_runs_link( @@ -41,7 +57,7 @@ def get_model_test_runs_link( if model_unique_id and report_url: formatted_report_url = _get_formatted_report_url(report_url) - url = f'{formatted_report_url}/report/test-runs/?treeNode={{"id":"{model_unique_id}"}}' - report_link = ReportLinkData(url=url, text=LINK_TEXT) + url = f'{formatted_report_url}/report/{ReportPath.TEST_RUNS.value}/?treeNode={{"id":"{model_unique_id}"}}' + report_link = ReportLinkData(url=url, text=TEST_RUNS_LINK_TEXT) return report_link