diff --git a/dashboard/e2e/logs.spec.ts b/dashboard/e2e/logs.spec.ts index 90aaaaaf..a7ec6cf5 100644 --- a/dashboard/e2e/logs.spec.ts +++ b/dashboard/e2e/logs.spec.ts @@ -75,6 +75,8 @@ interface Backend { findings: Finding[]; autofix: Record; calls: Call[]; + /** AWS accounts whose log checks are failing (GET /api/log-findings). */ + analysis_failing?: unknown[]; } const DEFAULT_AUTOFIX = { enabled: false, min_severity: "critical", daily_cap: 3, scope: "all", quiet_hours: null, overrides: [], enabled_at: "" }; @@ -117,6 +119,7 @@ async function mockApi(page: Page, init: Partial = {}): Promise f.log_group as string))].sort(), aws_connected: db.connected, + analysis_failing: db.analysis_failing ?? [], }); } if (p === "/api/log-findings/autofix") { @@ -200,6 +203,73 @@ test("a quiet finding says when it resolves on its own, and a resolved one says await expect(page.getByRole("button", { name: "Mark as new" })).toBeVisible(); }); +test("a resolve date that has passed is never shown as a promise", async ({ page }) => { + const day = 86_400_000; + const ago = (ms: number) => new Date(Date.now() - ms).toISOString(); + // Quiet for 7 days with an 8-day period that ended a day ago: the next check resolves it. + const due = finding({ + rec_id: "rec_due", + status: "acknowledged", + title: "Prerender cache writes fail with no space left", + last_seen: ago(9 * day), + quiet_days: 8, + resolves_at: ago(1 * day), + resolve: { state: "due", at: ago(1 * day) }, + }); + // An older server sends only the date, already passed. + const legacy = finding({ + rec_id: "rec_legacy", + status: "new", + title: "Upstream timed out reading the session store", + last_seen: ago(7 * day), + quiet_days: 3, + resolves_at: ago(4 * day), + }); + await mockApi(page, { findings: [due, legacy] }); + await page.goto("/logs/"); + + for (const id of ["rec_due", "rec_legacy"]) { + const row = page.getByTestId(`finding-${id}`); + await expect(row).toContainText("Resolves at the next log check (every 6 hours) unless seen again."); + await expect(row).not.toContainText("Resolves on its own"); + } + await expect(page.getByTestId("analysis-failing")).toHaveCount(0); +}); + +test("when log checks fail, the page says so and why nothing resolves", async ({ page }) => { + const day = 86_400_000; + const ago = (ms: number) => new Date(Date.now() - ms).toISOString(); + const blocked = finding({ + rec_id: "rec_blocked", + status: "acknowledged", + title: "Prerender cache writes fail with no space left", + last_seen: ago(7 * day), + quiet_days: 8, + resolves_at: ago(1 * day), + resolve: { + state: "blocked", + at: ago(1 * day), + analysis_ok_at: ago(5 * day), + reason: "this install's permissions boundary stops CoderHelm from reading your AWS logs through the log reader role (fixed by updating CoderHelm)", + }, + }); + await mockApi(page, { + findings: [blocked], + analysis_failing: [{ account_id: "111122223333", last_ok_at: ago(5 * day), reason: "this install's permissions boundary stops CoderHelm from reading your AWS logs through the log reader role (fixed by updating CoderHelm)" }], + }); + await page.goto("/logs/"); + + const banner = page.getByTestId("analysis-failing"); + await expect(banner).toContainText("Log checks are failing for AWS account 111122223333"); + await expect(banner).toContainText("findings in this account don't update or resolve on their own"); + await expect(banner).toContainText("permissions boundary"); + await expect(banner.getByRole("link", { name: "Open AWS settings" })).toHaveAttribute("href", /\/settings\/integrations\/aws/); + const row = page.getByTestId("finding-rec_blocked"); + await expect(row).toContainText("It was due to resolve on its own"); + await expect(row).toContainText("but log checks have failed since"); + await expect(row).not.toContainText("unless seen again"); +}); + test("Logs is its own menu item, with Logs and Alerts as its tabs", async ({ page }) => { await mockApi(page); await page.goto("/logs/"); diff --git a/dashboard/src/app/logs/page.tsx b/dashboard/src/app/logs/page.tsx index cee0b29c..18c14964 100644 --- a/dashboard/src/app/logs/page.tsx +++ b/dashboard/src/app/logs/page.tsx @@ -89,7 +89,8 @@ const DAY_MS = 86_400_000; * Whether a finding is quiet, in words: "Quiet for 3 days. Resolves on its own * Nov 5 unless seen again." for an open one with no line for a day or more, * "Resolved on its own Nov 5 (no new lines for 3 days)." once the analyzer - * resolved it; null otherwise. + * resolved it; null otherwise. A date that has passed is never shown as a + * promise: it says when the next check resolves it, or why none can. */ function quietWords(f: LogFinding, now = Date.now()): string | null { if (f.status === "fixed" && f.resolved_at && f.fix?.state !== "merged") { @@ -99,7 +100,15 @@ function quietWords(f: LogFinding, now = Date.now()): string | null { if ((f.status === "new" || f.status === "acknowledged") && f.resolves_at && f.last_seen) { const quiet = Math.floor((now - Date.parse(f.last_seen)) / DAY_MS); if (!(quiet >= 1)) return null; - return `Quiet for ${plural(quiet, "day")}. Resolves on its own ${formatDate(f.resolves_at)} unless seen again.`; + const lead = `Quiet for ${plural(quiet, "day")}.`; + // Older servers send only the date: decide "passed" here. + const state = f.resolve?.state ?? (Date.parse(f.resolves_at) > now ? "scheduled" : "due"); + if (state === "blocked") { + const since = f.resolve?.analysis_ok_at ? ` since ${formatDate(f.resolve.analysis_ok_at)}` : ""; + return `${lead} It was due to resolve on its own ${formatDate(f.resolves_at)}, but log checks have failed${since}: ${f.resolve?.reason ?? "checks of your AWS logs fail"}.`; + } + if (state === "due") return `${lead} Resolves at the next log check (every 6 hours) unless seen again.`; + return `${lead} Resolves on its own ${formatDate(f.resolves_at)} unless seen again.`; } return null; } @@ -307,6 +316,23 @@ function LogsPage() { ) : ( <> + {(data?.analysis_failing ?? []).map((a) => ( +
+ + Open AWS settings + + } + > + {a.last_ok_at ? `The last check that worked was ${formatDate(a.last_ok_at)}. ` : "No check has worked yet. "} + Until checks work again, findings in this account don't update or resolve on their own. Cause: {a.reason}. + +
+ ))} ; log_groups: string[]; aws_connected: boolean; + /** AWS accounts whose log checks are failing, so findings there can't resolve. */ + analysis_failing?: { account_id: string; last_ok_at: string | null; reason: string }[]; } export interface LogSample { diff --git a/dashboard/src/lib/openapi-fields.ts b/dashboard/src/lib/openapi-fields.ts index 50a115bd..90fb9dfd 100644 --- a/dashboard/src/lib/openapi-fields.ts +++ b/dashboard/src/lib/openapi-fields.ts @@ -2,7 +2,7 @@ // docs/api/openapi.json. Do not edit; run `npm run openapi:fields` instead. /** The platform commit this was generated from. */ -export const OPENAPI_REF = "de34e9c10940158650799353fda932d6ca73c0a0"; +export const OPENAPI_REF = "b25ce7b6fe2825b72a6bc191de6f288f2c22a9bc"; /** The fields each public API schema has. */ export interface OpenApiFields {