feat: add performance summary time windows

This commit is contained in:
lyon
2026-06-20 00:29:13 +08:00
parent 78113de2f2
commit c189270fca
6 changed files with 279 additions and 31 deletions
+36
View File
@@ -54,6 +54,42 @@ test("web performance summary exposes user-perceived route latency without high-
assert.doesNotMatch(json, /trc_secret|sessionId|conversationId|threadId|prompt|api key/iu);
});
test("web performance summary filters rows by requested recent window", () => {
let nowMs = 0;
const store = createWebPerformanceStore({
env: { HWLAB_METRICS_NAMESPACE: "hwlab-v03", HWLAB_GITOPS_TARGET: "v03" },
now: () => nowMs
});
nowMs = 1_000;
store.record({
schemaVersion: "hwlab-web-performance-v1",
page: "/workbench",
events: [{ kind: "api", metric: "api_request", route: "/v1/workbench/sessions", method: "GET", status: 200, statusClass: "2xx", outcome: "ok", valueMs: 2600, traceId: "trc_old_secret" }]
} as Record<string, unknown>);
nowMs = 20 * 60 * 1000;
store.record({
schemaVersion: "hwlab-web-performance-v1",
page: "/workbench",
events: [{ kind: "api", metric: "api_request", route: "/v1/workbench/sessions", method: "GET", status: 200, statusClass: "2xx", outcome: "ok", valueMs: 320, traceId: "trc_new_secret" }]
} as Record<string, unknown>);
const recent = store.summary({ window: "5m" });
const all = store.summary({ window: "all" });
const recentJson = JSON.stringify(recent);
const allJson = JSON.stringify(all);
assert.equal(recent.sampleWindow.id, "5m");
assert.equal(recent.summary.sampleCount, 1);
assert.equal(recent.apiRoutes[0].p95, 0.5);
assert.equal(all.sampleWindow.id, "all");
assert.equal(all.summary.sampleCount, 2);
assert.equal(all.apiRoutes[0].p95, 5);
assert.doesNotMatch(recentJson, /trc_old_secret|trc_new_secret|traceId|prompt|api key/iu);
assert.doesNotMatch(allJson, /trc_old_secret|trc_new_secret|traceId|prompt|api key/iu);
});
test("web performance store accepts v2 Workbench journey and phase metrics without high-cardinality labels", () => {
const store = createWebPerformanceStore({ env: { HWLAB_METRICS_NAMESPACE: "hwlab-v03", HWLAB_GITOPS_TARGET: "v03" } });
const result = store.record({