8000 fix: avoid missed logs when streaming startup logs by mafredri · Pull Request #8029 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

fix: avoid missed logs when streaming startup logs #8029

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 12 commits into from
Jun 16, 2023
Merged
Prev Previous commit
Next Next commit
fix(site): Unshow the eof log line from WebUI
  • Loading branch information
mafredri committed Jun 16, 2023
commit 1b589712f972ccec0733e8135a9e6ce2ef005564
13 changes: 9 additions & 4 deletions site/src/components/Resources/AgentRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { FixedSizeList as List, ListOnScrollProps } from "react-window"
import { colors } from "theme/colors"
import { combineClasses } from "utils/combineClasses"
import {
LineWithID,
LineWithIDAndEOF,
workspaceAgentLogsMachine,
} from "xServices/workspaceAgentLogs/workspaceAgentLogsXService"
import {
Expand Down Expand Up @@ -54,7 +54,7 @@ export interface AgentRowProps {
hideVSCodeDesktopButton?: boolean
serverVersion: string
onUpdateAgent: () => void
storybookStartupLogs?: LineWithID[]
storybookStartupLogs?: LineWithIDAndEOF[]
storybookAgentMetadata?: WorkspaceAgentMetadata[]
}

Expand Down Expand Up @@ -98,7 +98,8 @@ export const AgentRow: FC<AgentRowProps> = ({
const { proxy } = useProxy()

const [showStartupLogs, setShowStartupLogs] = useState(
agent.lifecycle_state !== "ready" && hasStartupFeatures,
["starting", "start_timeout"].includes(agent.lifecycle_state) &&
hasStartupFeatures,
)
useEffect(() => {
setShowStartupLogs(agent.lifecycle_state !== "ready" && hasStartupFeatures)
Expand All @@ -123,13 +124,17 @@ export const AgentRow: FC<AgentRowProps> = ({
const startupLogs = useMemo(() => {
const allLogs = logsMachine.context.startupLogs || []

const logs = [...allLogs]
// Filter out eof, since we don't want to show an empty line to the
// user. The timesetamp could be used to show when the log ended in
// the future.
const logs = [...allLogs.filter((log) => !log.eof)]
if (agent.startup_logs_overflowed) {
logs.push({
id: -1,
level: "error",
output: "Startup logs exceeded the max size of 1MB!",
time: new Date().toISOString(),
eof: false,
})
}
return logs
Expand Down
8000
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { Line } from "components/Logs/Logs"
// 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 {
export interface LineWithIDAndEOF extends Line {
id: number
eof: boolean
}

export const workspaceAgentLogsMachine = createMachine(
Expand All @@ -18,7 +19,7 @@ export const workspaceAgentLogsMachine = createMachine(
events: {} as
| {
type: "ADD_STARTUP_LOGS"
logs: LineWithID[]
logs: LineWithIDAndEOF[]
}
| {
type: "FETCH_STARTUP_LOGS"
Expand All @@ -28,11 +29,11 @@ export const workspaceAgentLogsMachine = createMachine(
},
context: {} as {
agentID: string
startupLogs?: LineWithID[]
startupLogs?: LineWithIDAndEOF[]
},
services: {} as {
getStartupLogs: {
data: LineWithID[]
data: LineWithIDAndEOF[]
}
},
},
Expand Down Expand Up @@ -82,6 +83,7 @@ export const workspaceAgentLogsMachine = createMachine(
level: log.level || "info",
output: log.output,
time: log.created_at,
eof: log.eof,
})),
),
streamStartupLogs: (ctx) => async (callback) => {
Expand All @@ -100,6 +102,7 @@ export const workspaceAgentLogsMachine = createMachine(
level: "info" as TypesGen.LogLevel,
output: log.output,
time: log.created_at,
eof: log.eof,
})),
})
},
Expand Down
0