Skip to content

Commit

Permalink
initial loadtest env commit
Browse files Browse the repository at this point in the history
  • Loading branch information
M_Westerholz committed Oct 10, 2024
1 parent d87e76a commit 9edd39f
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/Bap-spsh-k6-loadtest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build and push spsh-k6-loadtest Images

on:
push:
tags:
- 'spsh-k6-loadtest-[0-9]+.[0-9]+.[0-9]+'
jobs:
pre_build:
runs-on: ubuntu-latest
outputs:
tagName: ${{ steps.tagName.outputs.tag }}
versionName: ${{ steps.versionName.outputs.tag }}
steps:
- name: Filter Tag name
uses: olegtarasov/[email protected]
id: tagName
with:
tagRegex: "(.+?(?=-[0-9]))"
tagRegexGroup: 1

- name: Filter Version name
uses: olegtarasov/[email protected]
id: versionName
with:
tagRegex: "${{ steps.tagName.outputs.tag }}-(.*)"
tagRegexGroup: 1

build_and_push:
needs: pre_build
uses: hpi-schul-cloud/infra-tools/.github/workflows/build-and-push.yaml@master
with:
registry: ghcr.io
image: dbildungsplattform/${{ needs.pre_build.outputs.tagName }}
tag: ${{ needs.pre_build.outputs.versionName }}
context: ./infrastructure/${{ needs.pre_build.outputs.tagName }}/

24 changes: 24 additions & 0 deletions infrastructure/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/

5 changes: 5 additions & 0 deletions infrastructure/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
name: spsh-load-test
description: A Helm chart for distributed k6 loadtests in kubernetes.
version: 1.0.0
appVersion: "1.16.0"
9 changes: 9 additions & 0 deletions infrastructure/k6-loadtest/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Create image for running k6 with output for Prometheus
FROM grafana/k6:0.43.1
USER root

COPY wrapper-script.sh wrapper-script.sh
RUN apk add git && \
chmod +x wrapper-script.sh

ENTRYPOINT ["./wrapper-script.sh"]
7 changes: 7 additions & 0 deletions infrastructure/k6-loadtest/wrapper-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

git clone https://github.com/dBildungsplattform/schulportal-load-tests
cd schulportal-load-tests
git checkout $BRANCH

k6 "$@"
48 changes: 48 additions & 0 deletions infrastructure/templates/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{{- range $job_name, $job_options := .Values.cronjobs }}
apiVersion: batch/v1
kind: CronJob
metadata:
name: loadtest-spsh-{{ $job_name }}
namespace: loadtest
spec:
schedule: {{ $job_options.schedule }}
suspend: true
jobTemplate:
spec:
completions: {{ $job_options.jobsParallelism }}
parallelism: {{ $job_options.jobsParallelism }}
template:
metadata:
labels:
test: loadtest-{{ $job_options.serviceName }}
pod: {{ $job_name }}
spec:
containers:
- name: {{ $job_name }}
image: {{ $job_options.image }}
imagePullPolicy: Always
env:
- name: OPTIONS_FILE_PATH
value: testoption.json
- name: BRANCH
value: main
args:
['run', '-u', '0',
'./loadtest/tests/{{ $job_options.scriptPath }}',
'--tag','NAME={{ $job_options.serviceName }}',
#'--out', 'experimental-prometheus-rw',
'-e', 'ENVIRONMENT={{ $job_options.environment }}']
volumeMounts:
- name: secret-volume
mountPath: /secrets
readOnly: true
ports:
- containerPort: {{ $job_options.port }}
name: loadtest-pod
volumes:
- name: secret-volume
secret:
secretName: login-secret
restartPolicy: OnFailure
---
{{- end}}
11 changes: 11 additions & 0 deletions infrastructure/templates/login-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Secret
metadata:
name: login-secret
namespace: loadtest
type: Opaque
stringData:
userlogin.json: |-
{{ .Files.Get "userLogin.json" | indent 4}}
managerlogin.json: |-
{{ .Files.Get "managerLogin.json" | indent 4}}
9 changes: 9 additions & 0 deletions infrastructure/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cronjobs:
dev-scenario:
scriptPath: test.js
schedule: 0 8 * * *
port: 5656
serviceName: dev-scenario
image: ghcr.io/dbildungsplattform/spsh-k6-loadtest:latest
environment: spsh.loadtest.dbildungscloud.dev

7 changes: 7 additions & 0 deletions loadtest/config/options/testoption.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"stages": [
{ "duration": "5s", "target": 1 },
{ "duration": "20s", "target": 1 },
{ "duration": "5s", "target": 0 }
]
}
1 change: 1 addition & 0 deletions loadtest/tests/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Test JS executed!");
39 changes: 39 additions & 0 deletions startScript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
helpFunction()
{
echo ""
echo "Usage: ./script.sh -o optionsFile.json"
echo -e "\t-o Selection of the Option File to set virtual Users and test runtime."
echo -e "\t-b Selection of the Branch to use after cloning(Selection of the Loadtest)."
echo -e "Example: \n ./script -o 300s250u.json"
exit 1 # Exit script after printing help
}


while getopts "o:b:" opt
do
case "$opt" in
o ) optionsParameter="$OPTARG" ;; #Which options file to use as Loadtest Parameters
#e ) envParameter="$OPTARG" ;; # For later use to change the test environment dynamically
b ) branch="$OPTARG" ;; #To change the branch from where to clone
? ) helpFunction ;; # Print helpFunction in case parameter is non-existent
esac
done

# Print helpFunction in case parameters are empty
if [ -z "$optionsParameter" ]
then
echo "Some or all of the parameters are empty";
helpFunction
fi

for scenario in user-scenario; do
job_name=loadtest-${scenario}
template_cronjob_name=cronjob.batch/loadtest-${scenario}

kubectl set env cronjob.batch/loadtest-user-scenario OPTIONS_FILE_PATH=$optionsParameter BRANCH=$branch -n loadtest --kubeconfig /home/vscode/.kube/spsh-dev-loadtestdriver.yaml
echo "ENV changed to $optionsParameter"
kubectl create job ${job_name} -n loadtest --kubeconfig /home/vscode/.kube/spsh-dev-loadtestdriver.yaml --from=${template_cronjob_name}
echo "Launched job ${job_name} based on ${template_cronjob_name}"

done

0 comments on commit 9edd39f

Please sign in to comment.