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(projects): Increase project slug limit from 50 -> 100 #75737

Merged
merged 10 commits into from
Sep 30, 2024
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: 0003_drop_remote_subscription
replays: 0004_index_together
sentry: 0747_create_datasecrecywaiver_table
sentry: 0748_increase_project_slug_max_length
social_auth: 0002_default_auto_field
uptime: 0006_projectuptimesubscription_name_owner
4 changes: 2 additions & 2 deletions src/sentry/api/endpoints/team_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from sentry.apidocs.parameters import CursorQueryParam, GlobalParams
from sentry.apidocs.utils import inline_sentry_response_serializer
from sentry.constants import RESERVED_PROJECT_SLUGS, ObjectStatus
from sentry.models.project import Project
from sentry.models.project import PROJECT_SLUG_MAX_LENGTH, Project
from sentry.seer.similarity.utils import SEER_ELIGIBLE_PLATFORMS
from sentry.signals import project_created
from sentry.utils.snowflake import MaxSnowflakeRetryError
Expand All @@ -37,7 +37,7 @@ class ProjectPostSerializer(serializers.Serializer):
slug = SentrySerializerSlugField(
help_text="""Uniquely identifies a project and is used for the interface.
If not provided, it is automatically generated from the name.""",
max_length=50,
max_length=PROJECT_SLUG_MAX_LENGTH,
required=False,
allow_null=True,
)
Expand Down
34 changes: 34 additions & 0 deletions src/sentry/migrations/0748_increase_project_slug_max_length.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 5.0.7 on 2024-08-07 17:15

from django.db import migrations

import sentry.db.models.fields.slug
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we make this a post deployment migration? not quite sure how many projects there are or the scale of this migration.

Copy link
Member

@wedamija wedamija Aug 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, post deployment is for backfills and large indexes only, not things that modify the schema.

Increasing the size of this column should be fast. If it's not, we have a statement timeout that will cause the migration to abort within a few seconds.

I'd say that just make sure you're around to monitor this and revert it if it won't run - it should be ok though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might get hit with an index rebuild which could throw off query performance for slug lookups. The postgres docs state

When this form is used, the column's statistics are removed, so running ANALYZE on the table afterwards is recommended.

We have had an incident where a column resize invalided stats and caused an outage. We could have a similar outcome here.

Copy link
Contributor Author

@schew2381 schew2381 Aug 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you run ANALYZE, the example in docs is a little unclear

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call @markstory, I'd forgotten about that. Maybe in that case, we should make this a post_deploy migration and trigger the analyze as part of it, or even have ops run the entire thing manually for us.

I doubt we can run the ANALYZE as part of the deploy, it'll very likely time out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I switched it to post deploy, do I have to include the ANALYZE as part of the migration code?

# 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", "0747_create_datasecrecywaiver_table"),
]

operations = [
migrations.AlterField(
model_name="project",
name="slug",
field=sentry.db.models.fields.slug.SentrySlugField(max_length=100, null=True),
),
]
3 changes: 2 additions & 1 deletion src/sentry/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
from sentry.models.user import User

SENTRY_USE_SNOWFLAKE = getattr(settings, "SENTRY_USE_SNOWFLAKE", False)
PROJECT_SLUG_MAX_LENGTH = 100

# NOTE:
# - When you modify this list, ensure that the platform IDs listed in "sentry/static/app/data/platforms.tsx" match.
Expand Down Expand Up @@ -228,7 +229,7 @@ class Project(Model, PendingDeletionMixin):

__relocation_scope__ = RelocationScope.Organization

slug = SentrySlugField(null=True)
slug = SentrySlugField(null=True, max_length=PROJECT_SLUG_MAX_LENGTH)
# DEPRECATED do not use, prefer slug
name = models.CharField(max_length=200)
forced_color = models.CharField(max_length=6, null=True, blank=True)
Expand Down
Loading