Skip to content

fix: prevent invalid render output for build logs #17233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions site/src/components/Logs/LogLine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { MONOSPACE_FONT_FAMILY } from "theme/constants";
export const DEFAULT_LOG_LINE_SIDE_PADDING = 24;

export interface Line {
id: number;
time: string;
output: string;
level: LogLevel;
Expand Down
4 changes: 3 additions & 1 deletion site/src/components/Logs/Logs.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import type { Meta, StoryObj } from "@storybook/react";
import { chromatic } from "testHelpers/chromatic";
import { MockWorkspaceBuildLogs } from "testHelpers/entities";
import type { Line } from "./LogLine";
import { Logs } from "./Logs";

const meta: Meta<typeof Logs> = {
title: "components/Logs",
parameters: { chromatic },
component: Logs,
args: {
lines: MockWorkspaceBuildLogs.map((log) => ({
lines: MockWorkspaceBuildLogs.map<Line>((log) => ({
id: log.id,
level: log.log_level,
time: log.created_at,
output: log.output,
Expand Down
2 changes: 1 addition & 1 deletion site/src/components/Logs/Logs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const Logs: FC<LogsProps> = ({
<div css={styles.root} className={`${className} logs-container`}>
<div css={{ minWidth: "fit-content" }}>
{lines.map((line) => (
<LogLine key={line.output} level={line.level}>
<LogLine key={line.id} level={line.level}>
{!hideTimestamps && (
<LogLinePrefix>
{dayjs(line.time).format("HH:mm:ss.SSS")}
Expand Down
7 changes: 0 additions & 7 deletions site/src/modules/resources/AgentLogs/AgentLogLine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ import AnsiToHTML from "ansi-to-html";
import { type Line, LogLine, LogLinePrefix } from "components/Logs/LogLine";
import { type FC, type ReactNode, useMemo } from "react";

// Logs are stored as the Line interface to make rendering
// much more efficient. Instead of mapping objects each time, we're
// able to just pass the array of logs to the component.
export interface LineWithID extends Line {
id: number;
}

// Approximate height of a log line. Used to control virtualized list height.
export const AGENT_LOG_LINE_HEIGHT = 20;

Expand Down
9 changes: 3 additions & 6 deletions site/src/modules/resources/AgentLogs/AgentLogs.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import type { Interpolation, Theme } from "@emotion/react";
import Tooltip from "@mui/material/Tooltip";
import type { WorkspaceAgentLogSource } from "api/typesGenerated";
import type { Line } from "components/Logs/LogLine";
import { type ComponentProps, forwardRef, useMemo } from "react";
import { FixedSizeList as List } from "react-window";
import {
AGENT_LOG_LINE_HEIGHT,
AgentLogLine,
type LineWithID,
} from "./AgentLogLine";
import { AGENT_LOG_LINE_HEIGHT, AgentLogLine } from "./AgentLogLine";

type AgentLogsProps = Omit<
ComponentProps<typeof List>,
"children" | "itemSize" | "itemCount"
> & {
logs: readonly LineWithID[];
logs: readonly Line[];
sources: readonly WorkspaceAgentLogSource[];
};

Expand Down
4 changes: 2 additions & 2 deletions site/src/modules/resources/AgentLogs/mocks.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Those mocks are fetched from the Coder API in dev.coder.com

import type { LineWithID } from "./AgentLogLine";
import type { Line } from "components/Logs/LogLine";

export const MockSources = [
{
Expand Down Expand Up @@ -1128,4 +1128,4 @@ export const MockLogs = [
time: "2024-03-14T11:31:10.859531Z",
sourceId: "d9475581-8a42-4bce-b4d0-e4d2791d5c98",
},
] satisfies LineWithID[];
] satisfies Line[];
3 changes: 2 additions & 1 deletion site/src/modules/resources/AgentRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
WorkspaceAgentMetadata,
} from "api/typesGenerated";
import { DropdownArrow } from "components/DropdownArrow/DropdownArrow";
import type { Line } from "components/Logs/LogLine";
import { Stack } from "components/Stack/Stack";
import { useProxy } from "contexts/ProxyContext";
import {
Expand Down Expand Up @@ -318,7 +319,7 @@ export const AgentRow: FC<AgentRowProps> = ({
width={width}
css={styles.startupLogs}
onScroll={handleLogScroll}
logs={startupLogs.map((l) => ({
logs={startupLogs.map<Line>((l) => ({
id: l.id,
level: l.level,
output: l.output,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type Interpolation, type Theme, useTheme } from "@emotion/react";
import type { ProvisionerJobLog } from "api/typesGenerated";
import type { Line } from "components/Logs/LogLine";
import { DEFAULT_LOG_LINE_SIDE_PADDING, Logs } from "components/Logs/Logs";
import dayjs from "dayjs";
import { type FC, Fragment, type HTMLAttributes } from "react";
Expand Down Expand Up @@ -63,7 +64,8 @@ export const WorkspaceBuildLogs: FC<WorkspaceBuildLogsProps> = ({
>
{Object.entries(groupedLogsByStage).map(([stage, logs]) => {
const isEmpty = logs.every((log) => log.output === "");
const lines = logs.map((log) => ({
const lines = logs.map<Line>((log) => ({
id: log.id,
time: log.created_at,
output: log.output,
level: log.log_level,
Expand Down
3 changes: 2 additions & 1 deletion site/src/pages/WorkspaceBuildPage/WorkspaceBuildPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
import { Alert } from "components/Alert/Alert";
import { ErrorAlert } from "components/Alert/ErrorAlert";
import { Loader } from "components/Loader/Loader";
import type { Line } from "components/Logs/LogLine";
import { Margins } from "components/Margins/Margins";
import {
FullWidthPageHeader,
Expand Down Expand Up @@ -302,7 +303,7 @@ const AgentLogsContent: FC<{ workspaceId: string; agent: WorkspaceAgent }> = ({
return (
<AgentLogs
sources={agent.log_sources}
logs={logs.map((l) => ({
logs={logs.map<Line>((l) => ({
id: l.id,
output: l.output,
time: l.created_at,
Expand Down
Loading