Skip to content

Commit 19ac45c

Browse files
committed
ref(crons): Remove Monitor type field (state)
1 parent aced603 commit 19ac45c

32 files changed

+44
-153
lines changed

migrations_lockfile.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ remote_subscriptions: 0003_drop_remote_subscription
1717

1818
replays: 0004_index_together
1919

20-
sentry: 0855_give_monitor_type_a_db_default
20+
sentry: 0856_monitors_remove_type_column_state
2121

2222
social_auth: 0002_default_auto_field
2323

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Generated by Django 5.1.7 on 2025-04-01 20:02
2+
3+
from sentry.new_migrations.migrations import CheckedMigration
4+
from sentry.new_migrations.monkey.fields import SafeRemoveField
5+
from sentry.new_migrations.monkey.state import DeletionAction
6+
7+
8+
class Migration(CheckedMigration):
9+
# This flag is used to mark that a migration shouldn't be automatically run in production.
10+
# This should only be used for operations where it's safe to run the migration after your
11+
# code has deployed. So this should not be used for most operations that alter the schema
12+
# of a table.
13+
# Here are some things that make sense to mark as post deployment:
14+
# - Large data migrations. Typically we want these to be run manually so that they can be
15+
# monitored and not block the deploy for a long period of time while they run.
16+
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
17+
# run this outside deployments so that we don't block them. Note that while adding an index
18+
# is a schema change, it's completely safe to run the operation after the code has deployed.
19+
# Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment
20+
21+
is_post_deployment = False
22+
23+
dependencies = [
24+
("sentry", "0855_give_monitor_type_a_db_default"),
25+
]
26+
27+
operations = [
28+
SafeRemoveField(
29+
model_name="monitor", name="type", deletion_action=DeletionAction.MOVE_TO_PENDING
30+
),
31+
]

src/sentry/monitors/clock_tasks/check_missed.py

+4-9
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@
99

1010
from sentry.constants import ObjectStatus
1111
from sentry.monitors.logic.mark_failed import mark_failed
12-
from sentry.monitors.models import (
13-
CheckInStatus,
14-
MonitorCheckIn,
15-
MonitorEnvironment,
16-
MonitorStatus,
17-
MonitorType,
18-
)
12+
from sentry.monitors.models import CheckInStatus, MonitorCheckIn, MonitorEnvironment, MonitorStatus
1913
from sentry.monitors.schedule import get_prev_schedule
2014
from sentry.utils import metrics
2115

@@ -58,9 +52,10 @@ def dispatch_check_missing(ts: datetime):
5852
missed_envs = list(
5953
MonitorEnvironment.objects.filter(
6054
IGNORE_MONITORS,
61-
monitor__type__in=[MonitorType.CRON_JOB],
6255
next_checkin_latest__lte=ts,
63-
).values("id")[:MONITOR_LIMIT]
56+
).values(
57+
"id"
58+
)[:MONITOR_LIMIT]
6459
)
6560

