Bad Floating Point Format in Cost File 58/63058/3
authorTim Johnson <tijohnson@linuxfoundation.org>
Thu, 6 Feb 2020 17:25:09 +0000 (09:25 -0800)
committerTim Johnson <tijohnson@linuxfoundation.org>
Thu, 6 Feb 2020 21:05:49 +0000 (13:05 -0800)
Update format for uptime, cost & stack_cost. Changed default value for
resource (Instance Type) to 'unknown'. Created script (format-csv) to
fix the formats of the existing cost files.

ISSUE: RELENG-2715
Change-Id: Ibd8464faa1ba3983bf1e8ef5cd484d2f24c26e31
Signed-off-by: Tim Johnson <tijohnson@linuxfoundation.org>
job-cost/format-csv [new file with mode: 0755]
shell/job-cost.sh
shell/scrape-job-cost.sh

diff --git a/job-cost/format-csv b/job-cost/format-csv
new file mode 100755 (executable)
index 0000000..4a6e114
--- /dev/null
@@ -0,0 +1,23 @@
+#! /bin/bash
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2019 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+
+set -euf
+
+# This script can be run on a cost file (.csv) to standardize the formats of the
+# uptime, cost & stack_cost fields.
+
+cost_file=$1
+
+while IFS="," read -r job_name build_number date resource uptime cost stack_cost; do
+    [[ $resource == "0" ]] && resource='unknown'
+    printf "%s,%s,%s,%s,%d,%.2f,%.2f\n" "$job_name" "$build_number" "$date" \
+           "$resource" "$uptime" "$cost" "$stack_cost"
+done < "$cost_file"
index 769b972..ee2f4a5 100644 (file)
@@ -65,7 +65,7 @@ if jq <<< "$json_block" > /dev/null 2>&1; then
 else
     echo "ERROR: Pricing API returned invalid json"
     cost=0
-    resource=0
+    resource='unknown'
 fi
 
 # Archive the cost date
@@ -77,6 +77,6 @@ echo "INFO: Archiving Costs"
 # This format is readable by spreadsheet and is easily sortable
 date=$(TZ=GMT date +'%Y-%m-%d %H:%M:%S')
 
-cat << EOF > "$WORKSPACE/archives/cost.csv"
-$JOB_NAME,$BUILD_NUMBER,$date,$resource,$uptime,$cost,$stack_cost
-EOF
+# Format the uptime, cost & stack_cost fields
+printf "%s,%s,%s,%s,%d,%.2f,%.2f\n" "$JOB_NAME" "$BUILD_NUMBER" "$date" \
+       "$resource" "$uptime" "$cost" "$stack_cost" > "$WORKSPACE/archives/cost.csv"
index 9bd5205..7a753a5 100755 (executable)
 #
 # Each cost file contains one or more CSV records in the following format:
 #
-#   JobName , BuildNumber , Date , InstanceType , Uptime , Cost1 , Cost2
+#   JobName , BuildNumber , Date , InstanceType , Uptime , Cost , StackCost
 #
 #   Date format: '%Y-%m-%d %H:%M:%S'
+#   Cost format: '%.2f' (1.29)
 #
 ##############################################################################
 #