Skip to content

Commit

Permalink
feat: send results reports via email
Browse files Browse the repository at this point in the history
  • Loading branch information
NithinKuruba committed Jan 24, 2025
1 parent c35c66d commit 02698b3
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 24 deletions.
1 change: 1 addition & 0 deletions .github/workflows/publish-image-benchmark-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- main
- dev
- SSOTEAM-2187-01
paths:
- 'benchmark/**'
- '.github/workflows/publish-image-benchmark-runner.yml'
Expand Down
6 changes: 6 additions & 0 deletions benchmark/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SERVER_URL=
CHES_CLIENT_ID=
CHES_CLIENT_SECRET=
RECEPIENT=
ADMIN_USERNAME=
ADMIN_PASSWORD=
8 changes: 6 additions & 2 deletions benchmark/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ RUN rm ${KEYCLOAK_BENCHMARK_VERSION}.tar.gz

RUN chmod +x /app/${KEYCLOAK_BENCHMARK_VERSION}/bin/*.sh

WORKDIR /app/${KEYCLOAK_BENCHMARK_VERSION}/bin
WORKDIR /app/${KEYCLOAK_BENCHMARK_VERSION}

ENTRYPOINT ["./kcb.sh"]
COPY ./entrypoint.sh ./

RUN chmod +x /app/${KEYCLOAK_BENCHMARK_VERSION}/entrypoint.sh

ENTRYPOINT ["./entrypoint.sh"]
29 changes: 18 additions & 11 deletions benchmark/Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
include .env

SHELL := /usr/bin/env bash
NAMESPACE :=
NAME := sso-benchmark-runner
NAMESPACE := c6af30-dev
SCENARIO := keycloak.scenario.authentication.AuthorizationCode
SERVER_URL :=
ADMIN_USERNAME :=
ADMIN_PASSWORD :=

# 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"
ADDITIONAL_CONFIG := "--measurement=30"

# 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)
| 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
File renamed without changes.
39 changes: 39 additions & 0 deletions benchmark/entrypoint.sh
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.\nYou need to base64 decode the attached file (base64 -d -i results.tar.gz) before extracting it.\nRegards,\nBCGov SSO Team"
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 '$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 -i $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
61 changes: 50 additions & 11 deletions benchmark/openshift/dc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ kind: Template
apiVersion: v1
objects:
- apiVersion: v1
kind: PersistentVolumeClaim
kind: Secret
metadata:
name: ${NAME}-pvc
spec:
accessModes:
- ReadWriteMany
storageClassName: netapp-file-standard
volumeMode: Filesystem
resources:
requests:
storage: 200Mi
name: ${NAME}-secret
type: Opaque
stringData:
admin-username: ${ADMIN_USERNAME}
admin-password: ${ADMIN_PASSWORD}
ches-client-id: ${CHES_CLIENT_ID}
ches-client-secret: ${CHES_CLIENT_SECRET}
ches-token-url: ${CHES_TOKEN_URL}
mail-server: ${MAIL_SERVER}
- apiVersion: batch/v1
kind: Job
spec:
Expand Down Expand Up @@ -42,6 +42,37 @@ objects:
requests:
cpu: 500m
memory: 500Mi
env:
- name: MAIL_SERVER
valueFrom:
secretKeyRef:
name: ${NAME}-secret
key: mail-server
- name: CHES_TOKEN_URL
valueFrom:
secretKeyRef:
name: ${NAME}-secret
key: ches-token-url
- name: CHES_CLIENT_ID
valueFrom:
secretKeyRef:
name: ${NAME}-secret
key: ches-client-id
- name: CHES_CLIENT_SECRET
valueFrom:
secretKeyRef:
name: ${NAME}-secret
key: ches-client-secret
- name: ADMIN_USERNAME
valueFrom:
secretKeyRef:
name: ${NAME}-secret
key: admin-username
- name: ADMIN_PASSWORD
valueFrom:
secretKeyRef:
name: ${NAME}-secret
key: admin-password
volumeMounts:
- name: ${NAME}-pvc
mountPath: /app/${KEYCLOAK_BENCHMARK_VERSION}/results
Expand All @@ -53,7 +84,7 @@ objects:
component: ${NAME}-job
parameters:
- name: NAME
value: sso-benchmark-runner
description: The name of the job
- name: IMAGE_TAG
value: dev
- name: IMAGE_REPOSITORY
Expand All @@ -71,3 +102,11 @@ parameters:
description: The admin password
- name: ADDITIONAL_CONFIG
description: Configuration set of parameters for the test
- name: CHES_CLIENT_ID
description: The CHES client ID
- name: CHES_CLIENT_SECRET
description: The CHES client secret
- name: CHES_TOKEN_URL
description: The CHES token URL
- name: MAIL_SERVER
description: The mail server

0 comments on commit 02698b3

Please sign in to comment.