-
Notifications
You must be signed in to change notification settings - Fork 11
fix: stabilize release creation and add e2e #518
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| import _ from "lodash"; | ||
|
|
||
| import { eq } from "@ctrlplane/db"; | ||
| import { db } from "@ctrlplane/db/client"; | ||
| import * as schema from "@ctrlplane/db/schema"; | ||
| import { Channel, createWorker, getQueue } from "@ctrlplane/events"; | ||
|
|
||
| import { withSpan } from "./span.js"; | ||
|
|
@@ -24,14 +27,32 @@ export const updatedResourceWorker = createWorker( | |
| span.setAttribute("resource.name", resource.name); | ||
| span.setAttribute("workspace.id", resource.workspaceId); | ||
|
|
||
| await getQueue(Channel.ComputeDeploymentResourceSelector).add( | ||
| resource.id, | ||
| resource, | ||
| const workspace = await db.query.workspace.findFirst({ | ||
| where: eq(schema.workspace.id, resource.workspaceId), | ||
| with: { systems: { with: { environments: true, deployments: true } } }, | ||
| }); | ||
|
|
||
| if (workspace == null) throw new Error("Workspace not found"); | ||
|
|
||
| const deploymentJobs = workspace.systems.flatMap((system) => | ||
| system.deployments.map((deployment) => ({ | ||
| name: deployment.id, | ||
| data: deployment, | ||
| })), | ||
| ); | ||
|
|
||
| await getQueue(Channel.ComputeEnvironmentResourceSelector).add( | ||
| resource.id, | ||
| resource, | ||
| const environmentJobs = workspace.systems.flatMap((system) => | ||
| system.environments.map((environment) => ({ | ||
| name: environment.id, | ||
| data: environment, | ||
| })), | ||
| ); | ||
|
|
||
| await getQueue(Channel.ComputeDeploymentResourceSelector).addBulk( | ||
| deploymentJobs, | ||
| ); | ||
| await getQueue(Channel.ComputeEnvironmentResourceSelector).addBulk( | ||
| environmentJobs, | ||
| ); | ||
|
Comment on lines
+30
to
56
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainConsider potential performance impact for large workspaces. The new implementation fetches all systems, environments, and deployments for a workspace, which could be resource-intensive for workspaces with many entities. Consider implementing pagination or limiting the query if performance becomes an issue. Additionally, you might want to add some basic logging to indicate the number of jobs being processed, which would be helpful for monitoring. 🏁 Script executed: #!/bin/bash
# Check if there are workspaces with many systems, deployments, or environments that might cause performance issues
# Find workspaces with large numbers of systems
echo "Workspaces with many systems:"
rg -l "systems:" --type ts | xargs grep -l "findFirst" | xargs grep -l "workspace" | head -n 5
# Check if there are other places in the codebase where similar bulk queries are performed
echo "Similar bulk queries in the codebase:"
rg -A 3 "with: \{ systems: \{ with:" --type tsLength of output: 769 Add performance guardrails and logging for bulk job processing This handler eagerly loads every system, environment, and deployment for a workspace—which could exhaust memory or slow down the worker when a workspace grows large. To mitigate: • In apps/event-worker/src/workers/updated-resources/index.ts (around line 30): • For very large workspaces, consider paginating the DB query (using These changes will keep memory and response times bounded and give you visibility into workload spikes. |
||
| }), | ||
| ); | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Type safety:
dispatchEvaluateJobsexpects identifiers onlydispatchEvaluateJobsserialises every field inrtsonto the queue.If
tx.query.releaseTarget.findManyincludes heavy columns (timestamps, JSON blobs), you’ll bloat the job payload.Consider projecting only
{ deploymentId, environmentId, resourceId }before dispatching.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not really a concern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adityachoudhari26 Understood! I appreciate the clarification. I'll defer to your judgment on this since you have a better understanding of the system's requirements and performance characteristics.