2 # ============LICENSE_START=======================================================
3 # dcaegen2-collectors-veshv
4 # ================================================================================
5 # Copyright (C) 2019 NOKIA
6 # ================================================================================
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 # ============LICENSE_END=========================================================
20 SCRIPT_DIRECTORY="$(pwd "$0")"
22 COMPLETED_PRODUCERS_SUM=0
24 TEST_CONFIG_MAP=performance-test-config
25 PROPERTIES_FILE=${SCRIPT_DIRECTORY}/test.properties
26 PRODUCER_APPS_LABEL=hv-collector-producer
27 CONSUMER_APPS_LABEL=hv-collector-kafka-consumer
28 PROMETHEUS_CONF_LABEL=prometheus-server-conf
29 PROMETHEUS_APPS_LABEL=hv-collector-prometheus
30 GRAFANA_APPS_LABEL=hv-collector-grafana
31 GRAFANA_DATASOURCE=grafana-datasources
32 GRAFANA_DASHBOARD=grafana-dashboards
33 GRAFANA_DASHBOARD_PROVIDERS=grafana-dashboards-providers
35 MAXIMUM_BACK_OFF_CHECK_ITERATIONS=30
37 PRODUCERS_TO_RECREATE=0
38 NAME_REASON_PATTERN="custom-columns=NAME:.metadata.name,REASON:.status.containerStatuses[].state.waiting.reason"
39 HVVES_POD_NAME=$(kubectl -n ${ONAP_NAMESPACE} get pods --no-headers=true -o custom-columns=:metadata.name | grep hv-ves-collector)
40 HVVES_CERT_PATH=/etc/ves-hv/ssl/
41 KAFKA_RETENTION_TIME_MINUTES=60
42 MILISECONDS_IN_MINUTE=60000
43 CALC_RETENTION_TIME_IN_MS_CMD='expr $KAFKA_RETENTION_TIME_MINUTES \* $MILISECONDS_IN_MINUTE'
44 KAFKA_ROUTER_0_POD_NAME=$(kubectl -n ${ONAP_NAMESPACE} get pods --no-headers=true -o custom-columns=:metadata.name | grep router-kafka-0)
45 KAFKA_SET_TOPIC_RETENTION_TIME_CMD='kafka-topics.sh --zookeeper message-router-zookeeper:2181 --alter --topic HV_VES_PERF3GPP --config retention.ms='
46 HIDE_OUTPUT='grep abc | grep 123'
49 echo "Cleaning up environment"
51 echo "Attempting to delete test parameters ConfigMap"
52 kubectl delete configmap ${TEST_CONFIG_MAP} -n ${ONAP_NAMESPACE}
54 echo "Attempting to delete prometheus ConfigMap"
55 kubectl delete configmap -l name=${PROMETHEUS_CONF_LABEL} -n ${ONAP_NAMESPACE}
57 echo "Attempting to delete prometheus deployment and service"
58 kubectl delete service,deployments -l app=${PROMETHEUS_APPS_LABEL} -n ${ONAP_NAMESPACE}
60 echo "Attempting to delete grafana deployment and service"
61 kubectl delete service,deployments -l app=${GRAFANA_APPS_LABEL} -n ${ONAP_NAMESPACE}
63 echo "Attempting to delete grafana ConfigMap (DASHBOARD)"
64 kubectl delete configmap -l name=${GRAFANA_DASHBOARD} -n ${ONAP_NAMESPACE}
66 echo "Attempting to delete grafana ConfigMap (GRAFANA_DASHBOARD_PROVIDERS)"
67 kubectl delete configmap -l name=${GRAFANA_DASHBOARD_PROVIDERS} -n ${ONAP_NAMESPACE}
69 echo "Attempting to delete grafana ConfigMap (GRAFANA_DATASOURCE)"
70 kubectl delete configmap -l name=${GRAFANA_DATASOURCE} -n ${ONAP_NAMESPACE}
72 echo "Attempting to delete consumer deployments"
73 kubectl delete deployments -l app=${CONSUMER_APPS_LABEL} -n ${ONAP_NAMESPACE}
75 echo "Attempting to delete producer pods"
76 kubectl delete pods -l app=${PRODUCER_APPS_LABEL} -n ${ONAP_NAMESPACE}
78 echo "Attempting to delete client certs secret"
79 kubectl delete secret cert -n ${ONAP_NAMESPACE}
81 echo "Attempting to turn off SSL"
82 ./configure-consul.sh true
84 echo "Environment clean up finished!"
87 function copy_certs_to_hvves() {
89 for file in {trust.p12,trust.pass,server.p12,server.pass}
91 echo "Copying file: ${file}"
92 kubectl cp ${file} ${ONAP_NAMESPACE}/${HVVES_POD_NAME}:${HVVES_CERT_PATH}
96 function create_producers() {
97 echo "Recreating test properties ConfigMap from: $PROPERTIES_FILE"
98 kubectl delete configmap ${TEST_CONFIG_MAP} -n ${ONAP_NAMESPACE}
99 kubectl create configmap ${TEST_CONFIG_MAP} --from-env-file=${PROPERTIES_FILE} -n ${ONAP_NAMESPACE}
102 for i in $(seq 1 ${CONTAINERS_COUNT});
104 echo "Creating ${i}/${CONTAINERS_COUNT} producer"
105 kubectl create -f producer-pod.yaml -n ${ONAP_NAMESPACE}
107 echo "Producers created"
111 function generate_certs() {
112 echo "Generation of certs"
117 function handle_backoffs() {
118 IMAGE_PULL_BACK_OFFS=$(kubectl get pods -l app=${PRODUCER_APPS_LABEL} -n ${ONAP_NAMESPACE} -o ${NAME_REASON_PATTERN} | grep -c "ImagePullBackOff \| ErrImagePull")
119 if [[ ${IMAGE_PULL_BACK_OFFS} -gt 0 ]]; then
120 CHECK_NUMBER=$((CHECK_NUMBER + 1))
121 if [[ ${CHECK_NUMBER} -gt ${MAXIMUM_BACK_OFF_CHECK_ITERATIONS} ]]; then
122 echo "Error: Image pull problem"
128 function handle_key_interrupt() {
130 echo "Script interrupted, attempt to delete producers"
131 echo "Wait with patience"
132 COMPLETED_PRODUCERS_SUM=$(($(kubectl delete pods -l app=${PRODUCER_APPS_LABEL} -n ${ONAP_NAMESPACE} | grep producer | wc -l) + COMPLETED_PRODUCERS_SUM))
133 echo "Total number of completed producers: ${COMPLETED_PRODUCERS_SUM}"
137 function print_test_setup_info() {
138 echo "Starting cloud based performance tests"
139 echo "________________________________________"
140 echo "Test configuration:"
141 echo "Producer containers count: ${CONTAINERS_COUNT}"
142 echo "Properties file path: ${PROPERTIES_FILE}"
143 echo "Retention time of kafka messages in minutes: ${KAFKA_RETENTION_TIME_MINUTES}"
144 echo "________________________________________"
149 echo "Run cloud based HV-VES performance test"
150 echo "Usage $0 gen_certs|setup|start|clean|help"
151 echo " gen_certs: generate certs in ../../ssl directory"
152 echo " setup : set up ConfigMap and consumers"
153 echo " start : create producers - start the performance test"
154 echo " Optional parameters:"
155 echo " --load : should test keep defined containers number till script interruption (false)"
156 echo " --containers : number of producer containers to create (1)"
157 echo " --properties-file : path to file with benchmark properties (./test.properties)"
158 echo " --retention-time-minutes : messages retention time on kafka in minutes - only for load tests (60)"
159 echo " clean : remove ConfigMap, HV-VES consumers and producers"
160 echo " help : print usage"
161 echo "Example invocations:"
162 echo "./cloud-based-performance-test.sh gen_certs"
163 echo "./cloud-based-performance-test.sh setup"
164 echo "./cloud-based-performance-test.sh start"
165 echo "./cloud-based-performance-test.sh start --containers 10"
166 echo "./cloud-based-performance-test.sh start --load true --containers 10"
167 echo "./cloud-based-performance-test.sh start --load true --containers 10 --retention-time-minutes 50"
168 echo "./cloud-based-performance-test.sh start --properties-file ~/other_test.properties"
169 echo "./cloud-based-performance-test.sh clean"
173 function setup_environment() {
174 echo "Setting up environment"
176 echo "Copying certs to hv-ves pod"
179 echo "Creating secrets with clients cert"
180 kubectl create secret generic cert --from-file=./client.p12 --from-file=./client.pass -n ${ONAP_NAMESPACE}
181 cd ${SCRIPT_DIRECTORY}
183 echo "Turning on SSL"
184 ./configure-consul.sh false
186 echo "Creating test properties ConfigMap from: $PROPERTIES_FILE"
187 kubectl create configmap ${TEST_CONFIG_MAP} --from-env-file=${PROPERTIES_FILE} -n ${ONAP_NAMESPACE}
189 echo "Creating consumer deployment"
190 kubectl apply -f consumer-deployment.yaml
192 echo "Creating ConfigMap for prometheus deployment"
193 kubectl apply -f prometheus/prometheus-config-map.yaml
195 echo "Creating prometheus deployment"
196 kubectl apply -f prometheus-deployment.yaml
198 echo "Creating ConfigMap for grafana connections dashboard"
199 kubectl apply -f grafana/dashboards/connections.yaml
201 echo "Creating ConfigMap for grafana processing dashboard"
202 kubectl apply -f grafana/dashboards/processing.yaml
204 echo "Creating ConfigMap for grafana grafana-performance-tests dashboard"
205 kubectl apply -f grafana/dashboards/performance-tests.yaml
207 echo "Creating ConfigMap for grafana datasource"
208 kubectl apply -f grafana/datasources/datasource.yaml
210 echo "Creating ConfigMap for grafana dashboards-providers"
211 kubectl apply -f grafana/dashboards-providers/dashboards.yaml
213 echo "Creating grafana deployment"
214 kubectl apply -f grafana-deployment.yaml
216 echo "Waiting for consumers to be running."
217 while [[ $(kubectl get pods -l app=${CONSUMER_APPS_LABEL} -n ${ONAP_NAMESPACE} | grep -c "unhealthy\|starting") -ne 0 ]] ; do
220 echo "Setting up environment finished!"
223 function start_load_tests() {
224 print_test_setup_info
226 echo "Setting message retention time"
227 kubectl exec -it ${KAFKA_ROUTER_0_POD_NAME} -n ${ONAP_NAMESPACE} -- ${KAFKA_SET_TOPIC_RETENTION_TIME_CMD}$(eval $CALC_RETENTION_TIME_IN_MS_CMD) | eval $HIDE_OUTPUT
229 echo "CTRL + C to stop/interrupt this script"
232 trap "handle_key_interrupt" INT
234 echo "Constant producer number keeper started working"
236 PRODUCERS_TO_RECREATE=$((CONTAINERS_COUNT-$(kubectl get pods -l app=${PRODUCER_APPS_LABEL} -n ${ONAP_NAMESPACE} | grep -c "Running")))
240 for i in $(seq 1 ${PRODUCERS_TO_RECREATE});
242 echo "Recreating ${i}/${PRODUCERS_TO_RECREATE} producer"
243 kubectl create -f producer-pod.yaml -n ${ONAP_NAMESPACE}
246 COMPLETED_PRODUCERS_SUM=$((COMPLETED_PRODUCERS_SUM + PRODUCERS_TO_RECREATE))
247 echo "Attempting to clear completed producers"
248 kubectl delete pod --field-selector=status.phase==Succeeded -l app=${PRODUCER_APPS_LABEL} -n ${ONAP_NAMESPACE}
250 [[ ${CHECK_NUMBER} -gt ${MAXIMUM_BACK_OFF_CHECK_ITERATIONS} ]] && break
258 function start_performance_test() {
259 print_test_setup_info
263 echo "Waiting for producers completion"
265 COMPLETED_PRODUCERS=$(kubectl get pods -l app=${PRODUCER_APPS_LABEL} -n ${ONAP_NAMESPACE} | grep -c "Completed")
268 [[ ${COMPLETED_PRODUCERS} -eq ${CONTAINERS_COUNT} || ${CHECK_NUMBER} -gt ${MAXIMUM_BACK_OFF_CHECK_ITERATIONS} ]] && break
272 echo "Attempting to delete producer pods"
273 kubectl delete pods -l app=${PRODUCER_APPS_LABEL} -n ${ONAP_NAMESPACE}
274 echo "Performance test finished"
278 cd ${SCRIPT_DIRECTORY}
280 if [[ $# -eq 0 ]]; then
294 while [[ $(($#)) -gt 0 ]]; do
300 CONTAINERS_COUNT=${2}
305 --retention-time-minutes)
306 KAFKA_RETENTION_TIME_MINUTES=${2}
309 echo "Unknown option: ${1}"
315 if [ ${LOAD_TEST} == "true" ] ; then
318 start_performance_test
328 echo "Unknown action: ${arg}" >&2