From 8118a503ee8137300a7179347820cb1f4ac7b78a Mon Sep 17 00:00:00 2001 From: Dzmitry Lemechko Date: Tue, 9 May 2023 05:35:43 +0200 Subject: [PATCH] [performance] enable journey run against cloud deployments (#156720) ## Summary This PR adds changes and instructions how to run existing performance journeys against ESS instances. As previously discussed with @pheyos , there are few manual steps to be done before running the actual journey: 1. Create cloud deployment and re-configure it the way APM traces are reported the monitoring cluster 2. Check out the branch matching deployment version (main -> 8.9.0-SNAPSHOT), create user with `superuser` role (we don't test functional features, only performance metrics) Then you can run the journey like a regular cloud test suite: ``` export TEST_KIBANA_URL=https://:@ export TEST_ES_URL=https://:@j: export TEST_CLOUD=1 node scripts/functional_test_runner.js --config x-pack/performance/journeys/$YOUR_JOURNEY_NAME.ts ``` image --------- Co-authored-by: Jon (cherry picked from commit e55a92eab0ae28799b51238fb76efa6026673e6e) --- .../running_performance_journey_in_cloud.mdx | 93 +++++++++++++++++++ packages/kbn-journeys/journey/journey.ts | 1 + .../journey/journey_ftr_harness.ts | 6 +- packages/kbn-journeys/services/auth.ts | 29 +++++- x-pack/performance/journeys/login.ts | 9 +- 5 files changed, 128 insertions(+), 10 deletions(-) create mode 100644 dev_docs/tutorials/performance/running_performance_journey_in_cloud.mdx diff --git a/dev_docs/tutorials/performance/running_performance_journey_in_cloud.mdx b/dev_docs/tutorials/performance/running_performance_journey_in_cloud.mdx new file mode 100644 index 0000000000000..3f8b373afad39 --- /dev/null +++ b/dev_docs/tutorials/performance/running_performance_journey_in_cloud.mdx @@ -0,0 +1,93 @@ +--- +id: kibDevTutorialRunningPerformanceJourneyInCloud +slug: /kibana-dev-docs/tutorial/performance/running_performance_journey_in_cloud +title: Running Performance Journey In Cloud +summary: Learn how to run performance journey against Cloud cluster +date: 2023-05-04 +tags: ['kibana', 'onboarding', 'setup', 'performance', 'development', 'telemetry'] +--- + +## Overview +As a way to better understand user experience with Kibana in cloud, we support running performance journeys against +Cloud deployments. +The process takes a few steps: +- Create a cloud deployment +- Re-configure deployment with APM enabled and reporting metrics to the monitoring cluster +- Create a user with `superuser` role to run tests with +- Checkout the branch that matches your cloud deployment version +- Run the performance journey + +### Re-configure deployment for Kibana and Elasticsearch +We use [kibana-ops-e2e-perf](https://kibana-ops-e2e-perf.kb.us-central1.gcp.cloud.es.io/) cluster to monitor performance testing. + +If you would like to report APM metrics to this cluster, copy `SECRET_TOKEN` and `SERVER_URL` values from [packages/kbn-journeys/journey/journey_apm_config.ts](https://github.com/elastic/kibana/blob/60c82765779419d356a131e212682b69b035804b/packages/kbn-journeys/journey/journey_apm_config.ts#L10-L11) + +#### Change Elasticsearch configuration +In the ESS Admin Console, find your deployment and navigate to `Security` page. Click `Add Settings` under `Elasticsearch keystore` and add new entry: + +``` +Setting name: tracing.apm.secret_token +Secret: +``` + +Navigate to `Advanced Edit` page and change `Deployment Configuration` by adding the following JSON object to `resources.elasticsearch.plan.elasticsearch`: + +``` +"user_settings_override_json": { + "tracing.apm.enabled": "true", + "tracing.apm.environment": "development", + "tracing.apm.agent.service_name": "elasticsearch", + "tracing.apm.agent.server_url": "", + "tracing.apm.agent.metrics_interval": "120s", + "tracing.apm.agent.transaction_sample_rate": "1" +} +``` + +Save changes and make sure cluster is restarted successfully. + +#### Change Kibana configuration +Navigate to `Advanced Edit` page and change `Deployment Configuration` by adding the following JSON object to `resources.kibana.plan.kibana`: + +``` +"user_settings_override_json": { + "elastic.apm.active": true, + "elastic.apm.breakdownMetrics": false, + "elastic.apm.captureBody": "all", + "elastic.apm.captureRequestHeaders": "true", + "elastic.apm.captureSpanStackTraces": false, + "elastic.apm.centralConfig": false, + "elastic.apm.contextPropagationOnly": "false", + "elastic.apm.environment": "development", + "elastic.apm.globalLabels.deploymentId": "", + "elastic.apm.globalLabels.journeyName": "", + "elastic.apm.longFieldMaxLength": "300000", + "elastic.apm.metricsInterval": "120s", + "elastic.apm.propagateTracestate": true, + "elastic.apm.sanitizeFieldNames": "password,passwd,pwd,secret,*key,*token*,*session*,*credit*,*card*,*auth*,set-cookie,pw,pass,connect.sid", + "elastic.apm.secretToken": "", + "elastic.apm.serverUrl": "", + "elastic.apm.transactionSampleRate": 1 +} +``` + +Note: DEPLOYMENT_ID and YOUR_JOURNEY_NAME values are optional labels to find the APM traces for your run. + +Save changes and make sure cluster is restarted successfully. + +### Run the journey +Make sure you have created user with `superuser` role and the Kibana repo branch is matching your deployment version. +Set env variables to run FTR against your cloud deployment: + +``` +export TEST_KIBANA_URL=https://:@ +export TEST_ES_URL=https://:@: +export TEST_CLOUD=1 +``` + +Run your journey with the command: + +``` +node scripts/functional_test_runner.js --config x-pack/performance/journeys/$YOUR_JOURNEY_NAME.ts` +``` + + diff --git a/packages/kbn-journeys/journey/journey.ts b/packages/kbn-journeys/journey/journey.ts index 7bc14e6bebe14..e6778dc0fc088 100644 --- a/packages/kbn-journeys/journey/journey.ts +++ b/packages/kbn-journeys/journey/journey.ts @@ -35,6 +35,7 @@ export interface BaseStepCtx { kibanaServer: KibanaServer; es: Es; retry: RetryService; + auth: Auth; } export type AnyStep = Step<{}>; diff --git a/packages/kbn-journeys/journey/journey_ftr_harness.ts b/packages/kbn-journeys/journey/journey_ftr_harness.ts index 12590f05c44d6..bf5af70f3d698 100644 --- a/packages/kbn-journeys/journey/journey_ftr_harness.ts +++ b/packages/kbn-journeys/journey/journey_ftr_harness.ts @@ -99,10 +99,11 @@ export class JourneyFtrHarness { private async setupBrowserAndPage() { const browser = await this.getBrowserInstance(); - this.context = await browser.newContext({ bypassCSP: true }); + const browserContextArgs = this.auth.isCloud() ? {} : { bypassCSP: true }; + this.context = await browser.newContext(browserContextArgs); if (this.journeyConfig.shouldAutoLogin()) { - const cookie = await this.auth.login({ username: 'elastic', password: 'changeme' }); + const cookie = await this.auth.login(); await this.context.addCookies([cookie]); } @@ -373,6 +374,7 @@ export class JourneyFtrHarness { kibanaServer: this.kibanaServer, es: this.es, retry: this.retry, + auth: this.auth, }); return this.#_ctx; diff --git a/packages/kbn-journeys/services/auth.ts b/packages/kbn-journeys/services/auth.ts index b8c68a9fbb09c..e0f89d184e462 100644 --- a/packages/kbn-journeys/services/auth.ts +++ b/packages/kbn-journeys/services/auth.ts @@ -29,7 +29,7 @@ export class Auth { private readonly kibanaServer: KibanaServer ) {} - public async login({ username, password }: Credentials) { + public async login(credentials?: Credentials) { const baseUrl = new URL( Url.format({ protocol: this.config.get('servers.kibana.protocol'), @@ -37,9 +37,10 @@ export class Auth { port: this.config.get('servers.kibana.port'), }) ); - const loginUrl = new URL('/internal/security/login', baseUrl); - const provider = baseUrl.hostname === 'localhost' ? 'basic' : 'cloud-basic'; + const provider = this.isCloud() ? 'cloud-basic' : 'basic'; + + const version = await this.kibanaServer.version.get(); this.log.info('fetching auth cookie from', loginUrl.href); const authResponse = await axios.request({ @@ -49,11 +50,11 @@ export class Auth { providerType: 'basic', providerName: provider, currentURL: new URL('/login?next=%2F', baseUrl).href, - params: { username, password }, + params: credentials ?? { username: this.getUsername(), password: this.getPassword() }, }, headers: { 'content-type': 'application/json', - 'kbn-version': await this.kibanaServer.version.get(), + 'kbn-version': version, 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'same-origin', }, @@ -61,6 +62,12 @@ export class Auth { maxRedirects: 0, }); + if (authResponse.status !== 200) { + throw new Error( + `Kibana auth failed: code: ${authResponse.status}, message: ${authResponse.statusText}` + ); + } + const cookie = extractCookieValue(authResponse); if (cookie) { this.log.info('captured auth cookie'); @@ -82,4 +89,16 @@ export class Auth { url: baseUrl.href, }; } + + public getUsername() { + return this.config.get('servers.kibana.username'); + } + + public getPassword() { + return this.config.get('servers.kibana.password'); + } + + public isCloud() { + return this.config.get('servers.kibana.hostname') !== 'localhost'; + } } diff --git a/x-pack/performance/journeys/login.ts b/x-pack/performance/journeys/login.ts index 1990bd1babe0f..62e30a3968a33 100644 --- a/x-pack/performance/journeys/login.ts +++ b/x-pack/performance/journeys/login.ts @@ -34,11 +34,14 @@ export const journey = new Journey({ ], maxDuration: '10m', }, -}).step('Login', async ({ page, kbnUrl, inputDelays }) => { +}).step('Login', async ({ page, kbnUrl, inputDelays, auth }) => { await page.goto(kbnUrl.get()); + if (auth.isCloud()) { + await page.click(subj('loginCard-basic/cloud-basic'), { delay: inputDelays.MOUSE_CLICK }); + } - await page.type(subj('loginUsername'), 'elastic', { delay: inputDelays.TYPING }); - await page.type(subj('loginPassword'), 'changeme', { delay: inputDelays.TYPING }); + await page.type(subj('loginUsername'), auth.getUsername(), { delay: inputDelays.TYPING }); + await page.type(subj('loginPassword'), auth.getPassword(), { delay: inputDelays.TYPING }); await page.click(subj('loginSubmit'), { delay: inputDelays.MOUSE_CLICK }); await waitForChrome(page);