Skip to content

Commit

Permalink
Ignore resolve condition template if source resolving is disabled (#5049
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasb authored Sep 23, 2024
1 parent 737eaf7 commit 4abfb20
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion engine/apps/alerts/models/alert_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ def get_or_create_grouping(self, channel, channel_filter, group_data, received_a
pass

# If it's an "OK" alert, try to return the latest resolved group
if group_data.is_resolve_signal:
# (only if the channel allows source base resolving and the alert is a resolve signal)
if channel.allow_source_based_resolving and group_data.is_resolve_signal:
try:
return self.filter(**search_params, resolved=True).latest(), False
except self.model.DoesNotExist:
Expand Down
38 changes: 38 additions & 0 deletions engine/apps/alerts/tests/test_alert_group.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import hashlib
from unittest.mock import call, patch

import pytest
Expand Down Expand Up @@ -758,3 +759,40 @@ def test_update_state_by_backsync(
assert (last_log.action_source, last_log.author, last_log.step_specific_info) == expected_log_data
assert last_log.type == to_firing_log_type
mock_start_escalation_if_needed.assert_called_once()


@pytest.mark.django_db
def test_alert_group_created_if_resolve_condition_but_auto_resolving_disabled(
make_organization,
make_alert_receive_channel,
make_alert_group,
):
organization = make_organization()
# grouping condition will match. resolve condition will evaluate to True, but auto resolving is disabled
grouping_distinction = "abcdef"
alert_receive_channel = make_alert_receive_channel(
organization,
grouping_id_template=grouping_distinction,
resolve_condition_template="True",
allow_source_based_resolving=False,
)
# existing alert group, resolved, with a matching grouping distinction
resolved_alert_group = make_alert_group(
alert_receive_channel,
resolved=True,
distinction=hashlib.md5(grouping_distinction.encode()).hexdigest(),
)

# an alert for the same integration is received
alert = Alert.create(
title="the title",
message="the message",
alert_receive_channel=alert_receive_channel,
raw_request_data={},
integration_unique_data={},
image_url=None,
link_to_upstream_details=None,
)

# the alert will create a new alert group
assert alert.group != resolved_alert_group

0 comments on commit 4abfb20

Please sign in to comment.