forked from kiali/kiali
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-performance-tests.sh
executable file
·164 lines (143 loc) · 4.36 KB
/
run-performance-tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash
infomsg() {
echo "[INFO] ${1}"
}
SETUP_ONLY="false"
TESTS_ONLY="false"
DELETE_ONLY="false"
TEST_NAMESPACES="5"
# process command line args
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-so|--setup-only)
SETUP_ONLY="${2}"
if [ "${SETUP_ONLY}" != "true" -a "${SETUP_ONLY}" != "false" ]; then
echo "--setup-only option must be one of 'true' or 'false'"
exit 1
fi
shift;shift
;;
-to|--tests-only)
TESTS_ONLY="${2}"
if [ "${TESTS_ONLY}" != "true" -a "${TESTS_ONLY}" != "false" ]; then
echo "--tests-only option must be one of 'true' or 'false'"
exit 1
fi
shift;shift
;;
-do|--delete-only)
DELETE_ONLY="${2}"
if [ "${DELETE_ONLY}" != "true" -a "${DELETE_ONLY}" != "false" ]; then
echo "--delete-only option must be one of 'true' or 'false'"
exit 1
fi
shift;shift
;;
-tn|--test-namespaces)
TEST_NAMESPACES="${2}"
if [[ $2 -le 0 || $2 -ge 1000 ]]; then
echo "--test-namespaces option must be is a valid number between 1 and 1000."
exit 1
fi
shift;shift
;;
-h|--help)
cat <<HELPMSG
Valid command line arguments:
-so|--setup-only <true|false>
If true, only setup the test environment and exit without running the tests.
Default: false
-to|--tests-only <true|false>
If true, only run the tests and skip the setup.
Default: false
-do|--delete-only <true|false>
If true, only delete the test namespaces.
Default: false
-tn|--test-namespaces <number>
Number of test namespaces created before performance run.
Default: "5"
-h|--help:
This message
HELPMSG
exit 1
;;
*)
echo "ERROR: Unknown argument [$key]. Aborting."
exit 1
;;
esac
done
if [ "${SETUP_ONLY}" == "true" -a "${TESTS_ONLY}" == "true" -a "${DELETE_ONLY}" == "true" ]; then
echo "ERROR: --setup-only --tests-only and --delete-only cannot all be true. Aborting."
exit 1
fi
# print out our settings for debug purposes
cat <<EOM
=== SETTINGS ===
SETUP_ONLY=$SETUP_ONLY
TESTS_ONLY=$TESTS_ONLY
DELETE_ONLY=$DELETE_ONLY
TEST_NAMESPACES=$TEST_NAMESPACES
=== SETTINGS ===
EOM
set -e
# Determine where this script is and make it the cwd
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
COMMON_PARAMS="${SCRIPT_DIR}/../frontend/cypress/fixtures/perf/commonParams.json"
OUTPUT_DIR=${SCRIPT_DIR}/../frontend/cypress/results
OUTPUT_FILE=${OUTPUT_DIR}/performance.txt
ensureCypressInstalled() {
cd "${SCRIPT_DIR}"/../frontend
if ! yarn cypress --help &> /dev/null; then
echo "cypress binary was not detected in your PATH. Did you install the frontend directory? Before running the frontend tests you must run 'make build-ui'."
exit 1
fi
cd -
}
createNamespaces() {
ISTIO_INGRESS_IP="$(kubectl get svc istio-ingressgateway -n istio-system -o=jsonpath='{.status.loadBalancer.ingress[0].ip}')"
# Install demo apps
"${SCRIPT_DIR}"/istio/install-testing-demos.sh -c "kubectl" -g "${ISTIO_INGRESS_IP}"
for ((i = 1; i <= $TEST_NAMESPACES; i++)); do
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Namespace
metadata:
name: perf-test-${i}
labels:
kiali.io: perf-test
istio-injection: enabled
EOF
jq --arg i "$i" '.allNamespaces += ",perf-test-\($i)"' "$COMMON_PARAMS" > "$COMMON_PARAMS.tmp" && mv "$COMMON_PARAMS.tmp" "$COMMON_PARAMS"
done
}
deleteNamespaces() {
kubectl delete --ignore-not-found=true -l kiali.io=perf-test ns
jq '.allNamespaces = .namespaces' "$COMMON_PARAMS" > "$COMMON_PARAMS.tmp" && mv "$COMMON_PARAMS.tmp" "$COMMON_PARAMS"
}
if [ "${TESTS_ONLY}" != "true" -a "${DELETE_ONLY}" != "true" ]; then
infomsg "Install test namespaces"
createNamespaces
fi
if [ "${DELETE_ONLY}" == "true" ]; then
infomsg "Remove test namespaces"
deleteNamespaces
exit 0
fi
export CYPRESS_NUM_TESTS_KEPT_IN_MEMORY=0
# Recorded video is unusable due to low resources in CI: https://github.com/cypress-io/cypress/issues/4722
export CYPRESS_VIDEO=false
if [ "${SETUP_ONLY}" == "true" ]; then
exit 0
fi
ensureCypressInstalled
cd "${SCRIPT_DIR}"/../frontend
infomsg "Running cypress performance tests"
mkdir "$OUTPUT_DIR"
echo "[Running cypress performance tests for $TEST_NAMESPACES namespaces]" > $OUTPUT_FILE
yarn cypress:run:perf
if [ "${TESTS_ONLY}" != "true" ]; then
infomsg "Remove test namespaces"
deleteNamespaces
fi