diff --git a/torchci/lib/clickhouse.ts b/torchci/lib/clickhouse.ts index 4edf7366d4..07a1daff0f 100644 --- a/torchci/lib/clickhouse.ts +++ b/torchci/lib/clickhouse.ts @@ -32,7 +32,7 @@ export async function queryClickhouse( params: Record, query_id?: string, useQueryCache?: boolean -): Promise { +): Promise<{ [key: string]: any }[]> { if (query_id === undefined) { query_id = "adhoc"; } @@ -61,23 +61,26 @@ export async function queryClickhouse( return (await res.json()) as any[]; } +/** + * Returns the result of a query from the clickhouse database. + * + * The format is an array of json dictionaries/objects ex [{name: "foo", age: 42}, {name: "bar", age: 43}] + * + * @param queryName: string, the name of the query, which is the name of the folder in clickhouse_queries + * @param inputParams: Record, the parameters to the query, an object where keys are the parameter names + * @param useQueryCache: boolean, if true, cache the query result on Ch side (1 minute TTL) + * + * This function will filter the inputParams to only include the parameters + * that are in the query params json file. + * + * During local development, if this fails due to "cannot find module ... + * params.json", delete the .next folder and try again. + */ export async function queryClickhouseSaved( queryName: string, inputParams: Record, useQueryCache?: boolean ) { - /** - * queryClickhouseSaved - * @param queryName: string, the name of the query, which is the name of the folder in clickhouse_queries - * @param inputParams: Record, the parameters to the query, an object where keys are the parameter names - * @param useQueryCache: boolean, if true, cache the query result on Ch side (1 minute TTL) - * - * This function will filter the inputParams to only include the parameters - * that are in the query params json file. - * - * During local development, if this fails due to "cannot find module ... - * params.json", delete the .next folder and try again. - */ const query = readFileSync( // https://stackoverflow.com/questions/74924100/vercel-error-enoent-no-such-file-or-directory `${process.cwd()}/clickhouse_queries/${queryName}/query.sql`, diff --git a/torchci/lib/drciUtils.ts b/torchci/lib/drciUtils.ts index 2827b36feb..2e23927b28 100644 --- a/torchci/lib/drciUtils.ts +++ b/torchci/lib/drciUtils.ts @@ -510,12 +510,11 @@ export async function getPRMergeCommits( }); // If the array is empty, the PR hasn't been merged yet - return results.reduce((acc: { [prNumber: number]: string[] }, row: any) => { - if (!acc[row.pr_num]) { - acc[row.pr_num] = []; + return results.reduce((acc: Map, row: any) => { + if (!acc.has(row.pr_num)) { + acc.set(row.pr_num, []); } - - acc[row.pr_num].push(row.merge_commit_sha); + acc.get(row.pr_num)!.push(row.merge_commit_sha); return acc; }, new Map()); } diff --git a/torchci/lib/fetchDisabledNonFlakyTests.ts b/torchci/lib/fetchDisabledNonFlakyTests.ts index 2c11df1ecd..f8b292c7f5 100644 --- a/torchci/lib/fetchDisabledNonFlakyTests.ts +++ b/torchci/lib/fetchDisabledNonFlakyTests.ts @@ -4,8 +4,8 @@ import { DisabledNonFlakyTestData } from "./types"; export default async function fetchDisabledNonFlakyTests(): Promise< DisabledNonFlakyTestData[] > { - return await queryClickhouseSaved("flaky_tests/disabled_non_flaky_tests", { + return (await queryClickhouseSaved("flaky_tests/disabled_non_flaky_tests", { max_num_red: 0, min_num_green: 150, - }); + })) as DisabledNonFlakyTestData[]; } diff --git a/torchci/lib/fetchFlakyTests.ts b/torchci/lib/fetchFlakyTests.ts index 6433a2aab8..0aaf15e24f 100644 --- a/torchci/lib/fetchFlakyTests.ts +++ b/torchci/lib/fetchFlakyTests.ts @@ -12,7 +12,7 @@ export default async function fetchFlakyTests( name: testName, suite: testSuite, file: testFile, - }); + }) as any; } export async function fetchFlakyTestsAcrossJobs(): Promise { @@ -77,7 +77,7 @@ export async function fetchFlakyTestsAcrossFileReruns( if (!workflowJobMap.has(curr.job_id)) { return accum; } - const job_info = workflowJobMap.get(curr.job_id); + const job_info = workflowJobMap.get(curr.job_id)!; if (val === undefined) { accum.set(key, { file: curr.file, diff --git a/torchci/lib/fetchIssuesByLabel.ts b/torchci/lib/fetchIssuesByLabel.ts index fbd2ff7700..6d501fe931 100644 --- a/torchci/lib/fetchIssuesByLabel.ts +++ b/torchci/lib/fetchIssuesByLabel.ts @@ -5,11 +5,11 @@ export default async function fetchIssuesByLabel( label: string, useChCache?: boolean ): Promise { - return await queryClickhouseSaved( + return (await queryClickhouseSaved( "issue_query", { label, }, useChCache - ); + )) as IssueData[]; } diff --git a/torchci/lib/fetchRecentWorkflows.ts b/torchci/lib/fetchRecentWorkflows.ts index e29bc994e1..bfb2edce7a 100644 --- a/torchci/lib/fetchRecentWorkflows.ts +++ b/torchci/lib/fetchRecentWorkflows.ts @@ -6,17 +6,17 @@ export async function fetchRecentWorkflows( prNumbers: Array = [], numMinutes: string = "30" ): Promise { - return await queryClickhouseSaved("recent_pr_workflows_query", { + return (await queryClickhouseSaved("recent_pr_workflows_query", { numMinutes, prNumbers, repo, - }); + })) as RecentWorkflowsData[]; } export async function fetchFailedJobsFromCommits( shas: string[] ): Promise { - return await queryClickhouseSaved("commit_failed_jobs", { + return (await queryClickhouseSaved("commit_failed_jobs", { shas, - }); + })) as RecentWorkflowsData[]; } diff --git a/torchci/lib/getAuthors.ts b/torchci/lib/getAuthors.ts index a472650455..3796ee56af 100644 --- a/torchci/lib/getAuthors.ts +++ b/torchci/lib/getAuthors.ts @@ -36,5 +36,11 @@ where shas: _.map(jobs, (job: RecentWorkflowsData) => job.head_sha), }); - return _.keyBy(results, (record) => record.sha); + return _.keyBy(results, (record) => record.sha) as { + [key: string]: { + email: string; + commit_username: string; + pr_username: string; + }; + }; } diff --git a/torchci/lib/utilization/fetchListUtilizationMetadataInfo.ts b/torchci/lib/utilization/fetchListUtilizationMetadataInfo.ts index 39748556f9..25479cd719 100644 --- a/torchci/lib/utilization/fetchListUtilizationMetadataInfo.ts +++ b/torchci/lib/utilization/fetchListUtilizationMetadataInfo.ts @@ -34,14 +34,14 @@ export default async function fetchListUtilizationMetadataInfo( return { workflow_id: params.workflow_id, workflow_name: meta_resp[0].workflow_name, - metadata_list: meta_resp ? meta_resp : ([] as UtilizationMetadataInfo[]), + metadata_list: meta_resp ? meta_resp : [], }; } async function listUtilizationMetadataInfo( workflow_id: string, repo: string = UTILIZATION_DEFAULT_REPO -) { +): Promise { const response = await queryClickhouseSaved( LIST_UTIL_METADATA_INFO_QUERY_FOLDER_NAME, { @@ -49,7 +49,7 @@ async function listUtilizationMetadataInfo( repo: repo, } ); - return response; + return response as UtilizationMetadataInfo[]; } async function listUtilizationMetadataWithStats( diff --git a/torchci/lib/utilization/fetchUtilization.ts b/torchci/lib/utilization/fetchUtilization.ts index 01db0e934c..567c8f485f 100644 --- a/torchci/lib/utilization/fetchUtilization.ts +++ b/torchci/lib/utilization/fetchUtilization.ts @@ -81,7 +81,7 @@ async function getUtilizationMetadata( job_id: string, run_attempt: string, repo: string = UTILIZATION_DEFAULT_REPO -) { +): Promise { const response = await queryClickhouseSaved(UTIL_METADATA_QUERY_FOLDER_NAME, { workflowId: workflow_id, jobId: job_id, @@ -89,7 +89,7 @@ async function getUtilizationMetadata( type: UTILIZATION_TYPE, repo: repo, }); - return response; + return response as UtilizationMetadata[]; } function getDisplayName(name: string) { diff --git a/torchci/pages/api/flaky-tests/3dStats.ts b/torchci/pages/api/flaky-tests/3dStats.ts index 2bf2ea6e68..8d8bddc53f 100644 --- a/torchci/pages/api/flaky-tests/3dStats.ts +++ b/torchci/pages/api/flaky-tests/3dStats.ts @@ -31,7 +31,7 @@ async function getTest( for (const row of res) { row.conclusions = _.countBy(row.conclusions); } - return res; + return res as TestInfoAPIResponse; } export type TestInfoAPIResponse = { diff --git a/torchci/pages/api/flaky-tests/search.ts b/torchci/pages/api/flaky-tests/search.ts index 42cea6781e..9b97af2089 100644 --- a/torchci/pages/api/flaky-tests/search.ts +++ b/torchci/pages/api/flaky-tests/search.ts @@ -37,7 +37,7 @@ async function listTests( return { count: (await count)[0].count, - tests: await result, + tests: (await result) as any, }; }