Skip to content

Commit

Permalink
Merge branch 'master' into ele-1690-load-report-data-prior-to-calling…
Browse files Browse the repository at this point in the history
…-code
  • Loading branch information
elongl authored Sep 4, 2023
2 parents c51ac7d + e2ebe7e commit 6383891
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
11 changes: 4 additions & 7 deletions elementary/monitor/alerts/group_of_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
32 changes: 24 additions & 8 deletions elementary/monitor/alerts/report_link_utils.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,53 @@
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:
return report_url.strip("/")


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


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(
Expand All @@ -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

0 comments on commit 6383891

Please sign in to comment.