Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(uptime): Remove unique constraint and migrated column from UptimeSubscription #86081

Merged
merged 4 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion migrations_lockfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ social_auth: 0002_default_auto_field

tempest: 0002_make_message_type_nullable

uptime: 0026_region_mode_col
uptime: 0027_remove_migrated_and_unique_constraint

workflow_engine: 0032_remove_data_source_query_id
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated by Django 5.1.5 on 2025-02-27 23:09

from django.db import migrations

from sentry.new_migrations.migrations import CheckedMigration
from sentry.new_migrations.monkey.fields import SafeRemoveField
from sentry.new_migrations.monkey.state import DeletionAction


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 = [
("uptime", "0026_region_mode_col"),
]

operations = [
migrations.RemoveConstraint(
model_name="uptimesubscription",
name="uptime_uptimesubscription_unique_subscription_check_4",
),
SafeRemoveField(
model_name="uptimesubscription",
name="migrated",
deletion_action=DeletionAction.MOVE_TO_PENDING,
),
]
18 changes: 0 additions & 18 deletions src/sentry/uptime/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from django.conf import settings
from django.db import models
from django.db.models import Count, Q
from django.db.models.expressions import Value
from django.db.models.functions import MD5, Coalesce
from sentry_kafka_schemas.schema_types.uptime_configs_v1 import REGIONSCHEDULEMODE_ROUND_ROBIN

from sentry.backup.scopes import RelocationScope
Expand Down Expand Up @@ -90,8 +88,6 @@ class IntervalSeconds(models.IntegerChoices):
# How to sample traces for this monitor. Note that we always send a trace_id, so any errors will
# be associated, this just controls the span sampling.
trace_sampling = models.BooleanField(default=False)
# Temporary column we'll use to migrate away from the url based unique constraint
migrated = models.BooleanField(db_default=False)

objects: ClassVar[BaseManager[Self]] = BaseManager(
cache_fields=["pk", "subscription_id"],
Expand All @@ -102,20 +98,6 @@ class Meta:
app_label = "uptime"
db_table = "uptime_uptimesubscription"

constraints = [
models.UniqueConstraint(
"url",
"interval_seconds",
"timeout_ms",
"method",
"trace_sampling",
MD5("headers"),
Coalesce(MD5("body"), Value("")),
condition=Q(migrated=False),
name="uptime_uptimesubscription_unique_subscription_check_4",
),
]


@region_silo_model
class UptimeSubscriptionRegion(DefaultFieldsModel):
Expand Down
1 change: 0 additions & 1 deletion src/sentry/uptime/subscriptions/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def create_uptime_subscription(
headers=headers, # type: ignore[misc]
body=body,
trace_sampling=trace_sampling,
migrated=True,
)

# Associate active regions with this subscription
Expand Down
30 changes: 0 additions & 30 deletions tests/sentry/uptime/subscriptions/test_subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,36 +531,6 @@ def test_status_enable(self, mock_enable_project_uptime_subscription):
)
mock_enable_project_uptime_subscription.assert_called()

def test_migrated_does_not_violate_constraint(self):
with self.tasks():
proj_sub = create_project_uptime_subscription(
self.project,
self.environment,
url="https://sentry.io",
interval_seconds=3600,
timeout_ms=1000,
mode=ProjectUptimeSubscriptionMode.AUTO_DETECTED_ACTIVE,
)
uptime_sub_1 = proj_sub.uptime_subscription
uptime_sub_1.update(migrated=False)

proj_sub_2 = create_project_uptime_subscription(
self.project,
self.environment,
url="https://sentry.io",
interval_seconds=3600,
timeout_ms=1000,
mode=ProjectUptimeSubscriptionMode.AUTO_DETECTED_ACTIVE,
)
uptime_sub_2 = proj_sub_2.uptime_subscription

uptime_sub_1.refresh_from_db()
uptime_sub_2.refresh_from_db()
assert uptime_sub_1.url == uptime_sub_2.url
assert uptime_sub_1.interval_seconds == uptime_sub_2.interval_seconds
assert uptime_sub_1.id != uptime_sub_2.id
assert uptime_sub_1.subscription_id != uptime_sub_2.subscription_id


class DeleteUptimeSubscriptionsForProjectTest(UptimeTestCase):
def test_other_subscriptions(self):
Expand Down
61 changes: 0 additions & 61 deletions tests/sentry/uptime/test_models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import pytest
from django.db import router, transaction
from django.db.utils import IntegrityError

from sentry.testutils.cases import UptimeTestCase
from sentry.uptime.models import (
UptimeSubscription,
get_active_auto_monitor_count_for_org,
get_top_hosting_provider_names,
)
Expand All @@ -27,62 +22,6 @@ def test(self):
assert get_active_auto_monitor_count_for_org(other_org) == 1


class UniqueMonitorTest(UptimeTestCase):
def test(self):
self.create_uptime_subscription(
url="https://santry.io",
interval_seconds=60,
method="GET",
)
with (
pytest.raises(IntegrityError),
transaction.atomic(router.db_for_write(UptimeSubscription)),
):
self.create_uptime_subscription(
url="https://santry.io",
interval_seconds=60,
method="GET",
)

self.create_uptime_subscription(
url="https://santry.io",
interval_seconds=60,
method="POST",
)
self.create_uptime_subscription(
url="https://santry.io",
interval_seconds=60,
headers={"hi": "santry", "auth": "sentaur"},
)

with (
pytest.raises(IntegrityError),
transaction.atomic(router.db_for_write(UptimeSubscription)),
):
self.create_uptime_subscription(
url="https://santry.io",
interval_seconds=60,
headers={"auth": "sentaur", "hi": "santry"},
)

self.create_uptime_subscription(
url="https://santry.io",
interval_seconds=60,
headers={"hi": "santry", "auth": "sentaur"},
body="hello",
)
with (
pytest.raises(IntegrityError),
transaction.atomic(router.db_for_write(UptimeSubscription)),
):
self.create_uptime_subscription(
url="https://santry.io",
interval_seconds=60,
headers={"hi": "santry", "auth": "sentaur"},
body="hello",
)


class GetTopHostingProviderNamesTest(UptimeTestCase):
def test(self):
self.create_uptime_subscription(host_provider_name="prov1")
Expand Down
Loading