mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[ci-stats-reporter] use v2 test group APIs (#131001)
* [ci-stats-reporter] use v2 test group APIs * fix bazel deps * [CI] Auto-commit changed files from 'yarn kbn run build -i @kbn/pm' * avoid importing kbn/std in kbn-pm * removed kbn/std dependency Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
56d0112a22
commit
7fd166176d
2 changed files with 85 additions and 18 deletions
|
@ -96,10 +96,8 @@ export interface CiStatsReportTestsOptions {
|
|||
}
|
||||
|
||||
/* @internal */
|
||||
interface ReportTestsResponse {
|
||||
buildId: string;
|
||||
interface ReportTestGroupResponse {
|
||||
groupId: string;
|
||||
testRunCount: number;
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
|
@ -257,18 +255,51 @@ 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;
|
||||
}
|
||||
|
||||
let bufferBytes = 0;
|
||||
const buffer: string[] = [];
|
||||
const flushBuffer = async () => {
|
||||
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 ${bufferBytes} bytes`,
|
||||
body: buffer.join('\n'),
|
||||
});
|
||||
buffer.length = 0;
|
||||
bufferBytes = 0;
|
||||
};
|
||||
|
||||
// send test runs in chunks of ~500kb
|
||||
for (const testRun of testRuns) {
|
||||
const json = JSON.stringify(testRun);
|
||||
bufferBytes += json.length;
|
||||
buffer.push(json);
|
||||
if (bufferBytes >= 450000) {
|
||||
await flushBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
if (bufferBytes) {
|
||||
await flushBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
52
packages/kbn-pm/dist/index.js
vendored
52
packages/kbn-pm/dist/index.js
vendored
|
@ -1753,19 +1753,55 @@ class CiStatsReporter {
|
|||
throw new Error('unable to report tests unless buildId is configured and auth config available');
|
||||
}
|
||||
|
||||
return await this.req({
|
||||
const groupResp = await this.req({
|
||||
auth: true,
|
||||
path: '/v1/test_group',
|
||||
path: '/v2/test_group',
|
||||
query: {
|
||||
buildId: (_this$config7 = this.config) === null || _this$config7 === void 0 ? void 0 : _this$config7.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;
|
||||
}
|
||||
|
||||
let bufferBytes = 0;
|
||||
const buffer = [];
|
||||
|
||||
const flushBuffer = async () => {
|
||||
var _this$config8;
|
||||
|
||||
await this.req({
|
||||
auth: true,
|
||||
path: '/v2/test_runs',
|
||||
query: {
|
||||
buildId: (_this$config8 = this.config) === null || _this$config8 === void 0 ? void 0 : _this$config8.buildId,
|
||||
groupId: groupResp.groupId,
|
||||
groupType: group.type
|
||||
},
|
||||
bodyDesc: `[${group.name}/${group.type}] Chunk of ${bufferBytes} bytes`,
|
||||
body: buffer.join('\n')
|
||||
});
|
||||
buffer.length = 0;
|
||||
bufferBytes = 0;
|
||||
}; // send test runs in chunks of ~500kb
|
||||
|
||||
|
||||
for (const testRun of testRuns) {
|
||||
const json = JSON.stringify(testRun);
|
||||
bufferBytes += json.length;
|
||||
buffer.push(json);
|
||||
|
||||
if (bufferBytes >= 450000) {
|
||||
await flushBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
if (bufferBytes) {
|
||||
await flushBuffer();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* In order to allow this code to run before @kbn/utils is built, @kbn/pm will pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue