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

Rework load file script for using devfile samples from local resources #22853

Closed
wants to merge 2 commits into from
Closed
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
100 changes: 100 additions & 0 deletions tests/performance/load-tests/devfile-samples/emptyfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
apiVersion: workspace.devfile.io/v1alpha2
kind: DevWorkspaceTemplate
metadata:
name: che-code-empty
spec:
commands:
- id: init-container-command
apply:
component: che-code-injector
- id: init-che-code-command
exec:
component: che-code-runtime-description
commandLine: nohup /checode/entrypoint-volume.sh > /checode/entrypoint-logs.txt
2>&1 &
events:
preStart:
- init-container-command
postStart:
- init-che-code-command
components:
- name: che-code-runtime-description
container:
image: quay.io/devfile/universal-developer-image:latest
env:
- name: CODE_HOST
value: 0.0.0.0
volumeMounts:
- name: checode
path: /checode
memoryLimit: 1024Mi
memoryRequest: 256Mi
cpuLimit: 500m
cpuRequest: 30m
endpoints:
- name: che-code
attributes:
type: main
cookiesAuthEnabled: true
discoverable: false
urlRewriteSupported: true
targetPort: 3100
exposure: public
secure: false
protocol: https
- name: code-redirect-1
attributes:
discoverable: false
urlRewriteSupported: false
targetPort: 13131
exposure: public
protocol: http
- name: code-redirect-2
attributes:
discoverable: false
urlRewriteSupported: false
targetPort: 13132
exposure: public
protocol: http
- name: code-redirect-3
attributes:
discoverable: false
urlRewriteSupported: false
targetPort: 13133
exposure: public
protocol: http
attributes:
app.kubernetes.io/component: che-code-runtime
app.kubernetes.io/part-of: che-code.eclipse.org
controller.devfile.io/container-contribution: true
- name: checode
volume: {}
- name: che-code-injector
container:
image: quay.io/che-incubator/che-code:latest
command:
- /entrypoint-init-container.sh
volumeMounts:
- name: checode
path: /checode
memoryLimit: 256Mi
memoryRequest: 32Mi
cpuLimit: 500m
cpuRequest: 30m
---
apiVersion: workspace.devfile.io/v1alpha2
kind: DevWorkspace
metadata:
name: empty
annotations:
che.eclipse.org/devfile: |
schemaVersion: 2.2.0
metadata:
name: empty
spec:
started: true
template: {}
contributions:
- name: editor
kubernetes:
name: che-code-empty
154 changes: 83 additions & 71 deletions tests/performance/load-tests/load-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ set -e
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
#OPTIND=1

#trap cleanup ERR EXIT

function print() {
echo -e "${GREEN}$1${NC}"
Expand All @@ -18,79 +21,88 @@ function cleanup() {
echo "Clean up the environment"
kubectl delete dw --all > /dev/null
kubectl delete dwt --all > /dev/null

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

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
function parseArguments() {
while getopts "c:" opt; do
case $opt in
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
}

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
}

function setTestNamespace() {
# 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
}

function runTest() {
for ((i=1; i<=$COMPLETITIONS_COUNT; i++)); do
cat devfile-samples/emptyfile.yaml | sed "0,/name: empty/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
}

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."
}

parseArguments "$@"
setCompletitionsCount
setTestNamespace
cleanup
runTest
printResults






# 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

Loading