Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(crons): Move SimpleCheckIn back to just incident module #80774

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading