Skip to content

Commit 408b72a

Browse files
authored
Merge pull request #39 from IABTechLab/tjm-E2E-perf-testing
Update perf testing to pre-generate the requests
2 parents e349303 + 5eb83c8 commit 408b72a

File tree

4 files changed

+559
-0
lines changed

4 files changed

+559
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# UID2 Operator Performance Testing Tool
2+
The following instructions will work for any operator.
3+
4+
## Steps
5+
### Step 1 - Configure the K6 script
6+
The script as checked in has a basic config that will run a check against all endpoints.
7+
8+
9+
All the manual config can be changed at the top of the script.
10+
11+
To change/remove scenarios modify the options.scenarios. For information on configuring k6 scenarios see https://k6.io/docs/using-k6/scenarios/.
12+
13+
The variable `testDurationInSeconds` must be greater than the total duration of the test you are running.
14+
Any of the `*Tests` booleans can be set false if you are not running tests for that endpoint, this will save memory and start up time.
15+
### Step 2 - Execute K6 Script
16+
#### Option 2a - Execute K6 Script Locally (uid2-dev-workspace)
17+
If you would like to test locally, follow these steps:
18+
1. Pull the K6 Docker image: `docker pull grafana/k6`
19+
2. Execute the K6 script
20+
* PowerShell/Bash:
21+
```
22+
cat k6-uid2-operator.js `
23+
| docker run --network="host" --rm -i `
24+
-e CLIENT_KEY="<client_key>" `
25+
-e CLIENT_SECRET="<client_secret>" `
26+
-e BASE_URL="<operator_endpoint>" `
27+
grafana/k6 run -
28+
```
29+
30+
#### Option 2b - Execute K6 Script in K8s
31+
In order to reduce network latency, we should deploy k6 and its script with the same zone of UID2 operator.
32+
33+
Set environment variables `CLIENT_KEY`, `CLIENT_SECRET`, `BASE_URL` and then use k6 to execute the testing by following command.
34+
```
35+
k6 run k6-uid2-operator.js -e CLIENT_KEY=$CLIENT_KEY -e CLIENT_SECRET=$CLIENT_SECRET -e BASE_URL=$BASE_URL -e REFRESH_TOKEN=$REFRESH_TOKEN
36+
```
37+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import http from "k6/http";
2+
import { check } from 'k6'
3+
4+
const hosts = {
5+
prod: {
6+
uid2: {
7+
global: "https://prod.uidapi.com",
8+
au: "https://au.prod.uidapi.com",
9+
jp: "https://jp.prod.uidapi.com",
10+
sg: "https://sg.prod.uidapi.com",
11+
usw: "https://usw.prod.uidapi.com",
12+
globalAccelerator: "https://global.prod.uidapi.com"
13+
}
14+
}
15+
}
16+
17+
//change the const below to test different hosts
18+
const host = hosts.prod.uid2.usw;
19+
20+
export const options = {
21+
scenarios: {
22+
createTraffic: {
23+
executor: "shared-iterations",
24+
vus: 200,
25+
iterations: 15000,
26+
startTime: "0s",
27+
exec: "createTraffic"
28+
},
29+
assertIsBlocked: {
30+
executor: "shared-iterations",
31+
vus: 10,
32+
iterations: 1000,
33+
startTime: "120s",
34+
exec: "assertIsBlocked"
35+
},
36+
},
37+
};
38+
39+
const makeRequest = () => {
40+
const params = {
41+
headers: {
42+
"User-Agent": "k6",
43+
"Origin": 'k6-test-origin'
44+
}
45+
};
46+
47+
return http.post(host + "/v2/token/client-generate", null, params);
48+
}
49+
50+
export function createTraffic () {
51+
makeRequest();
52+
}
53+
54+
export function assertIsBlocked () {
55+
const res = makeRequest();
56+
check(res, {
57+
'Response is 429': (res) => res.status === 429
58+
})
59+
}

0 commit comments

Comments
 (0)