Browse Source

feat(SentryShot): Model for metadata (#65452)

Model for screenshot ref. It should include a url and what component
from that url we want to take screenshot of. Made it dependent on org
for better cleanup strategy.

Tech specs for more context:
https://www.notion.so/sentry/Snapshot-Service-b391791229ab4c988c641f9b0746a755?pvs=4#217368548f544a7e8acf79ae2300efa6
Athena Moghaddam 1 year ago
parent
commit
2ee4c008db

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

@@ -5677,6 +5677,24 @@
       ]
     ]
   },
+  "sentry.sentryshot": {
+    "dangling": false,
+    "foreign_keys": {
+      "organization_id": {
+        "kind": "HybridCloudForeignKey",
+        "model": "sentry.organization",
+        "nullable": false
+      }
+    },
+    "model": "sentry.sentryshot",
+    "relocation_dependencies": [],
+    "relocation_scope": "Excluded",
+    "silos": [
+      "Region"
+    ],
+    "table_name": "sentry_sentryshot",
+    "uniques": []
+  },
   "sentry.servicehook": {
     "dangling": false,
     "foreign_keys": {

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

@@ -781,6 +781,9 @@
   "sentry.sentryfunction": [
     "sentry.organization"
   ],
+  "sentry.sentryshot": [
+    "sentry.organization"
+  ],
   "sentry.servicehook": [
     "sentry.apiapplication",
     "sentry.organization",

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

@@ -45,6 +45,7 @@
   "sentry.reprocessingreport",
   "sentry.scheduleddeletion",
   "sentry.sentryfunction",
+  "sentry.sentryshot",
   "sentry.stringindexer",
   "sentry.team",
   "sentry.teamreplica",

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

@@ -45,6 +45,7 @@
   "sentry_reprocessingreport",
   "sentry_scheduleddeletion",
   "sentry_sentryfunction",
+  "sentry_sentryshot",
   "sentry_stringindexer",
   "sentry_team",
   "sentry_teamreplica",

+ 1 - 1
migrations_lockfile.txt

@@ -9,5 +9,5 @@ feedback: 0004_index_together
 hybridcloud: 0011_add_hybridcloudapitoken_index
 nodestore: 0002_nodestore_no_dictfield
 replays: 0004_index_together
-sentry: 0649_add_index_for_group_priority
+sentry: 0650_create_sentryshot
 social_auth: 0002_default_auto_field

+ 48 - 0
src/sentry/migrations/0650_create_sentryshot.py

@@ -0,0 +1,48 @@
+# Generated by Django 5.0.2 on 2024-02-21 20:04
+
+import uuid
+
+import django.utils.timezone
+from django.db import migrations, models
+
+import sentry.db.models.fields.bounded
+import sentry.db.models.fields.hybrid_cloud_foreign_key
+from sentry.new_migrations.migrations import CheckedMigration
+
+
+class Migration(CheckedMigration):
+    is_dangerous = False
+
+    dependencies = [
+        ("sentry", "0649_add_index_for_group_priority"),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name="SentryShot",
+            fields=[
+                (
+                    "id",
+                    sentry.db.models.fields.bounded.BoundedBigAutoField(
+                        primary_key=True, serialize=False
+                    ),
+                ),
+                ("uuid", models.UUIDField(db_index=True, default=uuid.uuid4, editable=False)),
+                ("sentry_url", models.URLField()),
+                ("component_identifier", models.CharField()),
+                (
+                    "organization_id",
+                    sentry.db.models.fields.hybrid_cloud_foreign_key.HybridCloudForeignKey(
+                        "sentry.Organization", db_index=True, on_delete="CASCADE"
+                    ),
+                ),
+                (
+                    "date_added",
+                    models.DateTimeField(db_index=True, default=django.utils.timezone.now),
+                ),
+            ],
+            options={
+                "db_table": "sentry_sentryshot",
+            },
+        ),
+    ]

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

@@ -114,6 +114,7 @@ from .savedsearch import *  # NOQA
 from .scheduledeletion import *  # NOQA
 from .search_common import *  # NOQA
 from .sentryfunction import *  # NOQA
+from .sentryshot import *  # NOQA
 from .servicehook import *  # NOQA
 from .sourcemapprocessingissue import *  # NOQA
 from .statistical_detectors import *  # NOQA

+ 32 - 0
src/sentry/models/sentryshot.py

@@ -0,0 +1,32 @@
+from __future__ import annotations
+
+import uuid
+
+from django.db import models
+from django.utils import timezone
+
+from sentry.backup.scopes import RelocationScope
+from sentry.db.models import Model
+from sentry.db.models.base import region_silo_only_model
+from sentry.db.models.fields.hybrid_cloud_foreign_key import HybridCloudForeignKey
+
+
+@region_silo_only_model
+class SentryShot(Model):
+    """
+    Represents metadata for a screenshot within Sentry product
+    """
+
+    __relocation_scope__ = RelocationScope.Excluded
+
+    # uuid represents the ID of the object for external use. We want something long and difficult to
+    # guess since the API reading these will be a public API
+    uuid = models.UUIDField(default=uuid.uuid4, editable=False, db_index=True)
+    sentry_url = models.URLField()
+    component_identifier = models.CharField()
+    organization_id = HybridCloudForeignKey("sentry.Organization", on_delete="CASCADE")
+    date_added = models.DateTimeField(default=timezone.now, db_index=True)
+
+    class Meta:
+        app_label = "sentry"
+        db_table = "sentry_sentryshot"