Skip to content

Commit ef5c1bc

Browse files
authored
Merge pull request #1927 from elementary-data/ele-4497-view-in-elementary-links
Enable support for multiple links and icons in alert messages
2 parents 925b94a + a1c2532 commit ef5c1bc

28 files changed

Lines changed: 443 additions & 407 deletions

File tree

elementary/messages/block_builders.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,28 @@ def ItalicTextLineBlock(*, text: SimpleLineBlock) -> LineBlock:
8282
return TextLineBlock(text=text, style=TextStyle.ITALIC)
8383

8484

85+
def LinkInlineBlocks(
86+
*, text: str, url: str, icon: Optional[Icon] = None
87+
) -> list[InlineBlock]:
88+
inlines: list[InlineBlock] = []
89+
if icon:
90+
inlines.append(IconBlock(icon=icon))
91+
inlines.append(LinkBlock(text=text, url=url))
92+
return inlines
93+
94+
8595
def LinkLineBlock(*, text: str, url: str) -> LineBlock:
86-
return LineBlock(inlines=[LinkBlock(text=text, url=url)])
96+
return LineBlock(inlines=LinkInlineBlocks(text=text, url=url))
97+
98+
99+
def LinksLineBlock(*, links: list[tuple[str, str, Optional[Icon]]]) -> LineBlock:
100+
return LineBlock(
101+
inlines=[
102+
inline
103+
for text, url, icon in links
104+
for inline in LinkInlineBlocks(text=text, url=url, icon=icon)
105+
]
106+
)
87107

88108

