Skip to content

Commit dcf8133

Browse files
nicktrnTrigger.dev RepoOps
authored andcommitted
feat(run-engine): count PENDING_EXECUTING stalls by outcome and plan type
Adds a `run_engine.pending_executing.stalls` counter to the run engine, recorded when a run's PENDING_EXECUTING heartbeat deadline passes before it starts, with `outcome` (`requeued` or `dropped`), `environment_type` and `plan_type` attributes. The stalled-snapshot log line now includes the organization, project and environment ids, and a redundant second log line on the same path has been removed. Mono-RevId: 88dc6e40f2f0946042f4a69d92d7c546fa0595b1
1 parent 6dcab1a commit dcf8133

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

  • internal-packages/run-engine/src/engine

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export class RunEngine {
125125
private tracer: Tracer;
126126
private meter: Meter;
127127
private snapshotsSinceReplicaMissCounter: Counter;
128+
private pendingExecutingStallsCounter: Counter;
128129
private snapshotsSinceReplicaRetryDelay: { minMs: number; maxMs: number };
129130
private heartbeatTimeouts: HeartbeatTimeouts;
130131
private repairSnapshotTimeoutMs: number;
@@ -369,6 +370,15 @@ export class RunEngine {
369370
}
370371
);
371372

373+
this.pendingExecutingStallsCounter = this.meter.createCounter(
374+
"run_engine.pending_executing.stalls",
375+
{
376+
description:
377+
"PENDING_EXECUTING snapshots whose heartbeat deadline passed before the run started, by whether the run was requeued or dropped",
378+
unit: "runs",
379+
}
380+
);
381+
372382
// Normalize the bounds, but keep maxMs <= 0 meaning "skip the replica retry".
373383
const retryDelay = options.readReplicaSnapshotsSinceRetryDelay ?? { minMs: 50, maxMs: 200 };
374384
const retryMinMs = Math.max(0, retryDelay.minMs);
@@ -2811,6 +2821,9 @@ export class RunEngine {
28112821
snapshotId: latestSnapshot.id,
28122822
executionStatus: latestSnapshot.executionStatus,
28132823
environmentType: latestSnapshot.environmentType,
2824+
organizationId: latestSnapshot.organizationId,
2825+
projectId: latestSnapshot.projectId,
2826+
environmentId: latestSnapshot.environmentId,
28142827
});
28152828

28162829
switch (latestSnapshot.executionStatus) {
@@ -2824,11 +2837,6 @@ export class RunEngine {
28242837
throw new NotImplementedError("There shouldn't be a heartbeat for QUEUED_EXECUTING");
28252838
}
28262839
case "PENDING_EXECUTING": {
2827-
this.logger.log("RunEngine stalled snapshot PENDING_EXECUTING", {
2828-
runId,
2829-
snapshotId: latestSnapshot.id,
2830-
});
2831-
28322840
//the run didn't start executing, we need to requeue it
28332841
const run = await this.runStore.findRun({ id: runId }, prisma);
28342842

@@ -2846,7 +2854,7 @@ export class RunEngine {
28462854
}
28472855

28482856
//it will automatically be requeued X times depending on the queue retry settings
2849-
await this.runAttemptSystem.tryNackAndRequeue({
2857+
const { wasRequeued } = await this.runAttemptSystem.tryNackAndRequeue({
28502858
run,
28512859
environment: {
28522860
id: latestSnapshot.environmentId,
@@ -2864,6 +2872,13 @@ export class RunEngine {
28642872
},
28652873
tx: prisma,
28662874
});
2875+
2876+
// run.planType rather than billingCache: the cache reports paid when billing is unreachable
2877+
this.pendingExecutingStallsCounter.add(1, {
2878+
outcome: wasRequeued ? "requeued" : "dropped",
2879+
environment_type: latestSnapshot.environmentType,
2880+
plan_type: run.planType ?? "unknown",
2881+
});
28672882
break;
28682883
}
28692884
case "EXECUTING":

0 commit comments

Comments
 (0)