Browse Source

ref: remove unused MetricsKeyIndexer model (#82405)

last reference removed in 9d11561b99c8c4e35347e9d2c5e208d2cfd41822

<!-- Describe your PR here. -->
anthony sottile 2 months ago
parent
commit
f5a26073e5

+ 1 - 17
fixtures/backup/model_dependencies/detailed.json

@@ -3223,22 +3223,6 @@
       ]
     ]
   },
-  "sentry.metricskeyindexer": {
-    "dangling": false,
-    "foreign_keys": {},
-    "model": "sentry.metricskeyindexer",
-    "relocation_dependencies": [],
-    "relocation_scope": "Excluded",
-    "silos": [
-      "Region"
-    ],
-    "table_name": "sentry_metricskeyindexer",
-    "uniques": [
-      [
-        "string"
-      ]
-    ]
-  },
   "sentry.monitor": {
     "dangling": false,
     "foreign_keys": {
@@ -6739,4 +6723,4 @@
       ]
     ]
   }
-}
+}

+ 1 - 2
fixtures/backup/model_dependencies/flat.json

@@ -447,7 +447,6 @@
   "sentry.lostpasswordhash": [
     "sentry.user"
   ],
-  "sentry.metricskeyindexer": [],
   "sentry.monitor": [
     "sentry.organization",
     "sentry.project",
@@ -931,4 +930,4 @@
     "workflow_engine.dataconditiongroup",
     "workflow_engine.workflow"
   ]
-}
+}

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

@@ -18,7 +18,6 @@
   "sentry.identityprovider",
   "sentry.integration",
   "sentry.integrationfeature",
-  "sentry.metricskeyindexer",
   "sentry.monitorlocation",
   "sentry.option",
   "sentry.organization",
@@ -248,4 +247,4 @@
   "sentry.incidentsnapshot",
   "sentry.incidentproject",
   "sentry.incidentactivity"
-]
+]

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

@@ -18,7 +18,6 @@
   "sentry_identityprovider",
   "sentry_integration",
   "sentry_integrationfeature",
-  "sentry_metricskeyindexer",
   "sentry_monitorlocation",
   "sentry_option",
   "sentry_organization",
@@ -248,4 +247,4 @@
   "sentry_incidentsnapshot",
   "sentry_incidentproject",
   "sentry_incidentactivity"
-]
+]

+ 1 - 1
migrations_lockfile.txt

@@ -15,7 +15,7 @@ remote_subscriptions: 0003_drop_remote_subscription
 
 replays: 0004_index_together
 
-sentry: 0802_remove_grouping_auto_update_option
+sentry: 0803_delete_unused_metricskeyindexer_pt1
 
 social_auth: 0002_default_auto_field
 

+ 29 - 0
src/sentry/migrations/0803_delete_unused_metricskeyindexer_pt1.py

@@ -0,0 +1,29 @@
+# Generated by Django 5.1.4 on 2024-12-19 20:24
+
+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", "0802_remove_grouping_auto_update_option"),
+    ]
+
+    operations = [
+        SafeDeleteModel(name="MetricsKeyIndexer", deletion_action=DeletionAction.MOVE_TO_PENDING),
+    ]

+ 2 - 31
src/sentry/sentry_metrics/indexer/postgres/models.py

@@ -1,8 +1,8 @@
 import logging
-from typing import Any, ClassVar, Self
+from typing import ClassVar, Self
 
 from django.conf import settings
-from django.db import connections, models, router
+from django.db import models
 from django.utils import timezone
 
 from sentry.backup.scopes import RelocationScope
@@ -16,35 +16,6 @@ logger = logging.getLogger(__name__)
 from collections.abc import Mapping
 
 
-@region_silo_model
-class MetricsKeyIndexer(Model):
-    __relocation_scope__ = RelocationScope.Excluded
-
-    string = models.CharField(max_length=200)
-    date_added = models.DateTimeField(default=timezone.now)
-
-    objects: ClassVar[BaseManager[Self]] = BaseManager(
-        cache_fields=("pk", "string"), cache_ttl=settings.SENTRY_METRICS_INDEXER_CACHE_TTL
-    )
-
-    class Meta:
-        db_table = "sentry_metricskeyindexer"
-        app_label = "sentry"
-        constraints = [
-            models.UniqueConstraint(fields=["string"], name="unique_string"),
-        ]
-
-    @classmethod
-    def get_next_values(cls, num: int) -> Any:
-        using = router.db_for_write(cls)
-        connection = connections[using].cursor()
-
-        connection.execute(
-            "SELECT nextval('sentry_metricskeyindexer_id_seq') from generate_series(1,%s)", [num]
-        )
-        return connection.fetchall()
-
-
 class BaseIndexer(Model):
     string = models.CharField(max_length=MAX_INDEXED_COLUMN_LENGTH)
     organization_id = BoundedBigIntegerField()

+ 0 - 4
tests/sentry/backup/snapshots/test_comparators/test_default_comparators.pysnap

@@ -808,10 +808,6 @@ source: tests/sentry/backup/test_comparators.py
     fields:
     - user
   model_name: sentry.lostpasswordhash
-- comparators:
-  - class: ForeignKeyComparator
-    fields: []
-  model_name: sentry.metricskeyindexer
 - comparators:
   - class: UUID4Comparator
     fields:

+ 0 - 2
tests/sentry/incidents/test_subscription_processor.py

@@ -65,7 +65,6 @@ from sentry.seer.anomaly_detection.types import (
 )
 from sentry.seer.anomaly_detection.utils import has_anomaly, translate_direction
 from sentry.sentry_metrics.configuration import UseCaseKey
-from sentry.sentry_metrics.indexer.postgres.models import MetricsKeyIndexer
 from sentry.sentry_metrics.utils import resolve_tag_key
 from sentry.snuba.dataset import Dataset
 from sentry.snuba.models import QuerySubscription, SnubaQuery, SnubaQueryEventType
@@ -3715,7 +3714,6 @@ class MetricsCrashRateAlertProcessUpdateTest(ProcessUpdateBaseClass, BaseMetrics
     def test_ensure_case_when_no_metrics_index_not_found_is_handled_gracefully(
         self, helper_metrics
     ):
-        MetricsKeyIndexer.objects.all().delete()
         rule = self.crash_rate_alert_rule
         subscription = rule.snuba_query.subscriptions.filter(project=self.project).get()
         processor = SubscriptionProcessor(subscription)