Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion elementary/messages/block_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,28 @@ def ItalicTextLineBlock(*, text: SimpleLineBlock) -> LineBlock:
return TextLineBlock(text=text, style=TextStyle.ITALIC)


def LinkInlineBlocks(
*, text: str, url: str, icon: Optional[Icon] = None
) -> list[InlineBlock]:
inlines: list[InlineBlock] = []
if icon:
inlines.append(IconBlock(icon=icon))
inlines.append(LinkBlock(text=text, url=url))
return inlines


def LinkLineBlock(*, text: str, url: str) -> LineBlock:
return LineBlock(inlines=[LinkBlock(text=text, url=url)])
return LineBlock(inlines=LinkInlineBlocks(text=text, url=url))


def LinksLineBlock(*, links: list[tuple[str, str, Optional[Icon]]]) -> LineBlock:
return LineBlock(
inlines=[
inline
for text, url, icon in links
for inline in LinkInlineBlocks(text=text, url=url, icon=icon)
]
)


def SummaryLineBlock(
Expand Down
22 changes: 17 additions & 5 deletions elementary/monitor/alerts/alert_messages/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
FactsBlock,
ItalicTextLineBlock,
JsonCodeBlock,
LinkLineBlock,
LinksLineBlock,
MentionLineBlock,
NonPrimaryFactBlock,
PrimaryFactBlock,
Expand Down Expand Up @@ -104,7 +104,7 @@ def _get_run_alert_subtitle_block(
detected_at_str: Optional[str] = None,
suppression_interval: Optional[int] = None,
env: Optional[str] = None,
report_link: Optional[ReportLinkData] = None,
links: list[ReportLinkData] = [],
) -> LinesBlock:
summary = []
summary.append((type.capitalize() + ":", name))
Expand All @@ -117,12 +117,23 @@ def _get_run_alert_subtitle_block(
summary.append(("Suppression interval:", str(suppression_interval)))
subtitle_lines = [SummaryLineBlock(summary=summary)]

if report_link:
if links:
subtitle_lines.append(
LinkLineBlock(text="View in Elementary", url=report_link.url)
LinksLineBlock(
links=[(link.text, link.url, link.icon) for link in links]
)
)
return LinesBlock(lines=subtitle_lines)

def _get_run_alert_subtitle_links(
self,
alert: Union[TestAlertModel, SourceFreshnessAlertModel, ModelAlertModel],
) -> List[ReportLinkData]:
report_link = alert.get_report_link()
if report_link:
return [report_link]
return []

def _get_run_alert_subtitle_blocks(
self,
alert: Union[TestAlertModel, SourceFreshnessAlertModel, ModelAlertModel],
Expand All @@ -138,6 +149,7 @@ def _get_run_alert_subtitle_blocks(
elif isinstance(alert, ModelAlertModel):
asset_type = "snapshot" if alert.materialization == "snapshot" else "model"
asset_name = alert.alias
links = self._get_run_alert_subtitle_links(alert)
return [
self._get_run_alert_subtitle_block(
type=asset_type,
Expand All @@ -146,7 +158,7 @@ def _get_run_alert_subtitle_blocks(
detected_at_str=alert.detected_at_str,
suppression_interval=alert.suppression_interval,
env=alert.env,
report_link=alert.get_report_link(),
links=links,
)
]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from enum import Enum
from typing import Optional

from elementary.messages.blocks import Icon
from elementary.utils.pydantic_shim import BaseModel

TEST_RUNS_LINK_TEXT = "View test runs"
Expand All @@ -10,6 +11,7 @@
class ReportLinkData(BaseModel):
url: str
text: str
icon: Optional[Icon] = None


class ReportPath(Enum):
Expand All @@ -31,9 +33,11 @@ def _get_run_history_report_link(
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,
text=(
TEST_RUNS_LINK_TEXT
if path == ReportPath.TEST_RUNS
else MODEL_RUNS_LINK_TEXT
),
)

return report_link
Expand Down Expand Up @@ -62,7 +66,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/{ReportPath.TEST_RUNS.value}/?treeNode={{"id":"{model_unique_id}"}}'
url = f'{formatted_report_url}/report/{ReportPath.TEST_RUNS.value}/?treeNode={{"id":"{model_unique_id}"}}' # noqa: E231
report_link = ReportLinkData(url=url, text=TEST_RUNS_LINK_TEXT)

return report_link
Original file line number Diff line number Diff line change
Expand Up @@ -36,52 +36,52 @@
},
{
"type": "TextBlock",
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_1** - [View Report](http://test.com)",
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_1** - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_2** - Owners: owner1 - [View Report](http://test.com)",
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_2** - Owners: owner1 - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_3** - Owners: owner1, owner2 - [View Report](http://test.com)",
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_3** - Owners: owner1, owner2 - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_4** - [View Report](http://test.com)",
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_4** - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_5** - Owners: owner1 - [View Report](http://test.com)",
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_5** - Owners: owner1 - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_6** - Owners: owner1, owner2 - [View Report](http://test.com)",
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_6** - Owners: owner1, owner2 - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_7** - [View Report](http://test.com)",
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_7** - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_8** - Owners: owner1 - [View Report](http://test.com)",
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_8** - Owners: owner1 - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_9** - Owners: owner1, owner2 - [View Report](http://test.com)",
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_9** - Owners: owner1, owner2 - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_10** - [View Report](http://test.com)",
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_10** - [View in Elementary](http://test.com)",
"wrap": true
}
]
Expand All @@ -97,52 +97,52 @@
},
{
"type": "TextBlock",
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_1** - [View Report](http://test.com)",
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_1** - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_2** - Owners: owner1 - [View Report](http://test.com)",
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_2** - Owners: owner1 - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_3** - Owners: owner1, owner2 - [View Report](http://test.com)",
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_3** - Owners: owner1, owner2 - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_4** - [View Report](http://test.com)",
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_4** - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_5** - Owners: owner1 - [View Report](http://test.com)",
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_5** - Owners: owner1 - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_6** - Owners: owner1, owner2 - [View Report](http://test.com)",
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_6** - Owners: owner1, owner2 - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_7** - [View Report](http://test.com)",
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_7** - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_8** - Owners: owner1 - [View Report](http://test.com)",
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_8** - Owners: owner1 - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_9** - Owners: owner1, owner2 - [View Report](http://test.com)",
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_9** - Owners: owner1, owner2 - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_10** - [View Report](http://test.com)",
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_10** - [View in Elementary](http://test.com)",
"wrap": true
}
]
Expand All @@ -158,52 +158,52 @@
},
{
"type": "TextBlock",
"text": "\u2757 **\"test_short_name\" test failed on test_table_1** - [View Report](http://test.com)",
"text": "\u2757 **\"test_short_name\" test failed on test_table_1** - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\u2757 **\"test_short_name\" test failed on test_table_2** - Owners: owner1 - [View Report](http://test.com)",
"text": "\u2757 **\"test_short_name\" test failed on test_table_2** - Owners: owner1 - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\u2757 **\"test_short_name\" test failed on test_table_3** - Owners: owner1, owner2 - [View Report](http://test.com)",
"text": "\u2757 **\"test_short_name\" test failed on test_table_3** - Owners: owner1, owner2 - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\u2757 **\"test_short_name\" test failed on test_table_4** - [View Report](http://test.com)",
"text": "\u2757 **\"test_short_name\" test failed on test_table_4** - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\u2757 **\"test_short_name\" test failed on test_table_5** - Owners: owner1 - [View Report](http://test.com)",
"text": "\u2757 **\"test_short_name\" test failed on test_table_5** - Owners: owner1 - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\u2757 **\"test_short_name\" test failed on test_table_6** - Owners: owner1, owner2 - [View Report](http://test.com)",
"text": "\u2757 **\"test_short_name\" test failed on test_table_6** - Owners: owner1, owner2 - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\u2757 **\"test_short_name\" test failed on test_table_7** - [View Report](http://test.com)",
"text": "\u2757 **\"test_short_name\" test failed on test_table_7** - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\u2757 **\"test_short_name\" test failed on test_table_8** - Owners: owner1 - [View Report](http://test.com)",
"text": "\u2757 **\"test_short_name\" test failed on test_table_8** - Owners: owner1 - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\u2757 **\"test_short_name\" test failed on test_table_9** - Owners: owner1, owner2 - [View Report](http://test.com)",
"text": "\u2757 **\"test_short_name\" test failed on test_table_9** - Owners: owner1, owner2 - [View in Elementary](http://test.com)",
"wrap": true
},
{
"type": "TextBlock",
"text": "\u2757 **\"test_short_name\" test failed on test_table_10** - [View Report](http://test.com)",
"text": "\u2757 **\"test_short_name\" test failed on test_table_10** - [View in Elementary](http://test.com)",
"wrap": true
}
]
Expand Down
Loading
Loading