Browse Source

migration(crons): Index trace_id for check-ins (#52635)

Indexes `trace_id` for faster lookups from issues backlinking to
check-ins.
Richard Ortenberg 1 year ago
parent
commit
510526f81f

+ 1 - 1
migrations_lockfile.txt

@@ -6,5 +6,5 @@ To resolve this, rebase against latest master and regenerate your migration. Thi
 will then be regenerated, and you should be able to merge without conflicts.
 
 nodestore: 0002_nodestore_no_dictfield
-sentry: 0509_merging_migrations
+sentry: 0510_index_checkin_traceid
 social_auth: 0001_initial

+ 30 - 0
src/sentry/migrations/0510_index_checkin_traceid.py

@@ -0,0 +1,30 @@
+# Generated by Django 2.2.28 on 2023-07-11 16:08
+
+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 = True
+
+    dependencies = [
+        ("sentry", "0509_merging_migrations"),
+    ]
+
+    operations = [
+        migrations.AddIndex(
+            model_name="monitorcheckin",
+            index=models.Index(fields=["trace_id"], name="sentry_moni_trace_i_c63ea4_idx"),
+        ),
+    ]

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

@@ -402,6 +402,7 @@ class MonitorCheckIn(Model):
             models.Index(fields=["monitor", "date_added", "status"]),
             models.Index(fields=["monitor_environment", "date_added", "status"]),
             models.Index(fields=["timeout_at", "status"]),
+            models.Index(fields=["trace_id"]),
         ]
 
     __repr__ = sane_repr("guid", "project_id", "status")