Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: display build timings when all timings are loaded#15728

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
BrunoQuaresma merged 5 commits intomainfrombq/fix-timings-update
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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
12 changes: 2 additions & 10 deletionssite/src/api/queries/workspaceBuilds.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,17 +58,9 @@ export const infiniteWorkspaceBuilds = (
};

// We use readyAgentsCount to invalidate the query when an agent connects
export const workspaceBuildTimings = (
workspaceBuildId: string,
readyAgentsCount: number,
) => {
export const workspaceBuildTimings = (workspaceBuildId: string) => {
return {
queryKey: [
"workspaceBuilds",
workspaceBuildId,
"timings",
{ readyAgentsCount },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What was thereadyAgentCount value doing before? I see that we were only using it for the query key, and now it's gone

BrunoQuaresma reacted with thumbs up emoji
Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It was to refetch the query when a new agent was marked as ready but it was very buggy and a bad decision on my end. The current refetch logic makes more sense and it is easier to follow.

],
queryKey: ["workspaceBuilds", workspaceBuildId, "timings"],
queryFn: () => API.workspaceBuildTimings(workspaceBuildId),
};
};
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -118,3 +118,11 @@ export const DuplicatedScriptTiming: Story = {
],
},
};

// Loading when agent script timings are empty
// Test case for https://github.com/coder/coder/issues/15273
export const LoadingWhenAgentScriptTimingsAreEmpty: Story = {
args: {
agentScriptTimings: undefined,
},
};
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,15 +58,25 @@ export const WorkspaceTimings: FC<WorkspaceTimingsProps> = ({
].sort((a, b) => {
return new Date(a.started_at).getTime() - new Date(b.started_at).getTime();
});

const [isOpen, setIsOpen] = useState(defaultIsOpen);
const isLoading = timings.length === 0;

// All stages
// If any of the timings are empty, we are still loading the data. They can be
// filled in different moments.
const isLoading = [
provisionerTimings,
agentScriptTimings,
agentConnectionTimings,
].some((t) => t.length === 0);

// Each agent connection timing is a stage in the timeline to make it easier
// to users to see the timing for connection and the other scripts.
const agentStageLabels = Array.from(
new Set(
agentConnectionTimings.map((t) => `agent (${t.workspace_agent_name})`),
),
);

const stages = [
...provisioningStages,
...agentStageLabels.flatMap((a) => agentStages(a)),
Expand DownExpand Up@@ -120,7 +130,8 @@ export const WorkspaceTimings: FC<WorkspaceTimingsProps> = ({
: mergeTimeRanges(stageTimings.map(toTimeRange));

// Prevent users from inspecting internal coder resources in
// provisioner timings.
// provisioner timings because they were not useful to the
// user and would add noise.
const visibleResources = stageTimings.filter((t) => {
const isProvisionerTiming = "resource" in t;
return isProvisionerTiming
Expand Down
24 changes: 19 additions & 5 deletionssite/src/pages/WorkspacePage/WorkspaceReadyPage.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -157,13 +157,27 @@ export const WorkspaceReadyPage: FC<WorkspaceReadyPageProps> = ({
// Cancel build
const cancelBuildMutation = useMutation(cancelBuild(workspace, queryClient));

// Build Timings. Fetch build timings only when the build job is completed.
const readyAgents = workspace.latest_build.resources
.flatMap((r) => r.agents)
.filter((a) => a && a.lifecycle_state !== "starting");
// Workspace Timings.
const timingsQuery = useQuery({
...workspaceBuildTimings(workspace.latest_build.id, readyAgents.length),
...workspaceBuildTimings(workspace.latest_build.id),

// Fetch build timings only when the build job is completed.
enabled: Boolean(workspace.latest_build.job.completed_at),

// 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
// expected amount of script timings with the current amount of script
// timings returned in the response.
refetchInterval: (data) => {
const expectedScriptTimingsCount = workspace.latest_build.resources
.flatMap((r) => r.agents)
.flatMap((a) => a?.scripts ?? []).length;
const currentScriptTimingsCount = data?.agent_script_timings?.length ?? 0;
return expectedScriptTimingsCount === currentScriptTimingsCount
? false
: 1_000;
},
});

const runLastBuild = (
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp