Handle multiple unpage event logs when getting paged users (#4698)
Related to https://github.com/grafana/oncall-private/issues/2816
This commit is contained in:
parent
dd84aa15c6
commit
7777a6003a
2 changed files with 22 additions and 2 deletions
|
|
@ -554,7 +554,7 @@ class AlertGroup(AlertGroupSlackRenderingMixin, EscalationSnapshotMixin, models.
|
|||
|
||||
log_records = self.log_records.filter(
|
||||
type__in=(AlertGroupLogRecord.TYPE_DIRECT_PAGING, AlertGroupLogRecord.TYPE_UNPAGE_USER)
|
||||
)
|
||||
).order_by("created_at")
|
||||
|
||||
for log_record in log_records:
|
||||
# filter paging events, track still active escalations
|
||||
|
|
@ -592,7 +592,9 @@ class AlertGroup(AlertGroupSlackRenderingMixin, EscalationSnapshotMixin, models.
|
|||
}
|
||||
else:
|
||||
# user was unpaged at some point, remove them
|
||||
del users[user_id]
|
||||
# there could be multiple unpage log records if API was hit several times
|
||||
if user_id in users:
|
||||
del users[user_id]
|
||||
|
||||
return list(users.values())
|
||||
|
||||
|
|
|
|||
|
|
@ -589,6 +589,24 @@ def test_alert_group_get_paged_users(
|
|||
assert len(paged_users) == 1
|
||||
assert alert_group.get_paged_users()[0]["pk"] == user.public_primary_key
|
||||
|
||||
# user was paged and then paged again, then unpaged - they should not show up
|
||||
alert_group = make_alert_group(alert_receive_channel)
|
||||
_make_log_record(alert_group, user, AlertGroupLogRecord.TYPE_DIRECT_PAGING)
|
||||
_make_log_record(alert_group, user, AlertGroupLogRecord.TYPE_DIRECT_PAGING)
|
||||
_make_log_record(alert_group, user, AlertGroupLogRecord.TYPE_UNPAGE_USER)
|
||||
|
||||
paged_users = alert_group.get_paged_users()
|
||||
assert len(paged_users) == 0
|
||||
|
||||
# adding extra unpage events should not break things
|
||||
_make_log_record(alert_group, user, AlertGroupLogRecord.TYPE_UNPAGE_USER)
|
||||
_make_log_record(alert_group, user, AlertGroupLogRecord.TYPE_UNPAGE_USER)
|
||||
_make_log_record(alert_group, user, AlertGroupLogRecord.TYPE_DIRECT_PAGING)
|
||||
|
||||
paged_users = alert_group.get_paged_users()
|
||||
assert len(paged_users) == 1
|
||||
assert alert_group.get_paged_users()[0]["pk"] == user.public_primary_key
|
||||
|
||||
|
||||
@patch("apps.alerts.models.AlertGroup.start_unsilence_task", return_value=None)
|
||||
@pytest.mark.django_db
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue