Browse Source

feat(grouping): Add `grouphashmetadata` table (#76084)

This adds a stub of the new `grouphashmetadata` table, which will allow us to track metadata about the grouping process - which config version generated the hash, whether it was based on stacktrace/message/etc, whether we used Seer as part of the process, and if so, which version of the model was used, and so on and so forth.

In this initial incarnation, all the table tracks is which `grouphash` record it's associated with, and when it was created.
Katie Byers 7 months ago
parent
commit
8b0ff103a7

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

@@ -2306,6 +2306,28 @@
       ]
     ]
   },
+  "sentry.grouphashmetadata": {
+    "dangling": false,
+    "foreign_keys": {
+      "grouphash": {
+        "kind": "FlexibleForeignKey",
+        "model": "sentry.grouphash",
+        "nullable": false
+      }
+    },
+    "model": "sentry.grouphashmetadata",
+    "relocation_dependencies": [],
+    "relocation_scope": "Excluded",
+    "silos": [
+      "Region"
+    ],
+    "table_name": "sentry_grouphashmetadata",
+    "uniques": [
+      [
+        "grouphash"
+      ]
+    ]
+  },
   "sentry.grouphistory": {
     "dangling": false,
     "foreign_keys": {

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

@@ -316,6 +316,9 @@
     "sentry.grouptombstone",
     "sentry.project"
   ],
+  "sentry.grouphashmetadata": [
+    "sentry.grouphash"
+  ],
   "sentry.grouphistory": [
     "sentry.group",
     "sentry.organization",

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

@@ -217,6 +217,7 @@
   "sentry.sentryappinstallationtoken",
   "sentry.sentryappinstallationforprovider",
   "sentry.incident",
+  "sentry.grouphashmetadata",
   "sentry.dashboardwidgetqueryondemand",
   "sentry.alertruletriggerexclusion",
   "sentry.alertruletriggeraction",

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

@@ -217,6 +217,7 @@
   "sentry_sentryappinstallationtoken",
   "sentry_sentryappinstallationforprovider",
   "sentry_incident",
+  "sentry_grouphashmetadata",
   "sentry_dashboardwidgetqueryondemand",
   "sentry_alertruletriggerexclusion",
   "sentry_alertruletriggeraction",

+ 1 - 1
migrations_lockfile.txt

@@ -10,6 +10,6 @@ hybridcloud: 0016_add_control_cacheversion
 nodestore: 0002_nodestore_no_dictfield
 remote_subscriptions: 0003_drop_remote_subscription
 replays: 0004_index_together
-sentry: 0747_create_datasecrecywaiver_table
+sentry: 0748_create_grouphashmetadata_table
 social_auth: 0002_default_auto_field
 uptime: 0007_update_detected_subscription_interval

+ 56 - 0
src/sentry/migrations/0748_create_grouphashmetadata_table.py

@@ -0,0 +1,56 @@
+# Generated by Django 5.0.7 on 2024-08-12 23:50
+
+import django.db.models.deletion
+import django.utils.timezone
+from django.db import migrations, models
+
+import sentry.db.models.fields.bounded
+import sentry.db.models.fields.foreignkey
+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 = [
+        ("sentry", "0747_create_datasecrecywaiver_table"),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name="GroupHashMetadata",
+            fields=[
+                (
+                    "id",
+                    sentry.db.models.fields.bounded.BoundedBigAutoField(
+                        primary_key=True, serialize=False
+                    ),
+                ),
+                ("date_added", models.DateTimeField(default=django.utils.timezone.now)),
+                (
+                    "grouphash",
+                    sentry.db.models.fields.foreignkey.FlexibleForeignKey(
+                        on_delete=django.db.models.deletion.CASCADE,
+                        related_name="metadata",
+                        to="sentry.grouphash",
+                        unique=True,
+                    ),
+                ),
+            ],
+            options={
+                "db_table": "sentry_grouphashmetadata",
+            },
+        ),
+    ]

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

@@ -46,6 +46,7 @@ from .groupcommitresolution import *  # NOQA
 from .groupemailthread import *  # NOQA
 from .groupenvironment import *  # NOQA
 from .grouphash import *  # NOQA
+from .grouphashmetadata import *  # NOQA
 from .grouphistory import *  # NOQA
 from .groupinbox import *  # NOQA
 from .grouplink import *  # NOQA

+ 18 - 0
src/sentry/models/grouphashmetadata.py

@@ -0,0 +1,18 @@
+from django.db import models
+from django.utils import timezone
+
+from sentry.backup.scopes import RelocationScope
+from sentry.db.models import FlexibleForeignKey, Model, region_silo_model
+
+
+@region_silo_model
+class GroupHashMetadata(Model):
+    __relocation_scope__ = RelocationScope.Excluded
+
+    # GENERAL
+    grouphash = FlexibleForeignKey("sentry.GroupHash", unique=True, related_name="metadata")
+    date_added = models.DateTimeField(default=timezone.now)
+
+    class Meta:
+        app_label = "sentry"
+        db_table = "sentry_grouphashmetadata"

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

@@ -1,5 +1,5 @@
 ---
-created: '2024-08-06T18:35:03.850325+00:00'
+created: '2024-08-13T18:47:42.048211+00:00'
 creator: sentry
 source: tests/sentry/backup/test_comparators.py
 ---
@@ -574,6 +574,11 @@ source: tests/sentry/backup/test_comparators.py
     - group_tombstone_id
     - project
   model_name: sentry.grouphash
+- comparators:
+  - class: ForeignKeyComparator
+    fields:
+    - grouphash
+  model_name: sentry.grouphashmetadata
 - comparators:
   - class: ForeignKeyComparator
     fields: