Skip to content

Commit d0409fe

Browse files
committed
feat(supervisor): set op + kind on all wide events
1 parent 5ffe5f0 commit d0409fe

4 files changed

Lines changed: 29 additions & 2 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: supervisor
3+
type: improvement
4+
---
5+
6+
Tag every supervisor structured event with `op` and `kind` fields for consistent filtering and aggregation.

apps/supervisor/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ class ManagedSupervisor {
269269
setMeta(state, "deployment_id", message.deployment.friendlyId);
270270
}
271271
setMeta(state, "machine_preset", message.run.machine.name);
272+
state.extras.op = "dequeue";
273+
state.extras.kind = "inbound";
272274
state.extras.iteration = "dequeue";
273275
state.extras.dequeue_response_ms = dequeueResponseMs;
274276
state.extras.polling_interval_ms = pollingIntervalMs;

apps/supervisor/src/services/computeSnapshotService.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export class ComputeSnapshotService {
7878
...this.wideEventOpts,
7979
populate: (state) => {
8080
state.extras.op = "snapshot.schedule";
81+
state.extras.kind = "event";
8182
state.meta.run_id = runFriendlyId;
8283
state.meta.snapshot_id = data.snapshotFriendlyId;
8384
state.extras.runner_id = data.runnerId;
@@ -99,6 +100,7 @@ export class ComputeSnapshotService {
99100
...this.wideEventOpts,
100101
populate: (state) => {
101102
state.extras.op = "snapshot.canceled";
103+
state.extras.kind = "event";
102104
state.meta.run_id = runFriendlyId;
103105
},
104106
});
@@ -247,6 +249,7 @@ export class ComputeSnapshotService {
247249
...this.wideEventOpts,
248250
setup: (state) => {
249251
state.extras.op = "snapshot.dispatch";
252+
state.extras.kind = "scheduled";
250253
state.meta.run_id = snapshot.runFriendlyId;
251254
state.meta.snapshot_id = snapshot.snapshotFriendlyId;
252255
state.extras.runner_id = snapshot.runnerId;

apps/supervisor/src/workloadServer/index.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
184184
*/
185185
private wideRoute<T>(
186186
ctx: { req: IncomingMessage; res: ServerResponse; params?: unknown },
187+
op: string,
187188
route: string,
188189
method: string,
189190
fn: () => Promise<T> | T,
@@ -199,7 +200,11 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
199200
method,
200201
traceparent: this.headerValueFromRequest(ctx.req, "traceparent"),
201202
inboundRequestId: this.headerValueFromRequest(ctx.req, "x-request-id"),
202-
setup: (state) => this.attachRouteMeta(state, ctx.params),
203+
setup: (state) => {
204+
state.extras.op = op;
205+
state.extras.kind = "inbound";
206+
this.attachRouteMeta(state, ctx.params);
207+
},
203208
},
204209
fn,
205210
(state) => {
@@ -231,6 +236,7 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
231236
handler: async (ctx) =>
232237
this.wideRoute(
233238
ctx,
239+
"attempt.start",
234240
"/api/v1/workload-actions/runs/:runFriendlyId/snapshots/:snapshotFriendlyId/attempts/start",
235241
"POST",
236242
async () => {
@@ -266,6 +272,7 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
266272
handler: async (ctx) =>
267273
this.wideRoute(
268274
ctx,
275+
"attempt.complete",
269276
"/api/v1/workload-actions/runs/:runFriendlyId/snapshots/:snapshotFriendlyId/attempts/complete",
270277
"POST",
271278
async () => {
@@ -303,6 +310,7 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
303310
handler: async (ctx) =>
304311
this.wideRoute(
305312
ctx,
313+
"heartbeat",
306314
"/api/v1/workload-actions/runs/:runFriendlyId/snapshots/:snapshotFriendlyId/heartbeat",
307315
"POST",
308316
async () => {
@@ -339,6 +347,7 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
339347
handler: async (ctx) =>
340348
this.wideRoute(
341349
ctx,
350+
"suspend",
342351
"/api/v1/workload-actions/runs/:runFriendlyId/snapshots/:snapshotFriendlyId/suspend",
343352
"GET",
344353
async () => {
@@ -434,6 +443,7 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
434443
handler: async (ctx) =>
435444
this.wideRoute(
436445
ctx,
446+
"continue",
437447
"/api/v1/workload-actions/runs/:runFriendlyId/snapshots/:snapshotFriendlyId/continue",
438448
"GET",
439449
async () => {
@@ -475,6 +485,7 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
475485
handler: async (ctx) =>
476486
this.wideRoute(
477487
ctx,
488+
"snapshots.since",
478489
"/api/v1/workload-actions/runs/:runFriendlyId/snapshots/since/:snapshotFriendlyId",
479490
"GET",
480491
async () => {
@@ -510,6 +521,7 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
510521
handler: async (ctx) =>
511522
this.wideRoute(
512523
ctx,
524+
"deployment.dequeue",
513525
"/api/v1/workload-actions/deployments/:deploymentId/dequeue",
514526
"GET",
515527
async () => {
@@ -541,6 +553,7 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
541553
handler: async (ctx) =>
542554
this.wideRoute(
543555
ctx,
556+
"logs.debug",
544557
"/api/v1/workload-actions/runs/:runFriendlyId/logs/debug",
545558
"POST",
546559
async () => {
@@ -562,6 +575,7 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
562575
handler: async (ctx) =>
563576
this.wideRoute(
564577
ctx,
578+
"logs.debug",
565579
"/api/v1/workload-actions/runs/:runFriendlyId/logs/debug",
566580
"POST",
567581
async () => {
@@ -576,7 +590,7 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
576590
httpServer.route("/api/v1/compute/snapshot-complete", "POST", {
577591
bodySchema: SnapshotCallbackPayloadSchema,
578592
handler: async (ctx) =>
579-
this.wideRoute(ctx, "/api/v1/compute/snapshot-complete", "POST", async () => {
593+
this.wideRoute(ctx, "snapshot.callback", "/api/v1/compute/snapshot-complete", "POST", async () => {
580594
const { reply, body } = ctx;
581595
if (!this.snapshotService) {
582596
reply.empty(404);
@@ -666,6 +680,8 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
666680
emitOneShot({
667681
...this.wideEventOpts,
668682
populate: (state) => {
683+
state.extras.op = event === "run_connected" ? "socket.run.connected" : "socket.run.disconnected";
684+
state.extras.kind = "event";
669685
state.extras.event = event;
670686
setMeta(state, "run_id", friendlyId);
671687
if (socket.data.deploymentId) {

0 commit comments

Comments
 (0)