diff --git a/packages/system/dashboard/images/console/apps/console/src/lib/observability/metrics.test.ts b/packages/system/dashboard/images/console/apps/console/src/lib/observability/metrics.test.ts index 0803940bf..0598c0c7f 100644 --- a/packages/system/dashboard/images/console/apps/console/src/lib/observability/metrics.test.ts +++ b/packages/system/dashboard/images/console/apps/console/src/lib/observability/metrics.test.ts @@ -32,10 +32,19 @@ describe("METRIC_PANELS", () => { ) }) - it("widens the rate window with the step on long ranges", () => { - const [query] = METRIC_PANELS.find((p) => p.id === "cpu")!.queries({ start: 0, end: 1, step: 2520 }) - - expect(query.expr).toContain("[5040s]") + // Long ranges are served by the longterm store, deduplicated at 5m, where a + // narrower window can hold no samples and the rate comes back empty. + it.each([ + [15, "300s"], + [75, "300s"], + [90, "360s"], + [2520, "10080s"], + ])("rates over max(5m, 4 x step) for step %is", (step, window) => { + for (const panel of METRIC_PANELS) { + for (const q of panel.queries({ start: 0, end: 1, step })) { + if (q.expr.includes("rate(")) expect(q.expr).toContain(`[${window}]`) + } + } }) it("reads memory as working set per pod", () => { diff --git a/packages/system/dashboard/images/console/apps/console/src/lib/observability/metrics.ts b/packages/system/dashboard/images/console/apps/console/src/lib/observability/metrics.ts index b23a51e27..d7182b8d6 100644 --- a/packages/system/dashboard/images/console/apps/console/src/lib/observability/metrics.ts +++ b/packages/system/dashboard/images/console/apps/console/src/lib/observability/metrics.ts @@ -23,10 +23,10 @@ export function rangeWindow(range: RangeKey, nowSeconds: number): RangeWindow { return { start: nowSeconds - span, end: nowSeconds, step: Math.max(MIN_STEP, Math.round(span / POINTS)) } } -// A rate needs several scrapes inside its window, and on long ranges the window -// must also cover the step or samples between points are skipped. +// The longterm store keeps one sample per 5m, so a narrower window can be empty; +// 4 x step also keeps samples between points from being skipped. function rateWindow(step: number): string { - return `${Math.max(300, step * 2)}s` + return `${Math.max(300, step * 4)}s` } const CONTAINERS = 'container!="",container!="POD"'