generated from ik-performance/performance-blueprint-project
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06ca8ee
commit 8b4175c
Showing
14 changed files
with
308 additions
and
25 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
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 @@ | ||
brew "k6" |
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
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
Empty file.
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,27 @@ | ||
{ | ||
"hosts": { | ||
"test.k6.io": "1.2.3.4" | ||
}, | ||
"stages": [ | ||
{ | ||
"duration": "1m", | ||
"target": 10 | ||
}, | ||
{ | ||
"duration": "1m", | ||
"target": 30 | ||
}, | ||
{ | ||
"duration": "1m", | ||
"target": 0 | ||
} | ||
], | ||
"thresholds": { | ||
"http_req_duration": [ | ||
"avg<100", | ||
"p(95)<200" | ||
] | ||
}, | ||
"noConnectionReuse": true, | ||
"userAgent": "MyK6UserAgentString/1.0" | ||
} |
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,8 @@ | ||
{ | ||
"vus": 100, | ||
"collectors": { | ||
"influxdb": { | ||
"tagsAsFields": ["vu","iter", "url", "name"] | ||
} | ||
} | ||
} |
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,24 @@ | ||
{ | ||
"stages": [ | ||
{ | ||
"duration": "10s", | ||
"target": 10 | ||
}, | ||
{ | ||
"duration": "20s", | ||
"target": 30 | ||
}, | ||
{ | ||
"duration": "10s", | ||
"target": 0 | ||
} | ||
], | ||
"thresholds": { | ||
"http_req_duration": [ | ||
"avg<100", | ||
"p(95)<200" | ||
] | ||
}, | ||
"noConnectionReuse": true, | ||
"userAgent": "MyK6UserAgentString/1.0" | ||
} |
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,16 @@ | ||
{ | ||
"users": [ | ||
{ | ||
"username": "admin", | ||
"password": "123" | ||
}, | ||
{ | ||
"username": "test", | ||
"password": "1234" | ||
}, | ||
{ | ||
"username": "invaliduser", | ||
"password": "password" | ||
} | ||
] | ||
} |
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,32 @@ | ||
import http from "k6/http"; | ||
import { check } from "k6"; | ||
|
||
/* | ||
* Stages (aka ramping) is how you, in code, specify the ramping of VUs. | ||
* That is, how many VUs should be active and generating traffic against | ||
* the target system at any specific point in time for the duration of | ||
* the test. | ||
* | ||
* The following stages configuration will result in up-flat-down ramping | ||
* profile over a 20s total test duration. | ||
*/ | ||
|
||
export let options = { | ||
stages: [ | ||
// Ramp-up from 1 to 5 VUs in 10s | ||
{ duration: "10s", target: 5 }, | ||
|
||
// Stay at rest on 5 VUs for 5s | ||
{ duration: "5s", target: 5 }, | ||
|
||
// Ramp-down from 5 to 0 VUs for 5s | ||
{ duration: "5s", target: 0 } | ||
], | ||
"noConnectionReuse": true, | ||
"userAgent": "K6UserAgentString/1.0" | ||
}; | ||
|
||
export default function () { | ||
let res = http.get("http://httpbin.org/"); | ||
check(res, { "status is 200": (r) => r.status === 200 }); | ||
} |
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,17 @@ | ||
import http from "k6/http"; | ||
import { check } from "k6"; | ||
|
||
export default function () { | ||
// Send a JSON encoded POST request | ||
let body = JSON.stringify({ key: "value" }); | ||
let res = http.post("http://httpbin.org/post", body, { headers: { "Content-Type": "application/json" } }); | ||
|
||
// Use JSON.parse to deserialize the JSON (instead of using the r.json() method) | ||
let j = JSON.parse(res.body); | ||
|
||
// Verify response | ||
check(res, { | ||
"status is 200": (r) => r.status === 200, | ||
"is key correct": (r) => j.json.key === "value", | ||
}); | ||
} |
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,122 @@ | ||
import http from "k6/http"; | ||
import { check, group, sleep } from "k6"; | ||
import { Counter, Rate, Trend } from "k6/metrics"; | ||
import { randomIntBetween } from "https://jslib.k6.io/k6-utils/1.0.0/index.js"; | ||
|
||
const loginData = JSON.parse(open("./opt/data/users.json")); | ||
|
||
/* Options | ||
Global options for your script | ||
stages - Ramping pattern | ||
thresholds - pass/fail criteria for the test | ||
ext - Options used by Load Impact cloud service test name and distribution | ||
*/ | ||
export let options = { | ||
stages: [ | ||
{ target: 200, duration: "20s" }, | ||
{ target: 200, duration: "1m" }, | ||
{ target: 0, duration: "10s" } | ||
], | ||
thresholds: { | ||
"http_req_duration": ["p(95)<500"], | ||
"http_req_duration{staticAsset:yes}": ["p(95)<100"], | ||
"check_failure_rate": ["rate<0.3"] | ||
}, | ||
ext: { | ||
loadimpact: { | ||
// projectID: 3113635, | ||
name: "Insights Demo with Cloud Execution", | ||
distribution: { | ||
scenarioLabel1: { loadZone: "amazon:us:ashburn", percent: 50 }, | ||
scenarioLabel2: { loadZone: "amazon:ie:dublin", percent: 50 } | ||
} | ||
} | ||
} | ||
}; | ||
|
||
// Custom metrics | ||
// We instantiate them before our main function | ||
let successfulLogins = new Counter("successful_logins"); | ||
let checkFailureRate = new Rate("check_failure_rate"); | ||
let timeToFirstByte = new Trend("time_to_first_byte", true); | ||
|
||
|
||
/* Main function | ||
The main function is what the virtual users will loop over during test execution. | ||
*/ | ||
export default function () { | ||
// We define our first group. Pages natually fit a concept of a group | ||
// You may have other similar actions you wish to "group" together | ||
group("Front page", function () { | ||
let res = null; | ||
// As mentioned above, this logic just forces the performance alert for too many urls, use env URL_ALERT to force it | ||
// It also highlights the ability to programmatically do things right in your script | ||
if (__ENV.URL_ALERT) { | ||
res = http.get("http://test.k6.io/?ts=" + Math.round(randomIntBetween(1, 2000))); | ||
} else { | ||
res = http.get("http://test.k6.io/?ts=" + Math.round(randomIntBetween(1, 2000)), { tags: { name: "http://test.k6.io/ Aggregated" } }); | ||
} | ||
let checkRes = check(res, { | ||
"Homepage body size is 11026 bytes": (r) => r.body.length === 11026, | ||
"Homepage welcome header present": (r) => r.body.indexOf("Welcome to the k6.io demo site!") !== -1 | ||
}); | ||
|
||
// Record check failures | ||
checkFailureRate.add(!checkRes); | ||
|
||
// Record time to first byte and tag it with the URL to be able to filter the results in Insights | ||
timeToFirstByte.add(res.timings.waiting, { ttfbURL: res.url }); | ||
|
||
// Load static assets | ||
group("Static assets", function () { | ||
let res = http.batch([ | ||
["GET", "http://test.k6.io/static/css/site.css", {}, { tags: { staticAsset: "yes" } }], | ||
["GET", "http://test.k6.io/static/js/prisms.js", {}, { tags: { staticAsset: "yes" } }] | ||
]); | ||
checkRes = check(res[0], { | ||
"Is stylesheet 4859 bytes?": (r) => r.body.length === 4859, | ||
}); | ||
|
||
// Record check failures | ||
checkFailureRate.add(!checkRes); | ||
|
||
// Record time to first byte and tag it with the URL to be able to filter the results in Insights | ||
timeToFirstByte.add(res[0].timings.waiting, { ttfbURL: res[0].url, staticAsset: "yes" }); | ||
timeToFirstByte.add(res[1].timings.waiting, { ttfbURL: res[1].url, staticAsset: "yes" }); | ||
}); | ||
|
||
}); | ||
|
||
sleep(10); | ||
|
||
group("Login", function () { | ||
let res = http.get("http://test.k6.io/my_messages.php"); | ||
let checkRes = check(res, { | ||
"Users should not be auth'd. Is unauthorized header present?": (r) => r.body.indexOf("Unauthorized") !== -1 | ||
}); | ||
|
||
// Record check failures | ||
checkFailureRate.add(!checkRes); | ||
|
||
let position = Math.floor(Math.random() * loginData.users.length); | ||
let credentials = loginData.users[position]; | ||
|
||
res = http.post("http://test.k6.io/login.php", { login: credentials.username, password: credentials.password, redir: '1' }); | ||
checkRes = check(res, { | ||
"is logged in welcome header present": (r) => r.body.indexOf("Welcome, admin!") !== -1 | ||
}); | ||
|
||
// Record successful logins | ||
if (checkRes) { | ||
successfulLogins.add(1); | ||
} | ||
|
||
// Record check failures | ||
checkFailureRate.add(!checkRes, { page: "login" }); | ||
|
||
// Record time to first byte and tag it with the URL to be able to filter the results in Insights | ||
timeToFirstByte.add(res.timings.waiting, { ttfbURL: res.url }); | ||
|
||
sleep(10); | ||
}); | ||
} |
Empty file.