Skip to content

Commit

Permalink
ref(crons): Move SimpleCheckIn back to just incident module
Browse files Browse the repository at this point in the history
Turns out we actually really don't need to expose this type more
broadly, and can just use it only in this module.
  • Loading branch information
evanpurkhiser committed Nov 14, 2024
1 parent 7eaeb8e commit 3ba5a1c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
21 changes: 18 additions & 3 deletions src/sentry/monitors/logic/incidents.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import logging
from dataclasses import dataclass
from datetime import datetime, timedelta

from django.utils import timezone
Expand All @@ -12,11 +13,25 @@
)
from sentry.monitors.models import CheckInStatus, MonitorCheckIn, MonitorIncident, MonitorStatus
from sentry.monitors.tasks.detect_broken_monitor_envs import NUM_DAYS_BROKEN_PERIOD
from sentry.monitors.types import SimpleCheckIn

logger = logging.getLogger(__name__)


@dataclass
class SimpleCheckIn:
"""
A stripped down check in object
"""

id: int
date_added: datetime
status: int

@classmethod
def from_checkin(cls, checkin: MonitorCheckIn) -> SimpleCheckIn:
return cls(checkin.id, checkin.date_added, checkin.status)


def try_incident_threshold(
failed_checkin: MonitorCheckIn,
received: datetime | None,
Expand Down Expand Up @@ -45,7 +60,7 @@ def try_incident_threshold(
# check to see if we need to update the status
if monitor_env.status in [MonitorStatus.OK, MonitorStatus.ACTIVE]:
if failure_issue_threshold == 1:
previous_checkins: list[SimpleCheckIn] = [failed_checkin.as_simple_checkin()]
previous_checkins: list[SimpleCheckIn] = [SimpleCheckIn.from_checkin(failed_checkin)]
else:
previous_checkins = [
SimpleCheckIn(**row)
Expand Down Expand Up @@ -86,7 +101,7 @@ def try_incident_threshold(
elif monitor_env.status == MonitorStatus.ERROR:
# if monitor environment has a failed status, use the failed
# check-in and send occurrence
previous_checkins = [failed_checkin.as_simple_checkin()]
previous_checkins = [SimpleCheckIn.from_checkin(failed_checkin)]

# get the active incident from the monitor environment
incident = monitor_env.active_incident
Expand Down
5 changes: 1 addition & 4 deletions src/sentry/monitors/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from sentry.locks import locks
from sentry.models.environment import Environment
from sentry.models.rule import Rule, RuleSource
from sentry.monitors.types import CrontabSchedule, IntervalSchedule, SimpleCheckIn
from sentry.monitors.types import CrontabSchedule, IntervalSchedule
from sentry.types.actor import Actor
from sentry.utils.retries import TimedRetryPolicy

Expand Down Expand Up @@ -581,9 +581,6 @@ def save(self, *args, **kwargs):
def _update_timestamps(self):
pass

def as_simple_checkin(self) -> SimpleCheckIn:
return SimpleCheckIn(self.id, self.date_added, self.status)


def delete_file_for_monitorcheckin(instance: MonitorCheckIn, **kwargs):
if file_id := instance.attachment_id:
Expand Down
11 changes: 0 additions & 11 deletions src/sentry/monitors/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,6 @@ def from_dict(cls, data: CheckinItemData) -> CheckinItem:
)


@dataclass
class SimpleCheckIn:
"""
A stripped down check in object
"""

id: int
date_added: datetime
status: int


IntervalUnit = Literal["year", "month", "week", "day", "hour", "minute"]


Expand Down

0 comments on commit 3ba5a1c

Please sign in to comment.