-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat(anomaly detection): Cron to cleanup disabled alerts #1455
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
83fb731
Create cron to delete timestamps from disabled alerts
aayush-se a8bf43c
Fix celery tests
aayush-se e15f312
Delete disabled alerts and update tests
aayush-se a52053d
Fully ensure timeseries for deleted alerts are also purged
aayush-se da00d16
Include date_threshold in log
aayush-se 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 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 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 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 |
---|---|---|
|
@@ -9,8 +9,8 @@ | |
from seer.anomaly_detection.models import MPTimeSeriesAnomalies | ||
from seer.anomaly_detection.models.external import AnomalyDetectionConfig, TimeSeriesPoint | ||
from seer.anomaly_detection.models.timeseries import TimeSeries | ||
from seer.anomaly_detection.tasks import cleanup_timeseries | ||
from seer.db import DbDynamicAlert, Session, TaskStatus | ||
from seer.anomaly_detection.tasks import cleanup_disabled_alerts, cleanup_timeseries | ||
from seer.db import DbDynamicAlert, DbDynamicAlertTimeSeries, Session, TaskStatus | ||
|
||
|
||
class TestCleanupTasks(unittest.TestCase): | ||
|
@@ -154,3 +154,62 @@ def test_cleanup_timeseries(self): | |
# Fails due to invalid alert_id | ||
with self.assertRaises(Exception): | ||
cleanup_timeseries(999, date_threshold) | ||
|
||
def test_cleanup_disabled_alerts(self): | ||
# Create and save alerts with old points | ||
external_alert_id1, _, _, _ = self._save_alert(1000, 0) | ||
external_alert_id2, _, _, _ = self._save_alert(500, 0) | ||
external_alert_id3, _, _, _ = self._save_alert(0, 500) | ||
external_alert_id4, _, _, _ = self._save_alert(0, 500) | ||
|
||
# Set last_queued_at to be over 28 days ago for alerts 1 and 2 | ||
with Session() as session: | ||
for alert_id in [external_alert_id1, external_alert_id2]: | ||
alert = ( | ||
session.query(DbDynamicAlert) | ||
.filter(DbDynamicAlert.external_alert_id == alert_id) | ||
.one_or_none() | ||
) | ||
assert alert is not None | ||
alert.last_queued_at = datetime.now() - timedelta(days=29) | ||
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. We should add a unit that includes one alert with last_queued_at as null |
||
|
||
for alert_id in [external_alert_id3]: | ||
alert = ( | ||
session.query(DbDynamicAlert) | ||
.filter(DbDynamicAlert.external_alert_id == alert_id) | ||
.one_or_none() | ||
) | ||
assert alert is not None | ||
alert.created_at = datetime.now() - timedelta(days=29) | ||
alert.last_queued_at = None | ||
|
||
session.commit() | ||
|
||
cleanup_disabled_alerts() | ||
|
||
with Session() as session: | ||
for alert_id in [external_alert_id1, external_alert_id2, external_alert_id3]: | ||
alert = ( | ||
session.query(DbDynamicAlert) | ||
.filter(DbDynamicAlert.external_alert_id == alert_id) | ||
.one_or_none() | ||
) | ||
assert alert is None | ||
|
||
timeseries = ( | ||
session.query(DbDynamicAlertTimeSeries) | ||
.filter(DbDynamicAlertTimeSeries.dynamic_alert_id == alert_id) | ||
.all() | ||
) | ||
assert len(timeseries) == 0 | ||
|
||
# Confirm that alert 4 and its respective timeseries are not deleted | ||
with Session() as session: | ||
alert = ( | ||
session.query(DbDynamicAlert) | ||
.filter(DbDynamicAlert.external_alert_id == external_alert_id4) | ||
.one_or_none() | ||
) | ||
|
||
assert alert is not None | ||
assert len(alert.timeseries) == 500 |
This file contains 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.
Minor nit - add
date_threshold
in this info message