-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add self-contained setup for load test (#275)
* Load test now provisions its own org, datasource, and dashboard * Load test run script now takes option for number of iterations Co-authored-by: Agnès Toulet <agnes.toulet@grafana.com>
- Loading branch information
1 parent
af78b2d
commit 4f3a10f
Showing
6 changed files
with
240 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
export const createTestOrgIfNotExists = (client) => { | ||
let orgId = 0; | ||
|
||
let res = client.orgs.getByName('k6-image-renderer'); | ||
if (res.status === 404) { | ||
res = client.orgs.create('k6-image-renderer'); | ||
if (res.status !== 200) { | ||
throw new Error('Expected 200 response status when creating org'); | ||
} | ||
return res.json().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 upsertTestdataDatasource = (client, name) => { | ||
const payload = { | ||
access: 'proxy', | ||
isDefault: false, | ||
name, | ||
type: 'testdata', | ||
}; | ||
|
||
let res = client.datasources.getByName(payload.name); | ||
let id; | ||
if (res.status === 404) { | ||
res = client.datasources.create(payload); | ||
|
||
if (res.status == 200) { | ||
id = res.json().id; | ||
} | ||
} else if (res.status == 200) { | ||
id = res.json().id; | ||
res = client.datasources.update(res.json().id, payload); | ||
} | ||
|
||
if (res.status !== 200) { | ||
throw new Error(`expected 200 response status when creating datasource, got ${res.status}`); | ||
} | ||
|
||
return id; | ||
}; | ||
|
||
export const upsertDashboard = (client, dashboard) => { | ||
const payload = { | ||
dashboard, | ||
overwrite: true, | ||
}; | ||
|
||
let res = client.dashboards.upsert(payload); | ||
|
||
if (res.status !== 200) { | ||
throw new Error(`expected 200 response status when creating dashboards, got ${res.status}`); | ||
} | ||
|
||
return res.json().id; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters