Skip to content

Commit c9a8cef

Browse files
committed
feat: k6 runner testing
1 parent d139466 commit c9a8cef

File tree

2 files changed

+123
-90
lines changed

2 files changed

+123
-90
lines changed

k6/k6-runner/openshift/k6/dc.yaml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,31 @@ objects:
1616
containers:
1717
- image: ${IMAGE_REPOSITORY}:${IMAGE_TAG}
1818
name: ${NAME}
19+
args:
20+
- 'run'
21+
- '-e'
22+
- 'CONFIG=/var/opt/config/config.json'
23+
- '/home/k6/scripts/constantRateAllFlows.js'
24+
env:
25+
- name: K6_INFLUXDB_URL
26+
value: https://k6-influxdb-c6af30-dev.apps.gold.devops.gov.bc.ca
27+
- name: K6_INFLUXDB_ORGANIZATION
28+
valueFrom:
29+
secretKeyRef:
30+
name: k6-influxdb-secret
31+
key: DOCKER_INFLUXDB_INIT_ORG
32+
- name: K6_INFLUXDB_BUCKET
33+
valueFrom:
34+
secretKeyRef:
35+
name: k6-influxdb-secret
36+
key: DOCKER_INFLUXDB_INIT_BUCKET
37+
- name: K6_INFLUXDB_TOKEN
38+
valueFrom:
39+
secretKeyRef:
40+
name: k6-influxdb-secret
41+
key: OPERATOR_API_TOKEN
42+
- name: HTTP_DEBUG
43+
value: ${HTTP_DEBUG}
1944
resources:
2045
limits:
2146
cpu: 2
@@ -36,9 +61,9 @@ parameters:
3661
- name: NAME
3762
value: sso-k6
3863
- name: IMAGE_TAG
39-
value: latest
64+
value: dev1
4065
- name: IMAGE_REPOSITORY
41-
value: ghcr.io/bcgov/sso-k6
66+
value: ghcr.io/bcgov/sso-k6-runner
4267
- name: HTTP_DEBUG
4368
description: enable http debug logging in the k6 pod
44-
value: "false"
69+
value: 'false'
Lines changed: 95 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import { sleep } from 'k6';
2-
import { createRealm, deleteRealm, createUser, generateRealms, getAccessToken, hitIntrospectionRoute, hitUserInfoRoute, createClient } from './helpers.js';
2+
import {
3+
createRealm,
4+
deleteRealm,
5+
createUser,
6+
generateRealms,
7+
getAccessToken,
8+
hitIntrospectionRoute,
9+
hitUserInfoRoute,
10+
createClient,
11+
} from './helpers.js';
312
import { user, client } from './constants.js';
413

514
let config = JSON.parse(open(__ENV.CONFIG));
@@ -16,100 +25,99 @@ const OFFLINE = false;
1625
const BASELINE_RATE = 34;
1726

