Skip to content

Commit f96e4b5

Browse files
authored
[HUD] Query for artifacts of all workflow ids (#6449)
Query for the artifacts for all workflow ids in the box. Previously we assumed that only one workflow would show up in the box at a time, but this might not be true. Change the api to accept a list of workflows in the form list.join(",") and get the artifacts for all the workflow ids in that list https://torchci-git-csl-moreartifacts-fbopensource.vercel.app/pytorch/pytorch/commit/970ac2d907195dc31debe28e9a7ff8f4aa701683 old: <img width="640" alt="image" src="https://github.com/user-attachments/assets/5aee2470-ff03-4f6b-a7bc-c7842a34044e" /> new: <img width="620" alt="image" src="https://github.com/user-attachments/assets/37a54316-f245-4f16-a8b3-53b17989daf3" /> Note that the artifacts button shows up for the first job (non rerun or memory leak one) Fixes #5298
1 parent 7a02312 commit f96e4b5

File tree

2 files changed

+47
-34
lines changed

2 files changed

+47
-34
lines changed

torchci/components/WorkflowBox.tsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export default function WorkflowBox({
167167
const { utilMetadataList } = useUtilMetadata(workflowId);
168168
const groupUtilMetadataList = groupMetadataByJobId(utilMetadataList);
169169

170-
const { artifacts, error } = useArtifacts(workflowId);
170+
const { artifacts, error } = useArtifacts(jobs.map((job) => job.workflowId));
171171
const [artifactsToShow, setArtifactsToShow] = useState(new Set<string>());
172172
const groupedArtifacts = groupArtifacts(jobs, artifacts);
173173
const [searchString, setSearchString] = useState("");
@@ -313,21 +313,22 @@ function useUtilMetadata(workflowId: string | undefined): {
313313
return { utilMetadataList: data.metadata_list, metaError: null };
314314
}
315315

316-
function useArtifacts(workflowId: string | undefined): {
316+
function useArtifacts(workflowIds: (string | number | undefined)[]): {
317317
artifacts: Artifact[];
318318
error: any;
319319
} {
320+
const uniqueWorkflowIds = Array.from(new Set(workflowIds)).filter(
321+
(id) => id !== undefined
322+
);
323+
// Get all artifacts for these ids
320324
const { data, error } = useSWR<Artifact[]>(
321-
`/api/artifacts/s3/${workflowId}`,
325+
`/api/artifacts/s3/${uniqueWorkflowIds.join(",")}`,
322326
fetcher,
323327
{
324328
refreshInterval: 60 * 1000,
325329
refreshWhenHidden: true,
326330
}
327331
);
328-
if (workflowId === undefined) {
329-
return { artifacts: [], error: "No workflow ID" };
330-
}
331332
if (data == null) {
332333
return { artifacts: [], error: "Loading..." };
333334
}

torchci/lib/fetchS3Links.ts

+40-28
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,46 @@ const GHA_ARTIFACTS_LAMBDA =
55
"https://np6xty2nm6jifkuuyb6wllx6ha0qtthb.lambda-url.us-east-1.on.aws";
66

77
export default async function fetchS3Links(
8-
suiteId: string
8+
suiteIds: string
99
): Promise<Artifact[]> {
10-
const response = await fetch(GHA_ARTIFACTS_LAMBDA, {
11-
method: "POST",
12-
body: JSON.stringify({
13-
workflow_id: suiteId,
14-
}),
15-
headers: {
16-
"Content-Type": "application/json",
17-
},
18-
});
10+
const unflattenedList = await Promise.all(
11+
_(suiteIds)
12+
.split(",")
13+
.uniq()
14+
.map(async (suiteId) => {
15+
suiteId = suiteId.trim();
16+
const response = await fetch(GHA_ARTIFACTS_LAMBDA, {
17+
method: "POST",
18+
body: JSON.stringify({
19+
workflow_id: suiteId,
20+
}),
21+
headers: {
22+
"Content-Type": "application/json",
23+
},
24+
});
1925

20-
const results = await response.json();
21-
const artifacts =
22-
_.keys(results).map((url: string) => {
23-
const size = results[url];
24-
const basename = url.split("/").slice(-1)[0];
25-
const name =
26-
basename !== "artifacts.zip"
27-
? basename
28-
: url.split("/").slice(-2).join("/");
29-
return {
30-
kind: "s3",
31-
name: name ?? "",
32-
sizeInBytes: size ?? 0,
33-
url: url,
34-
expired: false,
35-
};
36-
}) ?? [];
37-
return artifacts.sort((a, b) => a.name.localeCompare(b.name));
26+
const results = await response.json();
27+
return (
28+
_.keys(results).map((url: string) => {
29+
const size = results[url];
30+
const basename = url.split("/").slice(-1)[0];
31+
const name =
32+
basename !== "artifacts.zip"
33+
? basename
34+
: url.split("/").slice(-2).join("/");
35+
return {
36+
kind: "s3",
37+
name: name ?? "",
38+
sizeInBytes: size ?? 0,
39+
url: url,
40+
expired: false,
41+
};
42+
}) ?? []
43+
);
44+
})
45+
.value()
46+
);
47+
return _.flatten(unflattenedList).sort((a, b) => {
48+
return a.name.localeCompare(b.name);
49+
});
3850
}

0 commit comments

Comments
 (0)