Browse Source

feat(stats-detectors): Add regression group model (#60887)

This adds a regression group model for tracking metadata about a
regression.
Tony Xiao 1 year ago
parent
commit
dcd73cf6eb

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

@@ -4652,6 +4652,31 @@
     "table_name": "sentry_regiontombstone",
     "uniques": []
   },
+  "sentry.regressiongroup": {
+    "dangling": false,
+    "foreign_keys": {
+      "project_id": {
+        "kind": "ImplicitForeignKey",
+        "model": "sentry.project",
+        "nullable": false
+      }
+    },
+    "model": "sentry.regressiongroup",
+    "relocation_dependencies": [],
+    "relocation_scope": "Excluded",
+    "silos": [
+      "Region"
+    ],
+    "table_name": "sentry_regressiongroup",
+    "uniques": [
+      [
+        "fingerprint",
+        "project_id",
+        "type",
+        "version"
+      ]
+    ]
+  },
   "sentry.relay": {
     "dangling": false,
     "foreign_keys": {},

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

@@ -641,6 +641,9 @@
   "sentry.regionoutbox": [],
   "sentry.regionscheduleddeletion": [],
   "sentry.regiontombstone": [],
+  "sentry.regressiongroup": [
+    "sentry.project"
+  ],
   "sentry.relay": [],
   "sentry.relayusage": [],
   "sentry.release": [

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

@@ -36,6 +36,7 @@
   "sentry.regionoutbox",
   "sentry.regionscheduleddeletion",
   "sentry.regiontombstone",
+  "sentry.regressiongroup",
   "sentry.relay",
   "sentry.relayusage",
   "sentry.repository",

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

@@ -36,6 +36,7 @@
   "sentry_regionoutbox",
   "sentry_regionscheduleddeletion",
   "sentry_regiontombstone",
+  "sentry_regressiongroup",
   "sentry_relay",
   "sentry_relayusage",
   "sentry_repository",

+ 1 - 1
migrations_lockfile.txt

@@ -9,5 +9,5 @@ feedback: 0003_feedback_add_env
 hybridcloud: 0009_make_user_id_optional_for_slug_reservation_replica
 nodestore: 0002_nodestore_no_dictfield
 replays: 0003_add_size_to_recording_segment
-sentry: 0610_remove_notification_setting_table
+sentry: 0611_add_regression_group_model
 social_auth: 0002_default_auto_field

+ 56 - 0
src/sentry/migrations/0611_add_regression_group_model.py

@@ -0,0 +1,56 @@
+# Generated by Django 3.2.23 on 2023-12-01 17:39
+
+from django.db import migrations, models
+
+import sentry.db.models.fields.bounded
+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 = False
+
+    dependencies = [
+        ("sentry", "0610_remove_notification_setting_table"),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name="RegressionGroup",
+            fields=[
+                (
+                    "id",
+                    sentry.db.models.fields.bounded.BoundedBigAutoField(
+                        primary_key=True, serialize=False
+                    ),
+                ),
+                ("date_added", models.DateTimeField(auto_now_add=True)),
+                ("date_updated", models.DateTimeField(auto_now=True)),
+                ("date_regressed", models.DateTimeField()),
+                ("date_resolved", models.DateTimeField(null=True)),
+                ("version", models.IntegerField()),
+                ("active", models.BooleanField(default=True)),
+                (
+                    "project_id",
+                    sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
+                ),
+                ("type", sentry.db.models.fields.bounded.BoundedIntegerField()),
+                ("fingerprint", models.CharField(max_length=32)),
+                ("baseline", models.FloatField()),
+                ("regressed", models.FloatField()),
+            ],
+            options={
+                "unique_together": {("type", "project_id", "fingerprint", "version")},
+                "index_together": {("type", "project_id", "fingerprint", "active")},
+            },
+        ),
+    ]

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

@@ -115,6 +115,7 @@ from .search_common import *  # NOQA
 from .sentryfunction import *  # NOQA
 from .servicehook import *  # NOQA
 from .sourcemapprocessingissue import *  # NOQA
+from .statistical_detectors import *  # NOQA
 from .team import *  # NOQA
 from .teamreplica import *  # NOQA
 from .tombstone import *  # NOQA

+ 71 - 0
src/sentry/models/statistical_detectors.py

@@ -0,0 +1,71 @@
+from enum import Enum
+from typing import Sequence, Tuple
+
+from django.db import models
+
+from sentry.backup.scopes import RelocationScope
+from sentry.db.models import (
+    BoundedBigIntegerField,
+    BoundedIntegerField,
+    Model,
+    region_silo_only_model,
+    sane_repr,
+)
+
+
+class RegressionType(Enum):
+    ENDPOINT = 0
+    FUNCTION = 1
+
+    @classmethod
+    def as_choices(cls) -> Sequence[Tuple[int, str]]:
+        return (
+            (cls.ENDPOINT.value, "endpoint"),
+            (cls.FUNCTION.value, "function"),
+        )
+
+
+@region_silo_only_model
+class RegressionGroup(Model):
+    __relocation_scope__ = RelocationScope.Excluded
+
+    # Meta data about the regression group
+    date_added = models.DateTimeField(auto_now_add=True)
+    date_updated = models.DateTimeField(auto_now=True)
+
+    # When the regression started, this is the breakpoint.
+    date_regressed = models.DateTimeField()
+
+    # When the regression resolved.
+    date_resolved = models.DateTimeField(null=True)
+
+    # The version associated with the group. Each time a regression
+    # is detected for the group, we increment the version.
+    version = models.IntegerField()
+
+    # Indiciates if the regression group is active or not. This should
+    # be checked in conjunction with the issue group status to determine
+    # the status of the group as manual status changes do not
+    # propagate from the issue group to here.
+    active = models.BooleanField(default=True)
+
+    project_id = BoundedBigIntegerField(db_index=True)
+
+    type = BoundedIntegerField(choices=RegressionType.as_choices())
+
+    # The fingerprint sent to the issue platform which
+    # accepts a list of strings. This corresponds to the
+    # first string which is a 8-16 char hex value.
+    fingerprint = models.CharField(max_length=32)
+
+    # The value measured from before the regression.
+    baseline = models.FloatField()
+
+    # The value measured from after the regression.
+    regressed = models.FloatField()
+
+    class Meta:
+        index_together = (("type", "project_id", "fingerprint", "active"),)
+        unique_together = (("type", "project_id", "fingerprint", "version"),)
+
+    __repr__ = sane_repr("active", "version", "type", "project_id", "fingerprint")

+ 0 - 0
src/sentry/statistical_detectors/__init__.py