1827
export const options = {
19-
scenarios: {
20-
peakProfile: {
21-
executor: 'constant-arrival-rate',
22-
duration: '2h',
23-
timeUnit: '1m',
24-
rate: 34,
25-
preAllocatedVUs: 5,
26-
},
27-
// stress: {
28-
// executor: 'ramping-arrival-rate', //Assure load increase if the system slows
29-
// startRate: 0,
30-
// timeUnit: '1m',
31-
// preAllocatedVUs: 10000,
32-
// stages: [
33-
// // Ramp in 100 req/sec intervals, and hold 5 mins.
34-
// // Each loop runs 3 req/sec, so (target * 3) / 60 = req/sec.
35-
// { duration: '5m', target: 2000 },
36-
// { duration: '5m', target: 2000 },
37-
// { duration: '5m', target: 4000 },
38-
// { duration: '5m', target: 4000 },
39-
// { duration: '5m', target: 6000 },
40-
// { duration: '5m', target: 6000 },
41-
// { duration: '5m', target: 8000 },
42-
// { duration: '5m', target: 8000 },
43-
// { duration: '5m', target: 10000 },
44-
// { duration: '5m', target: 10000 },
45-
// ],
46-
// }
47-
48-
49-
// stress: {
50-
// executor: 'ramping-arrival-rate', //Assure load increase if the system slows
51-
// startRate: BASELINE_RATE,
52-
// timeUnit: '1m',
53-
// preAllocatedVUs: 20000,
54-
// stages: [
55-
// { duration: '1m', target: BASELINE_RATE }, // just slowly ramp-up to a HUGE load
56-
// // just slowly ramp-up to an EPIC load.
57-
// { duration: '1h', target: 20000 },
58-
// ],
59-
// }
60-
},
61-
thresholds: {
62-
http_req_failed: [
63-
{
64-
threshold: `rate<${MAX_ALLOWED_FAILURE_RATE}`,
65-
// Leave this in! Don't keep hammering the poor server after its failing, requests will queue
66-
abortOnFail: true,
67-
},
68-
],
69-
// Requests tend to drop after 60 second timeout. Can use below to fail earlier
70-
// http_req_duration: [
71-
// {
72-
// threshold: `p(95)<15000`,
73-
// abortOnFail: true,
74-
// },
75-
// ]
28+
scenarios: {
29+
peakProfile: {
30+
executor: 'constant-arrival-rate',
31+
duration: '2m',
32+
timeUnit: '1m',
33+
rate: 34,
34+
preAllocatedVUs: 5,
7635
},
36+
// stress: {
37+
// executor: 'ramping-arrival-rate', //Assure load increase if the system slows
38+
// startRate: 0,
39+
// timeUnit: '1m',
40+
// preAllocatedVUs: 10000,
41+
// stages: [
42+
// // Ramp in 100 req/sec intervals, and hold 5 mins.
43+
// // Each loop runs 3 req/sec, so (target * 3) / 60 = req/sec.
44+
// { duration: '5m', target: 2000 },
45+
// { duration: '5m', target: 2000 },
46+
// { duration: '5m', target: 4000 },
47+
// { duration: '5m', target: 4000 },
48+
// { duration: '5m', target: 6000 },
49+
// { duration: '5m', target: 6000 },
50+
// { duration: '5m', target: 8000 },
51+
// { duration: '5m', target: 8000 },
52+
// { duration: '5m', target: 10000 },
53+
// { duration: '5m', target: 10000 },
54+
// ],
55+
// }
56+
57+
// stress: {
58+
// executor: 'ramping-arrival-rate', //Assure load increase if the system slows
59+
// startRate: BASELINE_RATE,
60+
// timeUnit: '1m',
61+
// preAllocatedVUs: 20000,
62+
// stages: [
63+
// { duration: '1m', target: BASELINE_RATE }, // just slowly ramp-up to a HUGE load
64+
// // just slowly ramp-up to an EPIC load.
65+
// { duration: '1h', target: 20000 },
66+
// ],
67+
// }
68+
},
69+
thresholds: {
70+
http_req_failed: [
71+
{
72+
threshold: `rate<${MAX_ALLOWED_FAILURE_RATE}`,
73+
// Leave this in! Don't keep hammering the poor server after its failing, requests will queue
74+
abortOnFail: true,
75+
},
76+
],
77+
// Requests tend to drop after 60 second timeout. Can use below to fail earlier
78+
// http_req_duration: [
79+
// {
80+
// threshold: `p(95)<15000`,
81+
// abortOnFail: true,
82+
// },
83+
// ]
84+
},
7785
};
7886

7987
export function setup() {
80-
const accessToken = getAccessToken({ username, password, clientId, confidential: true });
81-
const emptyRealms = generateRealms(TOTAL_REALMS);
82-
emptyRealms.forEach((realm, i) => {
83-
createRealm(realm, accessToken);
84-
const newUser = Object.assign({}, user, { username: `${user.username}_${i}` })
85-
createUser(newUser, realm.realm, accessToken);
86-
// Create a confidential client to be able to use the introspection endpoint with this realm
87-
createClient(realm.realm, accessToken)
88-
});
89-
return emptyRealms;
88+
const accessToken = getAccessToken({ username, password, clientId, confidential: true });
89+
const emptyRealms = generateRealms(TOTAL_REALMS);
90+
emptyRealms.forEach((realm, i) => {
91+
createRealm(realm, accessToken);
92+
const newUser = Object.assign({}, user, { username: `${user.username}_${i}` });
93+
createUser(newUser, realm.realm, accessToken);
94+
// Create a confidential client to be able to use the introspection endpoint with this realm
95+
createClient(realm.realm, accessToken);
96+
});
97+
return emptyRealms;
9098
}
9199

92100
export default function (realms) {
93-
realms.forEach((realm, i) => {
94-
const accessToken = getAccessToken({
95-
username: `${user.username}_${i}`,
96-
password: user.credentials[0].value,
97-
clientId,
98-
confidential: true,
99-
realm: realm.realm,
100-
offline: OFFLINE
101-
});
102-
hitUserInfoRoute(accessToken, realm.realm)
103-
hitIntrospectionRoute(accessToken, realm.realm, client.clientId, client.secret)
104-
})
101+
realms.forEach((realm, i) => {
102+
const accessToken = getAccessToken({
103+
username: `${user.username}_${i}`,
104+
password: user.credentials[0].value,
105+
clientId,
106+
confidential: true,
107+
realm: realm.realm,
108+
offline: OFFLINE,
109+
});
110+
hitUserInfoRoute(accessToken, realm.realm);
111+
hitIntrospectionRoute(accessToken, realm.realm, client.clientId, client.secret);
112+
});
105113
}
106114

107115
export function teardown(realms) {
108-
// When stress testing, the enqueued requests can block teardown api requests from succeeding. Adding in a sleep to let the system recover a bit before trying to cleaunup.
109-
sleep(45)
110-
console.log('tearing down...')
111-
const accessToken = getAccessToken({ username, password, clientId, confidential: true });
112-
realms.forEach((realm, i) => {
113-
deleteRealm(realm.realm, accessToken);
114-
});
116+
// When stress testing, the enqueued requests can block teardown api requests from succeeding. Adding in a sleep to let the system recover a bit before trying to cleaunup.
117+
sleep(45);
118+
console.log('tearing down...');
119+
const accessToken = getAccessToken({ username, password, clientId, confidential: true });
120+
realms.forEach((realm, i) => {
121+
deleteRealm(realm.realm, accessToken);
122+
});
115123
}

0 commit comments

Comments
 (0)