Ignore resolve condition template if source resolving is disabled (#5049)

Related to https://github.com/grafana/support-escalations/issues/12528
This commit is contained in:
Matias Bordese 2024-09-23 15:01:59 -03:00 committed by GitHub
parent 737eaf79cc
commit 4abfb205ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 40 additions and 1 deletions

View file

@ -129,7 +129,8 @@ class AlertGroupQuerySet(models.QuerySet):
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:

View file

@ -1,3 +1,4 @@
import hashlib
from unittest.mock import call, patch
import pytest
@ -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