Skip to content
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

Ele 3893 alert rules operators #1768

Merged
merged 14 commits into from
Dec 29, 2024
Merged

Conversation

MikaKerman
Copy link
Contributor

@MikaKerman MikaKerman commented Dec 23, 2024

null

Copy link

linear bot commented Dec 23, 2024

Copy link
Contributor

👋 @MikaKerman
Thank you for raising your pull request.
Please make sure to add tests and document all user-facing changes.
You can do this by editing the docs files in this pull request.

- Updated test cases in `test_alert_filters.py` to replace direct calls to individual filter functions with the new `filter_alerts` method.
- Enhanced alert data structures to use `datetime` objects instead of string representations for timestamps.
- Improved the handling of alert statuses by using the `AlertStatus` enum.
- Adjusted test data to ensure consistency and correctness in the alert filtering logic.
…nd 'ALL' operator logic for value filtering.
…r 'IS_NOT' filter types across tags, owners, models, and statuses.
…ding logic in apply_filter function. Enhance unit tests to validate behavior of the new filter type in FilterSchema.
@MikaKerman MikaKerman force-pushed the ele-3893-alert-rules-operators branch from 5920f35 to b965c08 Compare December 23, 2024 13:39
alert_node_name = None
alert_type = AlertTypes(alert.type)
if alert_type is AlertTypes.TEST:
alert_node_name = alert.data.test_name # type: ignore[union-attr]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you can remove this type ignore by adding type hints in line 32: alert_node_name: Optional[str] = None

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently not :(

def _get_alert_node_name(alert: PendingAlertSchema) -> Optional[str]:
    alert_node_name: Optional[str] = None
    alert_type = AlertTypes(alert.type)
    if alert_type is AlertTypes.TEST:
        alert_node_name = alert.data.test_name
elementary/monitor/api/alerts/alert_filters.py:31: error: Item "ModelAlertDataSchema" of "Union[TestAlertDataSchema, ModelAlertDataSchema, SourceFreshnessAlertDataSchema]" has no attribute "test_name"  [union-attr]
elementary/monitor/api/alerts/alert_filters.py:31: error: Item "SourceFreshnessAlertDataSchema" of "Union[TestAlertDataSchema, ModelAlertDataSchema, SourceFreshnessAlertDataSchema]" has no attribute "test_name"  [union-attr]

It's from the earlier version.


class StatusFilterSchema(FilterSchema):
class StatusFilterSchema(FilterSchema[Status]):
values: List[Status]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove the re-definition of values here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so too, but apparently not.
pydantic/pydantic#4171

values: List[Status]


class ResourceTypeFilterSchema(FilterSchema):
class ResourceTypeFilterSchema(FilterSchema[ResourceType]):
values: List[ResourceType]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented above.

else []
)

return (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to separate function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@MikaKerman MikaKerman merged commit 69393bd into master Dec 29, 2024
3 checks passed
@MikaKerman MikaKerman deleted the ele-3893-alert-rules-operators branch December 29, 2024 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants