8000 fix: filter unique script timings per build · coder/coder@71033c9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 71033c9

Browse files
committed
fix: filter unique script timings per build
The timings endpoint is incorrectly returning multiple script timings instead of a single one. This commit implements a workaround to address the issue on the FE side.
1 parent 0008c13 commit 71033c9

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

site/src/modules/workspaces/WorkspaceTiming/WorkspaceTimings.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import type {
99
AgentScriptTiming,
1010
ProvisionerTiming,
1111
} from "api/typesGenerated";
12-
import sortBy from "lodash/sortBy";
13-
import uniqBy from "lodash/uniqBy";
1412
import { type FC, useState } from "react";
1513
import { type TimeRange, calcDuration, mergeTimeRanges } from "./Chart/utils";
1614
import { ResourcesChart, isCoderResource } from "./ResourcesChart";
@@ -44,16 +42,9 @@ export const WorkspaceTimings: FC<WorkspaceTimingsProps> = ({
4442
defaultIsOpen = false,
4543
}) => {
4644
const [view, setView] = useState<TimingView>({ name: "default" });
47-
// This is a workaround to deal with the BE returning multiple timings for a
48-
// single agent script when it should return only one. Reference:
49-
// https://github.com/coder/coder/issues/15413#issuecomment-2493663571
50-
const uniqScriptTimings = uniqBy(
51-
sortBy(agentScriptTimings, (t) => new Date(t.started_at).getTime() * -1),
52-
(t) => t.display_name,
53-
);
5445
const timings = [
5546
...provisionerTimings,
56-
...uniqScriptTimings,
47+
...agentScriptTimings,
5748
...agentConnectionTimings,
5849
].sort((a, b) => {
5950
return new Date(a.started_at).getTime() - new Date(b.started_at).getTime();

site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import { UpdateBuildParametersDialog } from "./UpdateBuildParametersDialog";
3737
import { Workspace } from "./Workspace";
3838
import { WorkspaceDeleteDialog } from "./WorkspaceDeleteDialog";
3939
import type { WorkspacePermissions } from "./permissions";
40+
import sortBy from "lodash/sortBy";
41+
import uniqBy from "lodash/uniqBy";
4042

4143
interface WorkspaceReadyPageProps {
4244
template: TypesGen.Template;
@@ -163,6 +165,21 @@ export const WorkspaceReadyPage: FC<WorkspaceReadyPageProps> = ({
163165
// Fetch build timings only when the build job is completed.
164166
enabled: Boolean(workspace.latest_build.job.completed_at),
165167

168+
// This is a workaround to deal with the BE returning multiple timings for a
169+
// single agent script when it should return only one. Reference:
170+
// https://github.com/coder/coder/issues/15413#issuecomment-2493663571
171+
select: (data) => {
172+
return {
173+
...data,
174+
agent_script_timings: uniqBy(
175+
sortBy(data.agent_script_timings, (t) =>
176+
new Date(t.started_at).getTime(),
177+
),
178+
(t) => t.display_name,
179+
),
180+
};
181+
},
182+
166183
// Sometimes, the timings can be fetched before the agent script timings are
167184
// done or saved in the database so we need to conditionally refetch the
168185
// timings. To refetch the timings, I found the best way was to compare the

0 commit comments

Comments
 (0)
0