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
2 changes: 1 addition & 1 deletion elementary/monitor/api/alerts/alert_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _filter_alerts_by_owner(

filtered_alerts = []
for alert in alerts:
raw_owners = alert.owners
raw_owners = alert.unified_owners
alert_owners = (
try_load_json(raw_owners) if isinstance(raw_owners, str) else raw_owners
)
Expand Down
20 changes: 14 additions & 6 deletions elementary/monitor/fetchers/alerts/schema/pending_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
ALERTS_CONFIG_KEY = "alerts_config"
CHANNEL_KEY = "channel"
DESCRIPTION_KEY = "description"
OWNERS_KEY = "owners"
OWNER_KEY = "owner"
SUBSCRIBERS_KEY = "subscribers"
ALERT_FIELDS_KEY = "alert_fields"
ALERT_SUPPRESSION_INTERVAL_KEY = "alert_suppression_interval"
Expand All @@ -32,6 +32,7 @@ class BasePendingAlertSchema(BaseModel):
database_name: Optional[str] = None
schema_name: str
tags: Optional[List[str]] = None
owners: Optional[List[str]] = None
model_meta: Optional[Dict] = None
suppression_status: str
sent_at: Optional[datetime] = None
Expand All @@ -54,8 +55,11 @@ def group_alerts_by(self) -> Optional[str]:
return self.unified_meta.get(GROUP_ALERTS_BY_KEY)

@property
def owners(self) -> List[str]:
return self._get_alert_meta_attrs(OWNERS_KEY)
def unified_owners(self) -> List[str]:
# Make sure we return both meta defined owners and config defined owners.
config_owners = self.owners or []
meta_owners = self._get_alert_meta_attrs(OWNER_KEY)
return list(set(config_owners + meta_owners))

@property
def subscribers(self) -> List[str]:
Expand All @@ -77,6 +81,10 @@ def validate_model_meta(cls, model_meta: Optional[Dict]) -> Dict:
def validate_tags(cls, tags: Optional[Union[List[str], str]]):
return unpack_and_flatten_and_dedup_list_of_strings(tags)

@validator("owners", pre=True, always=True)
def validate_owners(cls, owners: Optional[Union[List[str], str]]):
return unpack_and_flatten_and_dedup_list_of_strings(owners)

@staticmethod
def _flatten_meta(meta: Optional[Dict] = None) -> Dict:
return flatten_dict_by_key(meta, ALERTS_CONFIG_KEY) if meta else dict()
Expand Down Expand Up @@ -199,7 +207,7 @@ def format_alert(
detected_at=self.detected_at,
database_name=self.database_name,
schema_name=self.schema_name,
owners=self.owners,
owners=self.unified_owners,
tags=self.tags,
subscribers=self.subscribers,
status=self.status,
Expand Down Expand Up @@ -245,7 +253,7 @@ def format_alert(
detected_at=self.detected_at,
database_name=self.database_name,
schema_name=self.schema_name,
owners=self.owners,
owners=self.unified_owners,
tags=self.tags,
subscribers=self.subscribers,
status=self.status,
Expand Down Expand Up @@ -304,7 +312,7 @@ def format_alert(
detected_at=self.detected_at,
database_name=self.database_name,
schema_name=self.schema_name,
owners=self.owners,
owners=self.unified_owners,
tags=self.tags,
subscribers=self.subscribers,
status=self.status,
Expand Down
20 changes: 10 additions & 10 deletions tests/unit/monitor/api/alerts/test_alert_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def initial_alerts():
test_name="test_1",
test_created_at="2022-10-10 10:10:10",
tags='["one", "two"]',
model_meta=dict(owners='["jeff", "john"]'),
model_meta=dict(owner='["jeff", "john"]'),
status="fail",
elementary_unique_id="elementary.model_id_1.test_id_1.9cf2f5f6ad.None.generic",
detected_at="2022-10-10 10:00:00",
Expand All @@ -52,7 +52,7 @@ def initial_alerts():
test_name="test_2",
test_created_at="2022-10-10 09:10:10",
tags='["three"]',
model_meta=dict(owners='["jeff", "john"]'),
model_meta=dict(owner='["jeff", "john"]'),
status="fail",
elementary_unique_id="elementary.model_id_1.test_id_2.9cf2f5f6ad.None.generic",
detected_at="2022-10-10 10:00:00",
Expand All @@ -76,7 +76,7 @@ def initial_alerts():
test_created_at="2022-10-10 10:10:10",
# invalid tag
tags="one",
model_meta=dict(owners='["john"]'),
model_meta=dict(owner='["john"]'),
status="fail",
elementary_unique_id="elementary.model_id_1.test_id_3.9cf2f5f6ad.None.generic",
detected_at="2022-10-10 10:00:00",
Expand All @@ -99,7 +99,7 @@ def initial_alerts():
test_name="test_4",
test_created_at="2022-10-10 09:10:10",
tags='["three", "four"]',
model_meta=dict(owners='["jeff"]'),
model_meta=dict(owner='["jeff"]'),
status="warn",
elementary_unique_id="elementary.model_id_1.test_id_4.9cf2f5f6ad.None.generic",
detected_at="2022-10-10 10:00:00",
Expand Down Expand Up @@ -129,7 +129,7 @@ def initial_alerts():
detected_at="2022-10-10 10:00:00",
alert_suppression_interval=0,
tags='["one", "two"]',
model_meta=dict(owners='["jeff", "john"]'),
model_meta=dict(owner='["jeff", "john"]'),
status="error",
database_name="test_db",
schema_name="test_schema",
Expand All @@ -148,7 +148,7 @@ def initial_alerts():
detected_at="2022-10-10 09:00:00",
alert_suppression_interval=3,
tags='["three"]',
model_meta=dict(owners='["john"]'),
model_meta=dict(owner='["john"]'),
status="error",
database_name="test_db",
schema_name="test_schema",
Expand All @@ -167,7 +167,7 @@ def initial_alerts():
detected_at="2022-10-10 08:00:00",
alert_suppression_interval=1,
tags='["three", "four"]',
model_meta=dict(owners='["jeff"]'),
model_meta=dict(owner='["jeff"]'),
status="skipped",
database_name="test_db",
schema_name="test_schema",
Expand All @@ -189,7 +189,7 @@ def initial_alerts():
detected_at="2022-10-10 10:00:00",
alert_suppression_interval=0,
tags='["one", "two"]',
model_meta=dict(owners='["jeff", "john"]'),
model_meta=dict(owner='["jeff", "john"]'),
status="error",
normalized_status="fail",
snapshotted_at="2023-08-15T12:26:06.884065+00:00",
Expand Down Expand Up @@ -219,7 +219,7 @@ def initial_alerts():
detected_at="2022-10-10 10:00:00",
alert_suppression_interval=0,
tags='["one", "two"]',
model_meta=dict(owners='["jeff", "john"]'),
model_meta=dict(owner='["jeff", "john"]'),
status="warn",
normalized_status="warn",
snapshotted_at="2023-08-15T12:26:06.884065+00:00",
Expand Down Expand Up @@ -249,7 +249,7 @@ def initial_alerts():
detected_at="2022-10-10 10:00:00",
alert_suppression_interval=0,
tags='["one", "two"]',
model_meta=dict(owners='["jeff", "john"]'),
model_meta=dict(owner='["jeff", "john"]'),
status="runtime error",
normalized_status="error",
snapshotted_at="2023-08-15T12:26:06.884065+00:00",
Expand Down