Skip to content
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

[Test] Update load-tests script #22860

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/performance/load-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ What do you need to run those tests

## 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.
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). Set timeout for waiting workspaces to start by -t parameter in seconds(like ./load-test.sh -t 240).
3. This script uses local dewvorspace.yaml to starts workspaces.
4. As results there are average time of workspace starting and number of failed workspaces.


Expand Down
160 changes: 93 additions & 67 deletions tests/performance/load-tests/load-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,84 +6,110 @@ GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color

# Do cleanup if the script is interrupted or fails
trap cleanup ERR SIGINT

function print() {
echo -e "${GREEN}$1${NC}"
echo -e "${GREEN}$1${NC}"
}

function print_error() {
echo -e "${RED}$1${NC}"
echo -e "${RED}$1${NC}"
}

function cleanup() {
echo "Clean up the environment"
kubectl delete dw --all > /dev/null
kubectl delete dwt --all > /dev/null
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

# Delete all dw and dwt objects from test namespace
cleanup

# Delete logs
rm dw* || true > /dev/null


for ((i=1; i<=$COMPLETITIONS_COUNT; i++)); do
cat devfile.yaml | sed "0,/name: code-latest/s//name: dw$i/" | kubectl apply -f - &
done

wait

for ((i=1; i<=$COMPLETITIONS_COUNT; i++)); do
kubectl wait --for=condition=Ready "dw/dw$i" --timeout=360s || true &
done

wait
function parseArguments() {
while getopts "t:c:" opt; do
case $opt in
t) export WORKSPACE_IDLE_TIMEOUT=$OPTARG
;;
c) # Check if the argument to -c is a number
if ! [[ $OPTARG =~ ^[0-9]+$ ]]; then
print_error "Error: Option -c requires a numeric argument." >&2
exit 1
fi
export COMPLETITIONS_COUNT=$OPTARG
;;
\?)
print_error "Invalid option -c. Try for example something like ./load-test.sh -c 7"
exit 1
;;
esac
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 get dw dw$i --template='{{.status.phase}}')" == "Running" ]; 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))
function setCompletitionsCount() {
# 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
else
echo "Parameter -c was set to $COMPLETITIONS_COUNT ."
fi

# Set the number of timeouts for waiting for workspaces to start
if [ -z $WORKSPACE_IDLE_TIMEOUT ]; then
echo "Parameter -t wasn't set, setting timeout to 120 second."
export WORKSPACE_IDLE_TIMEOUT=120
else
echo "Parameter -t was set to $WORKSPACE_IDLE_TIMEOUT second."
fi
}

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 $(kubectl get dw dw$i --template='{{.status.devworkspaceId}}') > dw$i-pod.log || true
fi
done
function runTest() {
# start COMPLETITIONS_COUNT workspaces in parallel
for ((i=1; i<=$COMPLETITIONS_COUNT; i++)); do
cat devworkspace.yaml | sed "0,/name: code-latest/s//name: dw$i/" | kubectl apply -f - &
done
wait

# wait for all workspaces to be started
echo "Wait for all workspaces are started"
for ((i=1; i<=$COMPLETITIONS_COUNT; i++)); do
kubectl wait --for=condition=Ready "dw/dw$i" --timeout=${WORKSPACE_IDLE_TIMEOUT}s || true &
done
wait

# Delete logs on file system if it exists
rm -f logs/dw*

total_time=0
succeeded=0
echo "Calculate average workspaces starting time"
for ((i=1; i<=$COMPLETITIONS_COUNT; i++)); do
if [ "$(kubectl get dw dw$i --template='{{.status.phase}}')" == "Running" ]; 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 > logs/dw$i-log.log
kubectl logs $(oc get dw dw$i --template='{{.status.devworkspaceId}}') > logs/dw$i-pod.log || true
fi
done

wait
}

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."
function printResults() {
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
parseArguments "$@"
setCompletitionsCount
cleanup
runTest
printResults
cleanup
Loading