-
Notifications
You must be signed in to change notification settings - Fork 209
Ele 4074 selectable alert sections #1828
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
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| from enum import Enum | ||
|
|
||
|
|
||
| class AlertField(str, Enum): | ||
| TABLE = "table" | ||
| COLUMN = "column" | ||
| DESCRIPTION = "description" | ||
| OWNERS = "owners" | ||
| TAGS = "tags" | ||
| SUBSCRIBERS = "subscribers" | ||
| RESULT_MESSAGE = "result_message" | ||
| TEST_PARAMS = "test_parameters" | ||
| TEST_QUERY = "test_query" | ||
| TEST_RESULTS_SAMPLE = "test_results_sample" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ | |
| TextStyle, | ||
| ) | ||
| from elementary.messages.message_body import Color, MessageBlock, MessageBody | ||
| from elementary.monitor.alerts.alert_messages.alert_fields import AlertField | ||
| from elementary.monitor.alerts.alerts_groups.alerts_group import AlertsGroup | ||
| from elementary.monitor.alerts.alerts_groups.base_alerts_group import BaseAlertsGroup | ||
| from elementary.monitor.alerts.alerts_groups.grouped_by_table import ( | ||
|
|
@@ -185,6 +186,7 @@ def _get_details_blocks( | |
| subscribers: Optional[List[str]] = None, | ||
| description: Optional[str] = None, | ||
| path: Optional[str] = None, | ||
| fields: List[str] = [], | ||
| ) -> List[MessageBlock]: | ||
| tags = sorted(list(set(tags))) if tags else None | ||
| owners = sorted(list(set(owners))) if owners else None | ||
|
|
@@ -203,13 +205,13 @@ def _get_details_blocks( | |
| ) | ||
| ) | ||
| fact_blocks = [] | ||
| if table: | ||
| if table and AlertField.TABLE in fields: | ||
| fact_blocks.append( | ||
| PrimaryFactBlock( | ||
| (TextLineBlock(text="Table"), TextLineBlock(text=table)) | ||
| ) | ||
| ) | ||
| if column: | ||
| if column and AlertField.COLUMN in fields: | ||
| fact_blocks.append( | ||
| NonPrimaryFactBlock( | ||
| (TextLineBlock(text="Column"), TextLineBlock(text=column)) | ||
|
|
@@ -231,15 +233,22 @@ def _get_details_blocks( | |
| if subscribers | ||
| else ItalicTextLineBlock(text="No subscribers") | ||
| ) | ||
| fact_blocks.append(NonPrimaryFactBlock((TextLineBlock(text="Tags"), tags_line))) | ||
| fact_blocks.append( | ||
| NonPrimaryFactBlock((TextLineBlock(text="Owners"), owners_line)) | ||
| ) | ||
| fact_blocks.append( | ||
| NonPrimaryFactBlock((TextLineBlock(text="Subscribers"), subscribers_line)) | ||
| ) | ||
| if AlertField.TAGS in fields: | ||
| fact_blocks.append( | ||
| NonPrimaryFactBlock((TextLineBlock(text="Tags"), tags_line)) | ||
| ) | ||
| if AlertField.OWNERS in fields: | ||
| fact_blocks.append( | ||
| NonPrimaryFactBlock((TextLineBlock(text="Owners"), owners_line)) | ||
| ) | ||
| if AlertField.SUBSCRIBERS in fields: | ||
| fact_blocks.append( | ||
| NonPrimaryFactBlock( | ||
| (TextLineBlock(text="Subscribers"), subscribers_line) | ||
| ) | ||
| ) | ||
|
|
||
| if description: | ||
| if description and AlertField.DESCRIPTION in fields: | ||
| fact_blocks.append( | ||
| PrimaryFactBlock( | ||
| (TextLineBlock(text="Description"), TextLineBlock(text=description)) | ||
|
|
@@ -261,9 +270,10 @@ def _get_result_blocks( | |
| time_elapsed: Optional[str] = None, | ||
| last_record_at: Optional[str] = None, | ||
| sampled_at: Optional[str] = None, | ||
| fields: List[str] = [], | ||
| ) -> List[MessageBlock]: | ||
| result_blocks: List[MessageBlock] = [] | ||
| if result_message: | ||
| if result_message and AlertField.RESULT_MESSAGE in fields: | ||
| result_blocks.append( | ||
| LinesBlock( | ||
| lines=[ | ||
|
|
@@ -274,7 +284,9 @@ def _get_result_blocks( | |
| result_blocks.append( | ||
| CodeBlock(text=result_message.strip()), | ||
| ) | ||
| if result_sample: | ||
| if ( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unrelated - made more aligned with the way it was before: anomalous value should be considered as the result sample if present |
||
| result_sample or anomalous_value | ||
| ) and AlertField.TEST_RESULTS_SAMPLE in fields: | ||
| result_blocks.append( | ||
| LinesBlock( | ||
| lines=[ | ||
|
|
@@ -284,10 +296,26 @@ def _get_result_blocks( | |
| ] | ||
| ) | ||
| ) | ||
| result_blocks.append( | ||
| JsonCodeBlock(content=result_sample), | ||
| ) | ||
| if result_query: | ||
| if anomalous_value: | ||
| result_blocks.append( | ||
| LinesBlock( | ||
| lines=[ | ||
| LineBlock( | ||
| inlines=[ | ||
| TextBlock( | ||
| text="Anomalous Value:", style=TextStyle.BOLD | ||
| ), | ||
| TextBlock(text=str(anomalous_value)), | ||
| ] | ||
| ), | ||
| ] | ||
| ) | ||
| ) | ||
| elif result_sample: | ||
| result_blocks.append( | ||
| JsonCodeBlock(content=result_sample), | ||
| ) | ||
| if result_query and AlertField.TEST_QUERY in fields: | ||
| result_blocks.append( | ||
| LinesBlock( | ||
| lines=[ | ||
|
|
@@ -296,17 +324,6 @@ def _get_result_blocks( | |
| ) | ||
| ) | ||
| result_blocks.append(CodeBlock(text=result_query.strip())) | ||
| if anomalous_value: | ||
| result_blocks.append( | ||
| LinesBlock( | ||
| lines=[ | ||
| BoldTextLineBlock(text=["Anomalous Values"]), | ||
| ] | ||
| ) | ||
| ) | ||
| result_blocks.append( | ||
| JsonCodeBlock(content=anomalous_value), | ||
| ) | ||
|
|
||
| # facts | ||
| facts = [] | ||
|
|
@@ -323,10 +340,10 @@ def _get_result_blocks( | |
| return result_blocks | ||
|
|
||
| def _get_test_alert_config_blocks( | ||
| self, test_params: Optional[Dict[str, Any]] | ||
| self, test_params: Optional[Dict[str, Any]], fields: List[str] | ||
| ) -> List[MessageBlock]: | ||
| config_blocks: List[MessageBlock] = [] | ||
| if test_params: | ||
| if test_params and AlertField.TEST_PARAMS in fields: | ||
| config_blocks.append( | ||
| LinesBlock( | ||
| lines=[ | ||
|
|
@@ -483,6 +500,7 @@ def _get_alert_subtitle_blocks( | |
| def _get_alert_details_blocks( | ||
| self, | ||
| alert: AlertType, | ||
| fields: List[str], | ||
| ) -> List[MessageBlock]: | ||
| if isinstance(alert, TestAlertModel): | ||
| return self._get_details_blocks( | ||
|
|
@@ -492,13 +510,15 @@ def _get_alert_details_blocks( | |
| owners=alert.owners, | ||
| subscribers=alert.subscribers, | ||
| description=alert.test_description, | ||
| fields=fields, | ||
| ) | ||
| elif isinstance(alert, ModelAlertModel): | ||
| return self._get_details_blocks( | ||
| tags=alert.tags, | ||
| owners=alert.owners, | ||
| subscribers=alert.subscribers, | ||
| path=alert.original_path, | ||
| fields=fields, | ||
| ) | ||
| elif isinstance(alert, SourceFreshnessAlertModel): | ||
| return self._get_details_blocks( | ||
|
|
@@ -507,43 +527,50 @@ def _get_alert_details_blocks( | |
| subscribers=alert.subscribers, | ||
| path=alert.path, | ||
| description=alert.freshness_description, | ||
| fields=fields, | ||
| ) | ||
| elif isinstance(alert, GroupedByTableAlerts): | ||
| return self._get_details_blocks( | ||
| tags=alert.tags, | ||
| owners=alert.owners, | ||
| subscribers=alert.subscribers, | ||
| fields=fields, | ||
| ) | ||
| return [] | ||
|
|
||
| def _get_alert_result_blocks( | ||
| self, | ||
| alert: AlertType, | ||
| fields: List[str], | ||
| ) -> List[MessageBlock]: | ||
| result_blocks: List[MessageBlock] = [] | ||
| title = "Result" | ||
|
|
||
| if isinstance(alert, TestAlertModel): | ||
| is_anomaly_detection = alert.test_type == "anomaly_detection" | ||
| result_blocks = self._get_result_blocks( | ||
| result_message=alert.error_message, | ||
| result_sample=alert.test_rows_sample, | ||
| anomalous_value=( | ||
| alert.other if alert.test_type == "anomaly_detection" else None | ||
| result_sample=( | ||
| alert.test_rows_sample if not is_anomaly_detection else None | ||
| ), | ||
| anomalous_value=(alert.other if is_anomaly_detection else None), | ||
| result_query=alert.test_results_query, | ||
| fields=fields, | ||
| ) | ||
| title = "Test Result" | ||
| elif isinstance(alert, ModelAlertModel): | ||
| if alert.message: | ||
| result_blocks = self._get_result_blocks( | ||
| result_message=alert.message, | ||
| fields=fields, | ||
| ) | ||
| elif isinstance(alert, SourceFreshnessAlertModel): | ||
| result_blocks = self._get_result_blocks( | ||
| result_message=alert.error_message, | ||
| time_elapsed=f"{timedelta(seconds=alert.max_loaded_at_time_ago_in_s) if alert.max_loaded_at_time_ago_in_s else 'N/A'}", | ||
| last_record_at=alert.max_loaded_at, | ||
| sampled_at=alert.snapshotted_at_str, | ||
| fields=fields, | ||
| ) | ||
|
|
||
| if result_blocks: | ||
|
|
@@ -553,13 +580,16 @@ def _get_alert_result_blocks( | |
| def _get_alert_config_blocks( | ||
| self, | ||
| alert: AlertType, | ||
| fields: List[str], | ||
| ) -> List[MessageBlock]: | ||
| config_blocks: List[MessageBlock] = [] | ||
| title = "Configuration" | ||
| expandable = False | ||
|
|
||
| if isinstance(alert, TestAlertModel): | ||
| config_blocks = self._get_test_alert_config_blocks(alert.test_params) | ||
| config_blocks = self._get_test_alert_config_blocks( | ||
| alert.test_params, fields | ||
| ) | ||
| title = "Test Configuration" | ||
| elif isinstance(alert, ModelAlertModel): | ||
| if alert.materialization != "snapshot": | ||
|
|
@@ -603,6 +633,9 @@ def build( | |
| ) -> MessageBody: | ||
| color = self._get_alert_color(alert) | ||
|
|
||
| fields = alert.alert_fields if not isinstance(alert, BaseAlertsGroup) else None | ||
| fields = fields or [field.value for field in AlertField] | ||
|
|
||
| blocks: List[MessageBlock] = [] | ||
|
|
||
| title_blocks = self._get_alert_title_blocks(alert) | ||
|
|
@@ -613,15 +646,15 @@ def build( | |
|
|
||
| blocks.append(DividerBlock()) | ||
|
|
||
| details_blocks = self._get_alert_details_blocks(alert) | ||
| details_blocks = self._get_alert_details_blocks(alert, fields) | ||
| if details_blocks: | ||
| blocks.extend(details_blocks) | ||
| blocks.append(DividerBlock()) | ||
|
|
||
| result_blocks = self._get_alert_result_blocks(alert) | ||
| result_blocks = self._get_alert_result_blocks(alert, fields) | ||
| blocks.extend(result_blocks) | ||
|
|
||
| config_blocks = self._get_alert_config_blocks(alert) | ||
| config_blocks = self._get_alert_config_blocks(alert, fields) | ||
| blocks.extend(config_blocks) | ||
|
|
||
| if isinstance(alert, BaseAlertsGroup): | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Wouldn't it make more sense to move all these conditions to the alerts side?