Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[perf-testing] send detailed APM data from report generation #107592

Merged
merged 5 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/kbn-apm-config-loader/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@ export class ApmConfiguration {
config.transactionSampleRate = parseFloat(process.env.ELASTIC_APM_TRANSACTION_SAMPLE_RATE);
}

if (process.env.ELASTIC_APM_SERVER_URL) {
config.serverUrl = process.env.ELASTIC_APM_SERVER_URL;
}

if (process.env.ELASTIC_APM_GLOBAL_LABELS) {
config.globalLabels = Object.fromEntries(
process.env.ELASTIC_APM_GLOBAL_LABELS.split(',').map((p) => {
const [key, ...val] = p.split('=');
return [key, val.join('=')];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we need this join? in what cases val might be an array with length > 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the value includes an =

})
);
}

return config;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ export const schema = Joi.object()
.default(/Kibana is now available/),
})
.default(),
env: Joi.object().unknown().default(),
delayShutdown: Joi.number(),
})
.default(),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ function extendNodeOptions(installDir) {
export async function runKibanaServer({ procs, config, options }) {
const { installDir } = options;
const runOptions = config.get('kbnTestServer.runOptions');
const env = config.get('kbnTestServer.env');

await procs.run('kibana', {
cmd: getKibanaCmd(installDir),
args: filterCliArgs(collectCliArgs(config, options)),
env: {
FORCE_COLOR: 1,
...process.env,
...env,
...extendNodeOptions(installDir),
},
cwd: installDir || KIBANA_ROOT,
Expand Down
6 changes: 6 additions & 0 deletions packages/kbn-test/src/functional_tests/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ export async function runTests(options) {
await runFtr({ configPath, options: opts });
} finally {
try {
const delay = config.get('kbnTestServer.delayShutdown');
if (typeof delay === 'number') {
log.info('Delaying shutdown of Kibana for', delay, 'ms');
await new Promise((r) => setTimeout(r, delay));
}

await procs.stop('kibana');
} finally {
if (es) {
Expand Down
2 changes: 2 additions & 0 deletions vars/workers.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ def base(Map params, Closure closure) {
withEnv([
"CI=true",
"HOME=${env.JENKINS_HOME}",
"PR_NUMBER=${env.ghprbPullId ?: ''}",
"PR_SOURCE_BRANCH=${env.ghprbSourceBranch ?: ''}",
"PR_TARGET_BRANCH=${env.ghprbTargetBranch ?: ''}",
"PR_MERGE_BASE=${checkoutInfo.mergeBase ?: ''}",
"PR_AUTHOR=${env.ghprbPullAuthorLogin ?: ''}",
"TEST_BROWSER_HEADLESS=1",
"GIT_COMMIT=${checkoutInfo.commit}",
Expand Down
1 change: 1 addition & 0 deletions x-pack/scripts/functional_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const onlyNotInCoverageTests = [
require.resolve('../test/saved_object_tagging/api_integration/security_and_spaces/config.ts'),
require.resolve('../test/saved_object_tagging/api_integration/tagging_api/config.ts'),
require.resolve('../test/examples/config.ts'),
require.resolve('../test/performance/config.ts'),
];

require('../../src/setup_node_env');
Expand Down
56 changes: 56 additions & 0 deletions x-pack/test/performance/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { FtrConfigProviderContext } from '@kbn/test';

import { services } from './services';
import { pageObjects } from './page_objects';

// These "secret" values are intentionally written in the source. We would make the APM server accept annonymous traffic if we could
const APM_SERVER_URL = 'https://2fad4006bf784bb8a54e52f4a5862609.apm.us-west1.gcp.cloud.es.io:443';
const APM_PUBLIC_TOKEN = 'Q5q5rWQEw6tKeirBpw';

export default async function ({ readConfigFile }: FtrConfigProviderContext) {
const functionalConfig = await readConfigFile(require.resolve('../functional/config'));

return {
testFiles: [require.resolve('./tests/index.ts')],
services,
pageObjects,
servers: functionalConfig.get('servers'),
esTestCluster: functionalConfig.get('esTestCluster'),
apps: functionalConfig.get('apps'),
screenshots: functionalConfig.get('screenshots'),
junit: {
reportName: 'Performance Tests',
},
kbnTestServer: {
...functionalConfig.get('kbnTestServer'),
env: {
ELASTIC_APM_ACTIVE: 'true',
ELASTIC_APM_ENVIRONMENT: process.env.CI ? 'ci' : 'development',
ELASTIC_APM_TRANSACTION_SAMPLE_RATE: '1.0',
ELASTIC_APM_SERVER_URL: APM_SERVER_URL,
ELASTIC_APM_SECRET_TOKEN: APM_PUBLIC_TOKEN,
ELASTIC_APM_GLOBAL_LABELS: Object.entries({
ftrConfig: `x-pack/test/performance`,
jenkinsJobName: process.env.JOB_NAME,
jenkinsBuildNumber: process.env.BUILD_NUMBER,
prId: process.env.PR_NUMBER,
branch: process.env.GIT_BRANCH,
commit: process.env.GIT_COMMIT,
mergeBase: process.env.PR_MERGE_BASE,
targetBranch: process.env.PR_TARGET_BRANCH,
})
.filter(([, v]) => !!v)
.reduce((acc, [k, v]) => (acc ? `${acc},${k}=${v}` : `${k}=${v}`), ''),
},
// delay shutdown by 15 seconds to ensure that APM can report the data it collects during test execution
delayShutdown: 15_000,
},
};
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"type": "index",
"value": {
"aliases": {
},
"index": "foo",
"mappings": {
"properties": {
"@timestamp": {
"type": "date"
},
"group": {
"ignore_above": 256,
"type": "keyword"
},
"randomInt": {
"type": "integer"
},
"geo": {
"properties": {
"country_code": {
"type": "keyword"
},
"country_name": {
"type": "keyword"
},
"point": {
"type": "geo_point"
}
}
}
}
},
"settings": {
"index": {
"number_of_replicas": "1",
"number_of_shards": "1"
}
}
}
}
14 changes: 14 additions & 0 deletions x-pack/test/performance/ftr_provider_context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { GenericFtrProviderContext, GenericFtrService } from '@kbn/test';

import { pageObjects } from './page_objects';
import { services } from './services';

export type FtrProviderContext = GenericFtrProviderContext<typeof services, typeof pageObjects>;
export class FtrService extends GenericFtrService<FtrProviderContext> {}
193 changes: 193 additions & 0 deletions x-pack/test/performance/kbn_archives/reporting_dashboard.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions x-pack/test/performance/page_objects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export * from '../functional/page_objects';
8 changes: 8 additions & 0 deletions x-pack/test/performance/services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export * from '../functional/services';
16 changes: 16 additions & 0 deletions x-pack/test/performance/tests/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { FtrProviderContext } from '../ftr_provider_context';

export default function ({ loadTestFile }: FtrProviderContext) {
describe('performance', function () {
this.tags('ciGroup8');

loadTestFile(require.resolve('./reporting_dashboard'));
});
}
53 changes: 53 additions & 0 deletions x-pack/test/performance/tests/reporting_dashboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { FtrProviderContext } from '../ftr_provider_context';

export default function ({ getService, getPageObject }: FtrProviderContext) {
const retry = getService('retry');
const es = getService('es');
const esArchiver = getService('esArchiver');
const kibanaServer = getService('kibanaServer');
const common = getPageObject('common');
const dashboard = getPageObject('dashboard');
const reporting = getPageObject('reporting');

describe('reporting dashbaord', () => {
before(async () => {
await kibanaServer.importExport.load(
'x-pack/test/performance/kbn_archives/reporting_dashboard'
);
await esArchiver.loadIfNeeded('x-pack/test/performance/es_archives/reporting_dashboard');
});

after(async () => {
await kibanaServer.importExport.unload(
'x-pack/test/performance/kbn_archives/reporting_dashboard'
);
await esArchiver.unload('x-pack/test/performance/es_archives/reporting_dashboard');
await es.deleteByQuery({
index: '.reporting-*',
refresh: true,
body: { query: { match_all: {} } },
});
});

it('downloaded PDF has OK status', async function () {
this.timeout(180000);

await common.navigateToApp('dashboards');
await retry.waitFor('dashboard landing page', async () => {
return await dashboard.onDashboardLandingPage();
});
await dashboard.loadSavedDashboard('dashboard');
await reporting.openPdfReportingPanel();
await reporting.clickGenerateReportButton();

await reporting.getReportURL(60000);
});
});
}