mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
devenv: adds auth proxy load test (#17271)
This commit is contained in:
parent
2a52dbfb74
commit
bc3a718107
@ -6,6 +6,9 @@ Runs load tests and checks using [k6](https://k6.io/).
|
|||||||
|
|
||||||
Docker
|
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
|
||||||
|
|
||||||
Run load test for 15 minutes using 2 virtual users and targeting http://localhost:3000.
|
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.sh -v 10
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Run auth proxy test:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ ./run.sh -c auth_proxy_test
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
Example output:
|
Example output:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
56
devenv/docker/loadtest/auth_proxy_test.js
Normal file
56
devenv/docker/loadtest/auth_proxy_test.js
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
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'
|
duration='15m'
|
||||||
url='http://localhost:3000'
|
url='http://localhost:3000'
|
||||||
vus='2'
|
vus='2'
|
||||||
|
testcase='auth_token_test'
|
||||||
|
|
||||||
while getopts ":d:u:v:" o; do
|
while getopts ":d:u:v:c:" o; do
|
||||||
case "${o}" in
|
case "${o}" in
|
||||||
d)
|
d)
|
||||||
duration=${OPTARG}
|
duration=${OPTARG}
|
||||||
@ -18,11 +19,14 @@ run() {
|
|||||||
v)
|
v)
|
||||||
vus=${OPTARG}
|
vus=${OPTARG}
|
||||||
;;
|
;;
|
||||||
|
c)
|
||||||
|
testcase=${OPTARG}
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
shift $((OPTIND-1))
|
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 "$@"
|
run "$@"
|
||||||
|
Loading…
Reference in New Issue
Block a user