Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat(frontend): fold retried attempts into one row in the task-run log

zchpeter4e6c2b11ad5a
diff --git a/frontend/src/components/task-run-log/LogRows.tsx b/frontend/src/components/task-run-log/LogRows.tsx
new file mode 100644
index 0000000000..80e803cfa6
--- /dev/null
+++ b/frontend/src/components/task-run-log/LogRows.tsx
@@ -0,0 +1,195 @@
+import { ChevronRight, RotateCw } from "lucide-react";
+import type { ReactNode } from "react";
+import { useTranslation } from "react-i18next";
+import { buttonVariants } from "@/components/ui/button";
+import {
+ Collapsible,
+ CollapsiblePanel,
+ CollapsibleTrigger,
+} from "@/components/ui/collapsible";
+import { cn } from "@/lib/utils";
+import { soleAttemptOf } from "./model";
+import { SectionContent } from "./SectionContent";
+import { SectionHeader } from "./SectionHeader";
+import type { AttemptGroup, LogRow, Section } from "./types";
+
+export interface LogRowsProps {
+ rows: LogRow[];
+ indent: boolean;
+ // Whether the task run is still running: the log alone cannot tell an
+ // attempt in flight from one whose server stopped.
+ running: boolean;
+ isRowExpanded: (rowId: string) => boolean;
+ onToggleRow: (rowId: string) => void;
+ foldOverrides: ReadonlyMap<string, boolean>;
+ onFoldChange: (key: string, open: boolean) => void;
+}
+
+type RowState = Omit<LogRowsProps, "rows">;
+
+export const ROW_DIVIDER = "border-block-border border-b last:border-b-0";
+
+function SectionRow({
+ section,
+ indent,
+ isRowExpanded,
+ onToggleRow,
+ foldOverrides,
+ onFoldChange,
+}: { section: Section } & RowState) {
+ const expanded = isRowExpanded(section.id);
+ return (
+ <div className={ROW_DIVIDER}>
+ <SectionHeader
+ section={section}
+ indent={indent}
+ isExpanded={expanded}
+ onToggle={() => onToggleRow(section.id)}
+ />
+ {expanded ? (
+ <SectionContent
+ section={section}
+ indent={indent}
+ foldOverrides={foldOverrides}
+ onFoldChange={onFoldChange}
+ />
+ ) : null}
+ </div>
+ );
+}
+
+// The umbrella row and each attempt row inside it.
+function HistoryRow({
+ testId,
+ className,
+ expanded,
+ onToggle,
+ indent,
+ label,
+ note,
+ duration,
+ children,
+}: {
+ testId: string;
+ className?: string;
+ expanded: boolean;
+ onToggle: () => void;
+ indent: boolean;
+ label: string;
+ note?: string;
+ duration: string;
+ children: ReactNode;
+}) {
+ return (
+ <Collapsible open={expanded} onOpenChange={onToggle} className={className}>
+ <CollapsibleTrigger
+ data-testid={testId}
+ className={
+ // History reads like the section rows' Button except for the rotate
+ // icon and muted text: no fill, never a warning hue.
+ buttonVariants({
+ appearance: "secondary",
+ size: "sm",
+ className: cn(
+ "w-full justify-start rounded-none bg-background text-control-light hover:bg-control-bg",
+ indent ? "px-6" : "px-3"
+ ),
+ })
+ }
+ >
+ <ChevronRight
+ className={cn(
+ "size-3.5 shrink-0 text-control-placeholder transition-transform",
+ expanded && "rotate-90"
+ )}
+ />
+ <RotateCw className="size-3.5 shrink-0" />
+ <span>{label}</span>
+ {note ? (
+ <span className="min-w-0 truncate text-control-placeholder">
+ {note}
+ </span>
+ ) : null}
+ <span className="flex-1" />
+ {duration ? <span className="tabular-nums">{duration}</span> : null}
+ </CollapsibleTrigger>
+ <CollapsiblePanel className="border-block-border border-t pl-4">
+ {children}
+ </CollapsiblePanel>
+ </Collapsible>
+ );
+}
+
+function PreviousAttemptsRow({
+ group,
+ ...state
+}: { group: AttemptGroup } & RowState) {
+ const { t } = useTranslation();
+ const soleAttempt = soleAttemptOf(group);
+ return (
+ <HistoryRow
+ testId="task-run-log-previous-attempts"
+ className={ROW_DIVIDER}
+ expanded={state.isRowExpanded(group.id)}
+ onToggle={() => state.onToggleRow(group.id)}
+ indent={state.indent}
+ label={t("task-run.log-viewer.previous-attempts")}
+ note={`${t("task-run.log-viewer.attempt-count", {
+ count: group.attempts.length,
+ })}${
+ group.retrying && state.running
+ ? ` · ${t("task-run.log-viewer.retrying")}`
+ : ""
+ }`}
+ duration={group.duration}
+ >
+ {soleAttempt ? (
+ <LogRows rows={soleAttempt.sections} {...state} />
+ ) : (
+ <ul role="list">
+ {group.attempts.map((attempt) => (
+ <li key={attempt.id} className={ROW_DIVIDER}>
+ <HistoryRow
+ testId="task-run-log-attempt"
+ expanded={state.isRowExpanded(attempt.id)}
+ onToggle={() => state.onToggleRow(attempt.id)}
+ indent={state.indent}
+ label={t("task-run.log-viewer.attempt-n", {
+ n: attempt.number,
+ })}
+ note={
+ attempt.reason
+ ? t("task-run.log-viewer.attempt-reason", {
+ reason: attempt.reason,
+ })
+ : undefined
+ }
+ duration={attempt.duration}
+ >
+ <LogRows rows={attempt.sections} {...state} />
+ </HistoryRow>
+ </li>
+ ))}
+ </ul>
+ )}
+ </HistoryRow>
+ );
+}
+
+// One list of rows at any nesting level: sections, and umbrellas that open
+// onto their own rows.
+export function LogRows({ rows, ...state }: LogRowsProps) {
+ return (
+ <>
+ {rows.map((row) =>
+ row.kind === "section" ? (
+ <SectionRow key={row.id} section={row} {...state} />
+ ) : (
+ <PreviousAttemptsRow key={row.id} group={row} {...state} />
+ )
+ )}
+ </>
+ );
+}
+
+export default LogRows;
diff --git a/frontend/src/components/task-run-log/SectionContent.test.tsx b/frontend/src/components/task-run-log/SectionContent.test.tsx
index 67003a9d52..2c071d4308 100644
--- a/frontend/src/components/task-run-log/SectionContent.test.tsx
+++ b/frontend/src/components/task-run-log/SectionContent.test.tsx
@@ -154,6 +154,7 @@ const status = (key: string, detail: string): DisplayItem => ({
});
const sectionOf = (items: DisplayItem[]): Section => ({
+ kind: "section",
id: "section-0",
type: TaskRunLogEntry_Type.COMMAND_EXECUTE,
label: "Command Execute",
@@ -172,8 +173,8 @@ interface HarnessProps {
initialOverrides?: ReadonlyMap<string, boolean>;
}
-// The fold overrides live above SectionContent in the product, so the harness
-// owns them the same way.
+// In the product the fold overrides live above SectionContent and the viewer
+// keys it on the dataset key; the harness does both the same way.
const Harness = ({
items,
datasetKey = "runs/1",
@@ -183,8 +184,8 @@ const Harness = ({
() => initialOverrides ?? new Map()
);
return createElement(SectionContent, {
+ key: datasetKey,
section: sectionOf(items),
- datasetKey,
foldOverrides: overrides,
onFoldChange: (key: string, open: boolean) =>
setOverrides((previous) => new Map(previous).set(key, open)),
diff --git a/frontend/src/components/task-run-log/SectionContent.tsx b/frontend/src/components/task-run-log/SectionContent.tsx
index cc905c8a2f..9049a9c427 100644
--- a/frontend/src/components/task-run-log/SectionContent.tsx
+++ b/frontend/src/components/task-run-log/SectionContent.tsx
@@ -3,7 +3,6 @@ import {
type CSSProperties,
type MouseEvent,
useCallback,
- useEffect,
useLayoutEffect,
useMemo,
useRef,
@@ -40,7 +39,6 @@ const RELATIVE_TIME_COLUMN_MIN_CHARS = 7;
export interface SectionContentProps {
section: Section;
indent?: boolean;
- datasetKey?: string;
// The reader's explicit folds, by row key. Held by the viewer because this
// component unmounts whenever its enclosing section collapses.
foldOverrides: ReadonlyMap<string, boolean>;
@@ -100,10 +98,10 @@ const sameKeys = (a: ReadonlySet<string>, b: ReadonlySet<string>): boolean => {
return true;
};
+// Local state resets only by remount, which the viewer keys on the dataset key.
export function SectionContent({
section,
indent = false,
- datasetKey,
foldOverrides,
onFoldChange,
}: SectionContentProps) {
@@ -126,10 +124,6 @@ export function SectionContent({
[]
);
- useEffect(() => {
- setShowAllItems(false);
- }, [datasetKey, section.id]);
-
// The first MAX_RENDERED_ITEMS rows, plus the marked row when it falls
// outside them: a failure at statement 300 must not wait behind "Load more".
const { head, tail } = useMemo(() => {
@@ -233,7 +227,7 @@ export function SectionContent({
const renderRow = ({ item, index }: Row) => {
const open = isOpen(item, foldOverrides);
return (
- <LogRow
+ <EntryRow
key={item.key}
item={item}
index={index}
@@ -277,7 +271,7 @@ export function SectionContent({
);
}
-interface LogRowProps {
+interface EntryRowProps {
item: DisplayItem;
index: number;
indent: boolean;
@@ -290,7 +284,7 @@ interface LogRowProps {
const TEXT_CELL = "shrink-0 py-1 tabular-nums";
-function LogRow({
+function EntryRow({
item,
index,
indent,
@@ -299,7 +293,7 @@ function LogRow({
onToggle,
registerRow,
registerLine,
-}: LogRowProps) {
+}: EntryRowProps) {
const { t } = useTranslation();
const { statement, error } = item;
const showBlock = open && statement !== undefined;
diff --git a/frontend/src/components/task-run-log/TaskRunLogViewer.test.tsx b/frontend/src/components/task-run-log/TaskRunLogViewer.test.tsx
index 1df6740878..ec4efe8a6d 100644
--- a/frontend/src/components/task-run-log/TaskRunLogViewer.test.tsx
+++ b/frontend/src/components/task-run-log/TaskRunLogViewer.test.tsx
@@ -1,15 +1,22 @@
import { create } from "@bufbuild/protobuf";
-import { CheckCircle2 } from "lucide-react";
+import { CheckCircle2, XCircle } from "lucide-react";
+import { within } from "@testing-library/react";
import { act, createElement, useSyncExternalStore } from "react";
import { createRoot } from "react-dom/client";
-import { beforeEach, describe, expect, test, vi } from "vitest";
+import { beforeAll, beforeEach, describe, expect, test, vi } from "vitest";
+import i18n from "@/lib/i18n";
+import { retry, runningCommand } from "./taskRunLogEntries";
import {
TaskRun_Status,
type TaskRunLogEntry,
TaskRunLogEntry_Type,
TaskRunLogEntrySchema,
} from "@/types/proto-es/v1/rollout_service_pb";
-import { TaskRunLogViewer } from "./TaskRunLogViewer";
+import {
+ TaskRunLogViewer,
+ type TaskRunLogViewerProps,
+} from "./TaskRunLogViewer";
+import type { AttemptGroup, Section } from "./types";
import type {
UseTaskRunLogSectionsOptions,
useTaskRunLogSections,
@@ -27,48 +34,6 @@ const mocks = vi.hoisted(() => ({
| undefined,
}));
-vi.mock("react-i18next", () => ({
- initReactI18next: { type: "3rdParty", init: () => {} },
- useTranslation: () => ({
- t: (key: string, options?: Record<string, unknown> | number | string) => {
- if (key === "task-run.log-viewer.summary" && options) {
- const summary =
- typeof options === "object"
- ? options
- : { sections: options, entries: "" };
- return `${summary.sections} sections · ${summary.entries} entries`;
- }
- if (key === "task-run.log-detail.completed") {
- return "Completed";
- }
- if (key === "task-run.log-detail.dumping") {
- return "Dumping...";
- }
- if (key === "task-run.log-detail.syncing") {
- return "Syncing...";
- }
- if (key === "task-run.log-detail.backup-completed" && options) {
- const { count } = options as { count?: number };
- return `Completed (${count} tables)`;
- }
- if (key === "task-run.log-detail.backing-up") {
- return "Backing up...";
- }
- if (key === "task-run.log-detail.retry-attempt" && options) {
- const { current, max } = options as {
- current?: number;
- max?: number;
- };
- return `Attempt ${current}/${max}`;
- }
- if (key === "task-run.log-detail.computing") {
- return "Computing...";
- }
- return key;
- },
- }),
-}));
-
vi.mock("./useTaskRunLogData", () => ({
useTaskRunLogData: mocks.useTaskRunLogData,
}));
@@ -95,8 +60,9 @@ const createDefaultData = () => ({
});
const createDefaultSections = () => ({
- sections: [
+ rows: [
{
+ kind: "section",
id: "section-0",
type: TaskRunLogEntry_Type.COMMAND_EXECUTE,
label: "Command Execute",
@@ -124,10 +90,10 @@ const createDefaultSections = () => ({
hasReleaseFiles: false,
releaseFileGroups: [],
replicaGroups: [],
- toggleSection: vi.fn(),
+ toggleRow: vi.fn(),
toggleReplica: vi.fn(),
toggleReleaseFile: vi.fn(),
- isSectionExpanded: () => true,
+ isRowExpanded: () => true,
isReplicaExpanded: () => true,
isReleaseFileExpanded: () => true,
expandAll: vi.fn(),
@@ -137,17 +103,93 @@ const createDefaultSections = () => ({
totalEntries: 1,
});
-const renderIntoContainer = (element: ReturnType<typeof createElement>) => {
+const section = (
+ id: string,
+ label: string,
+ status: "success" | "error" = "success"
+): Section => ({
+ kind: "section",
+ id,
+ type: TaskRunLogEntry_Type.COMMAND_EXECUTE,
+ label,
+ status,
+ statusIcon: status === "error" ? XCircle : CheckCircle2,
+ statusClass: status === "error" ? "text-error" : "text-success",
+ duration: "1.0s",
+ entryCount: 1,
+ items: [
+ {
+ key: `${id}-item`,
+ time: "12:00:00.000",
+ timeMs: undefined,
+ relativeTime: "",
+ levelIndicator: status === "error" ? "✗" : "✓",
+ levelClass: status === "error" ? "text-error" : "text-success",
+ detail: `${label} entry`,
+ detailClass: status === "error" ? "text-error" : "text-control",
+ },
+ ],
+});
+
+const largeSection = (id: string, label: string): Section => ({
+ ...section(id, label),
+ entryCount: 60,
+ items: Array.from({ length: 60 }, (_, index) => ({
+ key: `item-${index}`,
+ time: `12:00:${String(index).padStart(2, "0")}.000`,
+ timeMs: undefined,
+ relativeTime: "",
+ levelIndicator: "✓",
+ levelClass: "text-success",
+ detail: `ROW ${index}`,
+ detailClass: "text-control",
+ })),
+});
+
+const attemptGroup = (attemptCount: number, retrying = false): AttemptGroup => ({
+ kind: "attempts",
+ id: "attempts-0",
+ duration: `${attemptCount}.0s`,
+ retrying,
+ attempts: Array.from({ length: attemptCount }, (_, index) => ({
+ id: `attempts-0-attempt-${index + 1}`,
+ number: index + 1,
+ reason: `lock timeout ${index + 1}`,
+ duration: "1.0s",
+ sections: [
+ section(`attempts-0-attempt-${index + 1}-section-0`, `Old Command ${index + 1}`, "error"),
+ ],
+ })),
+});
+
+// The hook result for a run with superseded attempts, with expansion driven by
+// the set the test hands in.
+const sectionsWithAttempts = (
+ group: AttemptGroup,
+ expandedRows: Set<string> = new Set()
+) => ({
+ ...createDefaultSections(),
+ rows: [group, section("section-1", "Final Command")],
+ isRowExpanded: (id: string) => expandedRows.has(id),
+});
+
+const button = (container: HTMLElement, name: RegExp) =>
+ within(container).getByRole("button", { name });
+
+const renderViewer = (props: Partial<TaskRunLogViewerProps> = {}) => {
const container = document.createElement("div");
const root = createRoot(container);
-
- act(() => {
- root.render(element);
- });
+ const rerender = (next: Partial<TaskRunLogViewerProps>) =>
+ act(() => {
+ root.render(
+ createElement(TaskRunLogViewer, { taskRunName: "runs/1", ...next })
+ );
+ });
+ rerender(props);
return {
container,
- root,
+ rerender,
unmount: () =>
act(() => {
root.unmount();
@@ -155,6 +197,10 @@ const renderIntoContainer = (element: ReturnType<typeof createElement>) => {
};
};
+beforeAll(async () => {
+ await i18n.changeLanguage("en-US");
+});
+
beforeEach(() => {
mocks.useTaskRunLogData.mockReturnValue(createDefaultData());
mocks.useTaskRunLogSections.mockReturnValue(createDefaultSections());
@@ -162,9 +208,7 @@ beforeEach(() => {
describe("TaskRunLogViewer", () => {
test("drops the summary scaffolding for a lone section", () => {
- const { container, unmount } = renderIntoContainer(
- createElement(TaskRunLogViewer, { taskRunName: "runs/1" })
- );
+ const { container, unmount } = renderViewer();
// A single section has no structure worth disclosing: no summary bar, but
// its label and entries render directly.
@@ -185,9 +229,7 @@ describe("TaskRunLogViewer", () => {
}
);
- const { unmount } = renderIntoContainer(
- createElement(TaskRunLogViewer, { taskRunName: "runs/1" })
- );
+ const { unmount } = renderViewer();
expect(capturedOptions?.detailText?.completed).toBe("Completed");
expect(capturedOptions?.detailText?.backingUp).toBe("Backing up...");
@@ -197,10 +239,7 @@ describe("TaskRunLogViewer", () => {
]
).toBe("Dumping...");
expect(capturedOptions?.detailText?.backupCompleted?.(3)).toBe(
- "Completed (3 tables)"
- );
- expect(capturedOptions?.detailText?.retryAttempt?.(2, 5)).toBe(
- "Attempt 2/5"
+ "completed (3 tables)"
);
unmount();
@@ -208,7 +247,7 @@ describe("TaskRunLogViewer", () => {
test("renders orphan release-file sections before labeled file headers", () => {
mocks.useTaskRunLogSections.mockReturnValue({
- sections: [],
+ rows: [],
hasMultipleReplicas: false,
hasReleaseFiles: true,
releaseFileGroups: [
@@ -217,8 +256,9 @@ describe("TaskRunLogViewer", () => {
version: "",
filePath: "",
isOrphan: true,
- sections: [
+ rows: [
{
+ kind: "section",
id: "orphan-section",
type: TaskRunLogEntry_Type.COMMAND_EXECUTE,
label: "Orphan Command",
@@ -245,8 +285,9 @@ describe("TaskRunLogViewer", () => {
id: "file-0",
version: "v1",
filePath: "001.sql",
- sections: [
+ rows: [
{
+ kind: "section",
id: "file-section",
type: TaskRunLogEntry_Type.COMMAND_EXECUTE,
label: "Release Command",
@@ -271,10 +312,10 @@ describe("TaskRunLogViewer", () => {
},
],
replicaGroups: [],
- toggleSection: vi.fn(),
+ toggleRow: vi.fn(),
toggleReplica: vi.fn(),
toggleReleaseFile: vi.fn(),
- isSectionExpanded: () => true,
+ isRowExpanded: () => true,
isReplicaExpanded: () => true,
isReleaseFileExpanded: () => true,
expandAll: vi.fn(),
@@ -284,9 +325,7 @@ describe("TaskRunLogViewer", () => {
totalEntries: 2,
});
- const { container, unmount } = renderIntoContainer(
- createElement(TaskRunLogViewer, { taskRunName: "runs/1" })
- );
+ const { container, unmount } = renderViewer();
// More than one section keeps the summary bar and the disclosure chrome.
expect(container.textContent).toContain("2 sections · 2 entries");
@@ -303,11 +342,236 @@ describe("TaskRunLogViewer", () => {
unmount();
});
+
+ test("folds superseded attempts into one collapsed Previous attempts row", () => {
+ const sections = sectionsWithAttempts(attemptGroup(2));
+ mocks.useTaskRunLogSections.mockReturnValue(sections);
+
+ const { container, unmount } = renderViewer();
+
+ const umbrella = button(container, /Previous attempts/);
+ expect(umbrella).toHaveTextContent("2 attempts");
+ expect(umbrella).toHaveTextContent("2.0s");
+ expect(umbrella).toHaveAttribute("aria-expanded", "false");
+ expect(container.textContent).not.toContain("Attempt 1");
+ expect(container.textContent).not.toContain("Old Command");
+ expect(container.textContent).toContain("Final Command");
+ expect(container.textContent?.indexOf("Previous attempts")).toBeLessThan(
+ container.textContent?.indexOf("Final Command") ?? -1
+ );
+
+ act(() => {
+ umbrella.click();
+ });
+ expect(sections.toggleRow).toHaveBeenCalledWith("attempts-0");
+
+ unmount();
+ });
+
+ test("an expanded umbrella lists one nested row per attempt, each opening onto its sections", () => {
+ const group = attemptGroup(2);
+ const sections = sectionsWithAttempts(
+ group,
+ new Set(["attempts-0", "attempts-0-attempt-2"])
+ );
+ mocks.useTaskRunLogSections.mockReturnValue(sections);
+
+ const { container, unmount } = renderViewer();
+
+ const umbrella = button(container, /Previous attempts/);
+ expect(umbrella).toHaveAttribute("aria-expanded", "true");
+ const panelId = umbrella.getAttribute("aria-controls");
+ expect(panelId).toBeTruthy();
+ const panel = container.querySelector(`#${panelId}`);
+ expect(panel?.querySelector("[role='list']")).not.toBeNull();
+
+ const first = button(container, /Attempt 1/);
+ const second = button(container, /Attempt 2/);
+ expect(first).toHaveTextContent("failed: lock timeout 1");
+ expect(first).toHaveTextContent("1.0s");
+ expect(second).toHaveTextContent("failed: lock timeout 2");
+ expect(first).toHaveAttribute("aria-expanded", "false");
+ expect(second).toHaveAttribute("aria-expanded", "true");
+ expect(container.textContent).not.toContain("Old Command 1");
+ expect(container.textContent).toContain("Old Command 2");
+
+ act(() => {
+ first.click();
+ });
+ expect(sections.toggleRow).toHaveBeenCalledWith("attempts-0-attempt-1");
+
+ unmount();
+ });
+
+ test("a single previous attempt expands straight to its sections", () => {
+ mocks.useTaskRunLogSections.mockReturnValue(
+ sectionsWithAttempts(attemptGroup(1), new Set(["attempts-0"]))
+ );
+
+ const { container, unmount } = renderViewer();
+
+ expect(button(container, /Previous attempts/)).toHaveTextContent("1 attempt");
+ expect(container.textContent).not.toContain("Attempt 1");
+ expect(container.textContent).toContain("Old Command 1");
+
+ unmount();
+ });
+
+ test("an opened superseded section shows its red error entry untouched", () => {
+ mocks.useTaskRunLogSections.mockReturnValue(
+ sectionsWithAttempts(
+ attemptGroup(1),
+ new Set(["attempts-0", "attempts-0-attempt-1-section-0"])
+ )
+ );
+
+ const { container, unmount } = renderViewer();
+
+ const entry = within(container).getByTestId("task-run-log-row");
+ expect(entry).toHaveTextContent("Old Command 1 entry");
+ expect(entry).toHaveTextContent("✗");
+ expect(entry.querySelector(".text-error")).not.toBeNull();
+
+ unmount();
+ });
+
+ test("a scope still retrying says so on its umbrella while the run runs", () => {
+ mocks.useTaskRunLogSections.mockReturnValue(
+ sectionsWithAttempts(attemptGroup(2, true))
+ );
+
+ const { container, unmount } = renderViewer({ taskRunStatus: TaskRun_Status.RUNNING });
+
+ expect(button(container, /Previous attempts/)).toHaveTextContent(
+ "2 attempts · retrying"
+ );
+
+ unmount();
+ });
+
+ test("a running run whose final attempt finished is not called retrying", () => {
+ // The run can go on after the retried call, for example to its schema sync.
+ mocks.useTaskRunLogSections.mockReturnValue(
+ sectionsWithAttempts(attemptGroup(2, false))
+ );
+
+ const { container, unmount } = renderViewer({
+ taskRunStatus: TaskRun_Status.RUNNING,
+ });
+
+ const umbrella = button(container, /Previous attempts/);
+ expect(umbrella).toHaveTextContent("2 attempts");
+ expect(umbrella).not.toHaveTextContent("retrying");
+
+ unmount();
+ });
+
+ // A run whose replica stopped mid-attempt is failed with its last command
+ // still unanswered in the log; pages without a status show finished runs.
+ for (const taskRunStatus of [TaskRun_Status.FAILED, undefined]) {
+ test(`an unfinished attempt is not called retrying when the run is ${taskRunStatus === undefined ? "of unknown status" : TaskRun_Status[taskRunStatus]}`, () => {
+ mocks.useTaskRunLogSections.mockReturnValue(
+ sectionsWithAttempts(attemptGroup(2, true))
+ );
+
+ const { container, unmount } = renderViewer({ taskRunStatus });
+
+ const umbrella = button(container, /Previous attempts/);
+ expect(umbrella).toHaveTextContent("2 attempts");
+ expect(umbrella).not.toHaveTextContent("retrying");
+
+ unmount();
+ });
+ }
+
+ test("an umbrella with nothing after it keeps the summary chrome", () => {
+ const group = attemptGroup(1);
+ mocks.useTaskRunLogSections.mockReturnValue({
+ ...sectionsWithAttempts(group),
+ rows: [group],
+ });
+
+ const { container, unmount } = renderViewer();
+
+ expect(container.textContent).toContain("1 sections · 1 entries");
+ button(container, /Previous attempts/);
+
+ unmount();
+ });
+
+ test("derives the dataset key from the run name and its marker count", () => {
+ const seenKeys: string[] = [];
+ mocks.useTaskRunLogSections.mockImplementation(
+ (options: UseTaskRunLogSectionsOptions) => {
+ seenKeys.push(options.datasetKey);
+ return createDefaultSections();
+ }
+ );
+
+ mocks.useTaskRunLogData.mockReturnValue({
+ ...createDefaultData(),
+ entries: [
+ runningCommand(1),
+ retry(2, 1),
+ runningCommand(3),
+ retry(4, 1),
+ runningCommand(5),
+ ],
+ });
+ const { unmount } = renderViewer();
+ expect(seenKeys.at(-1)).toBe("runs/1:2");
+ unmount();
+
+ mocks.useTaskRunLogData.mockReturnValue({
+ ...createDefaultData(),
+ entries: [runningCommand(1), runningCommand(3)],
+ });
+ const plain = renderViewer();
+ expect(seenKeys.at(-1)).toBe("runs/1:0");
+ plain.unmount();
+ });
+
+ test("a marker resets a section's load-more state; an ordinary append keeps it", () => {
+ const large = largeSection("section-0", "Big Command");
+ mocks.useTaskRunLogSections.mockReturnValue({
+ ...createDefaultSections(),
+ rows: [large, section("section-1", "Other")],
+ totalSections: 2,
+ totalEntries: 61,
+ });
+ mocks.useTaskRunLogData.mockReturnValue({
+ ...createDefaultData(),
+ entries: [runningCommand(1)],
+ });
+
+ const { container, rerender, unmount } = renderViewer();
+ act(() => {
+ button(container, /Load more/).click();
+ });
+ expect(container.textContent).toContain("ROW 59");
+
+ // `active` only reaches the mocked data hook; changing it is what makes
+ // the memoized viewer render again with the new entries.
+ const renderWith = (entries: TaskRunLogEntry[], active: boolean) => {
+ mocks.useTaskRunLogData.mockReturnValue({ ...createDefaultData(), entries });
+ rerender({ active });
+ };
+
+ renderWith([runningCommand(1), runningCommand(2)], false);
+ expect(container.textContent).toContain("ROW 59");
+
+ // The marker regroups the list, so the section instance at this position
+ // no longer shows the same section; its load-more state must go with it.
+ renderWith([runningCommand(1), runningCommand(2), retry(3, 1)], true);
+ expect(container.textContent).not.toContain("ROW 59");
+
+ unmount();
+ });
});
describe("TaskRunLogViewer row folds", () => {
- const SHOW = "task-run.log-detail.show-full-statement";
- const HIDE = "task-run.log-detail.hide-full-statement";
+ const SHOW = "Show full statement";
+ const HIDE = "Hide full statement";
const STATEMENT = "ALTER TABLE t\n ADD COLUMN c int;";
const ROW_HEIGHT = 28;
@@ -346,20 +610,14 @@ describe("TaskRunLogViewer row folds", () => {
props: { taskRunStatus?: TaskRun_Status } = {}
) => {
log.entries = entries;
- const view = renderIntoContainer(
- createElement(TaskRunLogViewer, { taskRunName: "runs/1", ...props })
- );
+ const view = renderViewer(props);
const poll = (next: TaskRunLogEntry[]) =>
act(() => {
log.entries = next;
for (const listener of log.listeners) listener();
});
const switchTo = (taskRunName: string) =>
- act(() => {
- view.root.render(
- createElement(TaskRunLogViewer, { ...props, taskRunName })
- );
- });
+ view.rerender({ ...props, taskRunName });
const foldControl = () =>
view.container.querySelector<HTMLButtonElement>(
`button[aria-label="${SHOW}"], button[aria-label="${HIDE}"]`
@@ -493,13 +751,33 @@ describe("TaskRunLogViewer row folds", () => {
]);
expect(view.container.textContent).toContain(
- "task-run.log-viewer.multiple-replicas-notice"
+ "Logs are grouped by replica"
);
expect(view.block()?.textContent).toContain("ADD COLUMN c int;");
view.unmount();
});
+ test("a row the reader unfolded stays unfolded when a retry marker folds it into Previous attempts", () => {
+ const attempt = [
+ transaction(1),
+ command(2, "ERROR: lock timeout"),
+ transaction(4),
+ ];
+ const view = mountViewer(attempt);
+ click(view.foldControl());
+ expect(view.block()).not.toBeNull();
+
+ view.poll([...attempt, retry(5, 1), transaction(6)]);
+ expect(view.block()).toBeNull();
+
+ click(view.sectionHeader("Previous attempts"));
+ expect(view.foldControl()?.getAttribute("aria-expanded")).toBe("true");
+ expect(view.block()).not.toBeNull();
+
+ view.unmount();
+ });
+
test("a different task run starts with no folds", () => {
const view = mountViewer([command(2, "ERROR: exists")]);
diff --git a/frontend/src/components/task-run-log/TaskRunLogViewer.tsx b/frontend/src/components/task-run-log/TaskRunLogViewer.tsx
index 5d22743063..8b01c2f8ae 100644
--- a/frontend/src/components/task-run-log/TaskRunLogViewer.tsx
+++ b/frontend/src/components/task-run-log/TaskRunLogViewer.tsx
@@ -11,12 +11,14 @@ import { useTranslation } from "react-i18next";
import { Button } from "@/components/ui/button";
import { useSeededState } from "@/hooks/useSeededState";
import {
- type TaskRun_Status,
+ TaskRun_Status,
TaskRunLogEntry_Type,
} from "@/types/proto-es/v1/rollout_service_pb";
-import type { TaskRunLogDetailText } from "./model";
+import { LogRows, ROW_DIVIDER } from "./LogRows";
+import { countRetryMarkers, type TaskRunLogDetailText } from "./model";
import { SectionContent } from "./SectionContent";
-import { SectionHeader, SectionStatusIcon } from "./SectionHeader";
+import { SectionStatusIcon } from "./SectionHeader";
+import type { LogRow } from "./types";
import { useTaskRunLogData } from "./useTaskRunLogData";
import { useTaskRunLogSections } from "./useTaskRunLogSections";
@@ -76,7 +78,6 @@ export const TaskRunLogViewer = memo(function TaskRunLogViewer({
[TaskRunLogEntry_Type.PRIOR_BACKUP]: t(
"task-run.log-type.prior-backup"
),
- [TaskRunLogEntry_Type.RETRY_INFO]: t("task-run.log-type.retry"),
[TaskRunLogEntry_Type.COMPUTE_DIFF]: t(
"task-run.log-type.compute-diff"
),
@@ -103,22 +104,23 @@ export const TaskRunLogViewer = memo(function TaskRunLogViewer({
},
backupCompleted: (count: number) =>
t("task-run.log-detail.backup-completed", { count }),
- retryAttempt: (current: number, max: number) =>
- t("task-run.log-detail.retry-attempt", { current, max }),
}),
[t]
);
+ // A retry marker regroups the positional rows, so it resets expansion the
+ // way switching runs does; an ordinary append leaves the key alone.
+ const datasetKey = `${taskRunName}:${countRetryMarkers(entries)}`;
const {
- sections,
+ rows,
hasMultipleReplicas,
hasReleaseFiles,
releaseFileGroups,
replicaGroups,
- toggleSection,
+ toggleRow,
toggleReplica,
toggleReleaseFile,
- isSectionExpanded,
+ isRowExpanded,
isReplicaExpanded,
isReleaseFileExpanded,
expandAll,
@@ -132,14 +134,14 @@ export const TaskRunLogViewer = memo(function TaskRunLogViewer({
sheetsMap,
getSectionLabel,
detailText,
- datasetKey: taskRunName,
+ datasetKey,
taskRunStatus,
});
const hasRenderableReleaseFiles =
hasReleaseFiles && releaseFileGroups.length > 0;
const hasContent =
- sections.length > 0 || hasMultipleReplicas || hasRenderableReleaseFiles;
+ rows.length > 0 || hasMultipleReplicas || hasRenderableReleaseFiles;
if (!taskRunName) {
return null;
@@ -162,13 +164,20 @@ export const TaskRunLogViewer = memo(function TaskRunLogViewer({
// A single section with no replicas or release files carries no structure
// worth disclosing — skip the summary bar and the collapsible section header
// and show the entries directly under a lightweight, non-collapsible label.
+ const firstRow = rows[0];
const soleSection =
- !hasMultipleReplicas && !hasRenderableReleaseFiles && sections.length === 1
- ? sections[0]
+ !hasMultipleReplicas &&
+ !hasRenderableReleaseFiles &&
+ rows.length === 1 &&
+ firstRow?.kind === "section"
+ ? firstRow
: undefined;
if (soleSection) {
return (
- <div className="w-full font-mono text-xs">
+ <div
+ className="w-full font-mono text-xs"
+ data-testid="task-run-log-viewer"
+ >
<div className="w-full overflow-hidden rounded-sm border border-block-border bg-control-bg/50">
<div className="flex items-center gap-x-2 px-3 py-1.5 text-control">
<SectionStatusIcon section={soleSection} />
@@ -180,8 +189,8 @@ export const TaskRunLogViewer = memo(function TaskRunLogViewer({
) : null}
</div>
<SectionContent
+ key={datasetKey}
section={soleSection}
- datasetKey={taskRunName}
foldOverrides={foldOverrides}
onFoldChange={handleFoldChange}
/>
@@ -198,30 +207,18 @@ export const TaskRunLogViewer = memo(function TaskRunLogViewer({
expandAll();
};
- const renderSection = (
- section: (typeof sections)[number],
- indent = false
- ) => (
- <div
- key={section.id}
- className="border-block-border border-b last:border-b-0"
- >
- <SectionHeader
- section={section}
- indent={indent}
- isExpanded={isSectionExpanded(section.id)}
- onToggle={() => toggleSection(section.id)}
- />
- {isSectionExpanded(section.id) ? (
- <SectionContent
- section={section}
- indent={indent}
- datasetKey={taskRunName}
- foldOverrides={foldOverrides}
- onFoldChange={handleFoldChange}
- />
- ) : null}
- </div>
+ // Keyed so every row's local state (load more) resets with the regrouping.
+ const logRows = (groupRows: LogRow[], indent = false) => (
+ <LogRows
+ key={datasetKey}
+ rows={groupRows}
+ indent={indent}
+ running={taskRunStatus === TaskRun_Status.RUNNING}
+ isRowExpanded={isRowExpanded}
+ onToggleRow={toggleRow}
+ foldOverrides={foldOverrides}
+ onFoldChange={handleFoldChange}
+ />
);
const renderReleaseFileGroup = (
@@ -229,18 +226,11 @@ export const TaskRunLogViewer = memo(function TaskRunLogViewer({
indent = false
) => {
if (fileGroup.isOrphan) {
- return (
- <div key={fileGroup.id}>
- {fileGroup.sections.map((section) => renderSection(section, indent))}
- </div>
- );
+ return <div key={fileGroup.id}>{logRows(fileGroup.rows, indent)}</div>;
}
return (
- <div
- key={fileGroup.id}
- className="border-block-border border-b last:border-b-0"
- >
+ <div key={fileGroup.id} className={ROW_DIVIDER}>
<div className={indent ? "pl-4" : ""}>
<Button
type="button"
@@ -263,9 +253,7 @@ export const TaskRunLogViewer = memo(function TaskRunLogViewer({
</Button>
{isReleaseFileExpanded(fileGroup.id) ? (
<div className={indent ? "pl-4" : ""}>
- {fileGroup.sections.map((section) =>
- renderSection(section, true)
- )}
+ {logRows(fileGroup.rows, true)}
</div>
) : null}
</div>
@@ -307,9 +295,7 @@ export const TaskRunLogViewer = memo(function TaskRunLogViewer({
{isReplicaExpanded(replicaGroup.replicaId) ? (
<div>
- {replicaGroup.sections.map((section) =>
- renderSection(section, true)
- )}
+ {logRows(replicaGroup.rows, true)}
{replicaGroup.releaseFileGroups.map((fileGroup) =>
renderReleaseFileGroup(fileGroup, true)
)}
@@ -323,11 +309,11 @@ export const TaskRunLogViewer = memo(function TaskRunLogViewer({
{releaseFileGroups.map((fileGroup) => renderReleaseFileGroup(fileGroup))}
</>
) : (
- <>{sections.map((section) => renderSection(section))}</>
+ logRows(rows)
);
return (
- <div className="w-full font-mono text-xs">
+ <div className="w-full font-mono text-xs" data-testid="task-run-log-viewer">
<div className="w-full overflow-hidden rounded-sm border border-block-border bg-control-bg/50">
<div className="flex items-center justify-between border-block-border border-b bg-control-bg px-2 py-1">
<div className="flex items-center gap-x-2 text-control-light">
diff --git a/frontend/src/components/task-run-log/model.test.ts b/frontend/src/components/task-run-log/model.test.ts
index f66f0bf01b..efae81f211 100644
--- a/frontend/src/components/task-run-log/model.test.ts
+++ b/frontend/src/components/task-run-log/model.test.ts
@@ -1,6 +1,4 @@
import { create } from "@bufbuild/protobuf";
-import { act, createElement } from "react";
-import { createRoot } from "react-dom/client";
import { describe, expect, test, vi } from "vitest";
import {
TaskRun_Status,
@@ -14,20 +12,29 @@ import {
assignEntryKeys,
type BuildSectionsOptions,
buildReleaseFileGroups,
- buildSectionsFromEntries,
+ buildRowsFromEntries,
+ collectLeafSections,
groupEntriesByReleaseFile,
hasReleaseFileMarkers,
type TaskRunLogDetailText,
} from "./model";
+import {
+ begin,
+ commit,
+ databaseSync,
+ failedAttempt,
+ LOCK_TIMEOUT,
+ passedAttempt,
+ priorBackup,
+ retry,
+ rollback,
+} from "./taskRunLogEntries";
+import type { AttemptGroup, LogRow, Section } from "./types";
import {
buildReleaseSheetFetchResult,
buildSheetFetchStateForMissingTask,
getUnresolvedTaskMetadataStateKey,
} from "./useTaskRunLogData";
-import {
- type UseTaskRunLogSectionsResult,
- useTaskRunLogSections,
-} from "./useTaskRunLogSections";
vi.mock("@/api", () => ({
rolloutServiceClientConnect: {},
@@ -51,16 +58,22 @@ const ts = (seconds: number, nanos = 0) => ({
nanos,
});
-const buildSections = (
+const buildRows = (
entries: TaskRunLogEntry[],
options?: Partial<BuildSectionsOptions>
) =>
- buildSectionsFromEntries(entries, {
+ buildRowsFromEntries(entries, {
getSectionLabel: (type) => String(type),
entryKeys: assignEntryKeys(entries),
...options,
});
+// Leaf sections in render order, superseded attempts included.
+const buildSections = (
+ entries: TaskRunLogEntry[],
+ options?: Partial<BuildSectionsOptions>
+) => collectLeafSections(buildRows(entries, options));
+
interface CommandOptions {
statement?: string;
range?: { start: number; end: number };
@@ -128,55 +141,6 @@ const markedDetails = (
sections.flatMap((section) =>
section.items.filter((item) => item.marked).map((item) => item.detail)
);
-(
- globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
-).IS_REACT_ACT_ENVIRONMENT = true;
-
-interface HookHarnessProps {
- entries: TaskRunLogEntry[];
- datasetKey?: string;
- taskRunStatus?: TaskRun_Status;
-}
-
-const createHookHarness = (initialProps: HookHarnessProps) => {
- const container = document.createElement("div");
- const root = createRoot(container);
- let current: UseTaskRunLogSectionsResult | undefined;
-
- const Harness = (props: HookHarnessProps) => {
- current = useTaskRunLogSections({
- entries: props.entries,
- datasetKey: props.datasetKey,
- taskRunStatus: props.taskRunStatus,
- getSectionLabel: (type) => String(type),
- });
- return null;
- };
-
- const render = (props: HookHarnessProps) => {
- act(() => {
- root.render(createElement(Harness, props));
- });
- };
-
- const getCurrent = () => {
- if (!current) {
- throw new Error("hook result is unavailable");
- }
- return current;
- };
-
- render(initialProps);
-
- return {
- render,
- getCurrent,
- unmount: () =>
- act(() => {
- root.unmount();
- }),
- };
-};
describe("task-run-log model", () => {
test("keeps unresolved task sheet state non-error while metadata is pending", () => {
@@ -295,13 +259,13 @@ describe("task-run-log model", () => {
id: "file-0",
version: "v1",
filePath: "001.sql",
- sections: [{ entryCount: 2 }],
+ rows: [{ entryCount: 2 }],
});
expect(groups[1]).toMatchObject({
id: "file-1",
version: "v2",
filePath: "002.sql",
- sections: [{ entryCount: 1 }],
+ rows: [{ entryCount: 1 }],
});
});
@@ -389,7 +353,7 @@ describe("task-run-log model", () => {
expect(sections[1]?.items[0]?.detail).toBe("copy failed");
});
- test("uses localized detail text for completed timed entries, prior backup completion, and retries", () => {
+ test("uses localized detail text for completed timed entries and prior backup completion", () => {
const detailText = {
completed: "Completed",
backingUp: "Backing up...",
@@ -397,8 +361,6 @@ describe("task-run-log model", () => {
[TaskRunLogEntry_Type.SCHEMA_DUMP]: "Dumping...",
},
backupCompleted: (count: number) => `Completed (${count} tables)`,
- retryAttempt: (current: number, max: number) =>
- `Attempt ${current}/${max}`,
} satisfies TaskRunLogDetailText;
const entries = [
@@ -432,22 +394,12 @@ describe("task-run-log model", () => {
error: "",
},
}),
- create(TaskRunLogEntrySchema, {
- type: TaskRunLogEntry_Type.RETRY_INFO,
- logTime: ts(5),
- retryInfo: {
- error: "",
- retryCount: 2,
- maximumRetries: 5,
- },
- }),
];
const sections = buildSections(entries, { detailText });
expect(sections[0]?.items[0]?.detail).toBe("Completed");
expect(sections[1]?.items[0]?.detail).toBe("Completed (2 tables)");
- expect(sections[2]?.items[0]?.detail).toBe("Attempt 2/5");
});
test("drops empty release-file groups created by consecutive and trailing markers", () => {
@@ -513,89 +465,253 @@ describe("task-run-log model", () => {
isOrphan: true,
version: "",
filePath: "",
- sections: [{ entryCount: 1 }],
+ rows: [{ entryCount: 1 }],
});
expect(groups[1]).toMatchObject({
id: "file-0",
version: "v2",
filePath: "002.sql",
- sections: [{ entryCount: 1 }],
+ rows: [{ entryCount: 1 }],
});
});
+});
- test("handles expand/collapse state for filtered release-file groups", () => {
- const entries = [
- create(TaskRunLogEntrySchema, {
- type: TaskRunLogEntry_Type.RELEASE_FILE_EXECUTE,
- logTime: ts(1),
- releaseFileExecute: { version: "v1", filePath: "001.sql" },
- }),
- create(TaskRunLogEntrySchema, {
- type: TaskRunLogEntry_Type.RELEASE_FILE_EXECUTE,
- logTime: ts(2),
- releaseFileExecute: { version: "v2", filePath: "002.sql" },
- }),
- create(TaskRunLogEntrySchema, {
- type: TaskRunLogEntry_Type.COMMAND_EXECUTE,
- logTime: ts(3),
- commandExecute: {
- statement: "SELECT 1;",
- response: { logTime: ts(4) },
- },
- }),
- ];
+const DEADLOCK = "ERROR: deadlock detected";
- const hook = createHookHarness({ entries, datasetKey: "marker-only" });
+describe("task-run-log attempt rows", () => {
+ test("an empty log has no rows", () => {
+ expect(buildRows([])).toEqual([]);
+ });
- expect(hook.getCurrent().releaseFileGroups).toHaveLength(1);
- expect(
- hook.getCurrent().releaseFileGroups.map((group) => group.id)
- ).toEqual(["file-0"]);
- expect(hook.getCurrent().totalSections).toBe(1);
+ test("without a retry marker every row is a section with positional ids", () => {
+ const rows = buildRows([
+ begin(1),
+ command(2, { error: "" }),
+ commit(4),
+ databaseSync(5, 7),
+ ]);
- act(() => {
- hook.getCurrent().collapseAll();
- });
- expect(hook.getCurrent().areAllExpanded).toBe(false);
+ expect(rows.map((row) => row.kind)).toEqual([
+ "section",
+ "section",
+ "section",
+ "section",
+ ]);
+ expect(rows.map((row) => row.id)).toEqual([
+ "section-0",
+ "section-1",
+ "section-2",
+ "section-3",
+ ]);
+ });
- act(() => {
- hook.getCurrent().expandAll();
- });
- expect(hook.getCurrent().areAllExpanded).toBe(true);
+ test("one retry marker folds the attempt before it into a Previous attempts row", () => {
+ const rows = buildRows([
+ begin(1),
+ command(1, { error: LOCK_TIMEOUT }),
+ rollback(2),
+ retry(3, 1),
+ begin(4),
+ command(4, { error: "" }),
+ commit(6),
+ databaseSync(6, 8),
+ ]);
- act(() => {
- hook.getCurrent().toggleReleaseFile("file-0");
+ expect(rows.map((row) => row.kind)).toEqual([
+ "attempts",
+ "section",
+ "section",
+ "section",
+ "section",
+ ]);
+ const umbrella = rows[0] as AttemptGroup;
+ expect(umbrella).toMatchObject({
+ id: "attempts-0",
+ duration: "1.0s",
+ retrying: false,
});
- expect(hook.getCurrent().areAllExpanded).toBe(false);
+ expect(umbrella.attempts).toHaveLength(1);
+ expect(umbrella.attempts[0]).toMatchObject({
+ id: "attempts-0-attempt-1",
+ number: 1,
+ reason: LOCK_TIMEOUT,
+ duration: "1.0s",
+ });
+ expect(
+ umbrella.attempts[0]?.sections.map((section) => [
+ section.id,
+ section.type,
+ section.status,
+ ])
+ ).toEqual([
+ [
+ "attempts-0-attempt-1-section-0",
+ TaskRunLogEntry_Type.TRANSACTION_CONTROL,
+ "success",
+ ],
+ [
+ "attempts-0-attempt-1-section-1",
+ TaskRunLogEntry_Type.COMMAND_EXECUTE,
+ "error",
+ ],
+ [
+ "attempts-0-attempt-1-section-2",
+ TaskRunLogEntry_Type.TRANSACTION_CONTROL,
+ "success",
+ ],
+ ]);
+
+ // The final attempt stays flat and green, ids continuing past the umbrella.
+ expect(
+ rows.slice(1).map((row) => [row.id, (row as Section).status])
+ ).toEqual([
+ ["section-1", "success"],
+ ["section-2", "success"],
+ ["section-3", "success"],
+ ["section-4", "success"],
+ ]);
- hook.unmount();
+ const leaves = collectLeafSections(rows);
+ expect(leaves.some((s) => s.type === TaskRunLogEntry_Type.RETRY_INFO)).toBe(
+ false
+ );
+ expect(leaves.reduce((sum, s) => sum + s.entryCount, 0)).toBe(7);
});
- test("resets expansion state when dataset key changes", () => {
- const entries = [
- create(TaskRunLogEntrySchema, {
- type: TaskRunLogEntry_Type.COMMAND_EXECUTE,
- logTime: ts(1),
- commandExecute: {
- statement: "SELECT 1;",
- response: { logTime: ts(2) },
- },
- }),
- ];
+ test("an auto-commit attempt, with no transaction entries, folds like any other", () => {
+ const rows = buildRows([
+ command(1, { error: "" }),
+ command(2, { error: LOCK_TIMEOUT }),
+ retry(4, 1),
+ command(5, { error: "" }),
+ command(6, { error: "" }),
+ ]);
- const hook = createHookHarness({ entries, datasetKey: "dataset-a" });
- const sectionId = hook.getCurrent().sections[0]?.id;
- expect(sectionId).toBe("section-0");
+ expect(rows.map((row) => [row.id, row.kind])).toEqual([
+ ["attempts-0", "attempts"],
+ ["section-1", "section"],
+ ]);
+ expect(
+ (rows[0] as AttemptGroup).attempts[0]?.sections.map((section) => [
+ section.entryCount,
+ section.status,
+ ])
+ ).toEqual([[2, "error"]]);
+ expect((rows[1] as Section).status).toBe("success");
+ });
+
+ test("several markers number the attempts and label each with the marker that closes it", () => {
+ const rows = buildRows([
+ ...failedAttempt(1, 1),
+ // Numbered by position, not by the marker's retryCount.
+ ...failedAttempt(4, 9, { error: DEADLOCK }),
+ ...passedAttempt(7),
+ ]);
- act(() => {
- hook.getCurrent().toggleSection(sectionId!);
- });
- expect(hook.getCurrent().isSectionExpanded(sectionId!)).toBe(true);
+ expect(rows.map((row) => row.kind)).toEqual([
+ "attempts",
+ "section",
+ "section",
+ "section",
+ ]);
+ const umbrella = rows[0] as AttemptGroup;
+ expect(umbrella.duration).toBe("2.0s");
+ expect(
+ umbrella.attempts.map((attempt) => [
+ attempt.number,
+ attempt.reason,
+ attempt.duration,
+ attempt.sections.length,
+ ])
+ ).toEqual([
+ [1, LOCK_TIMEOUT, "1.0s", 3],
+ [2, DEADLOCK, "1.0s", 3],
+ ]);
+ });
- hook.render({ entries, datasetKey: "dataset-b" });
- expect(hook.getCurrent().isSectionExpanded(sectionId!)).toBe(false);
+ test("prior backup and database sync stay outside the attempts, in place", () => {
+ const rows = buildRows([
+ priorBackup(1, 3),
+ ...failedAttempt(4, 1),
+ ...passedAttempt(7),
+ databaseSync(10, 14),
+ ]);
- hook.unmount();
+ expect(
+ rows.map((row) => [
+ row.kind,
+ row.kind === "section" ? row.type : row.attempts.length,
+ row.duration,
+ ])
+ ).toEqual([
+ ["section", TaskRunLogEntry_Type.PRIOR_BACKUP, "2.0s"],
+ ["attempts", 1, "1.0s"],
+ ["section", TaskRunLogEntry_Type.TRANSACTION_CONTROL, "<1ms"],
+ ["section", TaskRunLogEntry_Type.COMMAND_EXECUTE, "1.0s"],
+ ["section", TaskRunLogEntry_Type.TRANSACTION_CONTROL, "<1ms"],
+ ["section", TaskRunLogEntry_Type.DATABASE_SYNC, "4.0s"],
+ ]);
+ });
+
+ test("a marker with nothing after it renders the umbrella alone, not retrying", () => {
+ const rows = buildRows([priorBackup(1, 3), ...failedAttempt(4, 1)]);
+
+ expect(rows.map((row) => row.kind)).toEqual(["section", "attempts"]);
+ expect(rows[1]).toMatchObject({ retrying: false });
+ expect((rows[1] as AttemptGroup).attempts).toHaveLength(1);
+ });
+
+ test("a final segment still running marks the umbrella as retrying", () => {
+ const rows = buildRows([
+ ...failedAttempt(1, 1),
+ ...failedAttempt(4, 2),
+ begin(7),
+ command(7),
+ ]);
+
+ expect(rows.map((row) => row.kind)).toEqual([
+ "attempts",
+ "section",
+ "section",
+ ]);
+ expect(rows[0]).toMatchObject({ retrying: true });
+ expect((rows[0] as AttemptGroup).attempts).toHaveLength(2);
+ expect((rows[2] as Section).status).toBe("running");
+ });
+
+ test("each release file that retried gets its own umbrella with its own count", () => {
+ const entries = [
+ releaseFile(1, "v1"),
+ ...failedAttempt(2, 1),
+ ...passedAttempt(5),
+ releaseFile(8, "v2"),
+ ...passedAttempt(9),
+ releaseFile(12, "v3"),
+ ...failedAttempt(13, 1),
+ ...failedAttempt(16, 2),
+ ...passedAttempt(19),
+ ];
+ const groups = buildReleaseFileGroups(entries, {
+ getSectionLabel: (type) => String(type),
+ entryKeys: assignEntryKeys(entries),
+ });
+
+ const shape = (row: LogRow) =>
+ row.kind === "attempts" ? `attempts:${row.attempts.length}` : "section";
+ expect(
+ groups.map((group) => [group.version, group.rows.map(shape)])
+ ).toEqual([
+ ["v1", ["attempts:1", "section", "section", "section"]],
+ ["v2", ["section", "section", "section"]],
+ ["v3", ["attempts:2", "section", "section", "section"]],
+ ]);
+ // Ids nest under the file so two files' umbrellas never collide.
+ expect(groups[0]?.rows[0]?.id).toBe("file-0-attempts-0");
+ const thirdFileUmbrella = groups[2]?.rows[0] as AttemptGroup | undefined;
+ expect(thirdFileUmbrella?.id).toBe("file-2-attempts-0");
+ expect(thirdFileUmbrella?.attempts[1]?.id).toBe(
+ "file-2-attempts-0-attempt-2"
+ );
});
});
@@ -669,7 +785,7 @@ describe("command row payloads", () => {
});
test("entries that carry status words return the detail alone", () => {
- const sections = buildSections([transaction(1), retryMarker(2)]);
+ const sections = buildSections([transaction(1), databaseSync(2, 3)]);
for (const section of sections) {
expect(section.items[0]?.statement).toBeUndefined();
@@ -763,54 +879,6 @@ describe("the row that opens by default", () => {
expect(markedDetails(sections)).toEqual([]);
});
-
- test("one replica's success does not silence another replica's failure", () => {
- const hook = createHookHarness({
- entries: [
- command(1, { statement: "SELECT 1;", error: "boom", replicaId: "a" }),
- command(3, { statement: "SELECT 1;", error: "", replicaId: "b" }),
- ],
- datasetKey: "replicas",
- });
-
- const [first, second] = hook.getCurrent().replicaGroups;
- expect(markedDetails(first?.sections ?? [])).toEqual(["boom"]);
- expect(markedDetails(second?.sections ?? [])).toEqual([]);
-
- hook.unmount();
- });
-
- test("the hook forwards a DONE status into every builder it calls", () => {
- const failing = (replicaId: string) => [
- command(1, { statement: "SELECT 0;", error: "orphan", replicaId }),
- releaseFile(3, "v1", { replicaId }),
- command(4, { statement: "SELECT 1;", error: "in file", replicaId }),
- ];
- const entries = [...failing("a"), ...failing("b")];
- const allSections = (result: UseTaskRunLogSectionsResult) => [
- ...result.sections,
- ...result.releaseFileGroups.flatMap((group) => group.sections),
- ...result.replicaGroups.flatMap((group) => [
- ...group.sections,
- ...group.releaseFileGroups.flatMap((fileGroup) => fileGroup.sections),
- ]),
- ];
-
- const hook = createHookHarness({ entries, datasetKey: "done-guard" });
- // Flat, release-file, orphan, per-replica orphan and per-replica file.
- expect(
- markedDetails(allSections(hook.getCurrent())).length
- ).toBeGreaterThan(4);
-
- hook.render({
- entries,
- datasetKey: "done-guard",
- taskRunStatus: TaskRun_Status.DONE,
- });
- expect(markedDetails(allSections(hook.getCurrent()))).toEqual([]);
-
- hook.unmount();
- });
});
describe("row identity", () => {
@@ -841,7 +909,7 @@ describe("row identity", () => {
expect(groups).toHaveLength(2);
const [first, second] = groups.map(
- (group) => group.sections[0]?.items[0]?.key
+ (group) => collectLeafSections(group.rows)[0]?.items[0]?.key
);
expect(first).toBeDefined();
expect(first).not.toBe(second);
@@ -862,36 +930,13 @@ describe("row identity", () => {
const stranger = command(1, { statement: "SELECT 1;", error: "" });
expect(() =>
- buildSectionsFromEntries([stranger], {
+ buildRowsFromEntries([stranger], {
getSectionLabel: (type) => String(type),
entryKeys: assignEntryKeys([]),
})
).toThrow();
});
- test("a row's key survives a second replica appearing", () => {
- const first = () =>
- command(1, { statement: "SELECT 1;", error: "", replicaId: "a" });
- const hook = createHookHarness({ entries: [first()], datasetKey: "run" });
- const before = hook.getCurrent().sections[0]?.items[0]?.key;
-
- hook.render({
- entries: [
- first(),
- command(3, { statement: "SELECT 1;", error: "", replicaId: "b" }),
- ],
- datasetKey: "run",
- });
-
- expect(hook.getCurrent().hasMultipleReplicas).toBe(true);
- const after =
- hook.getCurrent().replicaGroups[0]?.sections[0]?.items[0]?.key;
- expect(before).toBeDefined();
- expect(after).toBe(before);
-
- hook.unmount();
- });
-
test("a row's key survives a retry marker splitting its section", () => {
const commands = () => [
command(1, { statement: "SELECT 1;", error: "" }),
@@ -901,8 +946,8 @@ describe("row identity", () => {
expect(before).toHaveLength(1);
const after = buildSections([...commands(), retryMarker(3)]);
- expect(after).toHaveLength(3);
- expect(after[2]?.items[0]?.key).toBe(before[0]?.items[1]?.key);
+ expect(after).toHaveLength(2);
+ expect(after[1]?.items[0]?.key).toBe(before[0]?.items[1]?.key);
expect(after[0]?.items[0]?.key).toBe(before[0]?.items[0]?.key);
});
});
diff --git a/frontend/src/components/task-run-log/model.ts b/frontend/src/components/task-run-log/model.ts
index 958902e9a9..d489cc7953 100644
--- a/frontend/src/components/task-run-log/model.ts
+++ b/frontend/src/components/task-run-log/model.ts
@@ -9,8 +9,11 @@ import {
} from "@/types/proto-es/v1/rollout_service_pb";
import type { Sheet } from "@/types/proto-es/v1/sheet_service_pb";
import type {
+ Attempt,
+ AttemptGroup,
DisplayItem,
EntryGroup,
+ LogRow,
ReleaseFileEntriesGroup,
ReleaseFileGroup,
Section,
@@ -61,10 +64,12 @@ export interface TaskRunLogDetailText {
backingUp?: string;
runningByType?: Partial<Record<TaskRunLogEntry_Type, string>>;
transactionError?: (typeLabel: string, error: string) => string;
- retryAttempt?: (current: number, max: number) => string;
backupCompleted?: (count: number) => string;
}
+const prefixId = (idPrefix: string | undefined, id: string): string =>
+ idPrefix ? `${idPrefix}-${id}` : id;
+
export const getTimestampMs = (timestamp?: Timestamp): number => {
if (!timestamp) return 0;
return Number(timestamp.seconds) * 1000 + timestamp.nanos / 1000000;
@@ -171,9 +176,6 @@ export const isComplete = (entry: TaskRunLogEntry): boolean => {
return Boolean(
entry.ghostMigration?.startTime && entry.ghostMigration?.endTime
);
- case TaskRunLogEntry_Type.TRANSACTION_CONTROL:
- case TaskRunLogEntry_Type.RETRY_INFO:
- return true;
default:
return true;
}
@@ -219,9 +221,7 @@ export const groupEntriesByReleaseFile = (
): ReleaseFileEntriesGroup[] => {
if (entries.length === 0) return [];
- const sorted = [...entries].sort(
- (a, b) => getTimestampMs(a.logTime) - getTimestampMs(b.logTime)
- );
+ const sorted = sortEntriesByTime(entries);
const groups: ReleaseFileEntriesGroup[] = [];
let current: ReleaseFileEntriesGroup = { file: null, entries: [] };
@@ -254,9 +254,7 @@ export const groupEntriesByReleaseFile = (
export const getUniqueReplicaIds = (entries: TaskRunLogEntry[]): string[] => {
if (entries.length === 0) return [];
- const sorted = [...entries].sort(
- (a, b) => getTimestampMs(a.logTime) - getTimestampMs(b.logTime)
- );
+ const sorted = sortEntriesByTime(entries);
const replicaIds: string[] = [];
const seen = new Set<string>();
@@ -442,18 +440,6 @@ const getPriorBackupDetail = (
return detailText?.backingUp ?? "";
};
-const getRetryInfoDetail = (
- entry: TaskRunLogEntry,
- detailText: TaskRunLogDetailText | undefined
-): string => {
- const retryInfo = entry.retryInfo;
- if (!retryInfo) return "";
- const attempt = detailText?.retryAttempt
- ? detailText.retryAttempt(retryInfo.retryCount, retryInfo.maximumRetries)
- : `${retryInfo.retryCount}/${retryInfo.maximumRetries}`;
- return retryInfo.error ? `${attempt}: ${retryInfo.error}` : attempt;
-};
-
const getReleaseFileExecuteDetail = (entry: TaskRunLogEntry): string => {
const releaseFile = entry.releaseFileExecute;
if (!releaseFile) return "";
@@ -487,8 +473,6 @@ const getStatusDetail = (
);
case TaskRunLogEntry_Type.PRIOR_BACKUP:
return getPriorBackupDetail(entry, detailText);
- case TaskRunLogEntry_Type.RETRY_INFO:
- return getRetryInfoDetail(entry, detailText);
case TaskRunLogEntry_Type.COMPUTE_DIFF:
return getTimedEntryDetail(
entry.computeDiff,
@@ -601,56 +585,208 @@ const pickMarkedEntry = (
return superseded ? undefined : sorted[lastFailedIndex];
};
+// The span covered by a run of entries. `durationMs` is undefined when no entry
+// has a start or none has an end; an unanswered command's end is its start.
+const getEntriesTimeSpan = (
+ entries: TaskRunLogEntry[]
+): { startTime: number; durationMs: number | undefined } => {
+ const timeRanges = entries.map(getEntryTimeRange);
+ const startTimes = timeRanges
+ .map((range) => range.start)
+ .filter((time) => time > 0);
+ const endTimes = timeRanges
+ .map((range) => range.end)
+ .filter((time) => time > 0);
+ const startTime = startTimes.length > 0 ? Math.min(...startTimes) : 0;
+ const endTime = endTimes.length > 0 ? Math.max(...endTimes) : 0;
+ return {
+ startTime,
+ durationMs:
+ startTime > 0 && endTime > 0
+ ? Math.max(endTime - startTime, 0)
+ : undefined,
+ };
+};
+
+const formatOptionalDuration = (durationMs: number | undefined): string =>
+ durationMs === undefined ? "" : formatDuration(durationMs);
+
const calculateSectionStatus = (entries: TaskRunLogEntry[]): SectionStatus => {
if (entries.some(hasError)) return "error";
if (entries.every(isComplete)) return "success";
return "running";
};
-export const buildSectionsFromEntries = (
+// Sections for one run of a context. `markedEntry` is the context's pick, which
+// a run cannot make on its own; `indexOffset` positions the run's first section
+// among its siblings.
+const buildSections = (
entries: TaskRunLogEntry[],
- options: BuildSectionsOptions
-): Section[] => {
- if (entries.length === 0) return [];
-
- const sorted = sortEntriesByTime(entries);
- const markedEntry = pickMarkedEntry(sorted, options.taskRunStatus);
-
- return groupEntriesByType(sorted).map((group, groupIndex) => {
+ options: BuildSectionsOptions,
+ markedEntry: TaskRunLogEntry | undefined,
+ indexOffset = 0
+): Section[] =>
+ groupEntriesByType(entries).map((group, index) => {
+ const groupIndex = indexOffset + index;
let status = calculateSectionStatus(group.entries);
if (options.forceError && status === "running") {
status = "error";
}
const statusConfig = STATUS_CONFIG[status];
-
- const timeRanges = group.entries.map(getEntryTimeRange);
- const startTimes = timeRanges
- .map((range) => range.start)
- .filter((time) => time > 0);
- const endTimes = timeRanges
- .map((range) => range.end)
- .filter((time) => time > 0);
- const startTime = startTimes.length > 0 ? Math.min(...startTimes) : 0;
- const endTime = endTimes.length > 0 ? Math.max(...endTimes) : 0;
- const durationMs = endTime - startTime;
+ const { startTime, durationMs } = getEntriesTimeSpan(group.entries);
return {
- id: options.idPrefix
- ? `${options.idPrefix}-section-${groupIndex}`
- : `section-${groupIndex}`,
+ kind: "section",
+ id: prefixId(options.idPrefix, `section-${groupIndex}`),
type: group.type,
label: options.getSectionLabel(group.type),
status,
statusIcon: statusConfig.icon,
statusClass: statusConfig.className,
- duration:
- startTime > 0 && endTime > 0
- ? formatDuration(Math.max(durationMs, 0))
- : "",
+ duration: formatOptionalDuration(durationMs),
entryCount: group.entries.length,
items: buildDisplayItems(group.entries, startTime, markedEntry, options),
};
});
+
+// Only entries the driver writes inside `driver.Execute` are retried; the
+// executor emits every other type once, around that call.
+const ATTEMPT_MATERIAL_TYPES: ReadonlySet<TaskRunLogEntry_Type> = new Set([
+ TaskRunLogEntry_Type.TRANSACTION_CONTROL,
+ TaskRunLogEntry_Type.COMMAND_EXECUTE,
+ TaskRunLogEntry_Type.RETRY_INFO,
+]);
+
+const isAttemptMaterial = (entry: TaskRunLogEntry): boolean =>
+ ATTEMPT_MATERIAL_TYPES.has(entry.type);
+
+const isRetryMarker = (entry: TaskRunLogEntry): boolean =>
+ entry.type === TaskRunLogEntry_Type.RETRY_INFO;
+
+export const countRetryMarkers = (entries: TaskRunLogEntry[]): number =>
+ entries.filter(isRetryMarker).length;
+
+interface AttemptEntries {
+ entries: TaskRunLogEntry[];
+ marker: TaskRunLogEntry;
+}
+
+// Marker i closes attempt i; the entries after the last marker are the final
+// attempt, which may be empty while the retry has not logged anything yet.
+const cutAttempts = (
+ scope: TaskRunLogEntry[]
+): { attempts: AttemptEntries[]; final: TaskRunLogEntry[] } => {
+ const attempts: AttemptEntries[] = [];
+ let segment: TaskRunLogEntry[] = [];
+ for (const entry of scope) {
+ if (isRetryMarker(entry)) {
+ attempts.push({ entries: segment, marker: entry });
+ segment = [];
+ continue;
+ }
+ segment.push(entry);
+ }
+ return { attempts, final: segment };
+};
+
+// Maximal contiguous runs of attempt material and of one-time entries. Sections
+// group by type, and the two kinds are disjoint, so cutting at every run
+// boundary changes nothing for a run that never retried.
+const splitByAttemptMaterial = (
+ sorted: TaskRunLogEntry[]
+): TaskRunLogEntry[][] => {
+ const runs: TaskRunLogEntry[][] = [];
+ for (const entry of sorted) {
+ const run = runs.at(-1);
+ if (run && isAttemptMaterial(run[0]) === isAttemptMaterial(entry)) {
+ run.push(entry);
+ } else {
+ runs.push([entry]);
+ }
+ }
+ return runs;
+};
+
+// Leaf sections in render order: top-level sections and every attempt's
+// sections, superseded attempts included. Umbrella and attempt rows are
+// containers, not sections.
+export const collectLeafSections = (rows: LogRow[]): Section[] =>
+ rows.flatMap((row) =>
+ row.kind === "section"
+ ? [row]
+ : row.attempts.flatMap((attempt) => attempt.sections)
+ );
+
+// With one previous attempt the umbrella opens straight onto its sections, so
+// that attempt has no row of its own.
+export const soleAttemptOf = (group: AttemptGroup): Attempt | undefined =>
+ group.attempts.length === 1 ? group.attempts[0] : undefined;
+
+// Ids of the umbrella and attempt rows a reader can open.
+export const collectAttemptRowIds = (rows: LogRow[]): string[] =>
+ rows.flatMap((row) => {
+ if (row.kind !== "attempts") return [];
+ if (soleAttemptOf(row)) return [row.id];
+ return [row.id, ...row.attempts.map((attempt) => attempt.id)];
+ });
+
+export const buildRowsFromEntries = (
+ entries: TaskRunLogEntry[],
+ options: BuildSectionsOptions
+): LogRow[] => {
+ const sorted = sortEntriesByTime(entries);
+ // Picked before the cut: an attempt on its own has lost the marker that
+ // supersedes its failure.
+ const markedEntry = pickMarkedEntry(sorted, options.taskRunStatus);
+ const rows: LogRow[] = [];
+
+ for (const run of splitByAttemptMaterial(sorted)) {
+ // A retried execution scope is a run of attempt material holding a marker.
+ if (!run.some(isRetryMarker)) {
+ rows.push(...buildSections(run, options, markedEntry, rows.length));
+ continue;
+ }
+
+ const scope = cutAttempts(run);
+ const groupId = prefixId(options.idPrefix, `attempts-${rows.length}`);
+ let groupDurationMs: number | undefined;
+ const attempts: Attempt[] = scope.attempts.map(
+ ({ entries: attemptEntries, marker }, index) => {
+ const id = `${groupId}-attempt-${index + 1}`;
+ const { durationMs } = getEntriesTimeSpan(attemptEntries);
+ if (durationMs !== undefined) {
+ groupDurationMs = (groupDurationMs ?? 0) + durationMs;
+ }
+ return {
+ id,
+ number: index + 1,
+ reason: marker.retryInfo?.error ?? "",
+ duration: formatOptionalDuration(durationMs),
+ sections: buildSections(
+ attemptEntries,
+ { ...options, idPrefix: id },
+ markedEntry
+ ),
+ };
+ }
+ );
+ const finalSections = buildSections(
+ scope.final,
+ options,
+ markedEntry,
+ rows.length + 1
+ );
+ rows.push({
+ kind: "attempts",
+ id: groupId,
+ attempts,
+ duration: formatOptionalDuration(groupDurationMs),
+ retrying: finalSections.some((section) => section.status === "running"),
+ });
+ rows.push(...finalSections);
+ }
+
+ return rows;
};
export const buildReleaseFileGroups = (
@@ -670,15 +806,13 @@ export const buildReleaseFileGroups = (
if (!buildOptions.includeOrphanGroup || group.entries.length === 0) {
continue;
}
- const orphanPrefix = buildOptions.idPrefix
- ? `${buildOptions.idPrefix}-orphan`
- : "orphan";
+ const orphanPrefix = prefixId(buildOptions.idPrefix, "orphan");
results.push({
id: orphanPrefix,
version: "",
filePath: "",
isOrphan: true,
- sections: buildSectionsFromEntries(group.entries, {
+ rows: buildRowsFromEntries(group.entries, {
...buildOptions,
idPrefix: orphanPrefix,
}),
@@ -690,15 +824,13 @@ export const buildReleaseFileGroups = (
continue;
}
- const filePrefix = buildOptions.idPrefix
- ? `${buildOptions.idPrefix}-file-${fileIndex}`
- : `file-${fileIndex}`;
+ const filePrefix = prefixId(buildOptions.idPrefix, `file-${fileIndex}`);
fileIndex++;
results.push({
id: filePrefix,
version: group.file.version,
filePath: group.file.filePath,
- sections: buildSectionsFromEntries(group.entries, {
+ rows: buildRowsFromEntries(group.entries, {
...buildOptions,
idPrefix: filePrefix,
fileVersion: group.file.version,
diff --git a/frontend/src/components/task-run-log/taskRunLogEntries.ts b/frontend/src/components/task-run-log/taskRunLogEntries.ts
new file mode 100644
index 0000000000..4d10d22a08
--- /dev/null
+++ b/frontend/src/components/task-run-log/taskRunLogEntries.ts
@@ -0,0 +1,134 @@
+import { create } from "@bufbuild/protobuf";
+import {
+ type TaskRunLogEntry,
+ TaskRunLogEntry_TransactionControl_Type,
+ TaskRunLogEntry_Type,
+ TaskRunLogEntrySchema,
+} from "@/types/proto-es/v1/rollout_service_pb";
+
+// Task run log entries for tests of the log viewer. Times are whole seconds so
+// durations read as literals ("2.0s") in assertions.
+
+export const LOCK_TIMEOUT = "ERROR: canceling statement due to lock timeout";
+const STATEMENT = "ALTER TABLE book ADD COLUMN title TEXT;";
+
+export const ts = (seconds: number) => ({ seconds: BigInt(seconds), nanos: 0 });
+
+interface EntryOptions {
+ replicaId?: string;
+}
+
+interface OutcomeOptions extends EntryOptions {
+ error?: string;
+}
+
+const transaction = (
+ at: number,
+ type: TaskRunLogEntry_TransactionControl_Type,
+ { replicaId = "" }: EntryOptions
+): TaskRunLogEntry =>
+ create(TaskRunLogEntrySchema, {
+ type: TaskRunLogEntry_Type.TRANSACTION_CONTROL,
+ logTime: ts(at),
+ replicaId,
+ transactionControl: { type, error: "" },
+ });
+
+export const begin = (at: number, options: EntryOptions = {}) =>
+ transaction(at, TaskRunLogEntry_TransactionControl_Type.BEGIN, options);
+export const commit = (at: number, options: EntryOptions = {}) =>
+ transaction(at, TaskRunLogEntry_TransactionControl_Type.COMMIT, options);
+export const rollback = (at: number, options: EntryOptions = {}) =>
+ transaction(at, TaskRunLogEntry_TransactionControl_Type.ROLLBACK, options);
+
+export const command = (
+ at: number,
+ done: number,
+ { error = "", replicaId = "" }: OutcomeOptions = {}
+) =>
+ create(TaskRunLogEntrySchema, {
+ type: TaskRunLogEntry_Type.COMMAND_EXECUTE,
+ logTime: ts(at),
+ replicaId,
+ commandExecute: {
+ logTime: ts(at),
+ statement: STATEMENT,
+ response: { logTime: ts(done), error },
+ },
+ });
+
+// A command with no response yet.
+export const runningCommand = (
+ at: number,
+ { replicaId = "" }: EntryOptions = {}
+) =>
+ create(TaskRunLogEntrySchema, {
+ type: TaskRunLogEntry_Type.COMMAND_EXECUTE,
+ logTime: ts(at),
+ replicaId,
+ commandExecute: { logTime: ts(at), statement: STATEMENT },
+ });
+
+export const retry = (
+ at: number,
+ retryCount: number,
+ { error = LOCK_TIMEOUT, replicaId = "" }: OutcomeOptions = {}
+) =>
+ create(TaskRunLogEntrySchema, {
+ type: TaskRunLogEntry_Type.RETRY_INFO,
+ logTime: ts(at),
+ replicaId,
+ retryInfo: { retryCount, maximumRetries: 5, error },
+ });
+
+export const priorBackup = (start: number, end: number) =>
+ create(TaskRunLogEntrySchema, {
+ type: TaskRunLogEntry_Type.PRIOR_BACKUP,
+ logTime: ts(start),
+ priorBackup: { startTime: ts(start), endTime: ts(end), error: "" },
+ });
+
+export const databaseSync = (
+ start: number,
+ end: number,
+ { error = "" }: OutcomeOptions = {}
+) =>
+ create(TaskRunLogEntrySchema, {
+ type: TaskRunLogEntry_Type.DATABASE_SYNC,
+ logTime: ts(start),
+ databaseSync: { startTime: ts(start), endTime: ts(end), error },
+ });
+
+export const releaseFile = (
+ at: number,
+ version: string,
+ filePath: string,
+ { replicaId = "" }: EntryOptions = {}
+) =>
+ create(TaskRunLogEntrySchema, {
+ type: TaskRunLogEntry_Type.RELEASE_FILE_EXECUTE,
+ logTime: ts(at),
+ replicaId,
+ releaseFileExecute: { version, filePath },
+ });
+
+// One failed attempt spanning [at, at + 1], closed by a marker at at + 2.
+export const failedAttempt = (
+ at: number,
+ retryCount: number,
+ { error = LOCK_TIMEOUT, replicaId = "" }: OutcomeOptions = {}
+) => [
+ begin(at, { replicaId }),
+ command(at, at + 1, { error, replicaId }),
+ rollback(at + 1, { replicaId }),
+ retry(at + 2, retryCount, { error, replicaId }),
+];
+
+export const passedAttempt = (
+ at: number,
+ { replicaId = "" }: EntryOptions = {}
+) => [
+ begin(at, { replicaId }),
+ command(at, at + 1, { replicaId }),
+ commit(at + 2, { replicaId }),
+];
diff --git a/frontend/src/components/task-run-log/types.ts b/frontend/src/components/task-run-log/types.ts
index 00530d4909..6c997f1346 100644
--- a/frontend/src/components/task-run-log/types.ts
+++ b/frontend/src/components/task-run-log/types.ts
@@ -37,6 +37,7 @@ export interface DisplayItem {
}
export interface Section {
+ kind: "section";
id: string;
type: TaskRunLogEntry_Type;
label: string;
@@ -48,6 +49,29 @@ export interface Section {
items: DisplayItem[];
}
+// A superseded attempt: the entries between two retry markers (or before the
+// first one). The marker that closed it supplies the reason.
+export interface Attempt {
+ id: string;
+ number: number;
+ reason: string;
+ duration: string;
+ sections: Section[];
+}
+
+// The "Previous attempts" umbrella: every superseded attempt of one retried
+// execution scope. It is history, so it has no status of its own.
+export interface AttemptGroup {
+ kind: "attempts";
+ id: string;
+ attempts: Attempt[];
+ duration: string;
+ // A section of the final attempt is still running.
+ retrying: boolean;
+}
+
+export type LogRow = Section | AttemptGroup;
+
export interface EntryGroup {
type: TaskRunLogEntry_Type;
entries: TaskRunLogEntry[];
@@ -68,11 +92,11 @@ export interface ReleaseFileGroup {
version: string;
filePath: string;
isOrphan?: boolean;
- sections: Section[];
+ rows: LogRow[];
}
export interface ReplicaGroup {
replicaId: string;
releaseFileGroups: ReleaseFileGroup[];
- sections: Section[];
+ rows: LogRow[];
}
diff --git a/frontend/src/components/task-run-log/useTaskRunLogSections.test.tsx b/frontend/src/components/task-run-log/useTaskRunLogSections.test.tsx
new file mode 100644
index 0000000000..b23afef53b
--- /dev/null
+++ b/frontend/src/components/task-run-log/useTaskRunLogSections.test.tsx
@@ -0,0 +1,406 @@
+import { act, renderHook } from "@testing-library/react";
+import { useLayoutEffect } from "react";
+import { describe, expect, test } from "vitest";
+import {
+ begin,
+ command,
+ commit,
+ databaseSync,
+ failedAttempt,
+ LOCK_TIMEOUT,
+ passedAttempt,
+ releaseFile,
+ rollback,
+ runningCommand,
+} from "./taskRunLogEntries";
+import {
+ TaskRun_Status,
+ type TaskRunLogEntry,
+} from "@/types/proto-es/v1/rollout_service_pb";
+import { collectLeafSections } from "./model";
+import type { AttemptGroup, LogRow, Section } from "./types";
+import {
+ type UseTaskRunLogSectionsResult,
+ useTaskRunLogSections,
+} from "./useTaskRunLogSections";
+
+interface HarnessProps {
+ entries: TaskRunLogEntry[];
+ datasetKey?: string;
+ taskRunStatus?: TaskRun_Status;
+}
+
+// The rows the transition test watches: the section the reader opened before
+// the marker and the umbrella that appears with it.
+const WATCHED_ROWS = ["section-1", "attempts-0"];
+
+// Snapshots every committed render before paint (a render-phase reset discards
+// the attempt it interrupts), so the list records exactly what the reader
+// would have seen after each commit.
+const renderSections = (initialProps: HarnessProps) => {
+ const renders: string[][] = [];
+ const hook = renderHook(
+ ({ entries, datasetKey = "run", taskRunStatus }: HarnessProps) => {
+ const result = useTaskRunLogSections({
+ entries,
+ datasetKey,
+ taskRunStatus,
+ getSectionLabel: (type) => String(type),
+ });
+ useLayoutEffect(() => {
+ renders.push(WATCHED_ROWS.filter(result.isRowExpanded));
+ });
+ return result;
+ },
+ { initialProps }
+ );
+ return { ...hook, renders };
+};
+
+const markedDetails = (rows: LogRow[]) =>
+ collectLeafSections(rows).flatMap((section) =>
+ section.items.filter((item) => item.marked).map((item) => item.detail)
+ );
+
+describe("useTaskRunLogSections", () => {
+ test("exposes the umbrella in the rows and counts only leaf sections and their entries", () => {
+ const hook = renderSections({
+ entries: [
+ ...failedAttempt(1, 1),
+ ...passedAttempt(4),
+ databaseSync(7, 9),
+ ],
+ });
+
+ expect(hook.result.current.rows.map((row) => row.kind)).toEqual([
+ "attempts",
+ "section",
+ "section",
+ "section",
+ "section",
+ ]);
+ expect(
+ (hook.result.current.rows[0] as AttemptGroup).attempts
+ ).toHaveLength(1);
+ // Three superseded sections, three final ones, one sync; the marker is
+ // neither a section nor an entry.
+ expect(hook.result.current.totalSections).toBe(7);
+ expect(hook.result.current.totalEntries).toBe(7);
+ });
+
+ test("auto-expands a failed final section, never the umbrella or an attempt", () => {
+ const hook = renderSections({
+ entries: [
+ ...failedAttempt(1, 1),
+ ...failedAttempt(4, 2),
+ begin(7),
+ command(7, 8, { error: LOCK_TIMEOUT }),
+ rollback(8),
+ ],
+ });
+
+ const rows = hook.result.current.rows;
+ expect(rows.map((row) => row.id)).toEqual([
+ "attempts-0",
+ "section-1",
+ "section-2",
+ "section-3",
+ ]);
+ expect((rows[2] as Section).status).toBe("error");
+ expect(hook.result.current.isRowExpanded("section-2")).toBe(true);
+ expect(hook.result.current.isRowExpanded("attempts-0")).toBe(false);
+ expect(hook.result.current.isRowExpanded("attempts-0-attempt-1")).toBe(
+ false
+ );
+
+ act(() => {
+ hook.result.current.toggleRow("attempts-0");
+ });
+ expect(hook.result.current.isRowExpanded("attempts-0")).toBe(true);
+ expect(hook.result.current.isRowExpanded("attempts-0-attempt-1")).toBe(
+ false
+ );
+ act(() => {
+ hook.result.current.toggleRow("attempts-0-attempt-1");
+ });
+ expect(hook.result.current.isRowExpanded("attempts-0-attempt-1")).toBe(
+ true
+ );
+ expect(
+ hook.result.current.isRowExpanded("attempts-0-attempt-1-section-1")
+ ).toBe(true);
+ });
+
+ test("a failed one-time section is red and open at top level while the umbrella stays shut", () => {
+ const hook = renderSections({
+ entries: [
+ ...failedAttempt(1, 1),
+ ...passedAttempt(4),
+ databaseSync(7, 9, { error: "sync failed" }),
+ ],
+ });
+
+ const rows = hook.result.current.rows;
+ expect(rows.map((row) => row.id)).toEqual([
+ "attempts-0",
+ "section-1",
+ "section-2",
+ "section-3",
+ "section-4",
+ ]);
+ expect((rows[4] as Section).status).toBe("error");
+ expect(hook.result.current.isRowExpanded("section-4")).toBe(true);
+ expect(hook.result.current.isRowExpanded("attempts-0")).toBe(false);
+ });
+
+ test("a replica group holds its own umbrella; abandonment only reddens the final segment", () => {
+ const hook = renderSections({
+ entries: [
+ ...failedAttempt(1, 1, { replicaId: "r1" }),
+ begin(4, { replicaId: "r1" }),
+ runningCommand(4, { replicaId: "r1" }),
+ ...passedAttempt(10, { replicaId: "r2" }),
+ ],
+ });
+
+ expect(hook.result.current.hasMultipleReplicas).toBe(true);
+ const [first, second] = hook.result.current.replicaGroups;
+ expect(first?.rows.map((row) => row.kind)).toEqual([
+ "attempts",
+ "section",
+ "section",
+ ]);
+ const umbrella = first?.rows[0] as AttemptGroup;
+ expect(umbrella.id).toBe("r1-attempts-0");
+ expect(
+ umbrella.attempts[0]?.sections.map((section) => section.status)
+ ).toEqual(["success", "error", "success"]);
+ // The abandoned final segment is forced red, so nothing is retrying.
+ expect((first?.rows[2] as Section).status).toBe("error");
+ expect(umbrella.retrying).toBe(false);
+ expect(second?.rows.map((row) => row.kind)).toEqual([
+ "section",
+ "section",
+ "section",
+ ]);
+ expect(hook.result.current.totalSections).toBe(8);
+ });
+
+ test("clears expansion in the render that regroups the list, not a frame later", () => {
+ const hook = renderSections({
+ entries: passedAttempt(1),
+ datasetKey: "run:4:0",
+ });
+ act(() => {
+ hook.result.current.toggleRow("section-1");
+ });
+ expect(hook.result.current.isRowExpanded("section-1")).toBe(true);
+
+ const before = hook.renders.length;
+ // The first marker lands: what was section-1 is now the umbrella's
+ // material, and section-1 names the final attempt's opening transaction.
+ hook.rerender({
+ entries: [...failedAttempt(1, 1), ...passedAttempt(4)],
+ datasetKey: "run:4:1",
+ });
+ expect(hook.result.current.rows.map((row) => row.id)).toEqual([
+ "attempts-0",
+ "section-1",
+ "section-2",
+ "section-3",
+ ]);
+
+ const afterMarker = hook.renders.slice(before);
+ expect(afterMarker.length).toBeGreaterThan(0);
+ expect(afterMarker.flat()).toEqual([]);
+ });
+
+ test("an ordinary append under the same key keeps opened rows open", () => {
+ const hook = renderSections({
+ entries: [...failedAttempt(1, 1), begin(4), runningCommand(4)],
+ datasetKey: "run:8:1",
+ });
+ act(() => {
+ hook.result.current.toggleRow("attempts-0");
+ hook.result.current.toggleRow("section-1");
+ });
+
+ // The next poll answers the running command and adds the commit.
+ hook.rerender({
+ entries: [...failedAttempt(1, 1), begin(4), command(4, 5), commit(6)],
+ datasetKey: "run:8:1",
+ });
+ expect(hook.result.current.isRowExpanded("attempts-0")).toBe(true);
+ expect(hook.result.current.isRowExpanded("section-1")).toBe(true);
+ });
+
+ test("expand all opens the umbrella and its attempts; collapse all closes them", () => {
+ const hook = renderSections({
+ entries: [
+ ...failedAttempt(1, 1),
+ ...failedAttempt(4, 2),
+ ...passedAttempt(7),
+ ],
+ });
+ expect(hook.result.current.areAllExpanded).toBe(false);
+
+ act(() => {
+ hook.result.current.expandAll();
+ });
+ expect(hook.result.current.areAllExpanded).toBe(true);
+ expect(hook.result.current.isRowExpanded("attempts-0")).toBe(true);
+ expect(hook.result.current.isRowExpanded("attempts-0-attempt-2")).toBe(
+ true
+ );
+ expect(
+ hook.result.current.isRowExpanded("attempts-0-attempt-2-section-0")
+ ).toBe(true);
+
+ act(() => {
+ hook.result.current.toggleRow("attempts-0-attempt-2");
+ });
+ expect(hook.result.current.areAllExpanded).toBe(false);
+
+ act(() => {
+ hook.result.current.collapseAll();
+ });
+ expect(hook.result.current.isRowExpanded("attempts-0")).toBe(false);
+ expect(hook.result.current.isRowExpanded("section-2")).toBe(false);
+ expect(hook.result.current.areAllExpanded).toBe(false);
+ });
+
+ test("everything a reader can open counts as all expanded when the umbrella holds one attempt", () => {
+ const hook = renderSections({
+ entries: [...failedAttempt(1, 1), ...passedAttempt(4)],
+ });
+
+ // The sole attempt has no row of its own; the umbrella opens onto its
+ // sections, of which the failed one is already open.
+ act(() => {
+ for (const id of [
+ "attempts-0",
+ "attempts-0-attempt-1-section-0",
+ "attempts-0-attempt-1-section-2",
+ "section-1",
+ "section-2",
+ "section-3",
+ ]) {
+ hook.result.current.toggleRow(id);
+ }
+ });
+ expect(hook.result.current.areAllExpanded).toBe(true);
+ });
+
+ test("reopening every visible row by hand after Collapse all counts as all expanded", () => {
+ // The sync logged before the first file marker forms a headerless group.
+ const hook = renderSections({
+ entries: [
+ databaseSync(1, 2),
+ releaseFile(3, "v1", "001.sql"),
+ command(4, 5),
+ ],
+ });
+ expect(
+ hook.result.current.releaseFileGroups.map((group) => [
+ group.id,
+ Boolean(group.isOrphan),
+ ])
+ ).toEqual([
+ ["orphan", true],
+ ["file-0", false],
+ ]);
+
+ act(() => {
+ hook.result.current.collapseAll();
+ });
+ act(() => {
+ hook.result.current.toggleReleaseFile("file-0");
+ hook.result.current.toggleRow("orphan-section-0");
+ hook.result.current.toggleRow("file-0-section-0");
+ });
+ expect(hook.result.current.areAllExpanded).toBe(true);
+ });
+
+ test("handles expand/collapse state for filtered release-file groups", () => {
+ const hook = renderSections({
+ entries: [
+ releaseFile(1, "v1", "001.sql"),
+ releaseFile(2, "v2", "002.sql"),
+ command(3, 4),
+ ],
+ });
+
+ expect(
+ hook.result.current.releaseFileGroups.map((group) => group.id)
+ ).toEqual(["file-0"]);
+ expect(hook.result.current.totalSections).toBe(1);
+
+ act(() => {
+ hook.result.current.collapseAll();
+ });
+ expect(hook.result.current.areAllExpanded).toBe(false);
+
+ act(() => {
+ hook.result.current.expandAll();
+ });
+ expect(hook.result.current.areAllExpanded).toBe(true);
+
+ act(() => {
+ hook.result.current.toggleReleaseFile("file-0");
+ });
+ expect(hook.result.current.areAllExpanded).toBe(false);
+ });
+
+ test("one replica's success does not silence another replica's failure", () => {
+ const hook = renderSections({
+ entries: [
+ command(1, 2, { error: "boom", replicaId: "a" }),
+ command(3, 4, { replicaId: "b" }),
+ ],
+ });
+
+ const [first, second] = hook.result.current.replicaGroups;
+ expect(markedDetails(first?.rows ?? [])).toEqual(["boom"]);
+ expect(markedDetails(second?.rows ?? [])).toEqual([]);
+ });
+
+ test("forwards a DONE status into every builder it calls", () => {
+ const failing = (replicaId: string) => [
+ command(1, 2, { error: "orphan", replicaId }),
+ releaseFile(3, "v1", "001.sql", { replicaId }),
+ command(4, 5, { error: "in file", replicaId }),
+ ];
+ const entries = [...failing("a"), ...failing("b")];
+ const allRows = (result: UseTaskRunLogSectionsResult) => [
+ ...result.rows,
+ ...result.releaseFileGroups.flatMap((group) => group.rows),
+ ...result.replicaGroups.flatMap((group) => [
+ ...group.rows,
+ ...group.releaseFileGroups.flatMap((fileGroup) => fileGroup.rows),
+ ]),
+ ];
+
+ const hook = renderSections({ entries });
+ // Flat, release-file, orphan, per-replica orphan and per-replica file.
+ expect(
+ markedDetails(allRows(hook.result.current)).length
+ ).toBeGreaterThan(4);
+
+ hook.rerender({ entries, taskRunStatus: TaskRun_Status.DONE });
+ expect(markedDetails(allRows(hook.result.current))).toEqual([]);
+ });
+
+ test("a row's key survives a second replica appearing", () => {
+ const first = () => command(1, 2, { replicaId: "a" });
+ const hook = renderSections({ entries: [first()] });
+ const before = (hook.result.current.rows[0] as Section).items[0]?.key;
+
+ hook.rerender({ entries: [first(), command(3, 4, { replicaId: "b" })] });
+
+ expect(hook.result.current.hasMultipleReplicas).toBe(true);
+ const after = (hook.result.current.replicaGroups[0]?.rows[0] as Section)
+ .items[0]?.key;
+ expect(before).toBeDefined();
+ expect(after).toBe(before);
+ });
+});
diff --git a/frontend/src/components/task-run-log/useTaskRunLogSections.ts b/frontend/src/components/task-run-log/useTaskRunLogSections.ts
index bb702c4f3b..a48d4e5101 100644
--- a/frontend/src/components/task-run-log/useTaskRunLogSections.ts
+++ b/frontend/src/components/task-run-log/useTaskRunLogSections.ts
@@ -1,4 +1,5 @@
-import { useEffect, useMemo, useState } from "react";
+import { useMemo, useState } from "react";
+import { useOnKeyChange } from "@/hooks/useOnKeyChange";
import type {
TaskRun_Status,
TaskRunLogEntry,
@@ -9,56 +10,65 @@ import type { TaskRunLogDetailText } from "./model";
import {
assignEntryKeys,
buildReleaseFileGroups,
- buildSectionsFromEntries,
+ buildRowsFromEntries,
+ collectAttemptRowIds,
+ collectLeafSections,
getUniqueReplicaIds,
groupEntriesByReleaseFile,
groupEntriesByReplica,
hasReleaseFileMarkers,
} from "./model";
-import type { ReleaseFileGroup, ReplicaGroup, Section } from "./types";
-
-const addToSet = (set: Set<string>, value: string): Set<string> => {
- if (set.has(value)) return set;
- const next = new Set(set);
- next.add(value);
- return next;
-};
-
-const deleteFromSet = (set: Set<string>, value: string): Set<string> => {
- if (!set.has(value)) return set;
- const next = new Set(set);
- next.delete(value);
- return next;
+import type { LogRow, ReleaseFileGroup, ReplicaGroup } from "./types";
+
+// One expansion lane: every id is open by its default until the reader, or
+// Expand all / Collapse all, overrides it. `ids` are exactly the rows a reader
+// can toggle, so the toolbar's all-expanded state matches the screen.
+const useExpansionLane = (
+ ids: string[],
+ defaultOpen: (id: string) => boolean
+) => {
+ const [overrides, setOverrides] = useState<ReadonlyMap<string, boolean>>(
+ () => new Map()
+ );
+ const isExpanded = (id: string): boolean =>
+ overrides.get(id) ?? defaultOpen(id);
+ return {
+ isExpanded,
+ toggle: (id: string) =>
+ setOverrides((previous) =>
+ new Map(previous).set(id, !(previous.get(id) ?? defaultOpen(id)))
+ ),
+ setAll: (open: boolean) =>
+ setOverrides(new Map(ids.map((id) => [id, open]))),
+ reset: () => setOverrides(new Map()),
+ allExpanded: ids.every(isExpanded),
+ };
};
-const countSections = (sections: Section[]): number => sections.length;
-const countEntries = (sections: Section[]): number =>
- sections.reduce((sum, section) => sum + section.entryCount, 0);
-
export interface UseTaskRunLogSectionsOptions {
entries: TaskRunLogEntry[];
sheet?: Sheet;
sheetsMap?: Map<string, Sheet>;
getSectionLabel: (type: TaskRunLogEntry_Type) => string;
detailText?: TaskRunLogDetailText;
- datasetKey?: string;
+ // Changing it clears every override: row ids are positional, so they only
+ // mean something within one grouping of one run.
+ datasetKey: string;
// Forwarded into every builder call below; see pickMarkedEntry.
taskRunStatus?: TaskRun_Status;
}
export interface UseTaskRunLogSectionsResult {
- sections: Section[];
+ rows: LogRow[];
hasMultipleReplicas: boolean;
hasReleaseFiles: boolean;
releaseFileGroups: ReleaseFileGroup[];
replicaGroups: ReplicaGroup[];
- expandedSections: Set<string>;
- expandedReplicas: Set<string>;
- expandedReleaseFiles: Set<string>;
- toggleSection: (sectionId: string) => void;
+ // Rows are sections, umbrellas and attempt rows, by id.
+ toggleRow: (rowId: string) => void;
toggleReplica: (replicaId: string) => void;
toggleReleaseFile: (releaseFileId: string) => void;
- isSectionExpanded: (sectionId: string) => boolean;
+ isRowExpanded: (rowId: string) => boolean;
isReplicaExpanded: (replicaId: string) => boolean;
isReleaseFileExpanded: (releaseFileId: string) => boolean;
expandAll: () => void;
@@ -77,31 +87,12 @@ export const useTaskRunLogSections = ({
datasetKey,
taskRunStatus,
}: UseTaskRunLogSectionsOptions): UseTaskRunLogSectionsResult => {
- const [expandedSections, setExpandedSections] = useState<Set<string>>(
- () => new Set()
- );
- const [userCollapsedSections, setUserCollapsedSections] = useState<
- Set<string>
- >(() => new Set());
- const [expandedReplicas, setExpandedReplicas] = useState<Set<string>>(
- () => new Set()
- );
- const [userCollapsedReplicas, setUserCollapsedReplicas] = useState<
- Set<string>
- >(() => new Set());
- const [expandedReleaseFiles, setExpandedReleaseFiles] = useState<Set<string>>(
- () => new Set()
- );
- const [userCollapsedReleaseFiles, setUserCollapsedReleaseFiles] = useState<
- Set<string>
- >(() => new Set());
-
// Every builder below sees a filtered slice of the run, so the keys are
// assigned here, over all of it.
const entryKeys = useMemo(() => assignEntryKeys(entries), [entries]);
- const sections = useMemo(() => {
- return buildSectionsFromEntries(entries, {
+ const rows = useMemo(() => {
+ return buildRowsFromEntries(entries, {
getSectionLabel,
entryKeys,
sheet,
@@ -140,7 +131,7 @@ export const useTaskRunLogSections = ({
taskRunStatus,
]);
- const replicaGroups = useMemo(() => {
+ const replicaGroups = useMemo<ReplicaGroup[]>(() => {
const replicaIds = getUniqueReplicaIds(entries);
if (replicaIds.length <= 1) return [];
@@ -153,7 +144,7 @@ export const useTaskRunLogSections = ({
return {
replicaId,
releaseFileGroups: [],
- sections: buildSectionsFromEntries(replicaEntries, {
+ rows: buildRowsFromEntries(replicaEntries, {
getSectionLabel,
entryKeys,
sheet,
@@ -182,9 +173,9 @@ export const useTaskRunLogSections = ({
detailText,
taskRunStatus,
}),
- sections:
+ rows:
orphanGroup && orphanGroup.entries.length > 0
- ? buildSectionsFromEntries(orphanGroup.entries, {
+ ? buildRowsFromEntries(orphanGroup.entries, {
getSectionLabel,
entryKeys,
sheet,
@@ -213,324 +204,101 @@ export const useTaskRunLogSections = ({
);
const hasMultipleReplicas = replicaGroups.length > 1;
- const allSectionIds = useMemo(() => {
+ // Every row the viewer will render, in order, whichever grouping applies.
+ const allRows = useMemo<LogRow[]>(() => {
if (hasMultipleReplicas) {
return replicaGroups.flatMap((group) => [
- ...group.sections.map((section) => section.id),
- ...group.releaseFileGroups.flatMap((fileGroup) =>
- fileGroup.sections.map((section) => section.id)
- ),
+ ...group.rows,
+ ...group.releaseFileGroups.flatMap((fileGroup) => fileGroup.rows),
]);
}
if (hasReleaseFiles) {
- return releaseFileGroups.flatMap((fileGroup) =>
- fileGroup.sections.map((section) => section.id)
- );
+ return releaseFileGroups.flatMap((fileGroup) => fileGroup.rows);
}
- return sections.map((section) => section.id);
+ return rows;
}, [
hasMultipleReplicas,
hasReleaseFiles,
releaseFileGroups,
replicaGroups,
- sections,
+ rows,
]);
- const allReplicaIds = useMemo(() => {
- return replicaGroups.map((group) => group.replicaId);
- }, [replicaGroups]);
-
+ const allLeafSections = useMemo(
+ () => collectLeafSections(allRows),
+ [allRows]
+ );
+ const allRowIds = [
+ ...allLeafSections.map((section) => section.id),
+ ...collectAttemptRowIds(allRows),
+ ];
+ const allReplicaIds = useMemo(
+ () => replicaGroups.map((group) => group.replicaId),
+ [replicaGroups]
+ );
const allReleaseFileIds = useMemo(() => {
if (hasMultipleReplicas) {
return replicaGroups.flatMap((group) =>
group.releaseFileGroups.map((fileGroup) => fileGroup.id)
);
}
- return releaseFileGroups.map((fileGroup) => fileGroup.id);
+ // The orphan group renders without a header of its own.
+ return releaseFileGroups
+ .filter((fileGroup) => !fileGroup.isOrphan)
+ .map((fileGroup) => fileGroup.id);
}, [hasMultipleReplicas, releaseFileGroups, replicaGroups]);
- const resolvedDatasetKey = useMemo(() => {
- if (datasetKey) return datasetKey;
- return entries
- .map((entry) => {
- return [
- entry.type,
- entry.replicaId,
- entry.logTime?.seconds.toString() ?? "",
- entry.logTime?.nanos ?? 0,
- entry.releaseFileExecute?.version ?? "",
- entry.releaseFileExecute?.filePath ?? "",
- ].join(":");
- })
- .join("|");
- }, [datasetKey, entries]);
-
- useEffect(() => {
- setExpandedSections(new Set());
- setUserCollapsedSections(new Set());
- setExpandedReplicas(new Set());
- setUserCollapsedReplicas(new Set());
- setExpandedReleaseFiles(new Set());
- setUserCollapsedReleaseFiles(new Set());
- }, [resolvedDatasetKey]);
-
- useEffect(() => {
- setExpandedSections((previous) => {
- let next = previous;
- for (const section of sections) {
- if (
- section.status === "error" &&
- !userCollapsedSections.has(section.id)
- ) {
- next = addToSet(next, section.id);
- }
- }
- return next;
- });
- }, [sections, userCollapsedSections]);
-
- useEffect(() => {
- setExpandedReplicas((previousReplicas) => {
- let next = previousReplicas;
- for (const group of replicaGroups) {
- if (!userCollapsedReplicas.has(group.replicaId)) {
- next = addToSet(next, group.replicaId);
- }
- }
- return next;
- });
-
- setExpandedReleaseFiles((previousFiles) => {
- let next = previousFiles;
- for (const group of replicaGroups) {
- group.releaseFileGroups.forEach((fileGroup) => {
- const fileId = fileGroup.id;
- if (!userCollapsedReleaseFiles.has(fileId)) {
- next = addToSet(next, fileId);
- }
- });
- }
- return next;
- });
-
- setExpandedSections((previousSections) => {
- let next = previousSections;
- for (const group of replicaGroups) {
- for (const section of group.sections) {
- if (
- section.status === "error" &&
- !userCollapsedSections.has(section.id)
- ) {
- next = addToSet(next, section.id);
- }
- }
- for (const fileGroup of group.releaseFileGroups) {
- for (const section of fileGroup.sections) {
- if (
- section.status === "error" &&
- !userCollapsedSections.has(section.id)
- ) {
- next = addToSet(next, section.id);
- }
- }
- }
- }
- return next;
- });
- }, [
- replicaGroups,
- userCollapsedReplicas,
- userCollapsedReleaseFiles,
- userCollapsedSections,
- ]);
-
- useEffect(() => {
- setExpandedReleaseFiles((previousFiles) => {
- let next = previousFiles;
- releaseFileGroups.forEach((fileGroup) => {
- const fileId = fileGroup.id;
- if (!userCollapsedReleaseFiles.has(fileId)) {
- next = addToSet(next, fileId);
- }
- });
- return next;
- });
-
- setExpandedSections((previousSections) => {
- let next = previousSections;
- for (const fileGroup of releaseFileGroups) {
- for (const section of fileGroup.sections) {
- if (
- section.status === "error" &&
- !userCollapsedSections.has(section.id)
- ) {
- next = addToSet(next, section.id);
- }
- }
- }
- return next;
- });
- }, [releaseFileGroups, userCollapsedReleaseFiles, userCollapsedSections]);
-
- const toggleSection = (sectionId: string) => {
- setExpandedSections((previousExpanded) => {
- const isExpanded = previousExpanded.has(sectionId);
- setUserCollapsedSections((previousCollapsed) =>
- isExpanded
- ? addToSet(previousCollapsed, sectionId)
- : deleteFromSet(previousCollapsed, sectionId)
- );
- return isExpanded
- ? deleteFromSet(previousExpanded, sectionId)
- : addToSet(previousExpanded, sectionId);
- });
- };
-
- const toggleReplica = (replicaId: string) => {
- setExpandedReplicas((previousExpanded) => {
- const isExpanded = previousExpanded.has(replicaId);
- setUserCollapsedReplicas((previousCollapsed) =>
- isExpanded
- ? addToSet(previousCollapsed, replicaId)
- : deleteFromSet(previousCollapsed, replicaId)
- );
- return isExpanded
- ? deleteFromSet(previousExpanded, replicaId)
- : addToSet(previousExpanded, replicaId);
- });
- };
-
- const toggleReleaseFile = (releaseFileId: string) => {
- setExpandedReleaseFiles((previousExpanded) => {
- const isExpanded = previousExpanded.has(releaseFileId);
- setUserCollapsedReleaseFiles((previousCollapsed) =>
- isExpanded
- ? addToSet(previousCollapsed, releaseFileId)
- : deleteFromSet(previousCollapsed, releaseFileId)
- );
- return isExpanded
- ? deleteFromSet(previousExpanded, releaseFileId)
- : addToSet(previousExpanded, releaseFileId);
- });
- };
-
- const isSectionExpanded = (sectionId: string): boolean => {
- return expandedSections.has(sectionId);
- };
-
- const isReplicaExpanded = (replicaId: string): boolean => {
- return expandedReplicas.has(replicaId);
- };
-
- const isReleaseFileExpanded = (releaseFileId: string): boolean => {
- return expandedReleaseFiles.has(releaseFileId);
- };
-
- const expandAll = () => {
- setExpandedSections(new Set(allSectionIds));
- setExpandedReplicas(new Set(allReplicaIds));
- setExpandedReleaseFiles(new Set(allReleaseFileIds));
- setUserCollapsedSections(new Set());
- setUserCollapsedReplicas(new Set());
- setUserCollapsedReleaseFiles(new Set());
- };
+ const errorSectionIds = useMemo(
+ () =>
+ new Set(
+ allLeafSections
+ .filter((section) => section.status === "error")
+ .map((section) => section.id)
+ ),
+ [allLeafSections]
+ );
- const collapseAll = () => {
- setExpandedSections(new Set());
- setExpandedReplicas(new Set());
- setExpandedReleaseFiles(new Set());
- setUserCollapsedSections(new Set(allSectionIds));
- setUserCollapsedReplicas(new Set(allReplicaIds));
- setUserCollapsedReleaseFiles(new Set(allReleaseFileIds));
+ // Failed sections are open by default wherever they sit; umbrella and
+ // attempt rows are not.
+ const rowLane = useExpansionLane(allRowIds, (id) => errorSectionIds.has(id));
+ const replicaLane = useExpansionLane(allReplicaIds, () => true);
+ const fileLane = useExpansionLane(allReleaseFileIds, () => true);
+
+ useOnKeyChange(datasetKey, () => {
+ rowLane.reset();
+ replicaLane.reset();
+ fileLane.reset();
+ });
+
+ const setAll = (open: boolean) => {
+ rowLane.setAll(open);
+ replicaLane.setAll(open);
+ fileLane.setAll(open);
};
- const areAllExpanded =
- (allSectionIds.length > 0 ||
- allReleaseFileIds.length > 0 ||
- allReplicaIds.length > 0) &&
- (allSectionIds.length === 0 ||
- allSectionIds.every((id) => expandedSections.has(id))) &&
- (allReleaseFileIds.length === 0 ||
- allReleaseFileIds.every((id) => expandedReleaseFiles.has(id))) &&
- (!hasMultipleReplicas ||
- allReplicaIds.length === 0 ||
- allReplicaIds.every((id) => expandedReplicas.has(id)));
-
- const totalSections = useMemo(() => {
- if (hasMultipleReplicas) {
- return replicaGroups.reduce(
- (sum, group) =>
- sum +
- countSections(group.sections) +
- group.releaseFileGroups.reduce(
- (fileSum, fileGroup) => fileSum + countSections(fileGroup.sections),
- 0
- ),
- 0
- );
- }
- if (hasReleaseFiles) {
- return releaseFileGroups.reduce(
- (sum, fileGroup) => sum + countSections(fileGroup.sections),
- 0
- );
- }
- return sections.length;
- }, [
- hasMultipleReplicas,
- hasReleaseFiles,
- releaseFileGroups,
- replicaGroups,
- sections.length,
- ]);
-
- const totalEntries = useMemo(() => {
- if (hasMultipleReplicas) {
- return replicaGroups.reduce(
- (sum, group) =>
- sum +
- countEntries(group.sections) +
- group.releaseFileGroups.reduce(
- (fileSum, fileGroup) => fileSum + countEntries(fileGroup.sections),
- 0
- ),
- 0
- );
- }
- if (hasReleaseFiles) {
- return releaseFileGroups.reduce(
- (sum, fileGroup) => sum + countEntries(fileGroup.sections),
- 0
- );
- }
- return countEntries(sections);
- }, [
- hasMultipleReplicas,
- hasReleaseFiles,
- releaseFileGroups,
- replicaGroups,
- sections,
- ]);
-
return {
- sections,
+ rows,
hasMultipleReplicas,
hasReleaseFiles,
releaseFileGroups,
replicaGroups,
- expandedSections,
- expandedReplicas,
- expandedReleaseFiles,
- toggleSection,
- toggleReplica,
- toggleReleaseFile,
- isSectionExpanded,
- isReplicaExpanded,
- isReleaseFileExpanded,
- expandAll,
- collapseAll,
- areAllExpanded,
- totalSections,
- totalEntries,
+ toggleRow: rowLane.toggle,
+ toggleReplica: replicaLane.toggle,
+ toggleReleaseFile: fileLane.toggle,
+ isRowExpanded: rowLane.isExpanded,
+ isReplicaExpanded: replicaLane.isExpanded,
+ isReleaseFileExpanded: fileLane.isExpanded,
+ expandAll: () => setAll(true),
+ collapseAll: () => setAll(false),
+ areAllExpanded:
+ allRowIds.length + allReleaseFileIds.length + allReplicaIds.length > 0 &&
+ rowLane.allExpanded &&
+ fileLane.allExpanded &&
+ replicaLane.allExpanded,
+ totalSections: allLeafSections.length,
+ totalEntries: allLeafSections.reduce(
+ (sum, section) => sum + section.entryCount,
+ 0
+ ),
};
};
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 036bb143ee..8c9c648402 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -3726,7 +3726,6 @@
"computing": "Computing...",
"dumping": "Dumping...",
"hide-full-statement": "Hide full statement",
- "retry-attempt": "attempt {{current}}/{{max}}",
"show-full-statement": "Show full statement",
"syncing": "Syncing..."
},
@@ -3737,15 +3736,20 @@
"ghost-migration": "gh-ost Migration",
"prior-backup": "Prior Backup",
"release-file-execute": "Release File",
- "retry": "Retry",
"schema-dump": "Schema Dump",
"transaction": "Transaction"
},
"log-viewer": {
+ "attempt-count_one": "{{count}} attempt",
+ "attempt-count_other": "{{count}} attempts",
+ "attempt-n": "Attempt {{n}}",
+ "attempt-reason": "failed: {{reason}}",
"collapse-all": "Collapse all",
"expand-all": "Expand all",
"multiple-replicas-notice": "Server restart detected during execution. Logs are grouped by replica.",
+ "previous-attempts": "Previous attempts",
"replica-n": "Replica #{{n}}",
+ "retrying": "retrying",
"summary": "{{sections}} sections · {{entries}} entries"
},
"no-blocking-sessions": "No blocking sessions",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 3cd41f19c2..eacd30aa51 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -3726,7 +3726,6 @@
"computing": "computación...",
"dumping": "dumping...",
"hide-full-statement": "Ocultar la declaración completa",
- "retry-attempt": "intento {{current}}/{{max}}",
"show-full-statement": "Mostrar la declaración completa",
"syncing": "sincronizando..."
},
@@ -3737,15 +3736,20 @@
"ghost-migration": "Migración gh-ost",
"prior-backup": "Copia de seguridad previa",
"release-file-execute": "Archivo de lanzamiento",
- "retry": "Reintentar",
"schema-dump": "Volcado de esquema",
"transaction": "Transacción"
},
"log-viewer": {
+ "attempt-count_one": "{{count}} intento",
+ "attempt-count_other": "{{count}} intentos",
+ "attempt-n": "Intento {{n}}",
+ "attempt-reason": "falló: {{reason}}",
"collapse-all": "Contraer todo",
"expand-all": "Expandir todo",
"multiple-replicas-notice": "Se detectó un reinicio del servidor durante la ejecución. Los registros están agrupados por réplica.",
+ "previous-attempts": "Intentos anteriores",
"replica-n": "Réplica #{{n}}",
+ "retrying": "reintentando",
"summary": "{{sections}} secciones · {{entries}} entradas"
},
"no-blocking-sessions": "Sin sesiones bloqueantes",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index cbd8493bcc..795e674d0b 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -3726,7 +3726,6 @@
"computing": "コンピューティング...",
"dumping": "ダンピング...",
"hide-full-statement": "ステートメント全体を非表示",
- "retry-attempt": "試行 {{current}}/{{max}}",
"show-full-statement": "ステートメント全体を表示",
"syncing": "同期中..."
},
@@ -3737,15 +3736,20 @@
"ghost-migration": "gh-ost マイグレーション",
"prior-backup": "事前のバックアップ",
"release-file-execute": "リリースファイル",
- "retry": "リトライ",
"schema-dump": "スキーマダンプ",
"transaction": "取引"
},
"log-viewer": {
+ "attempt-count_one": "{{count}} 回の試行",
+ "attempt-count_other": "{{count}} 回の試行",
+ "attempt-n": "試行 {{n}}",
+ "attempt-reason": "失敗: {{reason}}",
"collapse-all": "すべて折りたたむ",
"expand-all": "すべて展開",
"multiple-replicas-notice": "実行中にサーバーの再起動が検出されました。ログはレプリカごとにグループ化されています。",
+ "previous-attempts": "以前の試行",
"replica-n": "レプリカ #{{n}}",
+ "retrying": "再試行中",
"summary": "{{sections}} セクション · {{entries}} エントリ"
},
"no-blocking-sessions": "ブロッキングセッションはありません",
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 10e901b17f..0a8d72e01d 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -3726,7 +3726,6 @@
"computing": "tính toán...",
"dumping": "đang xuất...",
"hide-full-statement": "Ẩn toàn bộ câu lệnh",
- "retry-attempt": "nỗ lực {{current}}/{{max}}",
"show-full-statement": "Hiển thị toàn bộ câu lệnh",
"syncing": "đang đồng bộ hóa..."
},
@@ -3737,15 +3736,20 @@
"ghost-migration": "Di chuyển gh-ost",
"prior-backup": "Sao lưu trước",
"release-file-execute": "Tệp phát hành",
- "retry": "Thử lại",
"schema-dump": "Xuất schema",
"transaction": "Giao dịch"
},
"log-viewer": {
+ "attempt-count_one": "{{count}} lần thử",
+ "attempt-count_other": "{{count}} lần thử",
+ "attempt-n": "Lần thử {{n}}",
+ "attempt-reason": "thất bại: {{reason}}",
"collapse-all": "Thu gọn tất cả",
"expand-all": "Mở rộng tất cả",
"multiple-replicas-notice": "Phát hiện khởi động lại máy chủ trong quá trình thực thi. Nhật ký được nhóm theo bản sao.",
+ "previous-attempts": "Các lần thử trước",
"replica-n": "Bản sao #{{n}}",
+ "retrying": "đang thử lại",
"summary": "{{sections}} phần · {{entries}} mục"
},
"no-blocking-sessions": "Không có phiên chặn nào",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index a8aa5c1ac9..7a2e0a9ef4 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -3726,7 +3726,6 @@
"computing": "计算中...",
"dumping": "导出中...",
"hide-full-statement": "隐藏完整语句",
- "retry-attempt": "第 {{current}}/{{max}} 次尝试",
"show-full-statement": "显示完整语句",
"syncing": "同步中..."
},
@@ -3737,15 +3736,20 @@
"ghost-migration": "gh-ost 迁移",
"prior-backup": "预备份",
"release-file-execute": "发布包文件",
- "retry": "重试",
"schema-dump": "结构导出",
"transaction": "事务"
},
"log-viewer": {
+ "attempt-count_one": "{{count}} 次尝试",
+ "attempt-count_other": "{{count}} 次尝试",
+ "attempt-n": "第 {{n}} 次尝试",
+ "attempt-reason": "失败:{{reason}}",
"collapse-all": "全部收起",
"expand-all": "全部展开",
"multiple-replicas-notice": "检测到执行期间服务重启,日志按副本分组显示。",
+ "previous-attempts": "之前的尝试",
"replica-n": "副本 #{{n}}",
+ "retrying": "重试中",
"summary": "{{sections}} 个分组 · {{entries}} 条记录"
},
"no-blocking-sessions": "无阻塞会话",