-
Notifications
You must be signed in to change notification settings - Fork 209
Add orchestrator jobs data to alerts #1997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
9ef15ab
c7d89e2
476fae6
8244b2a
7f13126
f721a57
d0ae9ea
77dbc41
02eefca
0cb6f73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| Icon.BELL: "🔔", | ||
| Icon.GEM: "💎", | ||
| Icon.SPARKLES: "✨", | ||
| Icon.LINK: "🔗", | ||
| } | ||
|
|
||
| for icon in Icon: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,11 +4,13 @@ | |
| from pydantic import BaseModel | ||
|
|
||
| from elementary.messages.block_builders import ( | ||
| BoldTextBlock, | ||
| BoldTextLineBlock, | ||
| BulletListBlock, | ||
| FactsBlock, | ||
| ItalicTextLineBlock, | ||
| JsonCodeBlock, | ||
| LinkInlineBlocks, | ||
| LinksLineBlock, | ||
| MentionLineBlock, | ||
| NonPrimaryFactBlock, | ||
|
|
@@ -42,6 +44,9 @@ | |
| from elementary.monitor.alerts.model_alert import ModelAlertModel | ||
| from elementary.monitor.alerts.source_freshness_alert import SourceFreshnessAlertModel | ||
| from elementary.monitor.alerts.test_alert import TestAlertModel | ||
| from elementary.monitor.data_monitoring.alerts.integrations.utils.orchestrator_link import ( | ||
| create_orchestrator_link, | ||
| ) | ||
| from elementary.monitor.data_monitoring.alerts.integrations.utils.report_link import ( | ||
| ReportLinkData, | ||
| ) | ||
|
|
@@ -106,6 +111,7 @@ def _get_run_alert_subtitle_block( | |
| suppression_interval: Optional[int] = None, | ||
| env: Optional[str] = None, | ||
| links: list[ReportLinkData] = [], | ||
| orchestrator_info: Optional[Dict[str, str]] = None, | ||
| ) -> LinesBlock: | ||
| summary = [] | ||
| summary.append((type.capitalize() + ":", name)) | ||
|
|
@@ -114,16 +120,62 @@ def _get_run_alert_subtitle_block( | |
| summary.append(("Status:", status or "Unknown")) | ||
| if detected_at_str: | ||
| summary.append(("Time:", detected_at_str)) | ||
|
|
||
| # Initialize subtitle lines with summary | ||
|
||
| subtitle_lines = [] | ||
|
|
||
| if orchestrator_info and orchestrator_info.get("job_name"): | ||
| orchestrator_name = orchestrator_info.get("orchestrator", "orchestrator") | ||
| job_info_text = f"{orchestrator_info['job_name']} (via {orchestrator_name})" | ||
|
|
||
| # Create job info with inline orchestrator link | ||
| orchestrator_link = create_orchestrator_link(orchestrator_info) | ||
| if orchestrator_link: | ||
| # Create inline blocks for job info + link | ||
| job_inlines: List[InlineBlock] = [ | ||
ofek1weiss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| BoldTextBlock(text="Job:"), | ||
| TextBlock(text=job_info_text + " | "), | ||
| ] | ||
| job_inlines.extend( | ||
| LinkInlineBlocks( | ||
| text=orchestrator_link.text, | ||
| url=orchestrator_link.url, | ||
| icon=orchestrator_link.icon, | ||
| ) | ||
| ) | ||
|
|
||
| # Add custom line with job info + link instead of summary item | ||
| subtitle_lines.append(LineBlock(inlines=job_inlines)) | ||
| else: | ||
| summary.append(("Job:", job_info_text)) | ||
| if suppression_interval: | ||
| summary.append(("Suppression interval:", str(suppression_interval))) | ||
| subtitle_lines = [SummaryLineBlock(summary=summary)] | ||
|
|
||
| if links: | ||
| subtitle_lines.append( | ||
| LinksLineBlock( | ||
| links=[(link.text, link.url, link.icon) for link in links] | ||
| # Add the main summary line | ||
| subtitle_lines.append(SummaryLineBlock(summary=summary)) | ||
|
|
||
| # Combine regular links with orchestrator links | ||
| all_links = [] | ||
|
|
||
| # Add existing report links | ||
| for link in links: | ||
| all_links.append((link.text, link.url, link.icon)) | ||
|
|
||
| # Add orchestrator link if available (only if not already added inline) | ||
| if orchestrator_info and not orchestrator_info.get("job_name"): | ||
| orchestrator_link = create_orchestrator_link(orchestrator_info) | ||
| if orchestrator_link: | ||
| all_links.append( | ||
| ( | ||
| orchestrator_link.text, | ||
| orchestrator_link.url, | ||
| orchestrator_link.icon, | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| if all_links: | ||
| subtitle_lines.append(LinksLineBlock(links=all_links)) | ||
|
|
||
| return LinesBlock(lines=subtitle_lines) | ||
|
|
||
| def _get_run_alert_subtitle_links( | ||
|
|
@@ -151,6 +203,7 @@ def _get_run_alert_subtitle_blocks( | |
| asset_type = "snapshot" if alert.materialization == "snapshot" else "model" | ||
| asset_name = alert.alias | ||
| links = self._get_run_alert_subtitle_links(alert) | ||
| orchestrator_info = alert.orchestrator_info | ||
| return [ | ||
| self._get_run_alert_subtitle_block( | ||
| type=asset_type, | ||
|
|
@@ -160,6 +213,7 @@ def _get_run_alert_subtitle_blocks( | |
| suppression_interval=alert.suppression_interval, | ||
| env=alert.env, | ||
| links=links, | ||
| orchestrator_info=orchestrator_info, | ||
| ) | ||
| ] | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| from typing import Dict, Optional | ||
|
|
||
| from elementary.messages.blocks import Icon | ||
| from elementary.utils.pydantic_shim import BaseModel | ||
|
|
||
|
|
||
| class OrchestratorLinkData(BaseModel): | ||
| url: str | ||
| text: str | ||
| orchestrator: str | ||
| icon: Optional[Icon] = None | ||
|
|
||
|
|
||
| def create_orchestrator_link( | ||
| orchestrator_info: Dict[str, str] | ||
| ) -> Optional[OrchestratorLinkData]: | ||
| """Create an orchestrator link from orchestrator info if URL is available.""" | ||
| if not orchestrator_info or not orchestrator_info.get("run_url"): | ||
| return None | ||
|
|
||
| orchestrator = orchestrator_info.get("orchestrator", "orchestrator") | ||
|
|
||
| return OrchestratorLinkData( | ||
| url=orchestrator_info["run_url"], | ||
| text=f"View in {orchestrator}", | ||
| orchestrator=orchestrator, | ||
| icon=Icon.LINK, | ||
| ) | ||
|
|
||
|
|
||
| def create_job_link( | ||
| orchestrator_info: Dict[str, str] | ||
| ) -> Optional[OrchestratorLinkData]: | ||
| """Create a job-level orchestrator link if job URL is available.""" | ||
| if not orchestrator_info or not orchestrator_info.get("job_url"): | ||
| return None | ||
|
|
||
| orchestrator = orchestrator_info.get("orchestrator", "orchestrator") | ||
| job_name = orchestrator_info.get("job_name", "Job") | ||
|
|
||
| # Capitalize orchestrator name for display | ||
| display_name = orchestrator.replace("_", " ").title() | ||
|
|
||
| return OrchestratorLinkData( | ||
| url=orchestrator_info["job_url"], | ||
| text=f"{job_name} in {display_name}", | ||
| orchestrator=orchestrator, | ||
| icon=Icon.GEAR, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont return a dict to represent structured data, create a dedicated
OrchestratorInfoclass for itThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
OrchestratorInfoinstead