Skip to content

Commit 2792023

Browse files
committed
feat(gateway): persist event loop degradation metrics
1 parent f4766de commit 2792023

30 files changed

Lines changed: 1237 additions & 71 deletions

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,6 +1836,7 @@
18361836
"test:force": "node --import tsx scripts/test-force.ts",
18371837
"test:gateway": "node scripts/run-with-env.mjs OPENCLAW_GATEWAY_PROJECT_SHARDS=1 -- node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway.config.ts",
18381838
"test:gateway:cpu-scenarios": "node scripts/check-gateway-cpu-scenarios.mjs",
1839+
"test:gateway:concurrency": "node --import tsx scripts/bench-gateway-concurrency.ts",
18391840
"test:gateway:memory-fd-repro": "node scripts/check-memory-fd-repro.mjs",
18401841
"test:gateway:watch-regression": "node scripts/check-gateway-watch-regression.mjs",
18411842
"test:install:e2e": "bash scripts/test-install-sh-e2e-docker.sh",

‎packages/gateway-protocol/src/channels.schema.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ describe("ChannelsStatusResultSchema", () => {
7171
warnings: ["discord:default probe timed out after 1000ms"],
7272
eventLoop: {
7373
degraded: true,
74+
degradedSinceMs: 61_000,
7475
reasons: ["event_loop_delay", "cpu"],
7576
intervalMs: 62_000,
7677
delayP99Ms: 1_250.5,

‎packages/gateway-protocol/src/schema/channels.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@ const ChannelUiMetaSchema = closedObject({
701701
/** Event-loop health snapshot included with channel status responses. */
702702
const ChannelEventLoopHealthSchema = closedObject({
703703
degraded: Type.Boolean(),
704+
degradedSinceMs: Type.Optional(Type.Union([Type.Integer({ minimum: 0 }), Type.Null()])),
704705
reasons: Type.Array(
705706
Type.Union([
706707
Type.Literal("event_loop_delay"),

‎packages/gateway-protocol/src/schema/snapshot.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,24 @@ describe("SnapshotSchema", () => {
4040
),
4141
).toBe(true);
4242
});
43+
44+
it("accepts persistent event-loop health duration", () => {
45+
const snapshot = {
46+
...snapshotWithPresence({ ts: 1 }),
47+
health: {
48+
eventLoop: {
49+
degraded: true,
50+
degradedSinceMs: 61_000,
51+
reasons: ["event_loop_delay"],
52+
intervalMs: 30_000,
53+
delayP99Ms: 1_200,
54+
delayMaxMs: 1_500,
55+
utilization: 0.75,
56+
cpuCoreRatio: 0.5,
57+
},
58+
},
59+
};
60+
61+
expect(Value.Check(SnapshotSchema, snapshot)).toBe(true);
62+
});
4363
});

‎packages/gateway-protocol/src/schema/snapshot.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const HealthSnapshotSchema = closedObject({
6262
eventLoop: Type.Optional(
6363
closedObject({
6464
degraded: Type.Boolean(),
65+
degradedSinceMs: Type.Optional(Type.Union([Type.Integer({ minimum: 0 }), Type.Null()])),
6566
reasons: Type.Array(
6667
Type.Union([
6768
Type.Literal("event_loop_delay"),

‎packages/terminal-core/src/health-style.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export function styleHealthChannelLine(line: string, rich: boolean): string {
2525
if (normalized.startsWith("failed")) {
2626
return applyPrefix("failed", theme.error);
2727
}
28+
if (normalized.startsWith("degraded")) {
29+
return applyPrefix("degraded", theme.warn);
30+
}
2831
if (normalized.startsWith("ok")) {
2932
return applyPrefix("ok", theme.success);
3033
}

0 commit comments

Comments
 (0)