6661
metrics.gauge(

src/sentry/monitors/consumers/monitor_consumer.py

-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
MonitorEnvironmentLimitsExceeded,
4141
MonitorEnvironmentValidationFailed,
4242
MonitorLimitsExceeded,
43-
MonitorType,
4443
)
4544
from sentry.monitors.processing_errors.errors import (
4645
CheckinEnvironmentMismatch,
@@ -154,7 +153,6 @@ def _ensure_monitor_with_config(
154153
defaults={
155154
"name": monitor_slug,
156155
"status": ObjectStatus.ACTIVE,
157-
"type": MonitorType.CRON_JOB,
158156
"config": validated_config,
159157
"owner_user_id": owner_user_id,
160158
"owner_team_id": owner_team_id,

src/sentry/monitors/endpoints/base_monitor_details.py

-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ def update_monitor(
6969
"name": monitor.name,
7070
"slug": monitor.slug,
7171
"status": monitor.status,
72-
"type": monitor.type,
7372
"config": monitor.config,
7473
"project": project,
7574
},

src/sentry/monitors/endpoints/organization_monitor_index.py

-9
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
MonitorEnvironment,
4242
MonitorLimitsExceeded,
4343
MonitorStatus,
44-
MonitorType,
4544
)
4645
from sentry.monitors.serializers import (
4746
MonitorBulkEditResponse,
@@ -233,13 +232,6 @@ def get(self, request: AuthenticatedHttpRequest, organization: Organization) ->
233232
)
234233
except ValueError:
235234
queryset = queryset.none()
236-
elif key == "type":
237-
try:
238-
queryset = queryset.filter(
239-
type__in=map_value_to_constant(MonitorType, value)
240-
)
241-
except ValueError:
242-
queryset = queryset.none()
243235
else:
244236
queryset = queryset.none()
245237

@@ -294,7 +286,6 @@ def post(self, request: AuthenticatedHttpRequest, organization) -> Response:
294286
name=result["name"],
295287
slug=result.get("slug"),
296288
status=result["status"],
297-
type=result["type"],
298289
config=result["config"],
299290
)
300291
except MonitorLimitsExceeded as e:

src/sentry/monitors/logic/incident_occurrence.py

-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ def get_monitor_environment_context(monitor_environment: MonitorEnvironment):
265265
"name": monitor_environment.monitor.name,
266266
"config": monitor_environment.monitor.config,
267267
"status": monitor_environment.get_status_display(),
268-
"type": monitor_environment.monitor.get_type_display(),
269268
}
270269

271270

src/sentry/monitors/models.py

-29
Original file line numberDiff line numberDiff line change
@@ -190,26 +190,6 @@ def as_choices(cls):
190190
)
191191

192192

