Skip to content

Commit 3ce4221

Browse files
authored
Logs: say when a quiet finding resolves on its own (#297)
An open or acknowledged finding now reads "Quiet for N days. Resolves on its own <date> unless seen again", and one the analyzer closed reads "Resolved on its own <date>". Resolved and ignored findings show a dimmed severity and sort after open ones. Mark as new stays.
1 parent bc5245d commit 3ce4221

3 files changed

Lines changed: 74 additions & 3 deletions

File tree

‎dashboard/e2e/logs.spec.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,42 @@ async function shot(page: Page, name: string) {
164164
await page.screenshot({ path: path.join(SHOTS_DIR, `${name}.png`), fullPage: true });
165165
}
166166

167+
test("a quiet finding says when it resolves on its own, and a resolved one says it did", async ({ page }) => {
168+
const day = 24 * HOUR;
169+
const quiet = finding({
170+
rec_id: "rec_quiet",
171+
status: "acknowledged",
172+
title: "Prerender cache writes fail with no space left",
173+
last_seen: ago(3 * day),
174+
quiet_days: 8,
175+
resolves_at: new Date(Date.now() + 5 * day).toISOString(),
176+
});
177+
const resolved = finding({
178+
rec_id: "rec_resolved",
179+
status: "fixed",
180+
title: "Image resize worker ran out of memory",
181+
last_seen: ago(5 * day),
182+
resolved_at: ago(2 * day),
183+
resolved_reason: "Resolved: no new lines for 3 days",
184+
});
185+
await mockApi(page, { findings: [quiet, resolved] });
186+
await page.goto("/logs/");
187+
188+
const q = page.getByTestId("finding-rec_quiet");
189+
await expect(q).toContainText("Quiet for 3 days. Resolves on its own");
190+
await expect(q).toContainText("unless seen again");
191+
const r = page.getByTestId("finding-rec_resolved");
192+
await expect(r).toContainText("Resolved on its own");
193+
await expect(r).toContainText("(no new lines for 3 days)");
194+
// Open findings first, resolved after.
195+
const ids = await page.locator('[data-testid^="finding-rec_"]').evaluateAll((els) => els.map((e) => e.getAttribute("data-testid")));
196+
expect(ids.indexOf("finding-rec_quiet")).toBeLessThan(ids.indexOf("finding-rec_resolved"));
197+
// Mark as new stays on the open one.
198+
await q.getByRole("button", { name: "Show details of Prerender cache writes fail with no space left" }).click();
199+
await expect(page.getByTestId("finding-quiet")).toContainText("Resolves on its own");
200+
await expect(page.getByRole("button", { name: "Mark as new" })).toBeVisible();
201+
});
202+
167203
test("Logs is its own menu item, with Logs and Alerts as its tabs", async ({ page }) => {
168204
await mockApi(page);
169205
await page.goto("/logs/");

‎dashboard/src/app/logs/page.tsx‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { Code } from "@/components/settings/code";
2828
import { Page, PageHeader } from "@/components/page";
2929
import { buttonClass, focusRing, inputClass, linkButton, primaryButton, secondaryButton } from "@/components/ui";
3030
import { Select } from "@/components/select";
31+
import { formatDate } from "@/components/list/time";
3132
import {
3233
Chip,
3334
DetailBlock,
@@ -82,6 +83,27 @@ function plural(n: number, one: string, many = `${one}s`): string {
8283
return `${n.toLocaleString()} ${n === 1 ? one : many}`;
8384
}
8485

86+
const DAY_MS = 86_400_000;
87+
88+
/**
89+
* Whether a finding is quiet, in words: "Quiet for 3 days. Resolves on its own
90+
* Nov 5 unless seen again." for an open one with no line for a day or more,
91+
* "Resolved on its own Nov 5 (no new lines for 3 days)." once the analyzer
92+
* resolved it; null otherwise.
93+
*/
94+
function quietWords(f: LogFinding, now = Date.now()): string | null {
95+
if (f.status === "fixed" && f.resolved_at && f.fix?.state !== "merged") {
96+
const why = f.resolved_reason?.replace(/^Resolved:\s*/, "");
97+
return `Resolved on its own ${formatDate(f.resolved_at)}${why ? ` (${why})` : ""}.`;
98+
}
99+
if ((f.status === "new" || f.status === "acknowledged") && f.resolves_at && f.last_seen) {
100+
const quiet = Math.floor((now - Date.parse(f.last_seen)) / DAY_MS);
101+
if (!(quiet >= 1)) return null;
102+
return `Quiet for ${plural(quiet, "day")}. Resolves on its own ${formatDate(f.resolves_at)} unless seen again.`;
103+
}
104+
return null;
105+
}
106+
85107
function errorText(e: unknown, fallback: string): string {
86108
return e instanceof Error && e.message && !/^API \d+/.test(e.message) ? e.message : fallback;
87109
}
@@ -467,7 +489,7 @@ function FindingRow({
467489
status={look}
468490
title={f.title}
469491
titleText={f.title}
470-
quiet={f.status === "ignored"}
492+
quiet={f.status === "ignored" || (f.status === "fixed" && !!f.resolved_at)}
471493
meta={[
472494
<span key="g" title={f.log_group} className="font-medium text-zinc-300">
473495
{serviceName(f.log_group)}
@@ -478,11 +500,12 @@ function FindingRow({
478500
f.reopened_at ? `seen again ${timeAgo(f.reopened_at)} after it was resolved` : null,
479501
f.repo ? <span key="r">{f.repo}</span> : null,
480502
]}
481-
summary={fixWords(f) ?? autoNote ?? undefined}
503+
summary={fixWords(f) ?? autoNote ?? quietWords(f) ?? undefined}
482504
summaryTone={f.fix ? (f.fix.state === "merged" ? "success" : f.fix.state === "failed" || f.fix.state === "pr_closed" ? "attention" : "live") : "muted"}
483505
chips={
484506
<>
485-
<Chip tone={sev.tone}>{sev.label}</Chip>
507+
{/* A resolved finding's severity is history: shown, not alarming. */}
508+
<Chip tone={f.status === "fixed" || f.status === "ignored" ? "neutral" : sev.tone}>{sev.label}</Chip>
486509
<StatusText look={look} />
487510
{f.fix?.auto && <Chip tone="info" title="Started automatically from this finding">Auto</Chip>}
488511
{link}
@@ -571,6 +594,11 @@ function FindingDetail({
571594
</ul>
572595
</DetailBlock>
573596
)}
597+
{quietWords(f) && (
598+
<DetailBlock title="Quiet">
599+
<p className="text-zinc-300" data-testid="finding-quiet">{quietWords(f)}</p>
600+
</DetailBlock>
601+
)}
574602
{f.suggested_action && (
575603
<DetailBlock title="Recommendation">
576604
<p className="text-zinc-300">{f.suggested_action}</p>

‎dashboard/src/lib/api.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2722,6 +2722,13 @@ export interface LogFinding {
27222722
reopened_at?: string | null;
27232723
/** How many times it came back after it was resolved. */
27242724
reopen_count?: number;
2725+
/** Days without a matching line before it resolves on its own. */
2726+
quiet_days?: number;
2727+
/** Open: when it resolves on its own unless seen again. */
2728+
resolves_at?: string | null;
2729+
/** When the analyzer resolved it, and why. */
2730+
resolved_at?: string | null;
2731+
resolved_reason?: string | null;
27252732
}
27262733

27272734
/** Which repo a log group's (or alarm's) code lives in, how sure, and why. */

0 commit comments

Comments
 (0)