Skip to content

Commit

Permalink
Merge pull request #39 from IABTechLab/tjm-E2E-perf-testing
Browse files Browse the repository at this point in the history
Update perf testing to pre-generate the requests
  • Loading branch information
thomasm-ttd authored Aug 27, 2024
2 parents e349303 + 5eb83c8 commit 408b72a
Show file tree
Hide file tree
Showing 4 changed files with 559 additions and 0 deletions.
37 changes: 37 additions & 0 deletions performance-testing/uid2-operator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# UID2 Operator Performance Testing Tool
The following instructions will work for any operator.

## Steps
### Step 1 - Configure the K6 script
The script as checked in has a basic config that will run a check against all endpoints.


All the manual config can be changed at the top of the script.

To change/remove scenarios modify the options.scenarios. For information on configuring k6 scenarios see https://k6.io/docs/using-k6/scenarios/.

The variable `testDurationInSeconds` must be greater than the total duration of the test you are running.
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.
### Step 2 - Execute K6 Script
#### Option 2a - Execute K6 Script Locally (uid2-dev-workspace)
If you would like to test locally, follow these steps:
1. Pull the K6 Docker image: `docker pull grafana/k6`
2. Execute the K6 script
* PowerShell/Bash:
```
cat k6-uid2-operator.js `
| docker run --network="host" --rm -i `
-e CLIENT_KEY="<client_key>" `
-e CLIENT_SECRET="<client_secret>" `
-e BASE_URL="<operator_endpoint>" `
grafana/k6 run -
```
#### Option 2b - Execute K6 Script in K8s
In order to reduce network latency, we should deploy k6 and its script with the same zone of UID2 operator.
Set environment variables `CLIENT_KEY`, `CLIENT_SECRET`, `BASE_URL` and then use k6 to execute the testing by following command.
```
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
```
59 changes: 59 additions & 0 deletions performance-testing/uid2-operator/cstg-rate-limit-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import http from "k6/http";
import { check } from 'k6'

const hosts = {
prod: {
uid2: {
global: "https://prod.uidapi.com",
au: "https://au.prod.uidapi.com",
jp: "https://jp.prod.uidapi.com",
sg: "https://sg.prod.uidapi.com",
usw: "https://usw.prod.uidapi.com",
globalAccelerator: "https://global.prod.uidapi.com"
}
}
}

//change the const below to test different hosts
const host = hosts.prod.uid2.usw;

export const options = {
scenarios: {
createTraffic: {
executor: "shared-iterations",
vus: 200,
iterations: 15000,
startTime: "0s",
exec: "createTraffic"
},
assertIsBlocked: {
executor: "shared-iterations",
vus: 10,
iterations: 1000,
startTime: "120s",
exec: "assertIsBlocked"
},
},
};

const makeRequest = () => {
const params = {
headers: {
"User-Agent": "k6",
"Origin": 'k6-test-origin'
}
};

return http.post(host + "/v2/token/client-generate", null, params);
}

export function createTraffic () {
makeRequest();
}

export function assertIsBlocked () {
const res = makeRequest();
check(res, {
'Response is 429': (res) => res.status === 429
})
}
Loading

0 comments on commit 408b72a

Please sign in to comment.