feat(devops): diagnose slow HK requests and dependency timings
CI / check (push) Successful in 2m0s
CI / deploy (push) Successful in 1m35s
CI / publish-container (push) Successful in 46s

This commit is contained in:
Simo committed 2026-09-11 09:48:19 +02:00
1 parent 3b76d063a6
commit 00e33623f7
42 files changed
+1335 -132

No files matched your search

+70
View File
@@ -0,0 +1,70 @@
import { beforeEach, expect, it, vi } from "vitest";
const mock = vi.hoisted(() => ({
status: "ready",
exec: vi.fn(),
lrange: vi.fn(),
}));
vi.mock("@/lib/redis", () => ({
redis: {
get status() {
return mock.status;
},
multi() {
const chain = {
lpush: () => chain,
ltrim: () => chain,
expire: () => chain,
exec: mock.exec,
};
return chain;
},
lrange: mock.lrange,
},
}));
import { readPerformance, recordPerformance } from "./performance-store";
const sample = {
operationId: "op",
route: "/api/admin/test",
method: "GET",
status: 200,
at: Date.now(),
streaming: false,
metrics: {
durationMs: 1200,
database: { count: 2, durationMs: 1000, errors: 0 },
external: { count: 0, durationMs: 0, errors: 0 },
},
};
beforeEach(() => {
mock.status = "ready";
mock.exec.mockResolvedValue([]);
mock.lrange.mockResolvedValue([]);
});
it("does not fail a request when storage rejects writes", async () => {
mock.exec.mockRejectedValue(new Error("offline"));
expect(() => recordPerformance(sample)).not.toThrow();
await Promise.resolve();
await Promise.resolve();
});
it("falls back to bounded local samples when Redis is unavailable", async () => {
mock.status = "end";
for (let n = 0; n < 250; n++)
recordPerformance({ ...sample, operationId: String(n) });
const result = await readPerformance();
expect(result.shared).toBe(false);
expect(result.samples).toHaveLength(200);
expect(result.samples[0].operationId).toBe("249");
});
it("ignores expired and malformed shared records", async () => {
mock.lrange.mockResolvedValue([
"bad",
JSON.stringify({ ...sample, at: 1 }),
JSON.stringify(sample),
]);
const result = await readPerformance();
expect(result.shared).toBe(true);
expect(result.samples).toEqual([sample]);
});