Skip to content

Commit ce582d0

Browse files
authored
Not call list util metadata in workflow box (#7503)
we run into some memory issues, so improve some utilization queries: 1. list_util_metadata is called when a commit page is loaded, let's just show the button when a job is finished, if no util is record, let the page handle it. 2. change the util api to job_utilization, and not call the api unless the workflowId and jobId is ready
1 parent 1732e2c commit ce582d0

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

torchci/components/additionalTestInfo/TestInfo.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ export function genMessage({
3737
return errorString.trim();
3838
}
3939

40+
export function isPendingJob(job: JobData) {
41+
return IsJobInProgress(job.conclusion);
42+
}
43+
4044
export function isPending(jobs: JobData[]) {
4145
return jobs.some((job) => IsJobInProgress(job.conclusion));
4246
}

torchci/components/commit/WorkflowBox.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { Button, Stack, styled, Tooltip, Typography } from "@mui/material";
2-
import { isPending, TestInfo } from "components/additionalTestInfo/TestInfo";
2+
import {
3+
isPending,
4+
isPendingJob,
5+
TestInfo,
6+
} from "components/additionalTestInfo/TestInfo";
37
import styles from "components/commit/commit.module.css";
48
import LogViewer, { SearchLogViewer } from "components/common/log/LogViewer";
59
import { durationDisplay } from "components/common/TimeUtils";
@@ -97,18 +101,13 @@ function WorkflowJobSummary({
97101
</JobButton>
98102
);
99103
}
100-
if (utilMetadata && utilMetadata.length > 0) {
101-
if (utilMetadata.length > 1) {
102-
console.log(
103-
`Multiple util metadata found for job ${job.id}, currently only showing the first one`
104-
);
105-
}
106-
const m = utilMetadata[0];
104+
if (job.id && !isPendingJob(job)) {
105+
const m = job;
107106
subInfo.push(
108107
<>
109108
<JobButton
110109
variant="outlined"
111-
href={`/utilization/${m.workflow_id}/${m.job_id}/${m.run_attempt}`}
110+
href={`/utilization/${m.workflowId}/${m.id}/${m.runAttempt}`}
112111
data-ga-action="utilization_report_click"
113112
data-ga-label="nav_button"
114113
data-ga-category="user_interaction"

torchci/pages/api/utilization/[workflowId]/[jobId]/[attempt].ts renamed to torchci/pages/api/job_utilization/[workflowId]/[jobId]/[attempt].ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,30 @@ import { getErrorMessage } from "lib/error_utils";
22
import fetchUtilization from "lib/utilization/fetchUtilization";
33
import { UtilizationParams } from "lib/utilization/types";
44
import { NextApiRequest, NextApiResponse } from "next";
5+
import { getServerSession } from "next-auth";
6+
import { authOptions } from "pages/api/auth/[...nextauth]";
57

68
export default async function handler(
79
req: NextApiRequest,
810
res: NextApiResponse
911
) {
1012
const { workflowId, jobId, attempt } = req.query;
11-
if (workflowId === undefined || jobId === undefined || attempt == undefined) {
13+
14+
// @ts-ignore
15+
const session = await getServerSession(req, res, authOptions);
16+
if (!session?.user || !session?.accessToken) {
17+
return res
18+
.status(401)
19+
.json({ error: "Authentication required to require utilization data" });
20+
}
21+
22+
if (!workflowId || !jobId || !attempt) {
23+
console.log(
24+
"[api job_utilization][warning] No workflowId, jobId, or attempt provided"
25+
);
1226
return res.status(200).json({});
1327
}
28+
1429
const params: UtilizationParams = {
1530
workflow_id: workflowId as string,
1631
run_attempt: attempt as string,

torchci/pages/utilization/[workflowId]/[jobId]/[attempt]/[[...page]].tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ const JobUtilization = () => {
99
const router = useRouter();
1010
const { workflowId, jobId, attempt } = router.query;
1111

12+
let shouldFetch = workflowId && jobId;
1213
let { data, error } = useSWRImmutable(
13-
`/api/utilization/${workflowId}/${jobId}/${attempt}`,
14+
shouldFetch
15+
? `/api/job_utilization/${workflowId}/${jobId}/${attempt}`
16+
: null,
1417
fetcherHandleError,
1518
{
1619
errorRetryCount: 3,

0 commit comments

Comments
 (0)