Browse Source

feat(uptime): Add `uptime_status` column to `ProjectUptimeSubscription` (#74307)

This adds the `update_status` column to `ProjectUptimeSubscription` so
that we can keep track of the current state of the uptime monitor. This
is probably a temporary column, and will be replaced with a more
detailed table later on
Dan Fuller 8 months ago
parent
commit
4c2f2fd728

+ 1 - 1
migrations_lockfile.txt

@@ -12,4 +12,4 @@ remote_subscriptions: 0003_drop_remote_subscription
 replays: 0004_index_together
 sentry: 0741_metric_alert_anomaly_detection
 social_auth: 0002_default_auto_field
-uptime: 0004_projectuptimesubscription_mode
+uptime: 0005_uptime_status

+ 44 - 0
src/sentry/uptime/migrations/0005_uptime_status.py

@@ -0,0 +1,44 @@
+# Generated by Django 5.0.6 on 2024-07-15 20:16
+
+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.
+    # 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 post deployment:
+    # - Large data migrations. Typically we want these to be run manually 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
+    #   run this outside deployments so that we don't block them. Note that while adding an index
+    #   is a schema change, it's completely safe to run the operation after the code has deployed.
+    # Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment
+
+    is_post_deployment = False
+
+    dependencies = [
+        ("uptime", "0004_projectuptimesubscription_mode"),
+    ]
+
+    operations = [
+        migrations.SeparateDatabaseAndState(
+            database_operations=[
+                migrations.RunSQL(
+                    'ALTER TABLE "uptime_projectuptimesubscription" ADD COLUMN "uptime_status" smallint DEFAULT 1 NOT NULL CHECK ("uptime_status" >= 0);',
+                    reverse_sql='ALTER TABLE "uptime_projectuptimesubscription" DROP COLUMN "uptime_status";',
+                    hints={"tables": ["uptime_projectuptimesubscription"]},
+                ),
+            ],
+            state_operations=[
+                migrations.AddField(
+                    model_name="projectuptimesubscription",
+                    name="uptime_status",
+                    field=models.PositiveSmallIntegerField(default=1),
+                ),
+            ],
+        ),
+    ]

+ 7 - 0
src/sentry/uptime/models.py

@@ -50,6 +50,11 @@ class ProjectUptimeSubscriptionMode(enum.IntEnum):
     AUTO_DETECTED_ACTIVE = 3
 
 
+class UptimeStatus(enum.IntEnum):
+    OK = 1
+    FAILED = 2
+
+
 @region_silo_model
 class ProjectUptimeSubscription(DefaultFieldsModel):
     # TODO: This should be included in export/import, but right now it has no relation to
@@ -59,6 +64,8 @@ class ProjectUptimeSubscription(DefaultFieldsModel):
     project = FlexibleForeignKey("sentry.Project")
     uptime_subscription = FlexibleForeignKey("uptime.UptimeSubscription", on_delete=models.PROTECT)
     mode = models.SmallIntegerField(default=ProjectUptimeSubscriptionMode.MANUAL.value)
+    uptime_status = models.PositiveSmallIntegerField(default=UptimeStatus.OK.value)
+    # (Likely) temporary column to keep track of the current uptime status of this monitor
 
     objects: ClassVar[BaseManager[Self]] = BaseManager(
         cache_fields=["pk"], cache_ttl=int(timedelta(hours=1).total_seconds())