[SUPT] fix apm reporting (#135071)

This commit is contained in:
Spencer 2022-06-23 14:10:57 -05:00 committed by GitHub
parent 705e516701
commit 61b5349d95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 9 deletions

View file

@ -15,6 +15,21 @@ node scripts/es snapshot&
esPid=$!
# unset env vars defined in other parts of CI for automatic APM collection of
# Kibana. We manage APM config in our FTR config and performance service, and
# APM treats config in the ENV with a very high precedence.
unset ELASTIC_APM_ENVIRONMENT
unset ELASTIC_APM_TRANSACTION_SAMPLE_RATE
unset ELASTIC_APM_SERVER_URL
unset ELASTIC_APM_SECRET_TOKEN
unset ELASTIC_APM_ACTIVE
unset ELASTIC_APM_CONTEXT_PROPAGATION_ONLY
unset ELASTIC_APM_ACTIVE
unset ELASTIC_APM_SERVER_URL
unset ELASTIC_APM_SECRET_TOKEN
unset ELASTIC_APM_GLOBAL_LABELS
export TEST_ES_URL=http://elastic:changeme@localhost:9200
export TEST_ES_DISABLE_STARTUP=true
@ -30,19 +45,19 @@ for i in "${journeys[@]}"; do
checks-reporter-with-killswitch "Run Performance Tests with Playwright Config (Journey:${i},Phase: WARMUP)" \
node scripts/functional_tests \
--config "x-pack/test/performance/journeys/${i}/config.ts" \
--kibana-install-dir "$KIBANA_BUILD_LOCATION" \
--debug \
--bail
--config "x-pack/test/performance/journeys/${i}/config.ts" \
--kibana-install-dir "$KIBANA_BUILD_LOCATION" \
--debug \
--bail
export TEST_PERFORMANCE_PHASE=TEST
checks-reporter-with-killswitch "Run Performance Tests with Playwright Config (Journey:${i},Phase: TEST)" \
node scripts/functional_tests \
--config "x-pack/test/performance/journeys/${i}/config.ts" \
--kibana-install-dir "$KIBANA_BUILD_LOCATION" \
--debug \
--bail
--config "x-pack/test/performance/journeys/${i}/config.ts" \
--kibana-install-dir "$KIBANA_BUILD_LOCATION" \
--debug \
--bail
done
kill "$esPid"

View file

@ -9,6 +9,7 @@
import Url from 'url';
import { inspect } from 'util';
import { setTimeout } from 'timers/promises';
import apm, { Span, Transaction } from 'elastic-apm-node';
import playwright, { ChromiumBrowser, Page, BrowserContext, CDPSession } from 'playwright';
import { FtrService, FtrProviderContext } from '../ftr_provider_context';
@ -35,14 +36,45 @@ export class PerformanceTestingService extends FtrService {
ctx.getService('lifecycle').beforeTests.add(() => {
apm.start({
serviceName: 'functional test runner',
environment: process.env.CI ? 'ci' : 'development',
active: this.config.get(`kbnTestServer.env`).ELASTIC_APM_ACTIVE !== 'false',
serverUrl: this.config.get(`kbnTestServer.env`).ELASTIC_APM_SERVER_URL,
secretToken: this.config.get(`kbnTestServer.env`).ELASTIC_APM_SECRET_TOKEN,
globalLabels: this.config.get(`kbnTestServer.env`).ELASTIC_APM_GLOBAL_LABELS,
transactionSampleRate:
this.config.get(`kbnTestServer.env`).ELASTIC_APM_TRANSACTION_SAMPLE_RATE,
logger: process.env.VERBOSE_APM_LOGGING
? {
warn(...args: any[]) {
console.log('APM WARN', ...args);
},
info(...args: any[]) {
console.log('APM INFO', ...args);
},
fatal(...args: any[]) {
console.log('APM FATAL', ...args);
},
error(...args: any[]) {
console.log('APM ERROR', ...args);
},
debug(...args: any[]) {
console.log('APM DEBUG', ...args);
},
trace(...args: any[]) {
console.log('APM TRACE', ...args);
},
}
: undefined,
});
});
ctx.getService('lifecycle').cleanup.add(async () => {
await this.shutdownBrowser();
await new Promise<void>((resolve) => apm.flush(() => resolve()));
// wait for the HTTP request that apm.flush() starts, which we
// can't track but hope is complete within 3 seconds
// https://github.com/elastic/apm-agent-nodejs/issues/2088
await setTimeout(3000);
});
}
@ -173,7 +205,6 @@ export class PerformanceTestingService extends FtrService {
private async tearDown(page: Page, client: CDPSession, context: BrowserContext) {
if (page) {
apm.flush();
await client.detach();
await page.close();
await context.close();