Skip to content

Commit

Permalink
[Alerts] Set criteria to defaults if not provided (#5796)
Browse files Browse the repository at this point in the history
  • Loading branch information
yanburman committed Jun 23, 2024
1 parent f212bfb commit 65fd384
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mlrun/common/schemas/alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class AlertCriteria(pydantic.BaseModel):
pydantic.Field(
description="Number of events to wait until notification is sent"
),
] = 0
] = 1
period: Annotated[
str,
pydantic.Field(
Expand Down
3 changes: 3 additions & 0 deletions server/api/crud/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def store_alert(

self._validate_alert(alert_data, name, project)

if alert_data.criteria is None:
alert_data.criteria = mlrun.common.schemas.alert.AlertCriteria()

if alert is not None:
self._delete_notifications(alert)
else:
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/sdk_api/alerts/test_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def test_alert_operations(self):
# get alert and validate params
alert = self._get_alerts(project_name, created_alert.name)
self._validate_alert(alert, project_name, alert1["name"])
assert alert.criteria["count"] == 1
assert alert.criteria["period"] is None

# try to get non existent alert ID
with pytest.raises(mlrun.errors.MLRunNotFoundError):
Expand Down

0 comments on commit 65fd384

Please sign in to comment.