Skip to content

Commit 4866cfe

Browse files
committed
feat(supervisor): set op + kind on all wide events
1 parent 9a3a6b1 commit 4866cfe

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
@@ -196,6 +196,7 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
196196
*/
197197
private wideRoute<T>(
198198
ctx: { req: IncomingMessage; res: ServerResponse; params?: unknown },
199+
op: string,
199200
route: string,
200201
method: string,
201202
fn: () => Promise<T> | T,
@@ -211,7 +212,11 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
211212
method,
212213
traceparent: this.headerValueFromRequest(ctx.req, "traceparent"),
213214
inboundRequestId: this.headerValueFromRequest(ctx.req, "x-request-id"),
214-
setup: (state) => this.attachRouteMeta(state, ctx.params),
215+
setup: (state) => {
216+
state.extras.op = op;
217+
state.extras.kind = "inbound";
218+
this.attachRouteMeta(state, ctx.params);
219+
},
215220
},
216221
fn,
217222
(state) => {
@@ -243,6 +248,7 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
243248
handler: async (ctx) =>
244249
this.wideRoute(
245250
ctx,
251+
"attempt.start",
246252
"/api/v1/workload-actions/runs/:runFriendlyId/snapshots/:snapshotFriendlyId/attempts/start",
247253
"POST",
248254
async () => {
@@ -278,6 +284,7 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
278284
handler: async (ctx) =>
279285
this.wideRoute(
280286
ctx,
287+
"attempt.complete",
281288
"/api/v1/workload-actions/runs/:runFriendlyId/snapshots/:snapshotFriendlyId/attempts/complete",
282289
"POST",
283290
async () => {
@@ -315,6 +322,7 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
315322
handler: async (ctx) =>
316323
this.wideRoute(
317324
ctx,
325+
"heartbeat",
318326
"/api/v1/workload-actions/runs/:runFriendlyId/snapshots/:snapshotFriendlyId/heartbeat",
319327
"POST",
320328
async () => {
@@ -351,6 +359,7 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
351359
handler: async (ctx) =>
352360
this.wideRoute(
353361
ctx,
362+
"suspend",
354363
"/api/v1/workload-actions/runs/:runFriendlyId/snapshots/:snapshotFriendlyId/suspend",
355364
"GET",
356365
async () => {
@@ -446,6 +455,7 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
446455
handler: async (ctx) =>
447456
this.wideRoute(
448457
ctx,
458+
"continue",
449459
"/api/v1/workload-actions/runs/:runFriendlyId/snapshots/:snapshotFriendlyId/continue",
450460
"GET",
451461
async () => {
@@ -487,6 +497,7 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
487497
handler: async (ctx) =>
488498
this.wideRoute(
489499
ctx,
500+
"snapshots.since",
490501
"/api/v1/workload-actions/runs/:runFriendlyId/snapshots/since/:snapshotFriendlyId",
491502
"GET",
492503
async () => {
@@ -522,6 +533,7 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
522533
handler: async (ctx) =>
523534
this.wideRoute(
524535
ctx,
536+
"deployment.dequeue",
525537
"/api/v1/workload-actions/deployments/:deploymentId/dequeue",
526538
"GET",
527539
async () => {
@@ -555,6 +567,7 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
555567
handler: async (ctx) =>
556568
this.wideRoute(
557569
ctx,
570+
"logs.debug",
558571
"/api/v1/workload-actions/runs/:runFriendlyId/logs/debug",
559572
"POST",
560573
async () => {
@@ -576,6 +589,7 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
576589
handler: async (ctx) =>
577590
this.wideRoute(
578591
ctx,
592+
"logs.debug",
579593
"/api/v1/workload-actions/runs/:runFriendlyId/logs/debug",
580594
"POST",
581595
async () => {
@@ -590,7 +604,7 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
590604
httpServer.route("/api/v1/compute/snapshot-complete", "POST", {
591605
bodySchema: SnapshotCallbackPayloadSchema,
592606
handler: async (ctx) =>
593-
this.wideRoute(ctx, "/api/v1/compute/snapshot-complete", "POST", async () => {
607+
this.wideRoute(ctx, "snapshot.callback", "/api/v1/compute/snapshot-complete", "POST", async () => {
594608
const { reply, body } = ctx;
595609
if (!this.snapshotService) {
596610
reply.empty(404);
@@ -680,6 +694,8 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
680694
emitOneShot({
681695
...this.wideEventOpts,
682696
populate: (state) => {
697+
state.extras.op = event === "run_connected" ? "socket.run.connected" : "socket.run.disconnected";
698+
state.extras.kind = "event";
683699
state.extras.event = event;
684700
setMeta(state, "run_id", friendlyId);
685701
if (socket.data.deploymentId) {

0 commit comments

Comments
 (0)