Skip to content

Commit c732784

Browse files
committed
fix(run-engine,webapp,clickhouse): review fixes for the metrics tier
The plain dequeue gauge re-samples after admissions like the keyed one, the repair path clears a keyed run's variant and group slots by concurrency key, pause responses include the combined limit, stale wording and a leftover changeset from before the rename are cleaned up, and two empty flag blocks are removed from the fast-path scripts.
1 parent adb472e commit c732784

5 files changed

Lines changed: 32 additions & 14 deletions

File tree

‎apps/webapp/app/v3/querySchemas.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,7 @@ const queueMetricsByKeySchema: TableSchema = {
14261426
name: "max_limit",
14271427
...column("UInt32", {
14281428
description:
1429-
"The queue concurrency limit that applied to this key in the bucket. Aggregate with max().",
1429+
"The queue concurrency limit that applied to this key in the bucket (1000000 = no explicit limit). Aggregate with max().",
14301430
fillMode: "carry",
14311431
}),
14321432
},

‎apps/webapp/app/v3/services/pauseQueue.server.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ export class PauseQueueService extends BaseService {
9292
concurrencyLimitOverriddenAt: updatedQueue.concurrencyLimitOverriddenAt ?? null,
9393
concurrencyLimitOverriddenBy: queue.concurrencyLimitOverriddenBy ?? null,
9494
paused: updatedQueue.paused,
95+
totalConcurrencyLimit: updatedQueue.totalConcurrencyLimit ?? null,
96+
totalConcurrencyLimitBase: updatedQueue.totalConcurrencyLimitBase ?? null,
97+
totalConcurrencyLimitOverriddenAt: updatedQueue.totalConcurrencyLimitOverriddenAt ?? null,
9598
}),
9699
};
97100
} catch (error) {

‎internal-packages/clickhouse/schema/042_add_queue_metrics_combined_concurrency.sql‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
-- Total-concurrency gauges: combined_running is the in-flight count across ALL
44
-- concurrency-key variants of a queue (the groupConcurrency set), combined_limit the
55
-- RAW stored total cap (0 = none, readers clamp against max_env_limit). Emitted on
6-
-- base-queue gauge rows only. Per-key gauge rows now carry the EFFECTIVE per-key
7-
-- limit in queue_limit, surfaced in the ck tier as max_limit.
6+
-- base-queue gauge rows only. Per-key gauge rows carry the queue concurrency
7+
-- limit that applied in queue_limit, surfaced in the ck tier as max_limit
8+
-- (1000000 = no explicit limit).
89

910
ALTER TABLE trigger_dev.queue_metrics_raw_v1
1011
ADD COLUMN IF NOT EXISTS combined_running UInt32 DEFAULT 0,

‎internal-packages/run-engine/src/engine/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3001,6 +3001,7 @@ export class RunEngine {
30013001
{
30023002
select: {
30033003
queue: true,
3004+
concurrencyKey: true,
30043005
},
30053006
},
30063007
this.prisma
@@ -3022,6 +3023,7 @@ export class RunEngine {
30223023
runId,
30233024
orgId: latestSnapshot.organizationId,
30243025
queue: taskRun.queue,
3026+
concurrencyKey: taskRun.concurrencyKey ?? undefined,
30253027
env: {
30263028
id: latestSnapshot.environmentId,
30273029
type: latestSnapshot.environmentType,

‎internal-packages/run-engine/src/run-queue/index.ts‎

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,6 @@ export type RunQueueOptions = {
349349
* the total cap covering releases from builds without the mirror.
350350
*/
351351
gatesEnabled?: boolean;
352-
/** Cap on per-concurrency-key limit overrides stored per queue. Default 1000. */
353352
workerOptions?: {
354353
pollIntervalMs?: number;
355354
immediatePollIntervalMs?: number;
@@ -1567,6 +1566,7 @@ export class RunQueue {
15671566
runId: string;
15681567
orgId: string;
15691568
queue: string;
1569+
concurrencyKey?: string;
15701570
env: RunQueueKeyProducerEnvironment;
15711571
}) {
15721572
return this.#callClearMessageFromConcurrencySets(params);
@@ -3108,18 +3108,30 @@ export class RunQueue {
31083108
runId,
31093109
orgId,
31103110
queue,
3111+
concurrencyKey,
31113112
env,
31123113
}: {
31133114
runId: string;
31143115
orgId: string;
31153116
queue: string;
3117+
concurrencyKey?: string;
31163118
env: RunQueueKeyProducerEnvironment;
31173119
}) {
31183120
const messageId = runId;
31193121
const messageKey = this.keys.messageKey(orgId, messageId);
3120-
const queueCurrentConcurrencyKey = this.keys.queueCurrentConcurrencyKey(env, queue);
3122+
/**
3123+
* Callers pass the bare TaskRun queue name plus its concurrencyKey; the run's
3124+
* slots live on the ck variant, and the tracked clear additionally mirrors the
3125+
* group set and counters that only keyed queues maintain.
3126+
*/
3127+
const fullQueue = concurrencyKey ? this.keys.queueKey(env, queue, concurrencyKey) : queue;
3128+
const queueCurrentConcurrencyKey = this.keys.queueCurrentConcurrencyKey(
3129+
env,
3130+
queue,
3131+
concurrencyKey
3132+
);
31213133
const envCurrentConcurrencyKey = this.keys.envCurrentConcurrencyKey(env);
3122-
const queueCurrentDequeuedKey = this.keys.queueCurrentDequeuedKey(env, queue);
3134+
const queueCurrentDequeuedKey = this.keys.queueCurrentDequeuedKey(env, queue, concurrencyKey);
31233135
const envCurrentDequeuedKey = this.keys.envCurrentDequeuedKey(env);
31243136

31253137
this.logger.debug("Calling clearMessageFromConcurrencySets", {
@@ -3134,15 +3146,15 @@ export class RunQueue {
31343146
service: this.name,
31353147
});
31363148

3137-
if (queue.includes(":ck:")) {
3149+
if (fullQueue.includes(":ck:")) {
31383150
return this.redis.clearMessageFromConcurrencySetsTracked(
31393151
queueCurrentConcurrencyKey,
31403152
envCurrentConcurrencyKey,
31413153
queueCurrentDequeuedKey,
31423154
envCurrentDequeuedKey,
3143-
this.keys.queueRunningCounterKeyFromQueue(queue),
3144-
this.keys.ckIndexKeyFromQueue(queue),
3145-
this.keys.queueGroupConcurrencyKeyFromQueue(queue),
3155+
this.keys.queueRunningCounterKeyFromQueue(fullQueue),
3156+
this.keys.ckIndexKeyFromQueue(fullQueue),
3157+
this.keys.queueGroupConcurrencyKeyFromQueue(fullQueue),
31463158
messageKey,
31473159
messageId,
31483160
this.options.redis.keyPrefix ?? "",
@@ -4229,8 +4241,6 @@ if enableFastPath == '1' then
42294241
tonumber(redis.call('GET', queueConcurrencyLimitKey) or '1000000'),
42304242
envLimit
42314243
)
4232-
if totalConcurrencyEnabled then
4233-
end
42344244
42354245
if queueCurrent < queueLimit then
42364246
-- Total-cap gate: a fast-path admit consumes a group slot, so it must
@@ -4404,8 +4414,6 @@ if enableFastPath == '1' then
44044414
tonumber(redis.call('GET', queueConcurrencyLimitKey) or '1000000'),
44054415
envLimit
44064416
)
4407-
if totalConcurrencyEnabled then
4408-
end
44094417
44104418
if queueCurrent < queueLimit then
44114419
-- Total-cap gate: see enqueueMessageCkTracked.
@@ -4900,6 +4908,10 @@ else
49004908
redis.call('ZADD', masterQueueKey, earliestMessage[2], queueName)
49014909
end
49024910
4911+
-- Re-sample the gauge so the emitted snapshot includes this batch's admissions;
4912+
-- the top-of-script sample only covers the early returns where nothing was admitted.
4913+
${QUEUE_METRICS_GAUGE_LUA}
4914+
49034915
-- Return results as a flat array: [messageId1, messageScore1, messagePayload1, messageId2, messageScore2, messagePayload2, ...]
49044916
return __qmret(results)
49054917
`,

0 commit comments

Comments
 (0)