diff --git a/tests/performance/load-tests/README.md b/tests/performance/load-tests/README.md new file mode 100644 index 00000000000..95e79e14792 --- /dev/null +++ b/tests/performance/load-tests/README.md @@ -0,0 +1,18 @@ +# Overview +This script tests how well OpenShift environment can handle running simultaneously many of workspaces. It evaluates the performance of the system under test by checking the average results across all pods and identifying failures that occur during the testing process. + +## Prerequisites +What do you need to run those tests +- `kubectl` client installed +- Openshift cluster with running Openshift DevSpaces +- test user logged into DevSpaces Dashboard(this quaranies that user namespaces are created) + +## Running load tests +1. Log in to Openshift cluster with Openshift DevSpaces or Eclipse Che deployed from terminal +2. Start `load-test.sh` script from `test/e2e/performance/load-tests`. Set number of started workspaces by -c parameter(like ./load-test.sh -c 5). +3. This script gets `cpp` sample devfile.yaml from DevSpaces devfile registry and starts workspaces. +4. As results there are average time of workspace starting and number of failed workspaces. + + +## Results and logs +If workspace failed to start, logs are saved in current directory. diff --git a/tests/performance/load-tests/load-test.sh b/tests/performance/load-tests/load-test.sh new file mode 100755 index 00000000000..ebbca59aa1e --- /dev/null +++ b/tests/performance/load-tests/load-test.sh @@ -0,0 +1,96 @@ +#!/bin/bash + +set -e + +GREEN='\033[0;32m' +RED='\033[0;31m' +NC='\033[0m' # No Color + +function print() { + echo -e "${GREEN}$1${NC}" +} + +function print_error() { + echo -e "${RED}$1${NC}" +} + +function cleanup() { + echo "Clean up the environment" + kubectl delete dw --all > /dev/null + kubectl delete dwt --all > /dev/null +} + +while getopts "c:" opt; do + case $opt in + c) export COMPLETITIONS_COUNT=$OPTARG + ;; + \?) # invalid option + exit 1 + ;; + :) + echo "Option \"$opt\" needs an argument." + exit 1 + ;; + esac +done + +# Set the number of workspaces to start +if [ -z $COMPLETITIONS_COUNT ]; then + echo "Parameter -c wasn't set, setting completitions count to 3." + export COMPLETITIONS_COUNT=3 +fi + +# Checkout to user devspaces namespace +export userName=$(kubectl config view --minify -o jsonpath='{.users[0].name}' | sed 's|/.*||') +kubectl config set-context --current --namespace=$userName-devspaces + +# Delete all dw and dwt objects from test namespace +cleanup + +# Delete logs +rm dw* || true + +# Get Openshift DevSpaces url and path to sample devfile yaml from devfile-registry +export devworkspaceUrl=$(kubectl config view --minify -o jsonpath='{.clusters[0].cluster.server}' | sed 's/:6443//' | sed 's/api/devspaces.apps/') +export testDevfilePath="devfile-registry/devfiles/TP__cpp__c-plus-plus/devworkspace-che-code-latest.yaml" + +echo "Download the devfile" +curl --insecure "$devworkspaceUrl/$testDevfilePath" -o devfile.yaml + +echo "Start workspaces from sample devfile" +csplit devfile.yaml /---/ +mv xx00 dwt.yaml +mv xx01 dw.yaml +kubectl apply -f dwt.yaml + +for ((i=1; i<=$COMPLETITIONS_COUNT; i++)); do + cat dw.yaml | sed "0,/name: cpp/s//name: dw$i/" | kubectl apply -f - +done + +total_time=0 +succeeded=0 +echo "Wait for all workspaces are started and calculate average workspaces starting time" +for ((i=1; i<=$COMPLETITIONS_COUNT; i++)); do + if kubectl wait --for=condition=Ready "dw/dw$i" --timeout=120s; then + start_time=$(kubectl get dw dw$i --template='{{range .status.conditions}}{{if eq .type "Started"}}{{.lastTransitionTime}}{{end}}{{end}}') + end_time=$(kubectl get dw dw$i --template='{{range .status.conditions}}{{if eq .type "Ready"}}{{.lastTransitionTime}}{{end}}{{end}}') + start_timestamp=$(date -d $start_time +%s) + end_timestamp=$(date -d $end_time +%s) + dw_starting_time=$((end_timestamp - start_timestamp)) + + print "Devworkspace dw$i starting time: $dw_starting_time seconds" + total_time=$((total_time + dw_starting_time)) + succeeded=$((succeeded + 1)) + else + print_error "Timeout waiting for dw$i to become ready or an error occurred." + kubectl describe dw dw$i > dw$i-log.log + kubectl logs $(oc get dw dw$i --template='{{.status.devworkspaceId}}') > dw$i-pod.log || true +fi +done + +print "==================== Test results ====================" +print "Average workspace starting time for $succeeded workspaces from $COMPLETITIONS_COUNT started: $((total_time / succeeded)) seconds" +print "$((COMPLETITIONS_COUNT - succeeded)) workspaces failed. See failed workspace pod logs in the current folder for details." + +trap cleanup ERR EXIT +