From 952e037420e3e2d1616e4f97a4a4704cd5ca55e4 Mon Sep 17 00:00:00 2001 From: Graham Whaley Date: Tue, 12 Nov 2019 17:14:44 +0000 Subject: [PATCH] metrics: enable cpu-load ability across tests Rejig the framework a little to unify the init/shutdown calls and code, which allows us to add the cpu-load enable/disable ability to all the existing metrics. Signed-off-by: Graham Whaley --- metrics/collectd/collectd.bash | 2 -- metrics/lib/common.bash | 41 ++++++++++++++++++++++++++++++ metrics/scaling/k8s_parallel.sh | 7 ++--- metrics/scaling/k8s_scale.sh | 6 ++--- metrics/scaling/k8s_scale_nc.sh | 6 ++--- metrics/scaling/k8s_scale_rapid.sh | 30 +++------------------- 6 files changed, 51 insertions(+), 41 deletions(-) diff --git a/metrics/collectd/collectd.bash b/metrics/collectd/collectd.bash index 889613a..ba84b2a 100644 --- a/metrics/collectd/collectd.bash +++ b/metrics/collectd/collectd.bash @@ -25,8 +25,6 @@ init_stats() { } cleanup_stats() { - local delete_wait_time=$1 - # attempting to provide buffer for collectd CPU collection to record adequate history sleep 6 diff --git a/metrics/lib/common.bash b/metrics/lib/common.bash index de42b16..2bb8193 100755 --- a/metrics/lib/common.bash +++ b/metrics/lib/common.bash @@ -10,6 +10,7 @@ RESULT_DIR="${LIB_DIR}/../results" source ${LIB_DIR}/json.bash source ${LIB_DIR}/k8s-api.bash +source ${LIB_DIR}/cpu-load.bash source /etc/os-release || source /usr/lib/os-release die() { @@ -67,6 +68,46 @@ init_env() # been deliberately injected into the cluster under test. } +framework_init() { + info "Initialising" + + check_cmds "${cmds[@]}" + + info "Checking k8s accessible" + local worked=$( kubectl get nodes > /dev/null 2>&1 && echo $? || echo $? ) + if [ "$worked" != 0 ]; then + die "kubectl failed to get nodes" + fi + + info $(get_num_nodes) "k8s nodes in 'Ready' state found" + + k8s_api_init + + # Launch our stats gathering pod + if [ -n "$SMF_USE_COLLECTD" ]; then + info "Setting up collectd" + init_stats $wait_time + fi + + # Initialise the cpu load generators + cpu_load_init + + # And now we can set up our results storage then... + metrics_json_init "k8s" + save_config +} + +framework_shutdown() { + metrics_json_save + k8s_api_shutdown + cpu_load_shutdown + + if [ -n "$SMF_USE_COLLECTD" ]; then + cleanup_stats + fi + +} + # finds elements in $1 that are not in $2 find_unique_pods() { local list_a=$1 diff --git a/metrics/scaling/k8s_parallel.sh b/metrics/scaling/k8s_parallel.sh index 8390ddc..f67c006 100755 --- a/metrics/scaling/k8s_parallel.sh +++ b/metrics/scaling/k8s_parallel.sh @@ -126,7 +126,7 @@ init() { # a nice way to do it (unless you want to parse 'descibe nodes') # Have a read of https://github.com/kubernetes/kubernetes/issues/25353 - k8s_api_init + framework_init # Ensure we pre-cache the container image etc. warmup @@ -218,11 +218,8 @@ cleanup() { # First try to save any results we got metrics_json_end_array "BootResults" - metrics_json_save - kill_deployment "${deployment}" "${LABEL}" "${LABELVALUE}" ${delete_wait_time} - - k8s_api_shutdown + framework_shutdown } show_vars() diff --git a/metrics/scaling/k8s_scale.sh b/metrics/scaling/k8s_scale.sh index c3097d1..e0ef1a7 100755 --- a/metrics/scaling/k8s_scale.sh +++ b/metrics/scaling/k8s_scale.sh @@ -209,7 +209,7 @@ init() { # FIXME - check the node(s) can run enough pods - check 'max-pods' in the # kubelet config - from 'kubectl describe node -o json' ? - k8s_api_init + framework_init # Launch our stats gathering pod kubectl apply -f ${SCRIPT_PATH}/${stats_pod}.yaml @@ -347,9 +347,7 @@ EOF )" metrics_json_add_fragment "$json" - metrics_json_save - - k8s_api_shutdown + framework_shutdown } show_vars() diff --git a/metrics/scaling/k8s_scale_nc.sh b/metrics/scaling/k8s_scale_nc.sh index 6549525..2423de5 100755 --- a/metrics/scaling/k8s_scale_nc.sh +++ b/metrics/scaling/k8s_scale_nc.sh @@ -235,7 +235,7 @@ init() { # FIXME - check the node(s) can run enough pods - check 'max-pods' in the # kubelet config - from 'kubectl describe node -o json' ? - k8s_api_init + framework_init # Launch our stats gathering pod kubectl apply -f ${SCRIPT_PATH}/${stats_pod}.yaml @@ -410,9 +410,7 @@ EOF )" metrics_json_add_fragment "$json" - metrics_json_save - - k8s_api_shutdown + framework_shutdown } show_vars() diff --git a/metrics/scaling/k8s_scale_rapid.sh b/metrics/scaling/k8s_scale_rapid.sh index 15c991b..95f5fdd 100755 --- a/metrics/scaling/k8s_scale_rapid.sh +++ b/metrics/scaling/k8s_scale_rapid.sh @@ -15,6 +15,8 @@ source "${SCRIPT_PATH}/../collectd/collectd.bash" NUM_PODS=${NUM_PODS:-20} STEP=${STEP:-1} +SMF_USE_COLLECTD=true + LABELVALUE=${LABELVALUE:-gandalf} pod_command="[\"tail\", \"-f\", \"/dev/null\"]" @@ -64,27 +66,7 @@ EOF } init() { - info "Initialising" - - local cmds=("bc" "jq") - check_cmds "${cmds[@]}" - - info "Checking k8s accessible" - local worked=$( kubectl get nodes > /dev/null 2>&1 && echo $? || echo $? ) - if [ "$worked" != 0 ]; then - die "kubectl failed to get nodes" - fi - - info $(get_num_nodes) "k8s nodes in 'Ready' state found" - - k8s_api_init - - # Launch our stats gathering pod - init_stats $wait_time - - # And now we can set up our results storage then... - metrics_json_init "k8s" - save_config + framework_init } save_config(){ @@ -198,11 +180,7 @@ EOF )" metrics_json_add_fragment "$json" - metrics_json_save - - cleanup_stats $delete_wait_time - - k8s_api_shutdown + framework_shutdown } show_vars()