Skip to content

feat(cells): Add projectkeymapping table to control silo#109831

Merged
lynnagara merged 5 commits intomasterfrom
cells-projectkey-control-silo
Mar 4, 2026
Merged

feat(cells): Add projectkeymapping table to control silo#109831
lynnagara merged 5 commits intomasterfrom
cells-projectkey-control-silo

Conversation

@lynnagara
Copy link
Copy Markdown
Member

This is the first step to ensuring global projectkey uniqueness.

Right now we just create the table, not using it yet.

Note: in order to keep this table minimal we only put the publickey in here, and not the project_key_id.

This is the first step to ensuring global projectkey uniqueness.

Right now we just create the table, not using it yet.
@lynnagara lynnagara requested a review from a team as a code owner March 3, 2026 21:13
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 3, 2026

This PR has a migration; here is the generated SQL for src/sentry/migrations/1039_projectkeymapping.py

for 1039_projectkeymapping in sentry

--
-- Create model ProjectKeyMapping
--
CREATE TABLE "sentry_projectkeymapping" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "project_key_id" bigint NOT NULL, "public_key" varchar(32) NOT NULL UNIQUE, "cell_name" varchar(48) NOT NULL, "date_updated" timestamp with time zone DEFAULT (STATEMENT_TIMESTAMP()) NOT NULL);
CREATE INDEX CONCURRENTLY "sentry_projectkeymapping_project_key_id_fee1d050" ON "sentry_projectkeymapping" ("project_key_id");
CREATE INDEX CONCURRENTLY "sentry_projectkeymapping_public_key_c2b56897_like" ON "sentry_projectkeymapping" ("public_key" varchar_pattern_ops);
CREATE INDEX CONCURRENTLY "sentry_projkeymapping_date_updated_id_idx" ON "sentry_projectkeymapping" ((DATE_TRUNC('second', "date_updated" AT TIME ZONE 'UTC')), "id");

Copy link
Copy Markdown
Member

@wedamija wedamija left a comment

Choose a reason for hiding this comment

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

Migration lgtm



@control_silo_model
class ProjectKeyMapping(Model):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we make this DefaultFieldsModel so that we get date_created and date_updated for free?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'd rather not use that because:

  • the underlying region model doesn't use it
  • we don't need date_created
  • i think it's better to have the database level default for date_updated which is not present in the DefaultFieldsModel for when we do the migration later

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ProjectKey predates DefaultFieldsModel which is why it doesn't used that base class. Having date_created could be helpful for understanding when mapping records were created and seeing the latency between records created in the cells and mapping data in control.

primary_key=True, serialize=False
),
),
("public_key", models.CharField(db_index=True, max_length=32, unique=True)),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Currently public_key is mutable. If we don't have a project_key_id + organization_id/project_id available in this table it will be hard to do upserts when keys change.

If this key is unique, do we need a separate id field?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

added back the project key id to keep things aligned with the other hybrid cloud models

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 With public_key, project_key_id we'll be able to uniquely identify records to do upserts and deletes.



@control_silo_model
class ProjectKeyMapping(Model):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you want to put this model in the main sentry django app, or in the sentry.hybridcloud django app which also contains replica models for authtokens?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hmm, not sure. I modelled this off OrganizationMapping which is in the main app

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 That's fair. I forgot that those models were in the main django app.



@control_silo_model
class ProjectKeyMapping(Model):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 That's fair. I forgot that those models were in the main django app.

primary_key=True, serialize=False
),
),
("public_key", models.CharField(db_index=True, max_length=32, unique=True)),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 With public_key, project_key_id we'll be able to uniquely identify records to do upserts and deletes.

Comment on lines +56 to +60
sentry.db.models.indexes.IndexWithPostgresNameLimits(
django.db.models.functions.datetime.TruncSecond("date_updated"),
models.F("id"),
name="sentry_projkeymapping_date_updated_id_idx",
),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this index also include cell_name? I assume we'll mostly being doing filter queries based on the locality, date_updated.

Copy link
Copy Markdown
Member Author

@lynnagara lynnagara Mar 4, 2026

Choose a reason for hiding this comment

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

oh good point --- i need to add this to the org mapping index too



@control_silo_model
class ProjectKeyMapping(Model):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ProjectKey predates DefaultFieldsModel which is why it doesn't used that base class. Having date_created could be helpful for understanding when mapping records were created and seeing the latency between records created in the cells and mapping data in control.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 4, 2026

This PR has a migration; here is the generated SQL for src/sentry/migrations/1041_projectkeymapping.py

for 1041_projectkeymapping in sentry

--
-- Create model ProjectKeyMapping
--
CREATE TABLE "sentry_projectkeymapping" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "project_key_id" bigint NOT NULL, "public_key" varchar(32) NOT NULL UNIQUE, "cell_name" varchar(48) NOT NULL, "date_updated" timestamp with time zone DEFAULT (STATEMENT_TIMESTAMP()) NOT NULL);
CREATE INDEX CONCURRENTLY "sentry_projectkeymapping_project_key_id_fee1d050" ON "sentry_projectkeymapping" ("project_key_id");
CREATE INDEX CONCURRENTLY "sentry_projectkeymapping_public_key_c2b56897_like" ON "sentry_projectkeymapping" ("public_key" varchar_pattern_ops);
CREATE INDEX CONCURRENTLY "sentry_projkeymapping_cell_name_date_updated_id_idx" ON "sentry_projectkeymapping" ("cell_name", (DATE_TRUNC('second', "date_updated" AT TIME ZONE 'UTC')), "id");

@lynnagara lynnagara merged commit 798ba21 into master Mar 4, 2026
76 of 77 checks passed
@lynnagara lynnagara deleted the cells-projectkey-control-silo branch March 4, 2026 20:54
JonasBa pushed a commit that referenced this pull request Mar 5, 2026
This is the first step to ensuring global projectkey uniqueness.

Right now we just create the table, not using it yet.

Note: in order to keep this table minimal we only put the publickey in
here, and not the project_key_id.
@github-actions github-actions bot locked and limited conversation to collaborators Mar 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants