test(web): govern performance dashboard windows (#1683)
This commit is contained in:
@@ -227,7 +227,9 @@ async function handleRequest(request: IncomingMessage, response: ServerResponse)
|
||||
if (path === "/v1/hwpod-node-ops") return json(response, 200, hwpodNodeOpsPayload());
|
||||
if (path === "/v1/web-performance/summary") {
|
||||
if (state.scenarioId === "performance-summary-error") return json(response, 503, { ok: false, status: 503, error: { code: "performance_summary_unavailable", message: "performance summary read model is unavailable" } });
|
||||
return json(response, 200, state.scenarioId === "performance-empty" ? webPerformanceEmptyPayload(url) : webPerformanceSummaryPayload(url));
|
||||
if (state.scenarioId === "performance-empty") return json(response, 200, webPerformanceEmptyPayload(url));
|
||||
if (state.scenarioId === "performance-stale-window") return json(response, 200, webPerformanceStaleWindowPayload(url));
|
||||
return json(response, 200, webPerformanceSummaryPayload(url));
|
||||
}
|
||||
if (path.startsWith("/v1/") || path.startsWith("/auth/") || path.startsWith("/health")) return json(response, 500, { ok: false, status: 500, error: { code: "unmocked_request", path } });
|
||||
|
||||
@@ -364,6 +366,51 @@ function webPerformanceEmptyPayload(url: URL): JsonRecord {
|
||||
};
|
||||
}
|
||||
|
||||
function webPerformanceStaleWindowPayload(url: URL): JsonRecord {
|
||||
const sampleWindow = fakePerformanceWindow(url.searchParams.get("window"));
|
||||
const rows: JsonRecord[] = [];
|
||||
const collectionHealth = {
|
||||
schemaVersion: "hwlab-web-performance-collection-health-v1",
|
||||
status: "waiting",
|
||||
statusLabel: "等待数据",
|
||||
reason: "no_samples_in_window",
|
||||
reasonLabel: "当前窗口暂无样本",
|
||||
sampleCount: 0,
|
||||
retainedSampleCount: 37,
|
||||
sampleSeries: 0,
|
||||
lowSampleThreshold: 5,
|
||||
firstSampleAt: null,
|
||||
lastSampleAt: null,
|
||||
lastRetainedSampleAt: "2026-06-18T03:20:00.000Z",
|
||||
secondsSinceLastSample: 4200,
|
||||
windowCoverageSeconds: null,
|
||||
sourceFamilyCounts: [{ sourceFamily: "web", rowCount: 0, sampleCount: 37 }],
|
||||
unknownAttribution: { workbenchRows: 0, rowsWithUnknown: 0, samplesWithUnknown: 0, backendUnknownRows: 0, transportUnknownRows: 0 },
|
||||
diagnostics: [{ code: "no_samples_in_window", label: "当前窗口无样本", tone: "warn", detail: "保留样本存在,但当前窗口没有性能样本。" }]
|
||||
};
|
||||
return {
|
||||
ok: true,
|
||||
status: "waiting",
|
||||
source: "fake-server",
|
||||
observedAt: sampleWindow.generatedAt,
|
||||
namespace: "hwlab-v03",
|
||||
gitopsTarget: "D601/v03",
|
||||
sampleWindow: performanceSampleWindowPayload(sampleWindow),
|
||||
summary: performanceSummaryContract(sampleWindow, rows, { status: "waiting", sampleCount: 0, retainedSampleCount: 37, sampleSeries: 0, problemCount: 0 }),
|
||||
backendEvidence: { schemaVersion: "hwlab-backend-performance-evidence-v1", source: "fake-server-backend-performance-store", observedAt: sampleWindow.generatedAt, sampleCount: 0, retainedSampleCount: 37, routeCount: 0, rows: [], available: true, valuesRedacted: true },
|
||||
collectionHealth,
|
||||
dashboard: webPerformanceDashboardPayload(rows, sampleWindow, collectionHealth),
|
||||
rows,
|
||||
problems: [],
|
||||
webVitals: [],
|
||||
apiRoutes: [],
|
||||
longTasks: [],
|
||||
workbenchJourneys: [],
|
||||
workbenchEventPhases: [],
|
||||
workbenchBackendEvents: []
|
||||
};
|
||||
}
|
||||
|
||||
function performanceRow(row: JsonRecord, sampleWindow: FakePerformanceWindow): JsonRecord {
|
||||
const count = Number(row.count ?? 0);
|
||||
const sampleState = count === 0 ? "empty" : count < 5 ? "low-sample" : "ok";
|
||||
|
||||
Reference in New Issue
Block a user