-
Notifications
You must be signed in to change notification settings - Fork 183
feat: Group alerts by owner #1809
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
Open
szaffarano
wants to merge
5
commits into
elementary-data:master
Choose a base branch
from
szaffarano:szaffarano/group-by-owner
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import os | ||
from pathlib import Path | ||
from typing import Optional | ||
from typing import Optional, cast | ||
|
||
import google.auth # type: ignore[import] | ||
from dateutil import tz | ||
|
@@ -88,11 +88,11 @@ def __init__( | |
|
||
config = self._load_configuration() | ||
|
||
self.target_dir = self._first_not_none( | ||
self.target_dir = str(self._first_not_none( | ||
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. the changes here were because of some linting warnings from pyright I got |
||
target_path, | ||
config.get("target-path"), | ||
os.getcwd(), | ||
) | ||
)) | ||
os.makedirs(os.path.abspath(self.target_dir), exist_ok=True) | ||
os.environ["DBT_LOG_PATH"] = os.path.abspath(target_path) | ||
|
||
|
@@ -129,11 +129,11 @@ def __init__( | |
slack_config.get("group_alerts_by"), | ||
GroupingType.BY_ALERT.value, | ||
) | ||
self.group_alerts_threshold = self._first_not_none( | ||
self.group_alerts_threshold = cast(int, self._first_not_none( | ||
group_alerts_threshold, | ||
slack_config.get("group_alerts_threshold"), | ||
self.DEFAULT_GROUP_ALERTS_THRESHOLD, | ||
) | ||
)) | ||
|
||
teams_config = config.get(self._TEAMS, {}) | ||
self.teams_webhook = self._first_not_none( | ||
|
@@ -223,11 +223,13 @@ def has_send_report_platform(self): | |
|
||
@property | ||
def has_slack(self) -> bool: | ||
return self.slack_webhook or (self.slack_token and self.slack_channel_name) | ||
return self.slack_webhook is not None or ( | ||
self.slack_token is not None and self.slack_channel_name is not None | ||
) | ||
|
||
@property | ||
def has_teams(self) -> bool: | ||
return self.teams_webhook | ||
return self.teams_webhook is not None | ||
|
||
@property | ||
def has_s3(self): | ||
|
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
from .alerts_group import AlertsGroup | ||
from .base_alerts_group import BaseAlertsGroup | ||
from .grouped_by_owner import GroupedByOwnerAlerts | ||
from .grouped_by_table import GroupedByTableAlerts | ||
|
||
__all__ = [ | ||
"AlertsGroup", | ||
"BaseAlertsGroup", | ||
"GroupedByTableAlerts", | ||
"GroupedByOwnerAlerts", | ||
] |
50 changes: 50 additions & 0 deletions
50
elementary/monitor/alerts/alerts_groups/grouped_by_owner.py
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,50 @@ | ||
from typing import Dict, List, Optional, Union | ||
|
||
from elementary.monitor.alerts.alerts_groups.alerts_group import AlertsGroup | ||
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.report_link import ( | ||
ReportLinkData, | ||
get_test_runs_by_owner_link, | ||
) | ||
|
||
|
||
class GroupedByOwnerAlerts(AlertsGroup): | ||
owner: Optional[str] | ||
|
||
def __init__( | ||
self, | ||
owner: Optional[str], | ||
alerts: List[Union[TestAlertModel, ModelAlertModel, SourceFreshnessAlertModel]], | ||
) -> None: | ||
super().__init__(alerts) | ||
self.owner = owner | ||
|
||
@property | ||
def report_url(self) -> Optional[str]: | ||
return self.alerts[0].report_url | ||
|
||
@property | ||
def summary(self) -> str: | ||
return f"{self.owner}: {len(self.alerts)} issues detected" | ||
|
||
def get_report_link(self) -> Optional[ReportLinkData]: | ||
if not self.model_errors: | ||
return get_test_runs_by_owner_link(self.report_url, self.owner) | ||
|
||
return None | ||
|
||
@property | ||
def unified_meta(self) -> Dict: | ||
model_unified_meta = {} | ||
test_unified_meta = {} | ||
for alert in self.alerts: | ||
alert_unified_meta = alert.unified_meta | ||
if alert_unified_meta: | ||
if isinstance(alert, ModelAlertModel): | ||
model_unified_meta = alert_unified_meta | ||
break | ||
|
||
test_unified_meta = alert_unified_meta | ||
return model_unified_meta or test_unified_meta |
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 |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
class GroupingType(str, Enum): | ||
BY_ALERT = "alert" | ||
BY_TABLE = "table" | ||
BY_OWNER = "owner" |
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
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
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
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
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
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.
the changes here were because of some linting warnings from pyright I got