-
Notifications
You must be signed in to change notification settings - Fork 297
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
Add transaction on_commit before signals for alert group actions #3731
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
cb7aa98
Add transaction oncommit before signals for alert group actions
mderynck 5244da3
For delete make sure alert group still exists when signal is processed
mderynck 0fe9b3e
Split up delete tasks so slack message delete can retry separately
mderynck 51b320d
Fix tests
mderynck 54a3fed
Merge branch 'dev' into mderynck/oncommit-action-triggered-signal
mderynck 86fcd20
Fix log message
mderynck 068284f
Remove action_source from signal
mderynck abae499
Merge branch 'dev' into mderynck/oncommit-action-triggered-signal
mderynck 914ff15
Add debug log statements
mderynck 08ae20c
Add logging for delete alert group log record
mderynck 0b1ded2
Add transaction in acknowledge reminder
mderynck 76ae688
Merge branch 'dev' into mderynck/oncall-dev-debugging
mderynck c422c55
Add transactions
mderynck 74171e8
Merge branch 'dev' into mderynck/oncommit-action-triggered-signal
mderynck 19beec9
Merge dev
mderynck 807943f
Update changelog
mderynck 0c234ec
Merge dev
mderynck d9e7d40
Raise exceptions but do not retry on object does not exist
mderynck 9c84d26
Raise exception for missing in webhook trigger
mderynck f57b756
Raise exception
mderynck 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from celery.utils.log import get_task_logger | ||
from django.conf import settings | ||
|
||
from apps.alerts.signals import alert_group_action_triggered_signal | ||
from apps.slack.errors import SlackAPIRatelimitError | ||
from common.custom_celery_tasks import shared_dedicated_queue_retry_task | ||
|
||
|
@@ -10,7 +11,7 @@ | |
@shared_dedicated_queue_retry_task( | ||
autoretry_for=(Exception,), retry_backoff=True, max_retries=1 if settings.DEBUG else None | ||
) | ||
def delete_alert_group(alert_group_pk, user_pk): | ||
def delete_alert_group(alert_group_pk: int, user_pk: int) -> None: | ||
from apps.alerts.models import AlertGroup | ||
from apps.user_management.models import User | ||
|
||
|
@@ -25,9 +26,35 @@ def delete_alert_group(alert_group_pk, user_pk): | |
return | ||
|
||
logger.debug(f"User {user} is deleting alert group {alert_group} (channel: {alert_group.channel})") | ||
alert_group.delete_by_user(user) | ||
|
||
|
||
@shared_dedicated_queue_retry_task( | ||
autoretry_for=(Exception,), retry_backoff=True, max_retries=1 if settings.DEBUG else None | ||
) | ||
def send_alert_group_signal_for_delete(alert_group_pk: int, log_record_pk: int) -> None: | ||
try: | ||
alert_group.delete_by_user(user) | ||
alert_group_action_triggered_signal.send( | ||
sender=send_alert_group_signal_for_delete, | ||
log_record=log_record_pk, | ||
force_sync=True, | ||
) | ||
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. So, we trigger the action triggered signal and queue the cleanup task after that. Makes sense 👍 |
||
except SlackAPIRatelimitError as e: | ||
# Handle Slack API ratelimit raised in apps.slack.scenarios.distribute_alerts.DeleteGroupStep.process_signal | ||
delete_alert_group.apply_async((alert_group_pk, user_pk), countdown=e.retry_after) | ||
send_alert_group_signal_for_delete.apply_async((alert_group_pk, log_record_pk), countdown=e.retry_after) | ||
return | ||
|
||
finish_delete_alert_group.apply_async((alert_group_pk,)) | ||
|
||
|
||
@shared_dedicated_queue_retry_task( | ||
autoretry_for=(Exception,), retry_backoff=True, max_retries=1 if settings.DEBUG else None | ||
) | ||
def finish_delete_alert_group(alert_group_pk: int) -> None: | ||
from apps.alerts.models import AlertGroup | ||
|
||
alert_group = AlertGroup.objects.filter(pk=alert_group_pk).first() | ||
if not alert_group: | ||
logger.debug(f"Alert group id={alert_group_pk} not found, already deleted") | ||
return | ||
alert_group.finish_delete_by_user() |
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
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
Oops, something went wrong.
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.
Maybe not for this PR, but wondering if this still needs to be a task?
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.
I think we can keep it for now, I guess something could go wrong in the stop escalation part of delete and we could retry here.