-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
perf(webapp): read per-run environment config from the replica at dequeue #4560
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
Merged
Merged
Changes from all commits
Commits
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
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
68 changes: 68 additions & 0 deletions
68
apps/webapp/test/environmentVariablesReplicaRouting.test.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,68 @@ | ||
| import { setupAuthenticatedEnvironment } from "@internal/run-engine/tests"; | ||
| import { containerTest } from "@internal/testcontainers"; | ||
| import { describe, expect, vi } from "vitest"; | ||
| import type { PrismaClient, PrismaReplicaClient } from "~/db.server"; | ||
| import { EnvironmentVariablesRepository } from "~/v3/environmentVariables/environmentVariablesRepository.server"; | ||
|
|
||
| type OpLog = Array<{ label: string; model?: string; operation: string }>; | ||
|
|
||
| function instrument<T>(client: T, label: string, log: OpLog): T { | ||
| return (client as any).$extends({ | ||
| name: `spy-${label}`, | ||
| query: { | ||
| $allOperations({ model, operation, args, query }: any) { | ||
| log.push({ label, model, operation }); | ||
| return query(args); | ||
| }, | ||
| }, | ||
| }) as T; | ||
| } | ||
|
|
||
| vi.setConfig({ testTimeout: 60_000 }); | ||
|
|
||
| describe("EnvironmentVariablesRepository control-plane read routing", () => { | ||
| containerTest( | ||
| "getEnvironmentVariables reads SecretStore from the replica only when readFromReplica is set, returning the same values", | ||
| async ({ prisma }) => { | ||
| const environment = await setupAuthenticatedEnvironment(prisma, "PRODUCTION"); | ||
| const projectId = environment.projectId; | ||
| const environmentId = environment.id; | ||
|
|
||
| await prisma.secretStore.create({ | ||
| data: { | ||
| key: `environmentvariable:${projectId}:${environmentId}:MY_VAR`, | ||
| value: { secret: "hello-from-db" }, | ||
| }, | ||
| }); | ||
|
|
||
| const log: OpLog = []; | ||
| const writer = instrument(prisma, "writer", log) as unknown as PrismaClient; | ||
| const replica = instrument(prisma, "replica", log) as unknown as PrismaReplicaClient; | ||
| const repository = new EnvironmentVariablesRepository(writer, replica); | ||
|
|
||
| log.length = 0; | ||
| const viaReplica = await repository.getEnvironmentVariables( | ||
| projectId, | ||
| environmentId, | ||
| undefined, | ||
| { | ||
| readFromReplica: true, | ||
| } | ||
| ); | ||
| expect(viaReplica).toContainEqual({ key: "MY_VAR", value: "hello-from-db" }); | ||
|
|
||
| const replicaSecretOps = log.filter((l) => l.model === "SecretStore"); | ||
| expect(replicaSecretOps.length).toBeGreaterThan(0); | ||
| expect(replicaSecretOps.every((l) => l.label === "replica")).toBe(true); | ||
| expect(log.some((l) => l.model === "SecretStore" && l.label === "writer")).toBe(false); | ||
|
|
||
| log.length = 0; | ||
| const viaWriter = await repository.getEnvironmentVariables(projectId, environmentId); | ||
| expect(viaWriter).toContainEqual({ key: "MY_VAR", value: "hello-from-db" }); | ||
|
|
||
| const writerSecretOps = log.filter((l) => l.model === "SecretStore"); | ||
| expect(writerSecretOps.length).toBeGreaterThan(0); | ||
| expect(writerSecretOps.every((l) => l.label === "writer")).toBe(true); | ||
| } | ||
| ); | ||
| }); |
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.