Skip to content

feat(cells): introduce locality concept in configuration#108410

Merged
lynnagara merged 4 commits intomasterfrom
introduce-locality
Feb 20, 2026
Merged

feat(cells): introduce locality concept in configuration#108410
lynnagara merged 4 commits intomasterfrom
introduce-locality

Conversation

@lynnagara
Copy link
Copy Markdown
Member

This is a small initial PR to introduce the locality concept. Locality is a group of cells (which represent the geographic region, or tenant in the case of single-tenant deployments). The existing region_name / sentry-region terminology is deprecated in favor of locality + cells. This naming will contiue to be migrated in subsequent PRs / database migrations.

This PR includes the following:

  • introduce SENTRY_LOCALITIES setting to configure the cell -> locality mapping
  • when SENTRY_LOCALITIES is not present (rollout phase), synthesize a 1:1 locality per cell as a fallback
  • update the OrgCellMappingsEndpoint to return the real cell to locality map from config instead of the hardcoded value
  • update the OrgCellMappingsEndpoint to support multiple localities being requested
  • add TODO(cells) comments next to model fields where region_name should be later updated to cell_name in the DB

This is a small initial PR to introduce the locality concept. Locality is a group of cells (which
represent the geographic region, or tenant in the case of single-tenant deployments). The existing
region_name / sentry-region terminology is deprecated in favor of locality + cells. This naming will
contiue to be migrated in subsequent PRs / database migrations.

This PR includes the following:
- introduce SENTRY_LOCALITIES setting to configure the cell -> locality mapping
- when SENTRY_LOCALITIES is not present (rollout phase), synthesize a 1:1 locality per cell as a fallback
- update the OrgCellMappingsEndpoint to return the real cell to locality map from config instead of the hardcoded value
- update the OrgCellMappingsEndpoint to support multiple localities being requested
- add TODO(cells) comments next to model fields where region_name should be later updated to cell_name in the DB
@lynnagara lynnagara requested review from a team as code owners February 17, 2026 23:26
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Feb 17, 2026
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

)

# TODO(cells): rename to cell_name
region_name = models.CharField(max_length=REGION_NAME_LENGTH)
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.

I wouldn't attempt a rename. Instead we would have to add a column, dual write, shift reads and then drop the current column.

Changing the names on these columns will be a non-trivial amount of work for no benefit. Given the current scope and staffing levels on this workstream I don't see how we would be able to prioritize this work.

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.

seems like rename is a metadata-only change though https://www.postgresql.org/docs/9.6/sql-altertable.html
why would we need so many steps?

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.

Because of django and release boundaries. When we do deploys we apply migrations while the old code is running. When the column is renamed, the 'old' version of the application will still be using the old column name, and all queries will fail until application instances are restarted with new code which can can take several minutes.

Copy link
Copy Markdown
Member Author

@lynnagara lynnagara Feb 19, 2026

Choose a reason for hiding this comment

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

can't we handle that with aliasing rather than the full data migration though?

i've just written the task as a todo here since i think we could determine the exact strategy later but wanted to call it out now. long term i think there's benefit in names that are easy for future contributors to understand, and region_name will be very confusing in a few months time when it doesn't map to anything else in the codebase anymore.

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.

Yes we could alias in the django model. Then folks have to remember two different names between the schema and code. I agree that having region around long term isn't ideal, and if we're going to make a change we should do it across schema and code.

query = OrganizationMapping.objects.all()
if request.GET.get("locale"):
query = query.filter(region_name=request.GET.get("locale"))
localities = request.GET.getlist("locality")
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.

Which term are we using? Locality is longer and harder to say, and the words are rough synonyms.

When would synapse need more than a single locale?

Copy link
Copy Markdown
Member Author

@lynnagara lynnagara Feb 18, 2026

Choose a reason for hiding this comment

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

synapse only ever uses the word locality... locale is never used

this is from https://www.notion.so/sentry/Cell-Based-Architecture-Glossary-2158b10e4b5d801eb717e56fa183bd9c

locale is fine with me if we want to change the term everywhere, but i stuck to the ones previously documented

