1
0

feat: 动态粒度趋势图,支持 auto bucket 选择 + P95 延迟 + 状态条

This commit is contained in:
2026-05-23 23:53:18 +08:00
parent 6601ab458d
commit 4f33fba793
16 changed files with 315 additions and 106 deletions

View File

@@ -319,10 +319,12 @@ describe("API 路由", () => {
expect(body.trend[0]).toMatchObject({
availability: 50,
avgDurationMs: 150,
bucketEnd: "2025-01-01T01:00:00.000Z",
bucketStart: "2025-01-01T00:00:00.000Z",
downChecks: 2,
maxDurationMs: 200,
minDurationMs: 100,
p95DurationMs: 200,
totalChecks: 4,
upChecks: 2,
});
@@ -350,7 +352,11 @@ describe("API 路由", () => {
totalChecks: 0,
upChecks: 0,
});
expect(body.trend).toEqual([]);
expect(body.trend.length).toBeGreaterThan(0);
body.trend.forEach((point: { availability: number; totalChecks: number }) => {
expect(point.totalChecks).toBe(0);
expect(point.availability).toBe(0);
});
});
test("查询不存在的目标返回 404", async () => {
@@ -394,7 +400,7 @@ describe("API 路由", () => {
test("metrics 无效 bucket 和不存在目标返回错误", async () => {
const targets = store.getTargets();
const invalidBucket = await fetch(
`${baseUrl}/api/targets/${targets[0]!.id}/metrics?from=2025-01-01T00:00:00.000Z&to=2025-01-01T01:00:00.000Z&bucket=5m`,
`${baseUrl}/api/targets/${targets[0]!.id}/metrics?from=2025-01-01T00:00:00.000Z&to=2025-01-01T01:00:00.000Z&bucket=invalid`,
);
const missingTarget = await fetch(
`${baseUrl}/api/targets/99999/metrics?from=2025-01-01T00:00:00.000Z&to=2025-01-01T01:00:00.000Z`,