Browse Source

feat(performance): Add team key transactions table (#26060)

This adds in a new table for team based key transactions.
Tony Xiao 3 years ago
parent
commit
0ccde9c5ee

+ 1 - 1
migrations_lockfile.txt

@@ -7,5 +7,5 @@ will then be regenerated, and you should be able to merge without conflicts.
 
 jira_ac: 0001_initial
 nodestore: 0002_nodestore_no_dictfield
-sentry: 0194_add_custom_scm_provider
+sentry: 0195_add_team_key_transactions
 social_auth: 0001_initial

+ 2 - 0
src/sentry/conf/server.py

@@ -981,6 +981,8 @@ SENTRY_FEATURES = {
     "organizations:sso-rippling": False,
     # Enable workaround for migrating IdP instances
     "organizations:sso-migration": False,
+    # Enable team based key transactions for performance
+    "organizations:team-key-transactions": False,
     # Enable transaction comparison view for performance.
     "organizations:transaction-comparison": False,
     # Return unhandled information on the issue level

+ 16 - 0
src/sentry/discover/models.py

@@ -4,6 +4,7 @@ from sentry.db.models import FlexibleForeignKey, Model, sane_repr
 from sentry.db.models.fields import JSONField
 
 MAX_KEY_TRANSACTIONS = 10
+MAX_TEAM_KEY_TRANSACTIONS = 100
 
 
 class DiscoverSavedQueryProject(Model):
@@ -73,3 +74,18 @@ class KeyTransaction(Model):
         app_label = "sentry"
         db_table = "sentry_discoverkeytransaction"
         unique_together = (("project", "owner", "transaction"),)
+
+
+class TeamKeyTransaction(Model):
+    __core__ = False
+
+    # max_length here is based on the maximum for transactions in relay
+    transaction = models.CharField(max_length=200)
+    project = FlexibleForeignKey("sentry.Project", db_constraint=False)
+    team = FlexibleForeignKey("sentry.Team")
+    organization = FlexibleForeignKey("sentry.Organization")
+
+    class Meta:
+        app_label = "sentry"
+        db_table = "sentry_performanceteamkeytransaction"
+        unique_together = (("project", "team", "transaction"),)

+ 75 - 0
src/sentry/migrations/0195_add_team_key_transactions.py

@@ -0,0 +1,75 @@
+# Generated by Django 1.11.29 on 2021-05-14 20:56
+
+import django.db.models.deletion
+from django.db import migrations, models
+
+import sentry.db.models.fields.bounded
+import sentry.db.models.fields.foreignkey
+
+
+class Migration(migrations.Migration):
+    # This flag is used to mark that a migration shouldn't be automatically run in
+    # production. We set this to True for operations that we think are risky and want
+    # someone from ops to run manually and monitor.
+    # General advice is that if in doubt, mark your migration as `is_dangerous`.
+    # Some things you should always mark as dangerous:
+    # - Large data migrations. Typically we want these to be run manually by ops so that
+    #   they can be monitored. Since data migrations will now hold a transaction open
+    #   this is even more important.
+    # - Adding columns to highly active tables, even ones that are NULL.
+    is_dangerous = False
+
+    # This flag is used to decide whether to run this migration in a transaction or not.
+    # By default we prefer to run in a transaction, but for migrations where you want
+    # to `CREATE INDEX CONCURRENTLY` this needs to be set to False. Typically you'll
+    # want to create an index concurrently when adding one to an existing table.
+    # You'll also usually want to set this to `False` if you're writing a data
+    # migration, since we don't want the entire migration to run in one long-running
+    # transaction.
+    atomic = True
+
+    dependencies = [
+        ("sentry", "0194_add_custom_scm_provider"),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name="TeamKeyTransaction",
+            fields=[
+                (
+                    "id",
+                    sentry.db.models.fields.bounded.BoundedBigAutoField(
+                        primary_key=True, serialize=False
+                    ),
+                ),
+                ("transaction", models.CharField(max_length=200)),
+                (
+                    "organization",
+                    sentry.db.models.fields.foreignkey.FlexibleForeignKey(
+                        on_delete=django.db.models.deletion.CASCADE, to="sentry.Organization"
+                    ),
+                ),
+                (
+                    "project",
+                    sentry.db.models.fields.foreignkey.FlexibleForeignKey(
+                        db_constraint=False,
+                        on_delete=django.db.models.deletion.CASCADE,
+                        to="sentry.Project",
+                    ),
+                ),
+                (
+                    "team",
+                    sentry.db.models.fields.foreignkey.FlexibleForeignKey(
+                        on_delete=django.db.models.deletion.CASCADE, to="sentry.Team"
+                    ),
+                ),
+            ],
+            options={
+                "db_table": "sentry_performanceteamkeytransaction",
+            },
+        ),
+        migrations.AlterUniqueTogether(
+            name="teamkeytransaction",
+            unique_together={("project", "team", "transaction")},
+        ),
+    ]