synapse's design tries not make any assumptions about the shape of our infrastructure, even though our final deployments will probably only have one synapse per locality. so it can proxy for one locality as easily as for multiple.

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.

synapse's design tries not make any assumptions about the shape of our infrastructure, even though our final deployments will probably only have one synapse per locality. so it can proxy for one locality as easily as for multiple.

👍 If supporting multiple doesn't add too much complexity it is nice to have.

locale is fine with me if we want to change the term everywhere, but i stuck to the ones previously documented

I agree we should be consistent. I took a look through the ops repo and it has locality already. I don't think 'locale' is significantly more clear that it justifies making changes. Lets stick with locality in the code going forward.

for region in self.regions:
region.validate()

# Ensure that a cell cannot be registed to more than one locality
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.

Suggested change
# Ensure that a cell cannot be registed to more than one locality
# Ensure that a cell cannot be registered to more than one locality

@markstory
Copy link
Copy Markdown
Member

Refs INFRENG-219

Comment on lines +759 to +760
# Mapping of localities (e.g. "us", "de") to their constituent cells (e.g. "us1", "us2")
SENTRY_LOCALITIES: list[LocalityConfig] = []
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.

If each Region/Cell had a locality attribute assigned to them would we need this? We could infer the list of localities from the Cell configuration. Doing that would avoid any drift between REGION_CONFIG and LOCALITIES, which could arise during tests when we have to stub out the region lists, and would make generating config data for the application simpler.

Copy link
Copy Markdown
Member Author

@lynnagara lynnagara Feb 19, 2026

Choose a reason for hiding this comment

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

Locality might be an important concept we expand on later though. For example we will likely need to mark which ones are saas vs single-tenants, which default cell of a locality to send new organizations to, and other things.

So i think introducing the top level locality concept may make sense here, rather than burying it inside the cell configuration, even if it's not strictly needed yet.

The test cases are mostly stubbed correctly by the TestEnvRegionDirectory class so other test code won't have to handle it

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.

Good point about needing a place to denote the default cell for a locality, and hidden localities.

@lynnagara lynnagara merged commit 229bcb4 into master Feb 20, 2026
98 checks passed
@lynnagara lynnagara deleted the introduce-locality branch February 20, 2026 22:47
priscilawebdev pushed a commit that referenced this pull request Feb 24, 2026
This is a small initial PR to introduce the locality concept. Locality
is a group of cells (which represent the geographic region, or tenant in
the case of single-tenant deployments). The existing region_name /
sentry-region terminology is deprecated in favor of locality + cells.
This naming will contiue to be migrated in subsequent PRs / database
migrations.

This PR includes the following:
- introduce SENTRY_LOCALITIES setting to configure the cell -> locality
mapping
- when SENTRY_LOCALITIES is not present (rollout phase), synthesize a
1:1 locality per cell as a fallback
- update the OrgCellMappingsEndpoint to return the real cell to locality
map from config instead of the hardcoded value
- update the OrgCellMappingsEndpoint to support multiple localities
being requested
- add TODO(cells) comments next to model fields where region_name should
be later updated to cell_name in the DB
mchen-sentry pushed a commit that referenced this pull request Feb 24, 2026
This is a small initial PR to introduce the locality concept. Locality
is a group of cells (which represent the geographic region, or tenant in
the case of single-tenant deployments). The existing region_name /
sentry-region terminology is deprecated in favor of locality + cells.
This naming will contiue to be migrated in subsequent PRs / database
migrations.

This PR includes the following:
- introduce SENTRY_LOCALITIES setting to configure the cell -> locality
mapping
- when SENTRY_LOCALITIES is not present (rollout phase), synthesize a
1:1 locality per cell as a fallback
- update the OrgCellMappingsEndpoint to return the real cell to locality
map from config instead of the hardcoded value
- update the OrgCellMappingsEndpoint to support multiple localities
being requested
- add TODO(cells) comments next to model fields where region_name should
be later updated to cell_name in the DB
@github-actions github-actions bot locked and limited conversation to collaborators Mar 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

claude-code-assisted Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants