Browse Source

Prep to remove excluded projects trigger exclusion (#81264)

Follow up to https://github.com/getsentry/sentry/pull/81020 (and a few
others) to remove the `AlertRuleExcludedProjects` and
`AlertRuleTriggerExclusion` models. There will be a final PR to fully
remove them and then they're finally gone!
Colleen O'Rourke 3 months ago
parent
commit
2af89fa3a2

+ 0 - 56
fixtures/backup/model_dependencies/detailed.json

@@ -486,34 +486,6 @@
     "table_name": "sentry_alertruleactivity",
     "uniques": []
   },
-  "sentry.alertruleexcludedprojects": {
-    "dangling": false,
-    "foreign_keys": {
-      "alert_rule": {
-        "kind": "FlexibleForeignKey",
-        "model": "sentry.alertrule",
-        "nullable": false
-      },
-      "project": {
-        "kind": "FlexibleForeignKey",
-        "model": "sentry.project",
-        "nullable": false
-      }
-    },
-    "model": "sentry.alertruleexcludedprojects",
-    "relocation_dependencies": [],
-    "relocation_scope": "Organization",
-    "silos": [
-      "Region"
-    ],
-    "table_name": "sentry_alertruleexcludedprojects",
-    "uniques": [
-      [
-        "alert_rule",
-        "project"
-      ]
-    ]
-  },
   "sentry.alertruleprojects": {
     "dangling": false,
     "foreign_keys": {
@@ -593,34 +565,6 @@
     "table_name": "sentry_alertruletriggeraction",
     "uniques": []
   },
-  "sentry.alertruletriggerexclusion": {
-    "dangling": false,
-    "foreign_keys": {
-      "alert_rule_trigger": {
-        "kind": "FlexibleForeignKey",
-        "model": "sentry.alertruletrigger",
-        "nullable": false
-      },
-      "query_subscription": {
-        "kind": "FlexibleForeignKey",
-        "model": "sentry.querysubscription",
-        "nullable": false
-      }
-    },
-    "model": "sentry.alertruletriggerexclusion",
-    "relocation_dependencies": [],
-    "relocation_scope": "Organization",
-    "silos": [
-      "Region"
-    ],
-    "table_name": "sentry_alertruletriggerexclusion",
-    "uniques": [
-      [
-        "alert_rule_trigger",
-        "query_subscription"
-      ]
-    ]
-  },
   "sentry.apiapplication": {
     "dangling": false,
     "foreign_keys": {

+ 0 - 8
fixtures/backup/model_dependencies/flat.json

@@ -68,10 +68,6 @@
     "sentry.alertrule",
     "sentry.user"
   ],
-  "sentry.alertruleexcludedprojects": [
-    "sentry.alertrule",
-    "sentry.project"
-  ],
   "sentry.alertruleprojects": [
     "sentry.alertrule",
     "sentry.project"
@@ -84,10 +80,6 @@
     "sentry.integration",
     "sentry.sentryapp"
   ],
-  "sentry.alertruletriggerexclusion": [
-    "sentry.alertruletrigger",
-    "sentry.querysubscription"
-  ],
   "sentry.apiapplication": [
     "sentry.user"
   ],

+ 0 - 2
fixtures/backup/model_dependencies/sorted.json

@@ -225,7 +225,6 @@
   "sentry.dashboardpermissionsteam",
   "sentry.alertruletrigger",
   "sentry.alertruleprojects",
-  "sentry.alertruleexcludedprojects",
   "sentry.alertruleactivity",
   "sentry.alertruleactivations",
   "sentry.alertruleactivationcondition",
@@ -234,7 +233,6 @@
   "sentry.sentryappinstallationforprovider",
   "sentry.incident",
   "sentry.dashboardwidgetqueryondemand",
-  "sentry.alertruletriggerexclusion",
   "sentry.alertruletriggeraction",
   "sentry.timeseriessnapshot",
   "sentry.servicehookproject",

+ 0 - 2
fixtures/backup/model_dependencies/truncate.json

@@ -225,7 +225,6 @@
   "sentry_dashboardpermissionsteam",
   "sentry_alertruletrigger",
   "sentry_alertruleprojects",
-  "sentry_alertruleexcludedprojects",
   "sentry_alertruleactivity",
   "sentry_alertruleactivations",
   "sentry_alertruleactivationcondition",
@@ -234,7 +233,6 @@
   "sentry_sentryappinstallationforprovider",
   "sentry_incident",
   "sentry_dashboardwidgetqueryondemand",
-  "sentry_alertruletriggerexclusion",
   "sentry_alertruletriggeraction",
   "sentry_timeseriessnapshot",
   "sentry_servicehookproject",

+ 1 - 1
migrations_lockfile.txt

@@ -15,7 +15,7 @@ remote_subscriptions: 0003_drop_remote_subscription
 
 replays: 0004_index_together
 
-sentry: 0795_drop_included_excluded_projects
+sentry: 0796_rm_excluded_projects_triggers
 
 social_auth: 0002_default_auto_field
 

+ 0 - 40
src/sentry/incidents/models/alert_rule.py

@@ -241,26 +241,6 @@ class AlertRuleManager(BaseManager["AlertRule"]):
         return []
 
 
-@region_silo_model
-class AlertRuleExcludedProjects(Model):
-    """
-    Excludes a specific project from an AlertRule
-
-    NOTE: This feature is not currently utilized.
-    """
-
-    __relocation_scope__ = RelocationScope.Organization
-
-    alert_rule = FlexibleForeignKey("sentry.AlertRule", db_index=False, db_constraint=False)
-    project = FlexibleForeignKey("sentry.Project", db_constraint=False)
-    date_added = models.DateTimeField(default=timezone.now)
-
-    class Meta:
-        app_label = "sentry"
-        db_table = "sentry_alertruleexcludedprojects"
-        unique_together = (("alert_rule", "project"),)
-
-
 @region_silo_model
 class AlertRuleProjects(Model):
     """
@@ -473,26 +453,6 @@ class AlertRuleTrigger(Model):
         unique_together = (("alert_rule", "label"),)
 
 
-@region_silo_model
-class AlertRuleTriggerExclusion(Model):
-    """
-    Allows us to define a specific trigger to be excluded from a query subscription
-    """
-
-    __relocation_scope__ = RelocationScope.Organization
-
-    alert_rule_trigger = FlexibleForeignKey(
-        "sentry.AlertRuleTrigger", related_name="exclusions", db_constraint=False
-    )
-    query_subscription = FlexibleForeignKey("sentry.QuerySubscription", db_constraint=False)
-    date_added = models.DateTimeField(default=timezone.now)
-
-    class Meta:
-        app_label = "sentry"
-        db_table = "sentry_alertruletriggerexclusion"
-        unique_together = (("alert_rule_trigger", "query_subscription"),)
-
-
 class AlertRuleTriggerActionMethod(StrEnum):
     FIRE = "fire"
     RESOLVE = "resolve"

+ 36 - 0
src/sentry/migrations/0796_rm_excluded_projects_triggers.py

@@ -0,0 +1,36 @@
+# Generated by Django 5.1.1 on 2024-11-25 20:06
+
+from sentry.new_migrations.migrations import CheckedMigration
+from sentry.new_migrations.monkey.models import SafeDeleteModel
+from sentry.new_migrations.monkey.state import DeletionAction
+
+
+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 = [
+        ("sentry", "0795_drop_included_excluded_projects"),
+    ]
+
+    operations = [
+        SafeDeleteModel(
+            name="AlertRuleExcludedProjects",
+            deletion_action=DeletionAction.MOVE_TO_PENDING,
+        ),
+        SafeDeleteModel(
+            name="AlertRuleTriggerExclusion",
+            deletion_action=DeletionAction.MOVE_TO_PENDING,
+        ),
+    ]

+ 1 - 10
src/sentry/testutils/helpers/backups.py

@@ -44,11 +44,7 @@ from sentry.backup.scopes import ExportScope
 from sentry.backup.validate import validate
 from sentry.data_secrecy.models import DataSecrecyWaiver
 from sentry.db.models.paranoia import ParanoidModel
-from sentry.incidents.models.alert_rule import (
-    AlertRuleExcludedProjects,
-    AlertRuleMonitorTypeInt,
-    AlertRuleTriggerExclusion,
-)
+from sentry.incidents.models.alert_rule import AlertRuleMonitorTypeInt
 from sentry.incidents.models.incident import (
     IncidentActivity,
     IncidentSnapshot,
@@ -511,20 +507,15 @@ class ExhaustiveFixtures(Fixtures):
         )
 
         # AlertRule*
-        other_project = self.create_project(name=f"other-project-{slug}", teams=[team])
         alert = self.create_alert_rule(
             organization=org,
             projects=[project],
             user=owner,
         )
-        AlertRuleExcludedProjects.objects.create(alert_rule=alert, project=other_project)
         alert.user_id = owner_id
         alert.save()
         trigger = self.create_alert_rule_trigger(alert_rule=alert)
         assert alert.snuba_query is not None
-        AlertRuleTriggerExclusion.objects.create(
-            alert_rule_trigger=trigger, query_subscription=alert.snuba_query.subscriptions.get()
-        )
         self.create_alert_rule_trigger_action(alert_rule_trigger=trigger)
         activated_alert = self.create_alert_rule(
             organization=org,

+ 1 - 26
tests/sentry/backup/snapshots/SanitizationExhaustiveTests/test_clean_pks.pysnap

@@ -1,5 +1,5 @@
 ---
-created: '2024-11-15T23:09:32.075671+00:00'
+created: '2024-11-25T23:04:25.041092+00:00'
 creator: sentry
 source: tests/sentry/backup/test_sanitize.py
 ---
@@ -265,12 +265,6 @@ source: tests/sentry/backup/test_sanitize.py
   - date_added
   - name
   - slug
-- model_name: sentry.project
-  ordinal: 4
-  sanitized_fields:
-  - date_added
-  - name
-  - slug
 - model_name: sentry.orgauthtoken
   ordinal: 1
   sanitized_fields:
@@ -599,9 +593,6 @@ source: tests/sentry/backup/test_sanitize.py
 - model_name: sentry.projectteam
   ordinal: 1
   sanitized_fields: []
-- model_name: sentry.projectteam
-  ordinal: 2
-  sanitized_fields: []
 - model_name: sentry.projectredirect
   ordinal: 1
   sanitized_fields:
@@ -620,9 +611,6 @@ source: tests/sentry/backup/test_sanitize.py
 - model_name: sentry.projectoption
   ordinal: 3
   sanitized_fields: []
-- model_name: sentry.projectoption
-  ordinal: 4
-  sanitized_fields: []
 - model_name: sentry.projectkey
   ordinal: 1
   sanitized_fields:
@@ -638,11 +626,6 @@ source: tests/sentry/backup/test_sanitize.py
   sanitized_fields:
   - date_added
   - secret_key
-- model_name: sentry.projectkey
-  ordinal: 4
-  sanitized_fields:
-  - date_added
-  - secret_key
 - model_name: sentry.projectintegration
   ordinal: 1
   sanitized_fields:
@@ -814,10 +797,6 @@ source: tests/sentry/backup/test_sanitize.py
   ordinal: 3
   sanitized_fields:
   - date_added
-- model_name: sentry.alertruleexcludedprojects
-  ordinal: 1
-  sanitized_fields:
-  - date_added
 - model_name: sentry.alertruleactivity
   ordinal: 1
   sanitized_fields:
@@ -860,10 +839,6 @@ source: tests/sentry/backup/test_sanitize.py
   sanitized_fields:
   - date_added
   - date_modified
-- model_name: sentry.alertruletriggerexclusion
-  ordinal: 1
-  sanitized_fields:
-  - date_added
 - model_name: sentry.alertruletriggeraction
   ordinal: 1
   sanitized_fields:

+ 1 - 13
tests/sentry/backup/snapshots/test_comparators/test_default_comparators.pysnap

@@ -1,5 +1,5 @@
 ---
-created: '2024-11-25T20:44:29.207064+00:00'
+created: '2024-11-25T21:49:40.423739+00:00'
 creator: sentry
 source: tests/sentry/backup/test_comparators.py
 ---
@@ -120,12 +120,6 @@ source: tests/sentry/backup/test_comparators.py
     - previous_alert_rule
     - user_id
   model_name: sentry.alertruleactivity
-- comparators:
-  - class: ForeignKeyComparator
-    fields:
-    - alert_rule
-    - project
-  model_name: sentry.alertruleexcludedprojects
 - comparators:
   - class: ForeignKeyComparator
     fields:
@@ -144,12 +138,6 @@ source: tests/sentry/backup/test_comparators.py
     - integration_id
     - sentry_app_id
   model_name: sentry.alertruletriggeraction
-- comparators:
-  - class: ForeignKeyComparator
-    fields:
-    - alert_rule_trigger
-    - query_subscription
-  model_name: sentry.alertruletriggerexclusion
 - comparators:
   - class: HashObfuscatingComparator
     fields:

Some files were not shown because too many files changed in this diff