From 34c9b08438fd4314e0a5ffed414f367c282a700a Mon Sep 17 00:00:00 2001 From: Tim Johnson Date: Thu, 6 Feb 2020 09:25:09 -0800 Subject: [PATCH] Bad Floating Point Format in Cost File 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 --- job-cost/format-csv | 23 +++++++++++++++++++++++ shell/job-cost.sh | 8 ++++---- shell/scrape-job-cost.sh | 3 ++- 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100755 job-cost/format-csv diff --git a/job-cost/format-csv b/job-cost/format-csv new file mode 100755 index 00000000..4a6e1140 --- /dev/null +++ b/job-cost/format-csv @@ -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" diff --git a/shell/job-cost.sh b/shell/job-cost.sh index 769b972a..ee2f4a52 100644 --- a/shell/job-cost.sh +++ b/shell/job-cost.sh @@ -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" diff --git a/shell/scrape-job-cost.sh b/shell/scrape-job-cost.sh index 9bd5205e..7a753a51 100755 --- a/shell/scrape-job-cost.sh +++ b/shell/scrape-job-cost.sh @@ -20,9 +20,10 @@ # # 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) # ############################################################################## # -- 2.16.6