Skip to content

Commit 9889b59

Browse files
authored
[Utilization] Setup API and UI Inital page (#6240)
# Description Setup API and UI for utilization time series. Currently hooked with clickhouse fortesting tables to unblock UI development while waiting for the datapipline code merged. working api: https://torchci-git-utiltest-fbopensource.vercel.app/api/utilization/12937937547/36088234580/1 working UI rendering: https://torchci-git-utiltest-fbopensource.vercel.app/utilization/12937937547/36088234580/1 ##Details - set up sql, methods and API to fetch data from clickhouse - Add unittest for complicated logics - set up Page for utilization
1 parent 3660993 commit 9889b59

File tree

13 files changed

+743
-0
lines changed

13 files changed

+743
-0
lines changed

.lintrunner.toml

+3
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,9 @@ include_patterns = [
365365
'torchci/clickhouse_queries/oss_ci_benchmark_branches/query.sql',
366366
'torchci/clickhouse_queries/oss_ci_benchmark_llms/query.sql',
367367
'torchci/clickhouse_queries/oss_ci_benchmark_names/query.sql',
368+
'torchci/clickhouse_queries/oss_ci_util_metadata/query.sql',
369+
'torchci/clickhouse_queries/oss_ci_util_ts/query.sql'
370+
368371
]
369372
exclude_patterns = [
370373
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"params": {
3+
"workflowId": "UInt64",
4+
"jobId": "UInt64",
5+
"runAttempt": "UInt32",
6+
"repo": "String",
7+
"type": "String"
8+
},
9+
"tests":[]
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--- This query is used by utilization dashboard
2+
-- TODO(): change to misc. once the pipeline is ready, currently fetch data from fortesting for development
3+
SELECT
4+
usage_collect_interval AS collect_interval,
5+
data_model_version AS model_version,
6+
gpu_count,
7+
cpu_count,
8+
created_at,
9+
workflow_name,
10+
job_name,
11+
start_at,
12+
end_at,
13+
segments,
14+
tags
15+
FROM
16+
fortesting.oss_ci_utilization_metadata
17+
WHERE
18+
workflow_id = { workflowId: UInt64}
19+
AND run_attempt = {runAttempt: UInt32}
20+
AND job_id = {jobId: UInt64}
21+
AND repo = {repo: String }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"params": {
3+
"workflowId": "UInt64",
4+
"jobId": "UInt64",
5+
"runAttempt": "UInt32",
6+
"repo": "String",
7+
"type": "String"
8+
},
9+
"tests":[]
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--- This query is used by utilization dashboard
2+
-- TODO(): change to misc. once the pipeline is ready, currently fetch data from fortesting for development
3+
SELECT
4+
time_stamp AS ts,
5+
tags,
6+
json_data AS data
7+
FROM
8+
fortesting.oss_ci_time_series
9+
WHERE
10+
workflow_id = {workflowId: UInt64}
11+
AND run_attempt = {runAttempt: UInt32}
12+
AND job_id = {jobId: UInt64}
13+
AND repo = {repo: String }
14+
AND type = {type: String}
15+
ORDER BY
16+
ts

torchci/lib/GeneralUtils.ts

+24
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ import { Octokit } from "octokit";
22
import { isFailure } from "./JobClassifierUtil";
33
import { CommitData, JobData } from "./types";
44

5+
class ErrorWithStatusCode extends Error {
6+
status: number;
7+
info: any;
8+
constructor(message: string, status: number, info: any) {
9+
super(message);
10+
this.status = status;
11+
this.info = info;
12+
}
13+
}
14+
515
export function includesCaseInsensitive(
616
value: string,
717
pattern: string
@@ -11,6 +21,20 @@ export function includesCaseInsensitive(
1121

1222
export const fetcher = (url: string) => fetch(url).then((res) => res.json());
1323

24+
export const fetcherHandleError = async (url: string) => {
25+
const res = await fetch(url);
26+
if (!res.ok) {
27+
const info = await res.json();
28+
const error = new ErrorWithStatusCode(
29+
`An error occurred while fetching the data`,
30+
res.status,
31+
info?.error
32+
);
33+
throw error;
34+
}
35+
return res.json();
36+
};
37+
1438
export const getMessage = (
1539
message: string,
1640
classification: string,

torchci/lib/clickhouse.ts

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export async function queryClickhouse(
4343
* @param params: Record<string, unknown>, the parameters to the query ex { sha: "abcd" }
4444
*/
4545
const clickhouseClient = getClickhouseClient();
46+
4647
const res = await clickhouseClient.query({
4748
query,
4849
format: "JSONEachRow",

torchci/lib/error_utils.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// TypeScript defaults error type to unknown, this file is to handle error messages and types
2+
3+
type ErrorWithMessage = {
4+
message: string;
5+
};
6+
7+
function isErrorWithMessage(error: unknown): error is ErrorWithMessage {
8+
return (
9+
typeof error === "object" &&
10+
error !== null &&
11+
"message" in error &&
12+
typeof (error as Record<string, unknown>).message === "string"
13+
);
14+
}
15+
16+
function toErrorWithMessage(candidate: unknown): ErrorWithMessage {
17+
if (isErrorWithMessage(candidate)) {
18+
return candidate;
19+
}
20+
try {
21+
return new Error(JSON.stringify(candidate));
22+
} catch {
23+
return new Error(String(candidate));
24+
}
25+
}
26+
export function getErrorMessage(error: unknown) {
27+
return toErrorWithMessage(error).message;
28+
}

0 commit comments

Comments
 (0)