-
Notifications
You must be signed in to change notification settings - Fork 8
/
pokeapi-simplified.js
63 lines (56 loc) · 1.77 KB
/
pokeapi-simplified.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import http from 'k6/http';
import { sleep, check } from 'k6';
import papaparse from 'https://jslib.k6.io/papaparse/5.1.1/index.js';
import { SharedArray } from "k6/data";
import { Pods } from 'k6/x/chaos/k8s';
export const options = {
scenarios: {
pokeapi: {
executor: 'ramping-vus',
exec: 'getPokemon',
startVUs: 0,
stages: [
{ duration: '1m', target: 30 },
{ duration: '5m', target: 30 },
],
},
chaos: {
executor: 'per-vu-iterations',
exec: 'killAppPod',
vus: 1,
iterations: 1,
startTime: '3m',
},
},
thresholds: {
http_req_failed: ['rate<=0.05'],
load_generator_cpu_percent: ["value<=80"],
load_generator_memory_used_percent: ["value<=80"],
http_req_duration: ["p(95)<=5000"],
},
};
const domain = 'http://cluster.nicolevanderhoeven.com/api/v2';
const sharedData = new SharedArray("Shared Logins", function() {
let data = papaparse.parse(open('pokemon.csv'), { header: true }).data;
return data;
});
export function getPokemon() {
let randomMon = sharedData[Math.floor(Math.random() * sharedData.length)];
let res = http.get(domain + '/pokemon/' + randomMon.name, {tags: { name: '01_GetPokemon' }});
check(res, {
'is status 200': (r) => r.status === 200,
'01-text verification': (r) => r.body.includes(randomMon.name)
});
sleep(Math.random() * 5);
}
export function killAppPod() {
let victim;
const pod = new Pods();
for (let i = 0; i < pod.list().length; i++) {
victim = pod.list()[i];
if (victim.startsWith('app')) {
break;
}
}
pod.killByName('default', victim);
}