Skip to content

Commit

Permalink
Fixes cost and detailed cost queries for new billing setup as of …
Browse files Browse the repository at this point in the history
…2022 Aug 11 (#219)

* Updated `_PARTITIONTIME` to `partition_time` as per SADA billing changes.
* Fixing parsing error in `cost-detailed` function.
  • Loading branch information
jonn-smith authored Aug 19, 2022
1 parent e119c23 commit ad30776
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cromshell
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,7 @@ function cost()
local tmp_cost_file=$( makeTemp )

# Get the cost from Big Query:
bq query --use_legacy_sql=false "SELECT sum(cost) FROM \`${COST_TABLE}\`, UNNEST(labels) WHERE value = \"cromwell-${id}\" AND _PARTITIONDATE BETWEEN \"${START_DATE}\" AND \"${END_DATE}\";" > ${tmp_cost_file}
bq query --use_legacy_sql=false "SELECT sum(cost) FROM \`${COST_TABLE}\`, UNNEST(labels) WHERE value = \"cromwell-${id}\" AND partition_time BETWEEN \"${START_DATE}\" AND \"${END_DATE}\";" > ${tmp_cost_file}
r=$?

# Display the cost:
Expand Down Expand Up @@ -1626,14 +1626,14 @@ function cost-detailed()
AND task.key LIKE \"wdl-task-name\"
AND wfid.key LIKE \"cromwell-workflow-id\"
AND wfid.value like \"%${id}\"
AND _PARTITIONDATE BETWEEN \"${START_DATE}\" AND \"${END_DATE}\"
AND partition_time BETWEEN \"${START_DATE}\" AND \"${END_DATE}\"
GROUP BY 1,2,3
ORDER BY 4 DESC
;" | tail -n+4 | grep -v '^+' | tr -d '|' | awk 'BEGIN{OFS="\t"}{print $(NF-1), $NF}' | sort > ${tmp_cost_file}

r=$?

local total_cost=$(awk '{print $2}' ${tmp_cost_file} | tr '\n' '+' | sed 's#$#0#' | bc)
local total_cost=$(awk '{print $2}' ${tmp_cost_file} | tr '\n' '~' | sed -e 's#$#0#' -e 's@~@ + @g' -e 's@^@print(@' -e 's@$@)@' | python)
local total_cost=$(echo "scale=2;${total_cost}/1" | bc)

local tmpf2=$(makeTemp)
Expand Down

0 comments on commit ad30776

Please sign in to comment.