Skip to content

Commit 8597c3f

Browse files
authored
Merge branch 'main' into csp-ai-assistant-asset-inventory-phase1
2 parents a40d434 + e5d6048 commit 8597c3f

File tree

1,444 files changed

+18321
-8352
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,444 files changed

+18321
-8352
lines changed

.buildkite/package-lock.json

Lines changed: 32 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.buildkite/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"js-yaml": "^4.1.0",
1616
"minimatch": "^5.0.1",
1717
"minimist": "^1.2.8",
18+
"p-limit": "^3.1.0",
1819
"tslib": "*"
1920
},
2021
"devDependencies": {
@@ -23,7 +24,7 @@
2324
"@types/jscodeshift": "^0.12.0",
2425
"@types/minimatch": "^3.0.5",
2526
"@types/minimist": "^1.2.5",
26-
"@types/node": "^15.12.2",
27+
"@types/node": "^22.17.1",
2728
"jest": "^30.0.3",
2829
"jscodeshift": "^17.1.2",
2930
"nock": "^12.0.2",

.buildkite/pipelines/flaky_tests/pipeline.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ if (Number.isNaN(concurrency)) {
3434
const BASE_JOBS = 1;
3535
const MAX_JOBS = 500;
3636

37+
function getScoutConfigGroupType(configPath: string): string | null {
38+
// Match platform paths: x-pack/platform/... or src/platform/...
39+
if (/^(x-pack|src)\/platform\//.test(configPath)) {
40+
return 'platform';
41+
}
42+
// Match solution paths: x-pack/solutions/<solution>/plugins/...
43+
const match = configPath.match(/^x-pack\/solutions\/([^/]+)\/plugins\//);
44+
if (match) {
45+
return match[1];
46+
}
47+
return null;
48+
}
49+
3750
function getTestSuitesFromJson(json: string) {
3851
const fail = (errorMsg: string) => {
3952
console.error('+++ Invalid test config provided');
@@ -55,6 +68,7 @@ function getTestSuitesFromJson(json: string) {
5568
const testSuites: Array<
5669
| { type: 'group'; key: string; count: number }
5770
| { type: 'ftrConfig'; ftrConfig: string; count: number }
71+
| { type: 'scoutConfig'; scoutConfig: string; count: number }
5872
> = [];
5973
for (const item of parsed) {
6074
if (typeof item !== 'object' || item === null) {
@@ -160,6 +174,33 @@ for (const testSuite of testSuites) {
160174
continue;
161175
}
162176

177+
if (testSuite.type === 'scoutConfig') {
178+
const usesParallelWorkers = testSuite.scoutConfig.endsWith('parallel.playwright.config.ts');
179+
const scoutConfigGroupType = getScoutConfigGroupType(testSuite.scoutConfig);
180+
181+
steps.push({
182+
command: `.buildkite/scripts/steps/test/scout_configs.sh`,
183+
env: {
184+
SCOUT_CONFIG: testSuite.scoutConfig,
185+
SCOUT_CONFIG_GROUP_TYPE: scoutConfigGroupType!,
186+
},
187+
key: `scout-suite-${suiteIndex++}`,
188+
label: `${testSuite.scoutConfig}`,
189+
parallelism: testSuite.count,
190+
concurrency,
191+
concurrency_group: process.env.UUID,
192+
concurrency_method: 'eager',
193+
agents: expandAgentQueue(usesParallelWorkers ? 'n2-8-spot' : 'n2-4-spot'),
194+
depends_on: 'build',
195+
timeout_in_minutes: 30,
196+
cancel_on_build_failing: true,
197+
retry: {
198+
automatic: [{ exit_status: '-1', limit: 3 }],
199+
},
200+
});
201+
continue;
202+
}
203+
163204
const [category, suiteName] = testSuite.key.split('/');
164205
switch (category) {
165206
case 'cypress':

.buildkite/scripts/steps/storybooks/build_and_upload.ts

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10-
import { execSync } from 'child_process';
10+
import { execSync, spawn } from 'child_process';
1111
import fs from 'fs';
1212
import path from 'path';
13+
import os from 'os';
14+
import pLimit from 'p-limit';
1315
import { storybookAliases } from '../../../../src/dev/storybook/aliases';
1416
import { getKibanaDir } from '#pipeline-utils';
1517

@@ -25,6 +27,42 @@ const STORYBOOK_BASE_URL = `${STORYBOOK_BUCKET_URL}`;
2527

2628
const exec = (...args: string[]) => execSync(args.join(' '), { stdio: 'inherit' });
2729

30+
const buildStorybook = (storybook: string): Promise<{ logs: string }> => {
31+
return new Promise((resolve, reject) => {
32+
const logsBuffer: string[] = [];
33+
const handleBufferChunk = (chunk: Buffer) => {
34+
logsBuffer.push(chunk.toString());
35+
};
36+
37+
const child = spawn('yarn', ['storybook', '--site', storybook], {
38+
stdio: 'pipe',
39+
env: {
40+
...process.env,
41+
STORYBOOK_BASE_URL,
42+
NODE_OPTIONS: '--max-old-space-size=6144',
43+
},
44+
});
45+
46+
child.stdout?.on('data', handleBufferChunk);
47+
child.stderr?.on('data', handleBufferChunk);
48+
49+
child.on('close', (code) => {
50+
if (code === 0) {
51+
logsBuffer.unshift(`--- ✅ ${storybook} storybook\n`);
52+
resolve({ logs: logsBuffer.join('') });
53+
} else {
54+
logsBuffer.unshift(`--- ❌ ${storybook} storybook\n`);
55+
reject(new Error(logsBuffer.join('')));
56+
}
57+
});
58+
59+
child.on('error', () => {
60+
logsBuffer.unshift(`--- ❌ ${storybook} storybook\n`);
61+
reject(new Error(logsBuffer.join('')));
62+
});
63+
});
64+
};
65+
2866
const ghStatus = (state: string, description: string) =>
2967
exec(
3068
`gh api "repos/elastic/kibana/statuses/${process.env.BUILDKITE_COMMIT}"`,
@@ -35,15 +73,23 @@ const ghStatus = (state: string, description: string) =>
3573
`--silent`
3674
);
3775

38-
const build = () => {
76+
const build = async () => {
3977
console.log('--- Building Storybooks');
4078

41-
for (const storybook of Object.keys(storybookAliases)) {
42-
exec(
43-
`STORYBOOK_BASE_URL=${STORYBOOK_BASE_URL}`,
44-
`NODE_OPTIONS=--max-old-space-size=6144`,
45-
`yarn storybook --site ${storybook}`
79+
const limit = pLimit(os.availableParallelism());
80+
const storybooks = Object.keys(storybookAliases);
81+
82+
try {
83+
const results = await Promise.all(
84+
storybooks.map((storybook) => limit(() => buildStorybook(storybook)))
4685
);
86+
87+
results.forEach(({ logs }) => {
88+
console.log(logs);
89+
});
90+
} catch (error) {
91+
console.error(error);
92+
throw error;
4793
}
4894
};
4995

@@ -84,8 +130,8 @@ const upload = () => {
84130
);
85131
exec(`
86132
${activateScript} gs://ci-artifacts.kibana.dev
87-
gsutil -h "Cache-Control:no-cache, max-age=0, no-transform" -q -m cp -r -z js,css,html,json,map,txt,svg '*' 'gs://${STORYBOOK_BUCKET}/${STORYBOOK_DIRECTORY}/'
88-
gsutil -h "Cache-Control:no-cache, max-age=0, no-transform" cp -z html 'index.html' 'gs://${STORYBOOK_BUCKET}/${STORYBOOK_DIRECTORY}/latest/'
133+
gcloud storage cp --cache-control="no-cache, max-age=0, no-transform" --gzip-local=js,css,html,json,map,txt,svg --recursive --no-user-output-enabled '*' 'gs://${STORYBOOK_BUCKET}/${STORYBOOK_DIRECTORY}/'
134+
gcloud storage cp --cache-control="no-cache, max-age=0, no-transform" --gzip-local=html --no-user-output-enabled 'index.html' 'gs://${STORYBOOK_BUCKET}/${STORYBOOK_DIRECTORY}/latest/'
89135
`);
90136

91137
if (process.env.BUILDKITE_PULL_REQUEST && process.env.BUILDKITE_PULL_REQUEST !== 'false') {
@@ -98,12 +144,14 @@ const upload = () => {
98144
}
99145
};
100146

101-
try {
102-
ghStatus('pending', 'Building Storybooks');
103-
build();
104-
upload();
105-
ghStatus('success', 'Storybooks built');
106-
} catch (error) {
107-
ghStatus('error', 'Building Storybooks failed');
108-
throw error;
109-
}
147+
(async () => {
148+
try {
149+
ghStatus('pending', 'Building Storybooks');
150+
await build();
151+
upload();
152+
ghStatus('success', 'Storybooks built');
153+
} catch (error) {
154+
ghStatus('error', 'Building Storybooks failed');
155+
throw error;
156+
}
157+
})();

.buildkite/scripts/steps/test/scout_configs.sh

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,51 @@ source .buildkite/scripts/steps/functional/common.sh
77
BUILDKITE_PARALLEL_JOB=${BUILDKITE_PARALLEL_JOB:-}
88
SCOUT_CONFIG_GROUP_KEY=${SCOUT_CONFIG_GROUP_KEY:-}
99
SCOUT_CONFIG_GROUP_TYPE=${SCOUT_CONFIG_GROUP_TYPE:-}
10+
SCOUT_CONFIG=${SCOUT_CONFIG:-}
1011

11-
if [ "$SCOUT_CONFIG_GROUP_KEY" == "" ] && [ "$BUILDKITE_PARALLEL_JOB" == "" ]; then
12-
echo "Missing SCOUT_CONFIG_GROUP_KEY env var"
13-
exit 1
14-
fi
12+
EXTRA_ARGS=${FTR_EXTRA_ARGS:-}
13+
test -z "$EXTRA_ARGS" || buildkite-agent meta-data set "ftr-extra-args" "$EXTRA_ARGS"
14+
15+
configs=""
1516

1617
if [ "$SCOUT_CONFIG_GROUP_TYPE" == "" ]; then
1718
echo "Missing SCOUT_CONFIG_GROUP_TYPE env var"
1819
exit 1
1920
fi
2021

21-
EXTRA_ARGS=${FTR_EXTRA_ARGS:-}
22-
test -z "$EXTRA_ARGS" || buildkite-agent meta-data set "ftr-extra-args" "$EXTRA_ARGS"
23-
24-
export JOB="$SCOUT_CONFIG_GROUP_KEY"
25-
26-
FAILED_CONFIGS_KEY="${BUILDKITE_STEP_ID}${SCOUT_CONFIG_GROUP_KEY}"
27-
28-
configs=""
2922
group=$SCOUT_CONFIG_GROUP_TYPE
3023

24+
if [ "$SCOUT_CONFIG" != "" ]; then
25+
configs="$SCOUT_CONFIG"
26+
export JOB="$SCOUT_CONFIG"
27+
FAILED_CONFIGS_KEY="${BUILDKITE_STEP_ID}${SCOUT_CONFIG}"
28+
elif [ "$SCOUT_CONFIG_GROUP_KEY" != "" ]; then
29+
export JOB="$SCOUT_CONFIG_GROUP_KEY"
30+
FAILED_CONFIGS_KEY="${BUILDKITE_STEP_ID}${SCOUT_CONFIG_GROUP_KEY}"
31+
else
32+
if [ "$BUILDKITE_PARALLEL_JOB" == "" ]; then
33+
echo "Missing SCOUT_CONFIG_GROUP_KEY or SCOUT_CONFIG env var"
34+
exit 1
35+
fi
36+
fi
37+
3138
# The first retry should only run the configs that failed in the previous attempt
3239
# Any subsequent retries, which would generally only happen by someone clicking the button in the UI, will run everything
33-
if [[ ! "$configs" && "${BUILDKITE_RETRY_COUNT:-0}" == "1" ]]; then
40+
if [[ -z "$configs" && "${BUILDKITE_RETRY_COUNT:-0}" == "1" ]]; then
3441
configs=$(buildkite-agent meta-data get "$FAILED_CONFIGS_KEY" --default '')
35-
if [[ "$configs" ]]; then
42+
if [[ -n "$configs" ]]; then
3643
echo "--- Retrying only failed configs"
3744
echo "$configs"
3845
fi
3946
fi
4047

41-
if [ "$configs" == "" ] && [ "$SCOUT_CONFIG_GROUP_KEY" != "" ]; then
48+
if [ -z "$configs" ] && [ "$SCOUT_CONFIG_GROUP_KEY" != "" ]; then
4249
echo "--- downloading scout test configuration"
4350
download_artifact scout_playwright_configs.json .
4451
configs=$(jq -r '.[env.SCOUT_CONFIG_GROUP_KEY].configs[]' scout_playwright_configs.json)
4552
fi
4653

47-
if [ "$configs" == "" ]; then
54+
if [ -z "$configs" ]; then
4855
echo "unable to determine configs to run"
4956
exit 1
5057
fi

0 commit comments

Comments
 (0)