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

patch default user notification policy changes + fix failing e2e test #4635

Merged

Conversation

joeyorlando
Copy link
Contributor

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

  • Unit, integration, and e2e (if applicable) tests updated
  • Documentation added (or pr:no public docs PR label added if not required)
  • 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.

@joeyorlando joeyorlando added pr:no public docs Added to a PR that does not require public documentation updates release:ignore PR will not be added to release notes labels Jul 8, 2024
@joeyorlando joeyorlando requested review from Ferril and a team July 8, 2024 21:02
Copy link
Contributor Author

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)

@joeyorlando joeyorlando changed the title patch default user notification policy changes patch default user notification policy changes + fix failing e2e test Jul 8, 2024
… of github.com:grafana/oncall into jorlando/patches-for-fallback-user-notification-policy
Copy link
Member

@Ferril Ferril Jul 9, 2024

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:

  1. call notify_user_task with previous_notification_policy_pk=None
  2. get the first notification policy
  3. create log with type TRIGGERED and call perform_notification
  4. call next notify_user_task with previous_notification_policy_pk=<current notification_policy.pk>
  5. in the next notify_user_task get notifiction_policy.next()
  6. 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?

Copy link
Contributor Author

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

Before
Screenshot 2024-07-09 at 10 39 03

After
Screenshot 2024-07-09 at 10 39 10

Copy link
Member

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 = ""
Copy link
Contributor Author

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

@joeyorlando joeyorlando requested a review from Ferril July 9, 2024 14:43
@joeyorlando joeyorlando enabled auto-merge July 9, 2024 15:02
@joeyorlando joeyorlando disabled auto-merge July 9, 2024 15:23
@joeyorlando joeyorlando merged commit 34a9013 into dev Jul 9, 2024
21 checks passed
@joeyorlando joeyorlando deleted the jorlando/patches-for-fallback-user-notification-policy branch July 9, 2024 15:23
brojd pushed a commit that referenced this pull request Sep 18, 2024
…#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:no public docs Added to a PR that does not require public documentation updates release:ignore PR will not be added to release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants