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

feat: Introduce server component mode limitations #35994

Merged
merged 51 commits into from
Jul 28, 2022

Conversation

RyanSkonnord
Copy link
Contributor

@RyanSkonnord RyanSkonnord commented Jun 23, 2022

Previously submitted for incremental review in:

What this is

Some custom decorators that we'll soon apply to all (or most) endpoint and model classes in the code base. If you set an environment variable declaring the server to be in a particular "mode", decorated endpoints and models will be available only in that mode. (This excludes "monolith mode", which is the default where everything is available.)

If an "unavailable" model is accessed, an exception is raised. Models can allow read-only access from one mode and write access from another.

If a request hits an "unavailable" endpoint, it will return a 404 status, effectively making the endpoint nonexistent on that server as far as the outside world is concerned. There is a setting (for dev and testing environments) that raises an exception instead.

What it's for

This is motivated by a future move to a geographically distributed architecture. In such an architecture, individual server nodes will store only a subset of the data that's currently in Sentry's DB schema. Accordingly, those nodes will provide only a subset of the services. The decorators designate which database tables and API services will exist in each kind of node.

For the time being, the decorators are best understood as a tool for simulating that architecture. When you are running a dev stack in "control" mode, you are essentially pretending that only the "control" tables exist. If a "control" API service crosses the boundary and attempts to read a "customer" table, you get a conspicuous error and something to fix. Automated tests can be similarly scoped, where they're expected to work in a particular mode.

Future work, we hope, will bring reality into line with the simulation. The decorators should be able to stick around permanently, if only to provide more informative errors if a boundary-crossing bug emerges.

Obviously, only "monolith mode" is supported for production use. Because monolith mode is the default configuration, it should be safe to merge and ship this as-is.

RyanSkonnord and others added 30 commits May 24, 2022 16:39
Co-authored-by: Alberto Leal <[email protected]>
…method

The root motivation is to have `override_settings` work as expected in a
testing context. To that end, move a lot of infrastructure related to
creating the body of a method override into the new ModeLimited class in
servermode.py, a base class for the other decorators.

Also made some opportunistic improvements and reorganizations.
MONOLITH = "MONOLITH"
CONTROL = "CONTROL"
CUSTOMER = "CUSTOMER"
FRONTEND = "FRONTEND"
Copy link
Member

Choose a reason for hiding this comment

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

What is the FRONTEND mode for?

Copy link
Member

Choose a reason for hiding this comment

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

@markstory it's for running Sentry as a static file webserver.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's kind of a placeholder as I don't know if it will actually be needed on any of the individual request handlers mapped in Django. If the front-end silo's only job is serving static files, then by definition there is no business logic to tag. This is here because I wasn't sure if that assumption would hold. But, if it does, we can delete the enum value.

@RyanSkonnord RyanSkonnord enabled auto-merge (squash) July 28, 2022 19:35
@RyanSkonnord RyanSkonnord merged commit 7f9c213 into master Jul 28, 2022
@RyanSkonnord RyanSkonnord deleted the server-component-limited-modes branch July 28, 2022 19:45
@github-actions github-actions bot locked and limited conversation to collaborators Aug 13, 2022
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.

4 participants