-
Notifications
You must be signed in to change notification settings - Fork 8k
/
journey_ftr_config.ts
119 lines (103 loc) · 4.55 KB
/
journey_ftr_config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import Path from 'path';
import { v4 as uuidV4 } from 'uuid';
import { REPO_ROOT } from '@kbn/repo-info';
import type { FtrConfigProviderContext, FtrConfigProvider } from '@kbn/test';
import { commonFunctionalServices } from '@kbn/ftr-common-functional-services';
import { AnyStep } from './journey';
import { JourneyConfig } from './journey_config';
import { JOURNEY_APM_CONFIG } from './journey_apm_config';
export function makeFtrConfigProvider(
config: JourneyConfig<any>,
steps: AnyStep[]
): FtrConfigProvider {
return async ({ readConfigFile }: FtrConfigProviderContext) => {
const isServerless = !!process.env.TEST_SERVERLESS;
// Use the same serverless FTR config for all journeys
const configPath = isServerless
? 'x-pack/test_serverless/shared/config.base.ts'
: config.getFtrConfigPath();
const defaultConfigPath = config.isXpack()
? 'x-pack/test/functional/config.base.js'
: 'test/functional/config.base.js';
const ftrConfigPath = configPath ?? defaultConfigPath;
const baseConfig = (await readConfigFile(Path.resolve(REPO_ROOT, ftrConfigPath))).getAll();
const testBuildId = process.env.BUILDKITE_BUILD_ID ?? `local-${uuidV4()}`;
const testJobId = process.env.BUILDKITE_JOB_ID ?? `local-${uuidV4()}`;
const prId = process.env.GITHUB_PR_NUMBER
? Number.parseInt(process.env.GITHUB_PR_NUMBER, 10)
: undefined;
if (Number.isNaN(prId)) {
throw new Error('invalid GITHUB_PR_NUMBER environment variable');
}
// Set variable to collect performance events using EBT
const enableTelemetry = !!process.env.PERFORMANCE_ENABLE_TELEMETRY;
const telemetryLabels: Record<string, string | boolean | undefined | number> = {
branch: process.env.BUILDKITE_BRANCH,
ciBuildId: process.env.BUILDKITE_BUILD_ID,
ciBuildJobId: process.env.BUILDKITE_JOB_ID,
ciBuildNumber: Number(process.env.BUILDKITE_BUILD_NUMBER) || 0,
gitRev: process.env.BUILDKITE_COMMIT,
isPr: prId !== undefined,
...(prId !== undefined ? { prId } : {}),
ciBuildName: process.env.BUILDKITE_PIPELINE_SLUG,
journeyName: config.getName(),
};
return {
...baseConfig,
mochaOpts: {
...baseConfig.mochaOpts,
bail: true,
},
services: commonFunctionalServices,
pageObjects: {},
servicesRequiredForTestAnalysis: ['performance', 'journeyConfig'],
junit: {
reportName: `Journey: ${config.getName()}`,
metadata: {
journeyName: config.getName(),
stepNames: steps.map((s) => s.name),
},
},
kbnTestServer: {
...baseConfig.kbnTestServer,
// delay shutdown to ensure that APM can report the data it collects during test execution
delayShutdown: process.env.TEST_PERFORMANCE_PHASE === 'TEST' ? 15_000 : 0,
serverArgs: [
...baseConfig.kbnTestServer.serverArgs,
`--telemetry.optIn=${enableTelemetry && process.env.TEST_PERFORMANCE_PHASE === 'TEST'}`,
`--telemetry.labels=${JSON.stringify(telemetryLabels)}`,
'--csp.strict=false',
'--csp.warnLegacyBrowsers=false',
],
env: {
ELASTIC_APM_ACTIVE: JOURNEY_APM_CONFIG.active,
ELASTIC_APM_CONTEXT_PROPAGATION_ONLY: JOURNEY_APM_CONFIG.contextPropagationOnly,
ELASTIC_APM_ENVIRONMENT: JOURNEY_APM_CONFIG.environment,
ELASTIC_APM_TRANSACTION_SAMPLE_RATE: JOURNEY_APM_CONFIG.transactionSampleRate,
ELASTIC_APM_SERVER_URL: JOURNEY_APM_CONFIG.serverUrl,
ELASTIC_APM_SECRET_TOKEN: JOURNEY_APM_CONFIG.secretToken,
ELASTIC_APM_CAPTURE_BODY: JOURNEY_APM_CONFIG.captureBody,
ELASTIC_APM_CAPTURE_HEADERS: JOURNEY_APM_CONFIG.captureRequestHeaders,
ELASTIC_APM_LONG_FIELD_MAX_LENGTH: JOURNEY_APM_CONFIG.longFieldMaxLength,
ELASTIC_APM_GLOBAL_LABELS: Object.entries({
...config.getExtraApmLabels(),
testJobId,
testBuildId,
journeyName: config.getName(),
ftrConfig: config.getRepoRelPath(),
...JOURNEY_APM_CONFIG.globalLabels,
})
.flatMap(([key, value]) => (value == null ? [] : `${key}=${value}`))
.join(','),
},
},
};
};
}