Просмотр исходного кода

migration(crons): Add next_checkin_latest column to MonitorCheckIn (#53743)

Adds `next_checkin_latest` column + index for later use in missing
monitor task
Richard Ortenberg 1 год назад
Родитель
Сommit
535ed80838

+ 1 - 1
migrations_lockfile.txt

@@ -7,5 +7,5 @@ will then be regenerated, and you should be able to merge without conflicts.
 
 nodestore: 0002_nodestore_no_dictfield
 replays: 0003_add_size_to_recording_segment
-sentry: 0524_flip_checkin_index
+sentry: 0525_add_next_checkin_latest
 social_auth: 0002_default_auto_field

+ 37 - 0
src/sentry/migrations/0525_add_next_checkin_latest.py

@@ -0,0 +1,37 @@
+# Generated by Django 3.2.20 on 2023-07-27 20:53
+
+from django.db import migrations, models
+
+from sentry.new_migrations.migrations import CheckedMigration
+
+
+class Migration(CheckedMigration):
+    # This flag is used to mark that a migration shouldn't be automatically run in production. For
+    # the most part, this should only be used for operations where it's safe to run the migration
+    # after your code has deployed. So this should not be used for most operations that alter the
+    # schema of a table.
+    # Here are some things that make sense to mark as dangerous:
+    # - Large data migrations. Typically we want these to be run manually by ops so that they can
+    #   be monitored and not block the deploy for a long period of time while they run.
+    # - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
+    #   have ops run this and not block the deploy. Note that while adding an index is a schema
+    #   change, it's completely safe to run the operation after the code has deployed.
+    is_dangerous = False
+
+    dependencies = [
+        ("sentry", "0524_flip_checkin_index"),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name="monitorenvironment",
+            name="next_checkin_latest",
+            field=models.DateTimeField(null=True),
+        ),
+        migrations.AddIndex(
+            model_name="monitorenvironment",
+            index=models.Index(
+                fields=["status", "next_checkin_latest"], name="sentry_moni_status_9f06fe_idx"
+            ),
+        ),
+    ]

+ 7 - 1
src/sentry/monitors/models.py

@@ -471,7 +471,10 @@ class MonitorEnvironment(Model):
     status = BoundedPositiveIntegerField(
         default=MonitorStatus.ACTIVE, choices=MonitorStatus.as_choices()
     )
-    next_checkin = models.DateTimeField(null=True)
+    next_checkin = models.DateTimeField(null=True)  # the expected time of the next check-in
+    next_checkin_latest = models.DateTimeField(
+        null=True
+    )  # the latest expected time of the next check-in (includes check-in margin)
     last_checkin = models.DateTimeField(null=True)
     date_added = models.DateTimeField(default=timezone.now)
 
@@ -481,6 +484,9 @@ class MonitorEnvironment(Model):
         app_label = "sentry"
         db_table = "sentry_monitorenvironment"
         unique_together = (("monitor", "environment"),)
+        indexes = [
+            models.Index(fields=["status", "next_checkin_latest"]),
+        ]
 
     __repr__ = sane_repr("monitor_id", "environment_id")