89109
def SummaryLineBlock(

elementary/monitor/alerts/alert_messages/builder.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
FactsBlock,
1010
ItalicTextLineBlock,
1111
JsonCodeBlock,
12-
LinkLineBlock,
12+
LinksLineBlock,
1313
MentionLineBlock,
1414
NonPrimaryFactBlock,
1515
PrimaryFactBlock,
@@ -104,7 +104,7 @@ def _get_run_alert_subtitle_block(
104104
detected_at_str: Optional[str] = None,
105105
suppression_interval: Optional[int] = None,
106106
env: Optional[str] = None,
107-
report_link: Optional[ReportLinkData] = None,
107+
links: list[ReportLinkData] = [],
108108
) -> LinesBlock:
109109
summary = []
110110
summary.append((type.capitalize() + ":", name))
@@ -117,12 +117,23 @@ def _get_run_alert_subtitle_block(
117117
summary.append(("Suppression interval:", str(suppression_interval)))
118118
subtitle_lines = [SummaryLineBlock(summary=summary)]
119119

120-
if report_link:
120+
if links:
121121
subtitle_lines.append(
122-
LinkLineBlock(text="View in Elementary", url=report_link.url)
122+
LinksLineBlock(
123+
links=[(link.text, link.url, link.icon) for link in links]
124+
)
123125
)
124126
return LinesBlock(lines=subtitle_lines)
125127

128+
def _get_run_alert_subtitle_links(
129+
self,
130+
alert: Union[TestAlertModel, SourceFreshnessAlertModel, ModelAlertModel],
131+
) -> List[ReportLinkData]:
132+
report_link = alert.get_report_link()
133+
if report_link:
134+
return [report_link]
135+
return []
136+
126137
def _get_run_alert_subtitle_blocks(
127138
self,
128139
alert: Union[TestAlertModel, SourceFreshnessAlertModel, ModelAlertModel],
@@ -138,6 +149,7 @@ def _get_run_alert_subtitle_blocks(
138149
elif isinstance(alert, ModelAlertModel):
139150
asset_type = "snapshot" if alert.materialization == "snapshot" else "model"
140151
asset_name = alert.alias
152+
links = self._get_run_alert_subtitle_links(alert)
141153
return [
142154
self._get_run_alert_subtitle_block(
143155
type=asset_type,
@@ -146,7 +158,7 @@ def _get_run_alert_subtitle_blocks(
146158
detected_at_str=alert.detected_at_str,
147159
suppression_interval=alert.suppression_interval,
148160
env=alert.env,
149-
report_link=alert.get_report_link(),
161+
links=links,
150162
)
151163
]
152164

elementary/monitor/data_monitoring/alerts/integrations/utils/report_link.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from enum import Enum
22
from typing import Optional
33

4+
from elementary.messages.blocks import Icon
45
from elementary.utils.pydantic_shim import BaseModel
56

67
TEST_RUNS_LINK_TEXT = "View test runs"
@@ -10,6 +11,7 @@
1011
class ReportLinkData(BaseModel):
1112
url: str
1213
text: str
14+
icon: Optional[Icon] = None
1315

1416

1517
class ReportPath(Enum):
@@ -31,9 +33,11 @@ def _get_run_history_report_link(
3133
url = f"{formatted_report_url}/report/{path.value}/{unique_id}/"
3234
report_link = ReportLinkData(
3335
url=url,
34-
text=TEST_RUNS_LINK_TEXT
35-
if path == ReportPath.TEST_RUNS
36-
else MODEL_RUNS_LINK_TEXT,
36+
text=(
37+
TEST_RUNS_LINK_TEXT
38+
if path == ReportPath.TEST_RUNS
39+
else MODEL_RUNS_LINK_TEXT
40+
),
3741
)
3842

3943
return report_link
@@ -62,7 +66,7 @@ def get_model_test_runs_link(
6266

6367
if model_unique_id and report_url:
6468
formatted_report_url = _get_formatted_report_url(report_url)
65-
url = f'{formatted_report_url}/report/{ReportPath.TEST_RUNS.value}/?treeNode={{"id":"{model_unique_id}"}}'
69+
url = f'{formatted_report_url}/report/{ReportPath.TEST_RUNS.value}/?treeNode={{"id":"{model_unique_id}"}}' # noqa: E231
6670
report_link = ReportLinkData(url=url, text=TEST_RUNS_LINK_TEXT)
6771

6872
return report_link

tests/unit/alerts/alert_messages/fixtures/adaptive_card/alerts_group_model-errors-False_test-failures-True_test-warnings-True_test-errors-True_link-True_env-True_subscribers-False.json

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,52 +36,52 @@
3636
},
3737
{
3838
"type": "TextBlock",
39-
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_1** - [View Report](http://test.com)",
39+
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_1** - [View in Elementary](http://test.com)",
4040
"wrap": true
4141
},
4242
{
4343
"type": "TextBlock",
44-
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_2** - Owners: owner1 - [View Report](http://test.com)",
44+
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_2** - Owners: owner1 - [View in Elementary](http://test.com)",
4545
"wrap": true
4646
},
4747
{
4848
"type": "TextBlock",
49-
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_3** - Owners: owner1, owner2 - [View Report](http://test.com)",
49+
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_3** - Owners: owner1, owner2 - [View in Elementary](http://test.com)",
5050
"wrap": true
5151
},
5252
{
5353
"type": "TextBlock",
54-
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_4** - [View Report](http://test.com)",
54+
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_4** - [View in Elementary](http://test.com)",
5555
"wrap": true
5656
},
5757
{
5858
"type": "TextBlock",
59-
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_5** - Owners: owner1 - [View Report](http://test.com)",
59+
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_5** - Owners: owner1 - [View in Elementary](http://test.com)",
6060
"wrap": true
6161
},
6262
{
6363
"type": "TextBlock",
64-
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_6** - Owners: owner1, owner2 - [View Report](http://test.com)",
64+
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_6** - Owners: owner1, owner2 - [View in Elementary](http://test.com)",
6565
"wrap": true
6666
},
6767
{
6868
"type": "TextBlock",
69-
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_7** - [View Report](http://test.com)",
69+
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_7** - [View in Elementary](http://test.com)",
7070
"wrap": true
7171
},
7272
{
7373
"type": "TextBlock",
74-
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_8** - Owners: owner1 - [View Report](http://test.com)",
74+
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_8** - Owners: owner1 - [View in Elementary](http://test.com)",
7575
"wrap": true
7676
},
7777
{
7878
"type": "TextBlock",
79-
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_9** - Owners: owner1, owner2 - [View Report](http://test.com)",
79+
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_9** - Owners: owner1, owner2 - [View in Elementary](http://test.com)",
8080
"wrap": true
8181
},
8282
{
8383
"type": "TextBlock",
84-
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_10** - [View Report](http://test.com)",
84+
"text": "\ud83d\udd3a **\"test_short_name\" test failed on test_table_10** - [View in Elementary](http://test.com)",
8585
"wrap": true
8686
}
8787
]
@@ -97,52 +97,52 @@
9797
},
9898
{
9999
"type": "TextBlock",
100-
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_1** - [View Report](http://test.com)",
100+
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_1** - [View in Elementary](http://test.com)",
101101
"wrap": true
102102
},
103103
{
104104
"type": "TextBlock",
105-
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_2** - Owners: owner1 - [View Report](http://test.com)",
105+
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_2** - Owners: owner1 - [View in Elementary](http://test.com)",
106106
"wrap": true
107107
},
108108
{
109109
"type": "TextBlock",
110-
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_3** - Owners: owner1, owner2 - [View Report](http://test.com)",
110+
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_3** - Owners: owner1, owner2 - [View in Elementary](http://test.com)",
111111
"wrap": true
112112
},
113113
{
114114
"type": "TextBlock",
115-
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_4** - [View Report](http://test.com)",
115+
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_4** - [View in Elementary](http://test.com)",
116116
"wrap": true
117117
},
118118
{
119119
"type": "TextBlock",
120-
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_5** - Owners: owner1 - [View Report](http://test.com)",
120+
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_5** - Owners: owner1 - [View in Elementary](http://test.com)",
121121
"wrap": true
122122
},
123123
{
124124
"type": "TextBlock",
125-
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_6** - Owners: owner1, owner2 - [View Report](http://test.com)",
125+
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_6** - Owners: owner1, owner2 - [View in Elementary](http://test.com)",
126126
"wrap": true
127127
},
128128
{
129129
"type": "TextBlock",
130-
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_7** - [View Report](http://test.com)",
130+
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_7** - [View in Elementary](http://test.com)",
131131
"wrap": true
132132
},
133133
{
134134
"type": "TextBlock",
135-
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_8** - Owners: owner1 - [View Report](http://test.com)",
135+
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_8** - Owners: owner1 - [View in Elementary](http://test.com)",
136136
"wrap": true
137137
},
138138
{
139139
"type": "TextBlock",
140-
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_9** - Owners: owner1, owner2 - [View Report](http://test.com)",
140+
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_9** - Owners: owner1, owner2 - [View in Elementary](http://test.com)",
141141
"wrap": true
142142
},
143143
{
144144
"type": "TextBlock",
145-
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_10** - [View Report](http://test.com)",
145+
"text": "\u26a0\ufe0f **\"test_short_name\" test failed on test_table_10** - [View in Elementary](http://test.com)",
146146
"wrap": true
147147
}
148148
]
@@ -158,52 +158,52 @@
158158
},
159159
{
160160
"type": "TextBlock",
161-
"text": "\u2757 **\"test_short_name\" test failed on test_table_1** - [View Report](http://test.com)",
161+
"text": "\u2757 **\"test_short_name\" test failed on test_table_1** - [View in Elementary](http://test.com)",
162162
"wrap": true
163163
},
164164
{
165165
"type": "TextBlock",
166-
"text": "\u2757 **\"test_short_name\" test failed on test_table_2** - Owners: owner1 - [View Report](http://test.com)",
166+
"text": "\u2757 **\"test_short_name\" test failed on test_table_2** - Owners: owner1 - [View in Elementary](http://test.com)",
167167
"wrap": true
168168
},
169169
{
170170
"type": "TextBlock",
171-
"text": "\u2757 **\"test_short_name\" test failed on test_table_3** - Owners: owner1, owner2 - [View Report](http://test.com)",
171+
"text": "\u2757 **\"test_short_name\" test failed on test_table_3** - Owners: owner1, owner2 - [View in Elementary](http://test.com)",
172172
"wrap": true
173173
},
174174
{
175175
"type": "TextBlock",
176-
"text": "\u2757 **\"test_short_name\" test failed on test_table_4** - [View Report](http://test.com)",
176+
"text": "\u2757 **\"test_short_name\" test failed on test_table_4** - [View in Elementary](http://test.com)",
177177
"wrap": true
178178
},
179179
{
180180
"type": "TextBlock",
181-
"text": "\u2757 **\"test_short_name\" test failed on test_table_5** - Owners: owner1 - [View Report](http://test.com)",
181+
"text": "\u2757 **\"test_short_name\" test failed on test_table_5** - Owners: owner1 - [View in Elementary](http://test.com)",
182182
"wrap": true
183183
},
184184
{
185185
"type": "TextBlock",
186-
"text": "\u2757 **\"test_short_name\" test failed on test_table_6** - Owners: owner1, owner2 - [View Report](http://test.com)",
186+
"text": "\u2757 **\"test_short_name\" test failed on test_table_6** - Owners: owner1, owner2 - [View in Elementary](http://test.com)",
187187
"wrap": true
188188
},
189189
{
190190
"type": "TextBlock",
191-
"text": "\u2757 **\"test_short_name\" test failed on test_table_7** - [View Report](http://test.com)",
191+
"text": "\u2757 **\"test_short_name\" test failed on test_table_7** - [View in Elementary](http://test.com)",
192192
"wrap": true
193193
},
194194
{
195195
"type": "TextBlock",
196-
"text": "\u2757 **\"test_short_name\" test failed on test_table_8** - Owners: owner1 - [View Report](http://test.com)",
196+
"text": "\u2757 **\"test_short_name\" test failed on test_table_8** - Owners: owner1 - [View in Elementary](http://test.com)",
197197
"wrap": true
198198
},
199199
{
200200
"type": "TextBlock",
201-
"text": "\u2757 **\"test_short_name\" test failed on test_table_9** - Owners: owner1, owner2 - [View Report](http://test.com)",
201+
"text": "\u2757 **\"test_short_name\" test failed on test_table_9** - Owners: owner1, owner2 - [View in Elementary](http://test.com)",
202202
"wrap": true
203203
},
204204
{
205205
"type": "TextBlock",
206-
"text": "\u2757 **\"test_short_name\" test failed on test_table_10** - [View Report](http://test.com)",
206+
"text": "\u2757 **\"test_short_name\" test failed on test_table_10** - [View in Elementary](http://test.com)",
207207
"wrap": true
208208
}
209209
]

0 commit comments

Comments
 (0)