-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat(webapp): plan-aware compute migration #3957
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
Open
nicktrn
wants to merge
22
commits into
main
Choose a base branch
from
feat/compute-migration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
846c541
feat(webapp): add compute migration feature flags
nicktrn 8b12326
feat(webapp): add deterministic org hashBucket for rollout
nicktrn eeca099
feat(webapp): add compute migration env config
nicktrn 7e41492
feat(webapp): add compute migration resolver
nicktrn b36b83c
feat(webapp): add createReloadingRegistry helper
nicktrn 7067ac7
feat(webapp): boot global flags registry
nicktrn 266fc60
feat(webapp): route migrated orgs to the compute backing at trigger
nicktrn 58d8fe5
feat(webapp): build compute template for migrated orgs
nicktrn c4e0dcf
chore(webapp): server-changes note for compute migration
nicktrn 65ce342
test(webapp): move hashBucket test into test/ so vitest includes it
nicktrn 4791b01
fix(webapp): hide compute backing on read surfaces and fix replay
nicktrn 8060760
fix(webapp): store geo region in clickhouse to hide compute backing f…
nicktrn 25e3fe1
fix(webapp): serialize registry reloads and clear readiness timeout
nicktrn 18d5b11
fix(webapp): strict boolean kill switch, bound reload interval, cuid …
nicktrn aefdf3a
feat(database,webapp): add WorkerInstanceGroup.region + worker-region…
nicktrn 53eaa7a
refactor(webapp): resolve region<->backing from WorkerInstanceGroup.r…
nicktrn 222d653
feat(webapp): stamp geo region on runs, keep worker_queue raw, test-s…
nicktrn b75e18a
fix(webapp): fail-open entitlement lookup in migration mode, harden r…
nicktrn ea9a071
docs(webapp): trim server-changes note to one behavior-level line
nicktrn e3524e9
refactor(webapp): centralize display-region fallback in regionForDisplay
nicktrn 126a01f
fix(webapp): look up run's actual worker group, show geo region in sp…
nicktrn 188dac2
docs(webapp): trim hot-path comment, note region must stay whereTrans…
nicktrn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| area: webapp | ||
| type: feature | ||
| --- | ||
|
|
||
| Gradually roll out a new run execution backend to a configurable percentage of organizations. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
apps/webapp/app/runEngine/concerns/computeMigration.server.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import { hashBucket } from "~/utils/computeBucket"; | ||
|
|
||
| /** Subset of the global flags snapshot this resolver reads. */ | ||
| export type ComputeMigrationFlags = { | ||
| computeMigrationEnabled?: boolean; | ||
| computeMigrationFreePercentage?: number; | ||
| computeMigrationPaidPercentage?: number; | ||
| }; | ||
|
|
||
| type MigrationDecisionInput = { | ||
| planType: string | undefined; | ||
| orgId: string; | ||
| orgFeatureFlags: Record<string, unknown> | null | undefined; | ||
| flags: ComputeMigrationFlags | undefined; | ||
| }; | ||
|
|
||
| /** | ||
| * Whether this org should run on the compute backing. Shared by the trigger-time | ||
| * transform and the deploy-time template decision so a migrated org always gets a | ||
| * compute template. Precedence: per-org override (both directions) wins; otherwise | ||
| * global enable + the plan's percentage bucket. Enterprise and unknown plans are | ||
| * never enrolled by percentage (override only). The sole opt-out is the per-org | ||
| * `computeMigrationEnabled: false`. | ||
| */ | ||
| export function isOrgMigrated({ | ||
| planType, | ||
| orgId, | ||
| orgFeatureFlags, | ||
| flags, | ||
| }: MigrationDecisionInput): boolean { | ||
| const override = orgFeatureFlags?.["computeMigrationEnabled"]; | ||
| if (override === false) return false; | ||
| if (override === true) return true; | ||
|
|
||
| if (!(flags?.computeMigrationEnabled ?? false)) return false; | ||
|
|
||
| const pct = | ||
| planType === "free" | ||
| ? flags?.computeMigrationFreePercentage ?? 0 | ||
| : planType === "paid" | ||
| ? flags?.computeMigrationPaidPercentage ?? 0 | ||
| : 0; // enterprise / undefined | ||
|
|
||
| return hashBucket(orgId) < pct; | ||
| } | ||
|
|
||
| type ResolveInput = MigrationDecisionInput & { | ||
| baseWorkerQueue: string | undefined; | ||
| baseEnableFastPath: boolean; | ||
| region: string | undefined; // geo of the base queue (same whether migrated or not) | ||
| backing: { workerQueue: string; enableFastPath: boolean } | undefined; | ||
| envType: string; | ||
| }; | ||
|
|
||
| /** | ||
| * Produce the target descriptor `{ workerQueue, region, enableFastPath }` for a | ||
| * run. When the org is migrated and the region has a compute backing, the queue | ||
| * and fast-path setting come from the MICROVM backing group; `region` is the geo | ||
| * either way. Same-geo swap (us-east-1 -> us-east-1-next): any explicit placement | ||
| * is a geography preference, honored by staying in-region. Applied after region | ||
| * resolution, mirroring the scheduled-split. | ||
| */ | ||
| export function resolveComputeMigration({ | ||
| baseWorkerQueue, | ||
| baseEnableFastPath, | ||
| region, | ||
| backing, | ||
| envType, | ||
| ...decision | ||
| }: ResolveInput): { workerQueue: string | undefined; region: string | undefined; enableFastPath: boolean } { | ||
| const passthrough = { workerQueue: baseWorkerQueue, region, enableFastPath: baseEnableFastPath }; | ||
| if (baseWorkerQueue === undefined) return passthrough; | ||
| if (envType === "DEVELOPMENT") return passthrough; | ||
| if (!isOrgMigrated(decision)) return passthrough; | ||
| if (!backing) return passthrough; | ||
| return { workerQueue: backing.workerQueue, region, enableFastPath: backing.enableFastPath }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /** | ||
| * Deterministic 0-99 bucket for an org id, stable across processes and deploys. | ||
| * FNV-1a (non-crypto): we only need determinism + uniform spread, not collision | ||
| * resistance. Used for nested percentage rollout: `hashBucket(orgId) < percentage`. | ||
| * Ramping the percentage down keeps a strict subset (the low buckets), so an org | ||
| * never flaps in and out as the dial moves. | ||
| */ | ||
| export function hashBucket(orgId: string): number { | ||
| let hash = 0x811c9dc5; // FNV offset basis | ||
| for (let i = 0; i < orgId.length; i++) { | ||
| hash ^= orgId.charCodeAt(i); | ||
| hash = Math.imul(hash, 0x01000193) >>> 0; | ||
| } | ||
| return hash % 100; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.