feat(cells): Add projectkeymapping table to control silo#109831
feat(cells): Add projectkeymapping table to control silo#109831
Conversation
This is the first step to ensuring global projectkey uniqueness. Right now we just create the table, not using it yet.
|
This PR has a migration; here is the generated SQL for for --
-- 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"); |
|
|
||
|
|
||
| @control_silo_model | ||
| class ProjectKeyMapping(Model): |
There was a problem hiding this comment.
Should we make this DefaultFieldsModel so that we get date_created and date_updated for free?
There was a problem hiding this comment.
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_updatedwhich is not present in theDefaultFieldsModelfor when we do the migration later
There was a problem hiding this comment.
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)), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
added back the project key id to keep things aligned with the other hybrid cloud models
There was a problem hiding this comment.
👍 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): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Hmm, not sure. I modelled this off OrganizationMapping which is in the main app
There was a problem hiding this comment.
👍 That's fair. I forgot that those models were in the main django app.
|
|
||
|
|
||
| @control_silo_model | ||
| class ProjectKeyMapping(Model): |
There was a problem hiding this comment.
👍 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)), |
There was a problem hiding this comment.
👍 With public_key, project_key_id we'll be able to uniquely identify records to do upserts and deletes.
| sentry.db.models.indexes.IndexWithPostgresNameLimits( | ||
| django.db.models.functions.datetime.TruncSecond("date_updated"), | ||
| models.F("id"), | ||
| name="sentry_projkeymapping_date_updated_id_idx", | ||
| ), |
There was a problem hiding this comment.
Should this index also include cell_name? I assume we'll mostly being doing filter queries based on the locality, date_updated.
There was a problem hiding this comment.
oh good point --- i need to add this to the org mapping index too
|
|
||
|
|
||
| @control_silo_model | ||
| class ProjectKeyMapping(Model): |
There was a problem hiding this comment.
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.
|
This PR has a migration; here is the generated SQL for for --
-- 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"); |
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.
Note: in order to keep this table minimal we only put the publickey in here, and not the project_key_id.