-
Notifications
You must be signed in to change notification settings - Fork 298
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
patch default user notification policy changes + fix failing e2e test #4635
patch default user notification policy changes + fix failing e2e test #4635
Conversation
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.
These changes should fix this failing e2e test (which started failing after we recently got rid of autogenerating default user notification policy steps)
… of github.com:grafana/oncall into jorlando/patches-for-fallback-user-notification-policy
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 found another issue. It seems like there is an endless loop of notification. In the notify_user_task
we call next notify_user_task
here (line 231):
transaction.on_commit(
partial(
notify_user_task.apply_async,
(user.pk, alert_group.pk, notification_policy.pk, reason),
...
)
The next task will start with previous_notification_policy_pk=None
, notify user again and call next notify_user_task
with the same parameters -> 🔁
The regular flow is:
- call
notify_user_task
withprevious_notification_policy_pk=None
- get the first notification policy
- create log with type
TRIGGERED
and callperform_notification
- call next
notify_user_task
withprevious_notification_policy_pk=<current notification_policy.pk>
- in the next
notify_user_task
get notifiction_policy.next() - if it's not None: repeat from step 3. Otherwise create notification log with type
FINISHED
and stop notification.
So for one existing notification step the notify_user_task
is called twice.
For default notification we can add a flag to notify_user_task
when we call it again OR we can skip steps 4 and 5, create FINISHED
log and stop notification 🤔 wdyt?
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.
great catch and thanks for the really detailed breakdown, this was super helpful in understanding the flow of things 🫶 This should now be addressed in 716ad63
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.
LGTM 👍
@@ -42,7 +43,6 @@ def notify_user_task( | |||
|
|||
countdown = 0 | |||
stop_escalation = False | |||
log_message = "" |
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.
log_message
is only ever updated here, but then it is never referenced/used anywhere
…#4635) # What this PR does This is a follow-up PR to #4628. As @Ferril pointed out, there was a slight issue in `apps.alerts.tasks.notify_user.perform_notification` method when using a "fallback"/default user notification policy. This is because the `log_record_pk` arg passed into `perform_notification` will fetch the `UserNotificationPolicyLogRecord` object, but that object will have a `notification_policy` set to `None` (because there's no persistent `UserNotificationPolicy` object to refer to). Instead we now pass in a second argument to `perform_notification`, `use_default_notification_policy_fallback`. If this is true, simply grab the transient/in-memory `UserNotificationPolicy` and use that inside of this task Related to #4410 ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] Added the relevant release notes label (see labels prefixed w/ `release:`). These labels dictate how your PR will show up in the autogenerated release notes.
What this PR does
This is a follow-up PR to #4628. As @Ferril pointed out, there was a slight issue in
apps.alerts.tasks.notify_user.perform_notification
method when using a "fallback"/default user notification policy. This is because thelog_record_pk
arg passed intoperform_notification
will fetch theUserNotificationPolicyLogRecord
object, but that object will have anotification_policy
set toNone
(because there's no persistentUserNotificationPolicy
object to refer to).Instead we now pass in a second argument to
perform_notification
,use_default_notification_policy_fallback
. If this is true, simply grab the transient/in-memoryUserNotificationPolicy
and use that inside of this taskRelated to #4410
Checklist
pr:no public docs
PR label added if not required)release:
). These labels dictate how your PR willshow up in the autogenerated release notes.