From b6c7cf1b8e001c02179be6a08f46ca05efdfd8b2 Mon Sep 17 00:00:00 2001 From: Graham Whaley Date: Wed, 20 Nov 2019 11:28:27 +0000 Subject: [PATCH] metrics: make pods_per_gb valid JSON Under some circumstances, the pod_per_gb value would come out as <0, and be generated without any leading 0's (such as `.14` rather than `0.14`). This is not valid JSON, and would break the report generation parsing in R. Use `printf` to force a leading 0 prefix onto the value. Signed-off-by: Graham Whaley --- metrics/scaling/k8s_scale.sh | 2 +- metrics/scaling/k8s_scale_nc.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/metrics/scaling/k8s_scale.sh b/metrics/scaling/k8s_scale.sh index 6d7066d..6e774b8 100755 --- a/metrics/scaling/k8s_scale.sh +++ b/metrics/scaling/k8s_scale.sh @@ -169,7 +169,7 @@ EOF if [ $n_pods -eq 0 ]; then local pods_per_gb=0 else - local pods_per_gb=$(bc -l <<< "scale=2; ($total_mem_used/1024) / $n_pods") + local pods_per_gb=$(printf "%0f" $(bc -l <<< "scale=2; ($total_mem_used/1024) / $n_pods")) fi local mem_json="$(cat << EOF "memory": { diff --git a/metrics/scaling/k8s_scale_nc.sh b/metrics/scaling/k8s_scale_nc.sh index b92964d..f1b86b1 100755 --- a/metrics/scaling/k8s_scale_nc.sh +++ b/metrics/scaling/k8s_scale_nc.sh @@ -195,7 +195,7 @@ EOF if [ $n_pods -eq 0 ]; then local pods_per_gb=0 else - local pods_per_gb=$(bc -l <<< "scale=2; ($total_mem_used/1024) / $n_pods") + local pods_per_gb=$(printf "%0f" $(bc -l <<< "scale=2; ($total_mem_used/1024) / $n_pods")) fi local mem_json="$(cat << EOF "memory": {