Skip to content

Commit

Permalink
[ci-stats-reporter] use v2 test group APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Apr 26, 2022
1 parent 7ff1ffc commit 1050e97
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions packages/kbn-ci-stats-reporter/src/ci_stats_reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Axios, { AxiosRequestConfig } from 'axios';
// @ts-expect-error not "public", but necessary to prevent Jest shimming from breaking things
import httpAdapter from 'axios/lib/adapters/http';
import { ToolingLog } from '@kbn/tooling-log';
import { asyncForEachWithLimit } from '@kbn/std';

import { parseConfig, Config, CiStatsMetadata } from '@kbn/ci-stats-core';
import type { CiStatsTestGroupInfo, CiStatsTestRun } from './ci_stats_test_group_types';
Expand Down Expand Up @@ -84,10 +85,8 @@ export interface CiStatsReportTestsOptions {
}

/* @internal */
interface ReportTestsResponse {
buildId: string;
interface ReportTestGroupResponse {
groupId: string;
testRunCount: number;
}

/* @internal */
Expand Down Expand Up @@ -238,17 +237,43 @@ export class CiStatsReporter {
);
}

return await this.req<ReportTestsResponse>({
const groupResp = await this.req<ReportTestGroupResponse>({
auth: true,
path: '/v1/test_group',
path: '/v2/test_group',
query: {
buildId: this.config?.buildId,
},
bodyDesc: `[${group.name}/${group.type}] test groups with ${testRuns.length} tests`,
body: [
JSON.stringify({ group }),
...testRuns.map((testRun) => JSON.stringify({ testRun })),
].join('\n'),
bodyDesc: `[${group.name}/${group.type}] test group`,
body: group,
});

if (!groupResp) {
return;
}

const chunks: CiStatsTestRun[][] = [];
for (const testRun of testRuns) {
const chunk = chunks.at(-1);
if (!chunk || chunk.length >= 20) {
chunks.push([testRun]);
} else {
chunk.push(testRun);
}
}

// send test runs in chunks of 20, 10 chunks at a time
await asyncForEachWithLimit(chunks, 10, async (chunk) => {
await this.req<{ testRunCount: number }>({
auth: true,
path: '/v2/test_runs',
query: {
buildId: this.config?.buildId,
groupId: groupResp.groupId,
groupType: group.type,
},
bodyDesc: `[${group.name}/${group.type}] Chunk of ${chunk.length} tests`,
body: chunk.map((test) => JSON.stringify(test)).join('\n'),
});
});
}

Expand Down

0 comments on commit 1050e97

Please sign in to comment.