-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: benchmark tests email results report #425
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
02698b3
feat: send results reports via email
NithinKuruba a0be0f8
feat: minor fixes
NithinKuruba 8ab8326
fix: permission issue
NithinKuruba 5d53916
fix: missing env vars
NithinKuruba 9e8a143
fix: line breaks in json payload
NithinKuruba 0d619b0
feat: updated the documentation
NithinKuruba fb01b75
fix: tiny fix
NithinKuruba 82f3811
fix: tiny fixes
NithinKuruba 6eb3047
fix: updated docs about the building images
NithinKuruba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,12 @@ | ||
SERVER_URL= | ||
CHES_CLIENT_ID= | ||
CHES_CLIENT_SECRET= | ||
RECEPIENT=<EMAIL_ADDRESS> | ||
ADMIN_USERNAME= | ||
ADMIN_PASSWORD= | ||
ADDITIONAL_CONFIG="--measurement=30" | ||
CHES_TOKEN_URL= | ||
MAIL_SERVER= | ||
SCENARIO=keycloak.scenario.authentication.AuthorizationCode | ||
NAME=sso-benchmark-runner | ||
NAMESPACE= |
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 |
---|---|---|
@@ -1,21 +1,26 @@ | ||
SHELL := /usr/bin/env bash | ||
NAMESPACE := | ||
SCENARIO := keycloak.scenario.authentication.AuthorizationCode | ||
SERVER_URL := | ||
ADMIN_USERNAME := | ||
ADMIN_PASSWORD := | ||
include .env | ||
|
||
# make sure scenario is set to the correct value | ||
# test #1 - 34 users per second for 30 minutes (1800 seconds) with 101 users per realm and 101 clients per realm | ||
ADDITIONAL_CONFIG := "--users-per-sec=34 --ramp-up=300 --users-per-realm=101 --measurement=1800 --clients-per-realm=101" | ||
SHELL := /usr/bin/env bash | ||
|
||
# make <comand> NAMESPACE="<namespace>" | ||
|
||
.PHONY: run_job | ||
run_job: | ||
oc -n $(NAMESPACE) process -f ./openshift/dc.yaml -p SCENARIO=$(SCENARIO) -p SERVER_URL=$(SERVER_URL) -p ADMIN_USERNAME=$(ADMIN_USERNAME) -p ADMIN_PASSWORD=$(ADMIN_PASSWORD) -p ADDITIONAL_CONFIG=$(ADDITIONAL_CONFIG)| oc -n $(NAMESPACE) apply -f - | ||
oc -n $(NAMESPACE) process -f ./openshift/dc.yaml \ | ||
-p SCENARIO=$(SCENARIO) \ | ||
-p SERVER_URL=$(SERVER_URL) \ | ||
-p ADMIN_USERNAME=$(ADMIN_USERNAME) \ | ||
-p ADMIN_PASSWORD=$(ADMIN_PASSWORD) \ | ||
-p ADDITIONAL_CONFIG=$(ADDITIONAL_CONFIG) \ | ||
-p CHES_CLIENT_ID=$(CHES_CLIENT_ID) \ | ||
-p CHES_CLIENT_SECRET=$(CHES_CLIENT_SECRET) \ | ||
-p RECEPIENT=$(RECEPIENT) \ | ||
-p NAME=$(NAME) \ | ||
-p MAIL_SERVER=$(MAIL_SERVER) \ | ||
-p CHES_TOKEN_URL=$(CHES_TOKEN_URL) \ | ||
| oc -n $(NAMESPACE) apply -f - | ||
|
||
.PHONY: cleanup | ||
cleanup: | ||
oc -n $(NAMESPACE) delete job sso-benchmark-runner | ||
oc -n $(NAMESPACE) delete pvc sso-benchmark-runner-pvc | ||
oc -n $(NAMESPACE) delete job $(NAME) | ||
oc -n $(NAMESPACE) delete secret $(NAME)-secret |
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,92 @@ | ||
# Benchmark Guide | ||
|
||
## Building Images | ||
|
||
### Server Image | ||
|
||
- You need a keycloak server with dataset provider added to be able to use it for generating test data | ||
- To build such server image, run `.github/workflows/publish-image-keycloak-benchmark.yml` that builds an image using `docker/keycloak/Dockerfile-26-perf` that explicitly copies `docker/keycloak/dataset-providers/keycloak-benchmark-dataset-0.15-SNAPSHOT.jar` provider | ||
- Deploy keycloak server run from this image **ONLY** in a test namespace | ||
- After the testing is complete, uninstall the server from the namespace | ||
|
||
### Runner Image | ||
|
||
- The runner image is required if you need to run benchmark tests against test keycloak server in an openshift pod | ||
- The image can be built using `.github/workflows/publish-image-benchmark-runner.yml` that uses `benchmark/Dockerfile` | ||
- Existing image `sso-benchmark-runner:dev` can be used and if not found, re-build the image | ||
- The instructions for running the benchmark runner are provided [here](#running-the-tests) | ||
|
||
## Dataset | ||
|
||
- The dataset is required to pre-populate realms, clients, and users in Keycloak under test | ||
- The dataset comes with a jar file that embeds a provider for generating the data | ||
- The dataset can be invoked through API endpoints | ||
- The `./docker/keycloak/Dockerfile-26-perf` is used to build Keycloak image with dataset provider. To build the image run `./.github/workflows/publish-image-keycloak-benchmark.yml` if image (`sso-benchmark:dev`) doesn't exist already | ||
|
||
**DO NOT ADD THIS PROVIDER OR USE THIS IMAGE IN PROD ENVIRONMENTS** | ||
|
||
### Generate Data | ||
|
||
```sh | ||
export KC_BASE_URL= | ||
|
||
# create 1 realm (realm-0) | ||
GET https://${KC_BASE_URL}/auth/realms/master/dataset/create-realms?count=1 | ||
|
||
# create 10000 users under realm-0 | ||
GET https://${KC_BASE_URL}/auth/realms/master/dataset/create-users?count=10000&realm-name=realm-0 | ||
|
||
# create 400 clients under realm-0 | ||
GET https://${KC_BASE_URL}/auth/realms/master/dataset/create-clients?count=400&realm-name=realm-0 | ||
|
||
# check the status of data generation | ||
GET https://${KC_BASE_URL}/auth/realms/master/dataset/status | ||
``` | ||
|
||
## Running the Tests | ||
|
||
#### Pre-requisites | ||
|
||
- Java 21 if running locally | ||
- Access to Openshift cluster if running in a pod | ||
- CHES service account | ||
- Test instance of keycloak pre-loaded with test data using dataset | ||
|
||
### Locally - without entrypoint.sh | ||
|
||
- Download the benchmark test suite from `https://github.com/keycloak/keycloak-benchmark/releases/download/0.15-SNAPSHOT/keycloak-benchmark-0.15-SNAPSHOT.tar.gz` | ||
- Extract the folder and run | ||
|
||
```sh | ||
export SCENARIO= | ||
export SERVER_URL= | ||
export ADMIN_USERNAME= | ||
export ADMIN_PASSWORD= | ||
|
||
# using 100 users and 100 clients to make 34 req/s for a duration of upto 30 mins | ||
./bin/kcb.sh --scenario=${SCENARIO} --server-url=${SERVER_URL}/auth --admin-username=${ADMIN_USERNAME} --admin-password=${ADMIN_PASSWORD} --users-per-sec=34 --ramp-up=300 --users-per-realm=101 --measurement=1800 --clients-per-realm=101 | ||
``` | ||
|
||
### Locally - with entrypoint.sh | ||
|
||
- Create `.env` from `.env.example` and set the appropriate values for the variables | ||
- Run `./entrypoint.sh` | ||
|
||
### Openshift Pod | ||
|
||
- Create `.env` from `.env.example` and set the appropriate values for the variables | ||
- Ensure you are logged onto the Openshift cluster | ||
- Run `make cleanup` to ensure old resources get deleted | ||
- Run `make run_job` to deploy a secret and a job that executes `entrypoint.sh` script in a pod | ||
|
||
## Reports | ||
|
||
- The html report will be generated under the `./results` directory if running locally without using `entrypoint.sh` | ||
- Running `entrypoint.sh` locally or in a pod would send the report via email to the email address set under `RECEPIENT` environment variable | ||
- Download the attachment from the email and use `base64 --decode` to decode the file | ||
- After the decode, you can extract the contents from the archive | ||
|
||
## References | ||
|
||
- https://www.keycloak.org/keycloak-benchmark/benchmark-guide/latest/scenario-overview | ||
- https://github.com/keycloak/keycloak-benchmark |
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,39 @@ | ||
#!/bin/bash | ||
|
||
# Configuration | ||
SENDER="[email protected]" | ||
SUBJECT="Keycloak Benchmark Results - $(date +'%Y-%m-%d %H:%M:%S')" | ||
BODY="Please find the attached benchmark results. You need to base64 decode the attached file before extracting it." | ||
RESULTS_DIR="./results" | ||
ATTACHMENT_NAME="results.tar.gz" | ||
|
||
./bin/kcb.sh --scenario="$SCENARIO" --server-url="$SERVER_URL" --admin-username="$ADMIN_USERNAME" --admin-password="$ADMIN_PASSWORD" $ADDITIONAL_CONFIG | ||
|
||
if [ -d "$RESULTS_DIR" ]; then | ||
|
||
if [ -f "$ATTACHMENT_NAME" ]; then | ||
rm "$ATTACHMENT_NAME" | ||
fi | ||
|
||
tar -czvf "$ATTACHMENT_NAME" "$RESULTS_DIR" | ||
|
||
if [ $? -eq 0 ]; then | ||
echo "Folder '$RESULTS_DIR' compressed successfully to '$ATTACHMENT_NAME'." | ||
|
||
echo "Getting access token from '$CHES_TOKEN_URL'." | ||
|
||
# Get the access token | ||
ACCESS_TOKEN=$(curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "client_id=$CHES_CLIENT_ID" -d "client_secret=$CHES_CLIENT_SECRET" -d "grant_type=client_credentials" "$CHES_TOKEN_URL" | jq -r '.access_token') | ||
|
||
BASE64_DATA=$(base64 -w 0 $ATTACHMENT_NAME) | ||
|
||
echo '{"from": "'"$SENDER"'", "to": ["'"$RECEPIENT"'"], "subject": "'"$SUBJECT"'", "body": "'"$BODY"'", "bodyType": "text", "attachments": [{"filename": "'"$ATTACHMENT_NAME"'", "content": "'"$BASE64_DATA"'"}]}' | curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $ACCESS_TOKEN" --data-binary @- "$MAIL_SERVER" | ||
|
||
else | ||
echo "Error: Failed to compress folder '$RESULTS_DIR'." | ||
fi | ||
else | ||
echo "Folder '$RESULTS_DIR' does not exist." | ||
fi | ||
|
||
exit 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
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the java version installed to build the benchmark test runner that will be deployed in openshift? If so is it included in the keycloak repo's asdf tool version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You would need Java 21 only if you are running the tests locally in your machine but when running in the Openshift, the docker image has the Java Runtime pre-installed