Skip to content

Commit

Permalink
[load testing] add env vars to pass simulations and repo rootPath (el…
Browse files Browse the repository at this point in the history
…astic#89544) (elastic#92049)

* [load testing] add env vars to pass simulations and repo rootPath

* pass simulation to sript as argument

* export GATLING_SIMULATIONS

* fix export

* add validation
  • Loading branch information
dmlemeshko authored Feb 20, 2021
1 parent 9e13ac7 commit b164ae4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 9 deletions.
13 changes: 11 additions & 2 deletions test/scripts/jenkins_build_load_testing.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#!/usr/bin/env bash

while getopts s: flag
do
case "${flag}" in
s) simulations=${OPTARG};;
esac
done
echo "Simulation classes: $simulations";

cd "$KIBANA_DIR"
source src/dev/ci_setup/setup_env.sh

Expand All @@ -25,6 +33,7 @@ echo " -> test setup"
source test/scripts/jenkins_test_setup_xpack.sh

echo " -> run gatling load testing"
export GATLING_SIMULATIONS="$simulations"
node scripts/functional_tests \
--kibana-install-dir "$KIBANA_INSTALL_DIR" \
--config test/load/config.ts
--kibana-install-dir "$KIBANA_INSTALL_DIR" \
--config test/load/config.ts
63 changes: 56 additions & 7 deletions x-pack/test/load/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,78 @@
import { withProcRunner } from '@kbn/dev-utils';
import { resolve } from 'path';
import { REPO_ROOT } from '@kbn/utils';
import Fs from 'fs';
import { createFlagError } from '@kbn/dev-utils';
import { FtrProviderContext } from './../functional/ftr_provider_context';

const baseSimulationPath = 'src/test/scala/org/kibanaLoadTest/simulation';
const simulationPackage = 'org.kibanaLoadTest.simulation';
const simulationFIleExtension = '.scala';
const gatlingProjectRootPath: string =
process.env.GATLING_PROJECT_PATH || resolve(REPO_ROOT, '../kibana-load-testing');
const simulationEntry: string = process.env.GATLING_SIMULATIONS || 'DemoJourney';

if (!Fs.existsSync(gatlingProjectRootPath)) {
throw createFlagError(
`Incorrect path to load testing project: '${gatlingProjectRootPath}'\n
Clone 'elastic/kibana-load-testing' and set path using 'GATLING_PROJECT_PATH' env var`
);
}

const dropEmptyLines = (s: string) => s.split(',').filter((i) => i.length > 0);
const simulationClasses = dropEmptyLines(simulationEntry);
const simulationsRootPath = resolve(gatlingProjectRootPath, baseSimulationPath);

simulationClasses.map((className) => {
const simulationClassPath = resolve(
simulationsRootPath,
className.replace('.', '/') + simulationFIleExtension
);
if (!Fs.existsSync(simulationClassPath)) {
throw createFlagError(`Simulation class is not found: '${simulationClassPath}'`);
}
});

/**
*
* GatlingTestRunner is used to run load simulation against local Kibana instance
*
* Use GATLING_SIMULATIONS to pass comma-separated class names
* Use GATLING_PROJECT_PATH to override path to 'kibana-load-testing' project
*/
export async function GatlingTestRunner({ getService }: FtrProviderContext) {
const log = getService('log');
const gatlingProjectRootPath = resolve(REPO_ROOT, '../kibana-load-testing');

await withProcRunner(log, async (procs) => {
await procs.run('gatling', {
await procs.run('mvn: clean compile', {
cmd: 'mvn',
args: [
'clean',
'-q',
'-Dmaven.wagon.http.retryHandler.count=3',
'-Dmaven.test.failure.ignore=true',
'compile',
'gatling:test',
'-q',
'-Dgatling.simulationClass=org.kibanaLoadTest.simulation.DemoJourney',
'clean',
'compile',
],
cwd: gatlingProjectRootPath,
env: {
...process.env,
},
wait: true,
});
for (const simulationClass of simulationClasses) {
await procs.run('gatling: test', {
cmd: 'mvn',
args: [
'gatling:test',
'-q',
`-Dgatling.simulationClass=${simulationPackage}.${simulationClass}`,
],
cwd: gatlingProjectRootPath,
env: {
...process.env,
},
wait: true,
});
}
});
}

0 comments on commit b164ae4

Please sign in to comment.