193-
class MonitorType:
194-
# In the future we may have other types of monitors such as health check
195-
# monitors. But for now we just have CRON_JOB style monitors.
196-
UNKNOWN = 0
197-
CRON_JOB = 3
198-
UPTIME = 4
199-
200-
@classmethod
201-
def as_choices(cls):
202-
return (
203-
(cls.UNKNOWN, "unknown"),
204-
(cls.CRON_JOB, "cron_job"),
205-
(cls.UPTIME, "uptime"),
206-
)
207-
208-
@classmethod
209-
def get_name(cls, value):
210-
return dict(cls.as_choices())[value]
211-
212-
213193
class ScheduleType:
214194
UNKNOWN = 0
215195
CRONTAB = 1
@@ -263,14 +243,6 @@ class Monitor(Model):
263243
Human readable name of the monitor. Used for display purposes.
264244
"""
265245

266-
type = BoundedPositiveIntegerField(
267-
db_default=MonitorType.UNKNOWN,
268-
choices=[(k, str(v)) for k, v in MonitorType.as_choices()],
269-
)
270-
"""
271-
Type of monitor. Currently there are only CRON_JOB monitors.
272-
"""
273-
274246
owner_user_id = HybridCloudForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete="SET_NULL")
275247
"""
276248
The user assigned as the owner of this model.
@@ -346,7 +318,6 @@ def get_schedule_type_display(self):
346318
def get_audit_log_data(self):
347319
return {
348320
"name": self.name,
349-
"type": self.type,
350321
"status": self.status,
351322
"config": self.config,
352323
"is_muted": self.is_muted,

src/sentry/monitors/validators.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@
1919
from sentry.db.models import BoundedPositiveIntegerField
2020
from sentry.db.models.fields.slug import DEFAULT_SLUG_MAX_LENGTH
2121
from sentry.monitors.constants import MAX_THRESHOLD, MAX_TIMEOUT
22-
from sentry.monitors.models import CheckInStatus, Monitor, MonitorType, ScheduleType
22+
from sentry.monitors.models import CheckInStatus, Monitor, ScheduleType
2323
from sentry.monitors.schedule import get_next_schedule, get_prev_schedule
2424
from sentry.monitors.types import CrontabSchedule
2525
from sentry.utils.dates import AVAILABLE_TIMEZONES
2626

27-
MONITOR_TYPES = {"cron_job": MonitorType.CRON_JOB}
28-
2927
MONITOR_STATUSES = {
3028
"active": ObjectStatus.ACTIVE,
3129
"disabled": ObjectStatus.DISABLED,
@@ -274,11 +272,6 @@ class MonitorValidator(CamelSnakeSerializer):
274272
required=False,
275273
help_text="Disable creation of monitor incidents",
276274
)
277-
type = serializers.ChoiceField(
278-
choices=list(zip(MONITOR_TYPES.keys(), MONITOR_TYPES.keys())),
279-
required=False,
280-
default="cron_job",
281-
)
282275
config = ConfigValidator(help_text="The configuration for the monitor.")
283276
alert_rule = MonitorAlertRuleValidator(required=False)
284277

@@ -299,9 +292,6 @@ def validate_status(self, value):
299292

300293
return status
301294

302-
def validate_type(self, value):
303-
return MONITOR_TYPES.get(value, value)
304-
305295
def validate_slug(self, value):
306296
# Ignore if slug is equal to current value
307297
if not value or (self.instance and value == self.instance.get("slug")):

src/sentry/testutils/cases.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
from sentry.models.releasecommit import ReleaseCommit
107107
from sentry.models.repository import Repository
108108
from sentry.models.rule import RuleSource
109-
from sentry.monitors.models import Monitor, MonitorEnvironment, MonitorType, ScheduleType
109+
from sentry.monitors.models import Monitor, MonitorEnvironment,ScheduleType
110110
from sentry.new_migrations.monkey.state import SentryProjectState
111111
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
112112
from sentry.notifications.models.notificationsettingprovider import NotificationSettingProvider
@@ -3120,7 +3120,6 @@ def _create_monitor(self, **kwargs):
31203120
return Monitor.objects.create(
31213121
organization_id=self.organization.id,
31223122
project_id=self.project.id,
3123-
type=MonitorType.CRON_JOB,
31243123
config={
31253124
"schedule": "* * * * *",
31263125
"schedule_type": ScheduleType.CRONTAB,

src/sentry/testutils/fixtures.py

-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
MonitorCheckIn,
3131
MonitorEnvironment,
3232
MonitorIncident,
33-
MonitorType,
3433
ScheduleType,
3534
)
3635
from sentry.organizations.services.organization import RpcOrganization
@@ -459,7 +458,6 @@ def create_monitor(self, **kwargs):
459458
return Monitor.objects.create(
460459
organization_id=self.organization.id,
461460
project_id=project_id,
462-
type=MonitorType.CRON_JOB,
463461
config={
464462
"schedule": "* * * * *",
465463
"schedule_type": ScheduleType.CRONTAB,

src/sentry/testutils/helpers/backups.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
from sentry.models.rule import NeglectedRule, RuleActivity, RuleActivityType
9393
from sentry.models.savedsearch import SavedSearch, Visibility
9494
from sentry.models.search_common import SearchType
95-
from sentry.monitors.models import Monitor, MonitorType, ScheduleType
95+
from sentry.monitors.models import Monitor, ScheduleType
9696
from sentry.nodestore.django.models import Node
9797
from sentry.sentry_apps.logic import SentryAppUpdater
9898
from sentry.sentry_apps.models.sentry_app import SentryApp
@@ -502,7 +502,6 @@ def create_exhaustive_organization(
502502
Monitor.objects.create(
503503
organization_id=project.organization.id,
504504
project_id=project.id,
505-
type=MonitorType.CRON_JOB,
506505
config={"schedule": "* * * * *", "schedule_type": ScheduleType.CRONTAB},
507506
owner_user_id=owner_id,
508507
)

src/sentry/utils/mockdata/core.py

-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
MonitorCheckIn,
6060
MonitorEnvironment,
6161
MonitorStatus,
62-
MonitorType,
6362
)
6463
from sentry.services.organization import organization_provisioning_service
6564
from sentry.signals import mocks_loaded
@@ -432,7 +431,6 @@ def create_monitor(project: Project, environment: Environment) -> None:
432431
name=next(MONITOR_NAMES),
433432
project_id=project.id,
434433
organization_id=project.organization_id,
435-
type=MonitorType.CRON_JOB,
436434
defaults={
437435
"status": ObjectStatus.DISABLED,
438436
"config": {"schedule": next(MONITOR_SCHEDULES)},

tests/acceptance/test_organization_monitors.py

-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
MonitorCheckIn,
1010
MonitorEnvironment,
1111
MonitorStatus,
12-
MonitorType,
1312
ScheduleType,
1413
)
1514
from sentry.testutils.cases import AcceptanceTestCase
@@ -85,7 +84,6 @@ def test_list_monitors(self):
8584
monitor = Monitor.objects.create(
8685
organization_id=self.organization.id,
8786
project_id=self.project.id,
88-
type=MonitorType.CRON_JOB,
8987
name="My Monitor",
9088
config={
9189
"schedule": "0 0 * * *",
@@ -124,7 +122,6 @@ def test_edit_monitor(self):
124122
Monitor.objects.create(
125123
organization_id=self.organization.id,
126124
project_id=self.project.id,
127-
type=MonitorType.CRON_JOB,
128125
name="My Monitor",
129126
config={
130127
"schedule": "0 0 * * *",

tests/sentry/deletions/test_monitor.py

-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
Monitor,
77
MonitorCheckIn,
88
MonitorEnvironment,
9-
MonitorType,
109
ScheduleType,
1110
)
1211
from sentry.testutils.cases import APITestCase, TransactionTestCase
@@ -21,7 +20,6 @@ def test_simple(self):
2120
monitor = Monitor.objects.create(
2221
organization_id=project.organization.id,
2322
project_id=project.id,
24-
type=MonitorType.CRON_JOB,
2523
config={"schedule": "* * * * *", "schedule_type": ScheduleType.CRONTAB},
2624
)
2725
monitor_env = MonitorEnvironment.objects.create(

tests/sentry/deletions/test_monitor_environment.py

-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
Monitor,
77
MonitorCheckIn,
88
MonitorEnvironment,
9-
MonitorType,
109
ScheduleType,
1110
)
1211
from sentry.testutils.cases import APITestCase, TransactionTestCase
@@ -22,7 +21,6 @@ def test_simple(self):
2221
monitor = Monitor.objects.create(
2322
organization_id=project.organization.id,
2423
project_id=project.id,
25-
type=MonitorType.CRON_JOB,
2624
config={"schedule": "* * * * *", "schedule_type": ScheduleType.CRONTAB},
2725
)
2826
monitor_env = MonitorEnvironment.objects.create(

tests/sentry/deletions/test_project.py

-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
Monitor,
2424
MonitorCheckIn,
2525
MonitorEnvironment,
26-
MonitorType,
2726
ScheduleType,
2827
)
2928
from sentry.sentry_apps.models.servicehook import ServiceHook
@@ -95,7 +94,6 @@ def test_simple(self):
9594
monitor = Monitor.objects.create(
9695
organization_id=project.organization.id,
9796
project_id=project.id,
98-
type=MonitorType.CRON_JOB,
9997
config={"schedule": "* * * * *", "schedule_type": ScheduleType.CRONTAB},
10098
)
10199
monitor_env = MonitorEnvironment.objects.create(

tests/sentry/deletions/test_team.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from sentry.models.projectteam import ProjectTeam
44
from sentry.models.rule import Rule
55
from sentry.models.team import Team
6-
from sentry.monitors.models import Monitor, MonitorType
6+
from sentry.monitors.models import Monitor
77
from sentry.testutils.cases import TestCase
88
from sentry.testutils.hybrid_cloud import HybridCloudTestMixin
99
from sentry.types.actor import Actor
@@ -55,7 +55,6 @@ def test_monitor_blanking(self):
5555
monitor = Monitor.objects.create(
5656
organization_id=self.organization.id,
5757
project_id=self.project.id,
58-
type=MonitorType.CRON_JOB,
5958
name="My Awesome Monitor",
6059
owner_team_id=team.id,
6160
)

0 commit comments

Comments
 (0)