fix(dashboard): rate over at least 5m and four steps

Long metric ranges are served by the longterm store, which keeps one
sample per 5m, so a rate window narrower than that can hold no samples
and the chart comes back empty. Four steps also keep every sample
between two points inside some window.

Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
This commit is contained in:
ZverGuy committed 2026-11-04 05:53:50 +07:00
1 parent ebdd74ce4e
commit 2b823ab79f
2 files changed
+16 -7

No files matched your search

@@ -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", () => {
@@ -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"'