Skip to content

Commit

Permalink
ref(crons): Rename {create -> send}_incident_occurrence
Browse files Browse the repository at this point in the history
  • Loading branch information
evanpurkhiser committed Nov 15, 2024
1 parent 8dbe565 commit 46d6c54
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from sentry_kafka_schemas.schema_types.monitors_incident_occurrences_v1 import IncidentOccurrence

from sentry.conf.types.kafka_definition import Topic, get_topic_codec
from sentry.monitors.logic.incident_occurrence import create_incident_occurrence
from sentry.monitors.logic.incident_occurrence import send_incident_occurrence
from sentry.monitors.models import MonitorCheckIn, MonitorIncident

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

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

create_incident_occurrence(failed_checkin, previous_checkins, incident, received)
send_incident_occurrence(failed_checkin, previous_checkins, incident, received)


class MonitorIncidentOccurenceStrategyFactory(ProcessingStrategyFactory[KafkaPayload]):
Expand Down
6 changes: 5 additions & 1 deletion src/sentry/monitors/logic/incident_occurrence.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@
logger = logging.getLogger(__name__)


def create_incident_occurrence(
def send_incident_occurrence(
failed_checkin: MonitorCheckIn,
previous_checkins: Sequence[MonitorCheckIn],
incident: MonitorIncident,
received: datetime,
) -> None:
"""
Construct and send an issue occurrence given an incident and the associated
failing check-ins which caused that incident.
"""
monitor_env = failed_checkin.monitor_environment

if monitor_env is None:
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/monitors/logic/incidents.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

from sentry import analytics
from sentry.monitors.logic.incident_occurrence import (
create_incident_occurrence,
resolve_incident_group,
send_incident_occurrence,
)
from sentry.monitors.models import CheckInStatus, MonitorCheckIn, MonitorIncident, MonitorStatus
from sentry.monitors.tasks.detect_broken_monitor_envs import NUM_DAYS_BROKEN_PERIOD
Expand Down Expand Up @@ -115,7 +115,7 @@ def try_incident_threshold(
if not monitor_env.monitor.is_muted and not monitor_env.is_muted and incident:
checkins = list(MonitorCheckIn.objects.filter(id__in=[c.id for c in previous_checkins]))
for checkin in checkins:
create_incident_occurrence(checkin, checkins, incident, received)
send_incident_occurrence(checkin, checkins, incident, received)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ def sned_incident_occurrence(


class MonitorsIncidentOccurrenceConsumerTestCase(TestCase):
@mock.patch(
"sentry.monitors.consumers.incident_occurrences_consumer.create_incident_occurrence"
)
def test_simple(self, mock_create_incident_occurrence):
@mock.patch("sentry.monitors.consumers.incident_occurrences_consumer.send_incident_occurrence")
def test_simple(self, mock_send_incident_occurrence):
ts = timezone.now().replace(second=0, microsecond=0)

monitor = self.create_monitor()
Expand Down Expand Up @@ -89,8 +87,8 @@ def test_simple(self, mock_create_incident_occurrence):
},
)

assert mock_create_incident_occurrence.call_count == 1
assert mock_create_incident_occurrence.mock_calls[0] == mock.call(
assert mock_send_incident_occurrence.call_count == 1
assert mock_send_incident_occurrence.mock_calls[0] == mock.call(
failed_checkin,
[failed_checkin],
incident,
Expand Down
6 changes: 3 additions & 3 deletions tests/sentry/monitors/logic/test_incident_occurrence.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.utils import timezone

from sentry.issues.grouptype import MonitorIncidentType
from sentry.monitors.logic.incident_occurrence import create_incident_occurrence, get_failure_reason
from sentry.monitors.logic.incident_occurrence import get_failure_reason, send_incident_occurrence
from sentry.monitors.models import (
CheckInStatus,
Monitor,
Expand All @@ -21,7 +21,7 @@

class IncidentOccurrenceTestCase(TestCase):
@patch("sentry.monitors.logic.incident_occurrence.produce_occurrence_to_kafka")
def test_simple_failure(self, mock_produce_occurrence_to_kafka):
def test_send_incident_occurrence(self, mock_produce_occurrence_to_kafka):
monitor = Monitor.objects.create(
name="test monitor",
organization_id=self.organization.id,
Expand Down Expand Up @@ -74,7 +74,7 @@ def test_simple_failure(self, mock_produce_occurrence_to_kafka):
grouphash="abcd",
)

create_incident_occurrence(
send_incident_occurrence(
failed_checkin,
[timeout_checkin, failed_checkin],
incident,
Expand Down
40 changes: 20 additions & 20 deletions tests/sentry/monitors/logic/test_mark_failed.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@


class MarkFailedTestCase(TestCase):
@mock.patch("sentry.monitors.logic.incidents.create_incident_occurrence")
def test_mark_failed_default_params(self, mock_create_incident_occurrence):
@mock.patch("sentry.monitors.logic.incidents.send_incident_occurrence")
def test_mark_failed_default_params(self, mock_send_incident_occurrence):
monitor = Monitor.objects.create(
name="test monitor",
organization_id=self.organization.id,
Expand Down Expand Up @@ -61,16 +61,16 @@ def test_mark_failed_default_params(self, mock_create_incident_occurrence):
monitor_incidents = MonitorIncident.objects.filter(monitor_environment=monitor_environment)
assert len(monitor_incidents) == 1

assert mock_create_incident_occurrence.call_count == 1
assert mock_create_incident_occurrence.call_args == mock.call(
assert mock_send_incident_occurrence.call_count == 1
assert mock_send_incident_occurrence.call_args == mock.call(
checkin,
[checkin],
monitor_incidents[0],
checkin.date_added,
)

@mock.patch("sentry.monitors.logic.incidents.create_incident_occurrence")
def test_mark_failed_muted(self, mock_create_incident_occurrence):
@mock.patch("sentry.monitors.logic.incidents.send_incident_occurrence")
def test_mark_failed_muted(self, mock_send_incident_occurrence):
monitor = Monitor.objects.create(
name="test monitor",
organization_id=self.organization.id,
Expand Down Expand Up @@ -103,11 +103,11 @@ def test_mark_failed_muted(self, mock_create_incident_occurrence):
assert monitor.is_muted
assert monitor_environment.status == MonitorStatus.ERROR

assert mock_create_incident_occurrence.call_count == 0
assert mock_send_incident_occurrence.call_count == 0
assert monitor_environment.active_incident is not None

@mock.patch("sentry.monitors.logic.incidents.create_incident_occurrence")
def test_mark_failed_env_muted(self, mock_create_incident_occurrence):
@mock.patch("sentry.monitors.logic.incidents.send_incident_occurrence")
def test_mark_failed_env_muted(self, mock_send_incident_occurrence):
monitor = Monitor.objects.create(
name="test monitor",
organization_id=self.organization.id,
Expand Down Expand Up @@ -142,11 +142,11 @@ def test_mark_failed_env_muted(self, mock_create_incident_occurrence):
assert not monitor.is_muted
assert monitor_environment.is_muted
assert monitor_environment.status == MonitorStatus.ERROR
assert mock_create_incident_occurrence.call_count == 0
assert mock_send_incident_occurrence.call_count == 0
assert monitor_environment.active_incident is not None

@mock.patch("sentry.monitors.logic.incidents.create_incident_occurrence")
def test_mark_failed_issue_threshold(self, mock_create_incident_occurrence):
@mock.patch("sentry.monitors.logic.incidents.send_incident_occurrence")
def test_mark_failed_issue_threshold(self, mock_send_incident_occurrence):
failure_issue_threshold = 8
monitor = Monitor.objects.create(
name="test monitor",
Expand Down Expand Up @@ -222,7 +222,7 @@ def test_mark_failed_issue_threshold(self, mock_create_incident_occurrence):
assert monitor_incident.grouphash == monitor_environment.active_incident.grouphash

# assert correct number of occurrences was sent
assert mock_create_incident_occurrence.call_count == failure_issue_threshold
assert mock_send_incident_occurrence.call_count == failure_issue_threshold

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

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

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

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

# assert correct number of occurrences was sent
assert mock_create_incident_occurrence.call_count == failure_issue_threshold
assert mock_send_incident_occurrence.call_count == failure_issue_threshold

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

assert mock_create_incident_occurrence.call_count == 0
assert mock_send_incident_occurrence.call_count == 0
assert monitor_environment.active_incident is not None

def test_mark_failed_issue_assignment(self):
Expand Down

0 comments on commit 46d6c54

Please sign in to comment.