devenv: Add docker load test which authenticates with API key (#28905)

* Add loadtest which authenticates with API key
- Edit load tests to assign the orgId in the default function, as the setup function is only called once for all VUs and therefore the change is not persisted to each VU.
- Remove side effect from orgId setup function and explicitly set orgId in setup client

* sort semicolons, whitespace
This commit is contained in:
Dafydd
2020-11-24 07:34:47 +00:00
committed by GitHub
parent 763e958d9d
commit d29f73b197
8 changed files with 156 additions and 22 deletions
+15 -8
View File
@@ -1,20 +1,26 @@
export const createTestOrgIfNotExists = client => {
let orgId = 0;
let res = client.orgs.getByName('k6');
if (res.status === 404) {
res = client.orgs.create('k6');
if (res.status !== 200) {
throw new Error('Expected 200 response status when creating org');
}
orgId = res.json().orgId;
} else {
orgId = res.json().id;
return res.json().orgId;
}
client.withOrgId(orgId);
return orgId;
// This can happen e.g. in Hosted Grafana instances, where even admins
// cannot see organisations
if (res.status !== 200) {
console.info(`unable to get orgs from instance, continuing with default orgId ${orgId}`);
return orgId;
}
return res.json().id;
};
export const createTestdataDatasourceIfNotExists = client => {
const payload = {
access: 'proxy',
@@ -26,9 +32,10 @@ export const createTestdataDatasourceIfNotExists = client => {
let res = client.datasources.getByName(payload.name);
if (res.status === 404) {
res = client.datasources.create(payload);
if (res.status !== 200) {
throw new Error('Expected 200 response status when creating datasource');
}
}
if (res.status !== 200) {
throw new Error(`expected 200 response status when creating datasource, got ${res.status}`);
}
return res.json().id;