Skip to content

Commit

Permalink
feat(relocation): Add relocatin provenance (#73688)
Browse files Browse the repository at this point in the history
This will allow each relocation to track whether it is self-hosted or
Saas->Saas. We'll use this information to differentiate logic slightly
where appropriate.
  • Loading branch information
azaslavsky committed Jul 3, 2024
1 parent b6dcb4d commit 64152e9
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion migrations_lockfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ hybridcloud: 0016_add_control_cacheversion
nodestore: 0002_nodestore_no_dictfield
remote_subscriptions: 0002_remove_separate_remote_subscription
replays: 0004_index_together
sentry: 0732_add_span_attribute_extraction_rules
sentry: 0733_relocation_provenance
social_auth: 0002_default_auto_field
uptime: 0002_remove_separate_remote_subscription
48 changes: 48 additions & 0 deletions src/sentry/migrations/0733_relocation_provenance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Generated by Django 5.0.6 on 2024-07-02 20:56

from django.db import migrations, models

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", "0732_add_span_attribute_extraction_rules"),
]

operations = (
migrations.SeparateDatabaseAndState(
database_operations=[
migrations.RunSQL(
"""
ALTER TABLE "sentry_relocation" ADD COLUMN "provenance" integer NOT NULL DEFAULT 0;
""",
reverse_sql="""
ALTER TABLE "sentry_relocation" DROP COLUMN "provenance";
""",
hints={"tables": ["sentry_relocation"]},
),
],
state_operations=[
migrations.AddField(
model_name="relocation",
name="provenance",
field=models.SmallIntegerField(default=0),
),
],
),
)
2 changes: 2 additions & 0 deletions src/sentry/models/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class OrganizationStatus(IntEnum):
ACTIVE = 0
PENDING_DELETION = 1
DELETION_IN_PROGRESS = 2
RELOCATION_PENDING_APPROVAL = 3

# alias for OrganizationStatus.ACTIVE
VISIBLE = 0
Expand Down Expand Up @@ -78,6 +79,7 @@ def as_choices(cls):
OrganizationStatus.ACTIVE: "active",
OrganizationStatus.PENDING_DELETION: "pending deletion",
OrganizationStatus.DELETION_IN_PROGRESS: "deletion in progress",
OrganizationStatus.RELOCATION_PENDING_APPROVAL: "relocation pending approval",
}


Expand Down
17 changes: 16 additions & 1 deletion src/sentry/models/relocation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from enum import Enum, unique
from enum import Enum, IntEnum, unique
from uuid import uuid4

from django.db import models
Expand Down Expand Up @@ -81,6 +81,15 @@ class EmailKind(Enum):
def get_choices(cls) -> list[tuple[int, str]]:
return [(key.value, key.name) for key in cls]

class Provenance(IntEnum):
SELF_HOSTED = 0
SAAS_TO_SAAS = 1

# TODO(azaslavsky): Could we dedup this with a mixin in the future?
@classmethod
def get_choices(cls) -> list[tuple[int, str]]:
return [(key.value, key.name) for key in cls]

# The user that requested this relocation - if the request was made by an admin on behalf of a
# user, this will be different from `owner`. Otherwise, they are identical.
creator_id = BoundedBigIntegerField()
Expand All @@ -99,6 +108,12 @@ def get_choices(cls) -> list[tuple[int, str]]:
# Possible values are in the Stage enum.
step = models.SmallIntegerField(choices=Step.get_choices(), default=None)

# Possible values are in the Provenance enum. The relocation pipeline has different behaviors
# depending on the source of the relocation.
provenance = models.SmallIntegerField(
choices=Provenance.get_choices(), default=Provenance.SELF_HOSTED
)

# Possible values are in the Status enum.
status = models.SmallIntegerField(
choices=Status.get_choices(), default=Status.IN_PROGRESS.value
Expand Down

0 comments on commit 64152e9

Please sign in to comment.