Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions dashboard/e2e/logs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ interface Backend {
findings: Finding[];
autofix: Record<string, unknown>;
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: "" };
Expand Down Expand Up @@ -117,6 +119,7 @@ async function mockApi(page: Page, init: Partial<Backend> = {}): Promise<Backend
counts,
log_groups: [...new Set(db.findings.map((f) => f.log_group as string))].sort(),
aws_connected: db.connected,
analysis_failing: db.analysis_failing ?? [],
});
}
if (p === "/api/log-findings/autofix") {
Expand Down Expand Up @@ -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/");
Expand Down
30 changes: 28 additions & 2 deletions dashboard/src/app/logs/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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;
}
Expand Down Expand Up @@ -307,6 +316,23 @@ function LogsPage() {
</div>
) : (
<>
{(data?.analysis_failing ?? []).map((a) => (
<div key={a.account_id} className="mt-6">
<Callout
variant="error"
testId="analysis-failing"
title={`Log checks are failing for AWS account ${a.account_id}`}
actions={
<Link href="/settings/integrations/aws" className={secondaryButton}>
Open AWS settings
</Link>
}
>
{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&apos;t update or resolve on their own. Cause: {a.reason}.
</Callout>
</div>
))}
<ListToolbar
className="mt-6 mb-4"
search={{
Expand Down
13 changes: 13 additions & 0 deletions dashboard/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2910,6 +2910,17 @@ export interface LogFinding {
quiet_days?: number;
/** Open: when it resolves on its own unless seen again. */
resolves_at?: string | null;
/**
* Open: what can be promised about that date. `scheduled`: still ahead.
* `due`: passed, the next log check (every 6 hours) resolves it. `blocked`:
* passed, but log checks have failed since `analysis_ok_at`, for `reason`.
*/
resolve?: {
state: "scheduled" | "due" | "blocked";
at: string;
analysis_ok_at?: string;
reason?: string;
} | null;
/** When the analyzer resolved it, and why. */
resolved_at?: string | null;
resolved_reason?: string | null;
Expand Down Expand Up @@ -2939,6 +2950,8 @@ export interface LogFindingsList {
counts: Record<LogFindingStatus, number>;
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 {
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/lib/openapi-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading