Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: filter unique script timings per build #16123

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

Closed
wants to merge 5 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,6 @@ export const NavigateToStartStage: Story = {
},
};

// Test case for https://github.com/coder/coder/issues/15413
export const DuplicatedScriptTiming: Story = {
args: {
agentScriptTimings: [
WorkspaceTimingsResponse.agent_script_timings[0],
{
...WorkspaceTimingsResponse.agent_script_timings[0],
started_at: "2021-09-01T00:00:00Z",
ended_at: "2021-09-01T00:00:00Z",
},
],
},
};

// Loading when agent script timings are empty
// Test case for https://github.com/coder/coder/issues/15273
export const LoadingWhenAgentScriptTimingsAreEmpty: Story = {
Expand Down
11 changes: 1 addition & 10 deletions site/src/modules/workspaces/WorkspaceTiming/WorkspaceTimings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import type {
AgentScriptTiming,
ProvisionerTiming,
} from "api/typesGenerated";
import sortBy from "lodash/sortBy";
import uniqBy from "lodash/uniqBy";
import { type FC, useState } from "react";
import { type TimeRange, calcDuration, mergeTimeRanges } from "./Chart/utils";
import { ResourcesChart, isCoderResource } from "./ResourcesChart";
Expand Down Expand Up @@ -44,16 +42,9 @@ export const WorkspaceTimings: FC<WorkspaceTimingsProps> = ({
defaultIsOpen = false,
}) => {
const [view, setView] = useState<TimingView>({ name: "default" });
// This is a workaround to deal with the BE returning multiple timings for a
// single agent script when it should return only one. Reference:
// https://github.com/coder/coder/issues/15413#issuecomment-2493663571
const uniqScriptTimings = uniqBy(
sortBy(agentScriptTimings, (t) => new Date(t.started_at).getTime() * -1),
(t) => t.display_name,
);
const timings = [
...provisionerTimings,
...uniqScriptTimings,
...agentScriptTimings,
...agentConnectionTimings,
].sort((a, b) => {
return new Date(a.started_at).getTime() - new Date(b.started_at).getTime();
Expand Down
26 changes: 26 additions & 0 deletions site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,32 @@ export const WorkspaceReadyPage: FC<WorkspaceReadyPageProps> = ({
// Fetch build timings only when the build job is completed.
enabled: Boolean(workspace.latest_build.job.completed_at),

// This is a workaround to deal with the BE returning multiple timings for a
// single agent script when it should return only one. Reference:
// https://github.com/coder/coder/issues/16124
select: (data) => {
// Select the most recent agent script timing for each script.
const fixedAgentScriptTimings = Object.values(
data.agent_script_timings.reduce(
(acc, item) => {
const existing = acc[item.display_name];
if (
!existing ||
new Date(item.started_at) > new Date(existing.started_at)
) {
acc[item.display_name] = item;
}
return acc;
},
{} as Record<string, TypesGen.AgentScriptTiming>,
),
);
return {
...data,
agent_script_timings: fixedAgentScriptTimings,
};
},

// Sometimes, the timings can be fetched before the agent script timings are
// done or saved in the database so we need to conditionally refetch the
// timings. To refetch the timings, I found the best way was to compare the
Expand Down
Loading