Commit bc3a7181 by Marcus Efraimsson Committed by GitHub

devenv: adds auth proxy load test (#17271)

parent 2a52dbfb
......@@ -6,6 +6,9 @@ Runs load tests and checks using [k6](https://k6.io/).
Docker
To run the auth proxy test you'll need to setup nginx proxy from docker block and
enable auth proxy together with configuring Grafana for auth proxy.
## Run
Run load test for 15 minutes using 2 virtual users and targeting http://localhost:3000.
......@@ -32,6 +35,13 @@ Run load test for 10 virtual users:
$ ./run.sh -v 10
```
Run auth proxy test:
```bash
$ ./run.sh -c auth_proxy_test
```
Example output:
```bash
......
import { sleep, check, group } from 'k6';
import { createBasicAuthClient } from './modules/client.js';
export let options = {
noCookiesReset: true
};
let endpoint = __ENV.URL || 'http://localhost:10080/grafana';
const client = createBasicAuthClient(endpoint, 'user1', 'grafana');
client.withOrgId(1);
export const setup = () => {
const adminClient = createBasicAuthClient(endpoint, 'admin', 'admin');
let res = adminClient.datasources.getByName('gdev-prometheus');
if (res.status !== 200) {
throw new Error('Expected 200 response status when creating datasource');
}
return {
datasourceId: res.json().id,
};
}
export default (data) => {
group("auth proxy test", () => {
group("batch proxy requests", () => {
const d = new Date();
const batchCount = 300;
const requests = [];
const query = encodeURI('topk(5, max(scrape_duration_seconds) by (job))');
const start = (d.getTime() / 1000) - 3600;
const end = (d.getTime() / 1000);
const step = 20;
requests.push({ method: 'GET', url: '/api/annotations?dashboardId=8&from=1558670300607&to=1558691900607' });
for (let n = 0; n < batchCount; n++) {
requests.push({
method: 'GET',
url: `/api/datasources/proxy/${data.datasourceId}/api/v1/query_range?query=${query}&start=${start}&end=${end}&step=${step}`,
});
}
let responses = client.batch(requests);
for (let n = 0; n < batchCount; n++) {
check(responses[n], {
'response status is 200': (r) => r.status === 200,
});
}
});
});
sleep(5)
}
export const teardown = (data) => {}
......@@ -6,8 +6,9 @@ run() {
duration='15m'
url='http://localhost:3000'
vus='2'
testcase='auth_token_test'
while getopts ":d:u:v:" o; do
while getopts ":d:u:v:c:" o; do
case "${o}" in
d)
duration=${OPTARG}
......@@ -18,11 +19,14 @@ run() {
v)
vus=${OPTARG}
;;
c)
testcase=${OPTARG}
;;
esac
done
shift $((OPTIND-1))
docker run -t --network=host -v $PWD:/src -e URL=$url --rm -i loadimpact/k6:master run --vus $vus --duration $duration src/auth_token_test.js
docker run -t --network=host -v $PWD:/src -e URL=$url --rm -i loadimpact/k6:master run --vus $vus --duration $duration src/$testcase.js
}
run "$@"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment