-
-
Notifications
You must be signed in to change notification settings - Fork 985
feat(dashboard): Display environment queue length limits on queues and limits page #2980
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
base: main
Are you sure you want to change the base?
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,4 +1,5 @@ | ||||||||||||||||||||||||||||||||
| import { Ratelimit } from "@upstash/ratelimit"; | ||||||||||||||||||||||||||||||||
| import { RuntimeEnvironmentType } from "@trigger.dev/database"; | ||||||||||||||||||||||||||||||||
| import { createHash } from "node:crypto"; | ||||||||||||||||||||||||||||||||
| import { env } from "~/env.server"; | ||||||||||||||||||||||||||||||||
| import { getCurrentPlan } from "~/services/platform.v3.server"; | ||||||||||||||||||||||||||||||||
|
|
@@ -12,6 +13,8 @@ import { BasePresenter } from "./basePresenter.server"; | |||||||||||||||||||||||||||||||
| import { singleton } from "~/utils/singleton"; | ||||||||||||||||||||||||||||||||
| import { logger } from "~/services/logger.server"; | ||||||||||||||||||||||||||||||||
| import { CheckScheduleService } from "~/v3/services/checkSchedule.server"; | ||||||||||||||||||||||||||||||||
| import { engine } from "~/v3/runEngine.server"; | ||||||||||||||||||||||||||||||||
| import { getQueueSizeLimit, getQueueSizeLimitSource } from "~/v3/utils/queueLimits.server"; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Create a singleton Redis client for rate limit queries | ||||||||||||||||||||||||||||||||
| const rateLimitRedisClient = singleton("rateLimitQueryRedisClient", () => | ||||||||||||||||||||||||||||||||
|
|
@@ -66,8 +69,7 @@ export type LimitsResult = { | |||||||||||||||||||||||||||||||
| logRetentionDays: QuotaInfo | null; | ||||||||||||||||||||||||||||||||
| realtimeConnections: QuotaInfo | null; | ||||||||||||||||||||||||||||||||
| batchProcessingConcurrency: QuotaInfo; | ||||||||||||||||||||||||||||||||
| devQueueSize: QuotaInfo; | ||||||||||||||||||||||||||||||||
| deployedQueueSize: QuotaInfo; | ||||||||||||||||||||||||||||||||
| queueSize: QuotaInfo; | ||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||
| features: { | ||||||||||||||||||||||||||||||||
| hasStagingEnvironment: FeatureInfo; | ||||||||||||||||||||||||||||||||
|
|
@@ -84,11 +86,13 @@ export class LimitsPresenter extends BasePresenter { | |||||||||||||||||||||||||||||||
| organizationId, | ||||||||||||||||||||||||||||||||
| projectId, | ||||||||||||||||||||||||||||||||
| environmentId, | ||||||||||||||||||||||||||||||||
| environmentType, | ||||||||||||||||||||||||||||||||
| environmentApiKey, | ||||||||||||||||||||||||||||||||
| }: { | ||||||||||||||||||||||||||||||||
| organizationId: string; | ||||||||||||||||||||||||||||||||
| projectId: string; | ||||||||||||||||||||||||||||||||
| environmentId: string; | ||||||||||||||||||||||||||||||||
| environmentType: RuntimeEnvironmentType; | ||||||||||||||||||||||||||||||||
| environmentApiKey: string; | ||||||||||||||||||||||||||||||||
| }): Promise<LimitsResult> { | ||||||||||||||||||||||||||||||||
| // Get organization with all limit-related fields | ||||||||||||||||||||||||||||||||
|
|
@@ -167,6 +171,30 @@ export class LimitsPresenter extends BasePresenter { | |||||||||||||||||||||||||||||||
| batchRateLimitConfig | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Get current queue size for this environment | ||||||||||||||||||||||||||||||||
| // We need the runtime environment fields for the engine query | ||||||||||||||||||||||||||||||||
| const runtimeEnv = await this._replica.runtimeEnvironment.findFirst({ | ||||||||||||||||||||||||||||||||
| where: { id: environmentId }, | ||||||||||||||||||||||||||||||||
| select: { | ||||||||||||||||||||||||||||||||
| id: true, | ||||||||||||||||||||||||||||||||
| maximumConcurrencyLimit: true, | ||||||||||||||||||||||||||||||||
| concurrencyLimitBurstFactor: true, | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| let currentQueueSize = 0; | ||||||||||||||||||||||||||||||||
| if (runtimeEnv) { | ||||||||||||||||||||||||||||||||
| const engineEnv = { | ||||||||||||||||||||||||||||||||
| id: runtimeEnv.id, | ||||||||||||||||||||||||||||||||
| type: environmentType, | ||||||||||||||||||||||||||||||||
| maximumConcurrencyLimit: runtimeEnv.maximumConcurrencyLimit, | ||||||||||||||||||||||||||||||||
| concurrencyLimitBurstFactor: runtimeEnv.concurrencyLimitBurstFactor, | ||||||||||||||||||||||||||||||||
| organization: { id: organizationId }, | ||||||||||||||||||||||||||||||||
| project: { id: projectId }, | ||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||
| currentQueueSize = (await engine.lengthOfEnvQueue(engineEnv)) ?? 0; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Get plan-level limits | ||||||||||||||||||||||||||||||||
| const schedulesLimit = limits?.schedules?.number ?? null; | ||||||||||||||||||||||||||||||||
| const teamMembersLimit = limits?.teamMembers?.number ?? null; | ||||||||||||||||||||||||||||||||
|
|
@@ -282,19 +310,12 @@ export class LimitsPresenter extends BasePresenter { | |||||||||||||||||||||||||||||||
| canExceed: true, | ||||||||||||||||||||||||||||||||
| isUpgradable: true, | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| devQueueSize: { | ||||||||||||||||||||||||||||||||
| name: "Dev queue size", | ||||||||||||||||||||||||||||||||
| description: "Maximum pending runs in development environments", | ||||||||||||||||||||||||||||||||
| limit: organization.maximumDevQueueSize ?? null, | ||||||||||||||||||||||||||||||||
| currentUsage: 0, // Would need to query Redis for this | ||||||||||||||||||||||||||||||||
| source: organization.maximumDevQueueSize ? "override" : "default", | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| deployedQueueSize: { | ||||||||||||||||||||||||||||||||
| name: "Deployed queue size", | ||||||||||||||||||||||||||||||||
| description: "Maximum pending runs in deployed environments", | ||||||||||||||||||||||||||||||||
| limit: organization.maximumDeployedQueueSize ?? null, | ||||||||||||||||||||||||||||||||
| currentUsage: 0, // Would need to query Redis for this | ||||||||||||||||||||||||||||||||
| source: organization.maximumDeployedQueueSize ? "override" : "default", | ||||||||||||||||||||||||||||||||
| queueSize: { | ||||||||||||||||||||||||||||||||
| name: "Max queued runs", | ||||||||||||||||||||||||||||||||
| description: "Maximum pending runs across all queues in this environment", | ||||||||||||||||||||||||||||||||
| limit: getQueueSizeLimit(environmentType, organization), | ||||||||||||||||||||||||||||||||
| currentUsage: currentQueueSize, | ||||||||||||||||||||||||||||||||
| source: getQueueSizeLimitSource(environmentType, organization), | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
|
Comment on lines
+313
to
319
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. Queue-size quota never shows an upgrade action.
💡 Suggested change queueSize: {
name: "Max queued runs",
description: "Maximum pending runs across all queues in this environment",
limit: getQueueSizeLimit(environmentType, organization),
currentUsage: currentQueueSize,
source: getQueueSizeLimitSource(environmentType, organization),
+ isUpgradable: true,
},📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| features: { | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { RuntimeEnvironmentType } from "@trigger.dev/database"; | ||
| import { env } from "~/env.server"; | ||
|
|
||
| /** | ||
| * Organization fields needed for queue limit calculation. | ||
| */ | ||
| export type QueueLimitOrganization = { | ||
| maximumDevQueueSize: number | null; | ||
| maximumDeployedQueueSize: number | null; | ||
| }; | ||
|
|
||
| /** | ||
| * Calculates the queue size limit for an environment based on its type and organization settings. | ||
| * | ||
| * Resolution order: | ||
| * 1. Organization-level override (set by billing sync or admin) | ||
| * 2. Environment variable fallback | ||
| * 3. null if neither is set | ||
| * | ||
| * @param environmentType - The type of the runtime environment | ||
| * @param organization - Organization with queue limit fields | ||
| * @returns The queue size limit, or null if unlimited | ||
| */ | ||
| export function getQueueSizeLimit( | ||
| environmentType: RuntimeEnvironmentType, | ||
| organization: QueueLimitOrganization | ||
| ): number | null { | ||
| if (environmentType === "DEVELOPMENT") { | ||
| return organization.maximumDevQueueSize ?? env.MAXIMUM_DEV_QUEUE_SIZE ?? null; | ||
| } | ||
|
|
||
| return organization.maximumDeployedQueueSize ?? env.MAXIMUM_DEPLOYED_QUEUE_SIZE ?? null; | ||
| } | ||
|
|
||
| /** | ||
| * Determines the source of the queue size limit for display purposes. | ||
| * | ||
| * @param environmentType - The type of the runtime environment | ||
| * @param organization - Organization with queue limit fields | ||
| * @returns "plan" if org has a value (typically set by billing), "default" if using env var fallback | ||
| */ | ||
| export function getQueueSizeLimitSource( | ||
| environmentType: RuntimeEnvironmentType, | ||
| organization: QueueLimitOrganization | ||
| ): "plan" | "default" { | ||
| if (environmentType === "DEVELOPMENT") { | ||
| return organization.maximumDevQueueSize !== null ? "plan" : "default"; | ||
| } | ||
|
|
||
| return organization.maximumDeployedQueueSize !== null ? "plan" : "default"; | ||
| } |
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.
Defaulting
MAXIMUM_DEV_QUEUE_SIZEchanges enforcement behavior.This turns previously-unlimited dev environments into a hard 500-queue cap (via
guardQueueSizeLimitsForEnv). If that’s not intentional, remove the default and require an explicit env var to enable the limit.💡 Suggested change (avoid unintended hard limit)
📝 Committable suggestion
🤖 Prompt for AI Agents