Skip to content

Commit 9562944

Browse files
ref(crons): Rename {create -> send}_incident_occurrence (#80839)
1 parent 4bb54ba commit 9562944

File tree

6 files changed

+37
-35
lines changed

6 files changed

+37
-35
lines changed

src/sentry/monitors/consumers/incident_occurrences_consumer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from sentry_kafka_schemas.schema_types.monitors_incident_occurrences_v1 import IncidentOccurrence
1515

1616
from sentry.conf.types.kafka_definition import Topic, get_topic_codec
17-
from sentry.monitors.logic.incident_occurrence import create_incident_occurrence
17+
from sentry.monitors.logic.incident_occurrence import send_incident_occurrence
1818
from sentry.monitors.models import MonitorCheckIn, MonitorIncident
1919

2020
logger = logging.getLogger(__name__)
@@ -27,7 +27,7 @@
2727
def process_incident_occurrence(message: Message[KafkaPayload | FilteredPayload]):
2828
"""
2929
Process a incident occurrence message. This will immediately dispatch an
30-
issue occurrence via create_incident_occurrence.
30+
issue occurrence via send_incident_occurrence.
3131
"""
3232
assert not isinstance(message.payload, FilteredPayload)
3333
assert isinstance(message.value, BrokerValue)
@@ -57,7 +57,7 @@ def has_all(checkins: list[MonitorCheckIn | None]) -> TypeGuard[list[MonitorChec
5757

5858
received = datetime.fromtimestamp(wrapper["received_ts"], UTC)
5959

60-
create_incident_occurrence(failed_checkin, previous_checkins, incident, received)
60+
send_incident_occurrence(failed_checkin, previous_checkins, incident, received)
6161

6262

6363
class MonitorIncidentOccurenceStrategyFactory(ProcessingStrategyFactory[KafkaPayload]):

src/sentry/monitors/logic/incident_occurrence.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@
2828
logger = logging.getLogger(__name__)
2929

3030

31-
def create_incident_occurrence(
31+
def send_incident_occurrence(
3232
failed_checkin: MonitorCheckIn,
3333
previous_checkins: Sequence[MonitorCheckIn],
3434
incident: MonitorIncident,
3535
received: datetime,
3636
) -> None:
37+
"""
38+
Construct and send an issue occurrence given an incident and the associated
39+
failing check-ins which caused that incident.
40+
"""
3741
monitor_env = failed_checkin.monitor_environment
3842

3943
if monitor_env is None:

src/sentry/monitors/logic/incidents.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
from sentry import analytics
1010
from sentry.monitors.logic.incident_occurrence import (
11-
create_incident_occurrence,
1211
resolve_incident_group,
12+
send_incident_occurrence,
1313
)
1414
from sentry.monitors.models import CheckInStatus, MonitorCheckIn, MonitorIncident, MonitorStatus
1515
from sentry.monitors.tasks.detect_broken_monitor_envs import NUM_DAYS_BROKEN_PERIOD
@@ -115,7 +115,7 @@ def try_incident_threshold(
115115
if not monitor_env.monitor.is_muted and not monitor_env.is_muted and incident:
116116
checkins = list(MonitorCheckIn.objects.filter(id__in=[c.id for c in previous_checkins]))
117117
for checkin in checkins:
118-
create_incident_occurrence(checkin, checkins, incident, received)
118+
send_incident_occurrence(checkin, checkins, incident, received)
119119

120120
monitor_environment_failed.send(monitor_environment=monitor_env, sender=type(monitor_env))
121121

tests/sentry/monitors/consumers/test_incident_occurrence_consumer.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ def sned_incident_occurrence(
4545

4646

4747
class MonitorsIncidentOccurrenceConsumerTestCase(TestCase):
48-
@mock.patch(
49-
"sentry.monitors.consumers.incident_occurrences_consumer.create_incident_occurrence"
50-
)
51-
def test_simple(self, mock_create_incident_occurrence):
48+
@mock.patch("sentry.monitors.consumers.incident_occurrences_consumer.send_incident_occurrence")
49+
def test_simple(self, mock_send_incident_occurrence):
5250
ts = timezone.now().replace(second=0, microsecond=0)
5351

5452
monitor = self.create_monitor()
@@ -89,8 +87,8 @@ def test_simple(self, mock_create_incident_occurrence):
8987
},
9088
)
9189

92-
assert mock_create_incident_occurrence.call_count == 1
93-
assert mock_create_incident_occurrence.mock_calls[0] == mock.call(
90+
assert mock_send_incident_occurrence.call_count == 1
91+
assert mock_send_incident_occurrence.mock_calls[0] == mock.call(
9492
failed_checkin,
9593
[failed_checkin],
9694
incident,

tests/sentry/monitors/logic/test_incident_occurrence.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from django.utils import timezone
66

77
from sentry.issues.grouptype import MonitorIncidentType
8-
from sentry.monitors.logic.incident_occurrence import create_incident_occurrence, get_failure_reason
8+
from sentry.monitors.logic.incident_occurrence import get_failure_reason, send_incident_occurrence
99
from sentry.monitors.models import (
1010
CheckInStatus,
1111
Monitor,
@@ -21,7 +21,7 @@
2121

2222
class IncidentOccurrenceTestCase(TestCase):
2323
@patch("sentry.monitors.logic.incident_occurrence.produce_occurrence_to_kafka")
24-
def test_simple_failure(self, mock_produce_occurrence_to_kafka):
24+
def test_send_incident_occurrence(self, mock_produce_occurrence_to_kafka):
2525
monitor = Monitor.objects.create(
2626
name="test monitor",
2727
organization_id=self.organization.id,
@@ -74,7 +74,7 @@ def test_simple_failure(self, mock_produce_occurrence_to_kafka):
7474
grouphash="abcd",
7575
)
7676

77-
create_incident_occurrence(
77+
send_incident_occurrence(
7878
failed_checkin,
7979
[timeout_checkin, failed_checkin],
8080
incident,

tests/sentry/monitors/logic/test_mark_failed.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323

2424
class MarkFailedTestCase(TestCase):
25-
@mock.patch("sentry.monitors.logic.incidents.create_incident_occurrence")
26-
def test_mark_failed_default_params(self, mock_create_incident_occurrence):
25+
@mock.patch("sentry.monitors.logic.incidents.send_incident_occurrence")
26+
def test_mark_failed_default_params(self, mock_send_incident_occurrence):
2727
monitor = Monitor.objects.create(
2828
name="test monitor",
2929
organization_id=self.organization.id,
@@ -61,16 +61,16 @@ def test_mark_failed_default_params(self, mock_create_incident_occurrence):
6161
monitor_incidents = MonitorIncident.objects.filter(monitor_environment=monitor_environment)
6262
assert len(monitor_incidents) == 1
6363

64-
assert mock_create_incident_occurrence.call_count == 1
65-
assert mock_create_incident_occurrence.call_args == mock.call(
64+
assert mock_send_incident_occurrence.call_count == 1
65+
assert mock_send_incident_occurrence.call_args == mock.call(
6666
checkin,
6767
[checkin],
6868
monitor_incidents[0],
6969
checkin.date_added,
7070
)
7171

72-
@mock.patch("sentry.monitors.logic.incidents.create_incident_occurrence")
73-
def test_mark_failed_muted(self, mock_create_incident_occurrence):
72+
@mock.patch("sentry.monitors.logic.incidents.send_incident_occurrence")
73+
def test_mark_failed_muted(self, mock_send_incident_occurrence):
7474
monitor = Monitor.objects.create(
7575
name="test monitor",
7676
organization_id=self.organization.id,
@@ -103,11 +103,11 @@ def test_mark_failed_muted(self, mock_create_incident_occurrence):
103103
assert monitor.is_muted
104104
assert monitor_environment.status == MonitorStatus.ERROR
105105

106-
assert mock_create_incident_occurrence.call_count == 0
106+
assert mock_send_incident_occurrence.call_count == 0
107107
assert monitor_environment.active_incident is not None
108108

109-
@mock.patch("sentry.monitors.logic.incidents.create_incident_occurrence")
110-
def test_mark_failed_env_muted(self, mock_create_incident_occurrence):
109+
@mock.patch("sentry.monitors.logic.incidents.send_incident_occurrence")
110+
def test_mark_failed_env_muted(self, mock_send_incident_occurrence):
111111
monitor = Monitor.objects.create(
112112
name="test monitor",
113113
organization_id=self.organization.id,
@@ -142,11 +142,11 @@ def test_mark_failed_env_muted(self, mock_create_incident_occurrence):
142142
assert not monitor.is_muted
143143
assert monitor_environment.is_muted
144144
assert monitor_environment.status == MonitorStatus.ERROR
145-
assert mock_create_incident_occurrence.call_count == 0
145+
assert mock_send_incident_occurrence.call_count == 0
146146
assert monitor_environment.active_incident is not None
147147

148-
@mock.patch("sentry.monitors.logic.incidents.create_incident_occurrence")
149-
def test_mark_failed_issue_threshold(self, mock_create_incident_occurrence):
148+
@mock.patch("sentry.monitors.logic.incidents.send_incident_occurrence")
149+
def test_mark_failed_issue_threshold(self, mock_send_incident_occurrence):
150150
failure_issue_threshold = 8
151151
monitor = Monitor.objects.create(
152152
name="test monitor",
@@ -222,7 +222,7 @@ def test_mark_failed_issue_threshold(self, mock_create_incident_occurrence):
222222
assert monitor_incident.grouphash == monitor_environment.active_incident.grouphash
223223

224224
# assert correct number of occurrences was sent
225-
assert mock_create_incident_occurrence.call_count == failure_issue_threshold
225+
assert mock_send_incident_occurrence.call_count == failure_issue_threshold
226226

227227
# send another check-in to make sure the incident does not change
228228
status = next(failure_statuses)
@@ -242,7 +242,7 @@ def test_mark_failed_issue_threshold(self, mock_create_incident_occurrence):
242242
assert monitor_incident.grouphash == monitor_environment.active_incident.grouphash
243243

244244
# assert correct number of occurrences was sent
245-
assert mock_create_incident_occurrence.call_count == failure_issue_threshold + 1
245+
assert mock_send_incident_occurrence.call_count == failure_issue_threshold + 1
246246

247247
# Resolve the incident with an OK check-in
248248
ok_checkin = MonitorCheckIn.objects.create(
@@ -273,8 +273,8 @@ def test_mark_failed_issue_threshold(self, mock_create_incident_occurrence):
273273

274274
# Test to make sure that timeout mark_failed (which occur in the past)
275275
# correctly create issues once passing the failure_issue_threshold
276-
@mock.patch("sentry.monitors.logic.incidents.create_incident_occurrence")
277-
def test_mark_failed_issue_threshold_timeout(self, mock_create_incident_occurrence):
276+
@mock.patch("sentry.monitors.logic.incidents.send_incident_occurrence")
277+
def test_mark_failed_issue_threshold_timeout(self, mock_send_incident_occurrence):
278278
failure_issue_threshold = 8
279279
monitor = Monitor.objects.create(
280280
name="test monitor",
@@ -341,11 +341,11 @@ def test_mark_failed_issue_threshold_timeout(self, mock_create_incident_occurren
341341
assert monitor_incident.grouphash == monitor_environment.active_incident.grouphash
342342

343343
# assert correct number of occurrences was sent
344-
assert mock_create_incident_occurrence.call_count == failure_issue_threshold
344+
assert mock_send_incident_occurrence.call_count == failure_issue_threshold
345345

346346
# we are duplicating this test as the code paths are different, for now
347-
@mock.patch("sentry.monitors.logic.incidents.create_incident_occurrence")
348-
def test_mark_failed_issue_threshold_disabled(self, mock_create_incident_occurrence):
347+
@mock.patch("sentry.monitors.logic.incidents.send_incident_occurrence")
348+
def test_mark_failed_issue_threshold_disabled(self, mock_send_incident_occurrence):
349349
failure_issue_threshold = 8
350350
monitor = Monitor.objects.create(
351351
name="test monitor",
@@ -381,7 +381,7 @@ def test_mark_failed_issue_threshold_disabled(self, mock_create_incident_occurre
381381
assert monitor.is_muted
382382
assert monitor_environment.status == MonitorStatus.ERROR
383383

384-
assert mock_create_incident_occurrence.call_count == 0
384+
assert mock_send_incident_occurrence.call_count == 0
385385
assert monitor_environment.active_incident is not None
386386

387387
def test_mark_failed_issue_assignment(self):

0 commit comments

Comments
 (0)