From 440255724063cda8984962c6867ee5fdb9cf20ad Mon Sep 17 00:00:00 2001 From: hujambo-dunia Date: Sat, 15 Jul 2023 10:03:37 +1000 Subject: [PATCH 1/2] Initial commit; scaffolding --- parts/03-query-utils.sh | 11 +++++++++++ parts/22-query.sh | 24 +++++++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/parts/03-query-utils.sh b/parts/03-query-utils.sh index aca74ed..30f3fc4 100644 --- a/parts/03-query-utils.sh +++ b/parts/03-query-utils.sh @@ -159,3 +159,14 @@ summary_statistics() { get_user_filter() { echo "(galaxy_user.email = '$1' or galaxy_user.username = '$1' or galaxy_user.id = CAST(REGEXP_REPLACE('$1', '.*\D+.*', '-1') AS INTEGER))" } + +function create_sql_parameters_select() { + #TODO do need "function" and "return" ? + #TODO insert cut CLI here + return ""; +} + +function create_sql_parameters_where() { + #TODO insert cut CLI here + return ""; +} diff --git a/parts/22-query.sh b/parts/22-query.sh index 6938815..044e1fb 100644 --- a/parts/22-query.sh +++ b/parts/22-query.sh @@ -4723,7 +4723,17 @@ query_potentially-duplicated-reclaimable-space() { ##? EOF } -query_tpt-tool-cpu() { ##? [--startyear=] [--endyear=] [--formula=avg]: Start year is required. Formula returns sum if blank. +query_tpt-tool-cpu() { ##? [--startyear=] [--endyear=] [--formula=avg] [--arrSelect1={type};{hypothesis};{conclusion}] [--arrSelect2=...] [--arrWhere1={hypothesis};{conclusion}] [--arrWhere2=...]: Start year is required. Formula returns sum if blank. arrSelect maximum inputs is 5. arrWhere maximum inputs is 5. + +# Example arguments: +# --startyear=2022 +# --endyear=2024 +# --formula=sum +# --arrSelect1="when;destination_id LIKE 'stampede%';metric_value" +# --arrSelect2="else; null;metric_value / 1000000000" +# --arrWhere1="destination_id LIKE 'stampede%';metric_name = 'runtime_seconds'" +# --arrWhere2="metric_name = 'cpuacct.usage';null" + meta <<-EOF AUTHORS: hujambo-dunia ADDED: 20 @@ -4760,16 +4770,24 @@ query_tpt-tool-cpu() { ##? [--startyear=] [--endyear=] [--formula=av sql_formula="SUM" fi + if [[ -n $arg_arrSelect1 ]]; then + sql_select=$(create_sql_parameters_select "$arg_arrSelect1" "$arg_arrSelect2" "$arg_arrSelect3" "$arg_arrSelect4" "$arg_arrSelect5") + fi + + if [[ -n $arg_arrWhere1 ]]; then + sql_where=$(create_sql_parameters_where "$arg_arrWhere1" "$arg_arrWhere2" "$arg_arrWhere3" "$arg_arrWhere4" "$arg_arrWhere5") + fi + read -r -d '' QUERY <<-EOF WITH cpu_usage AS ( SELECT DISTINCT job_id, destination_id, - metric_value / 1000000000 AS cpu_usage_seconds + $sql_select cpu_usage_seconds FROM job_metric_numeric WHERE - metric_name = 'cpuacct.usage' + $sql_where ) SELECT job.tool_id, From 70c7c5aa83cb450d2a682887739643d7d07853b1 Mon Sep 17 00:00:00 2001 From: hujambo-dunia Date: Sat, 15 Jul 2023 10:43:07 +1000 Subject: [PATCH 2/2] Added new parameter to allow user to modify CPU calculation based on server processor/name --- parts/03-query-utils.sh | 73 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 6 deletions(-) diff --git a/parts/03-query-utils.sh b/parts/03-query-utils.sh index 30f3fc4..52eb3dc 100644 --- a/parts/03-query-utils.sh +++ b/parts/03-query-utils.sh @@ -160,13 +160,74 @@ get_user_filter() { echo "(galaxy_user.email = '$1' or galaxy_user.username = '$1' or galaxy_user.id = CAST(REGEXP_REPLACE('$1', '.*\D+.*', '-1') AS INTEGER))" } -function create_sql_parameters_select() { - #TODO do need "function" and "return" ? - #TODO insert cut CLI here - return ""; +function create_sql_parameters_select() { + local strSelect = "" + + if [[ -n $arg_arrSelect1 ]]; then + if [[ $(echo "$arg_arrSelect1" | cut -d';' -f1) == "when" ]]; then + strSelect+=" WHEN" $(echo "$arg_arrSelect1" | cut -d';' -f2) "THEN" $(echo "$arg_arrSelect1" | cut -d';' -f3) + else + strSelect+="ELSE" $(echo "$arg_arrSelect1" | cut -d';' -f3) + fi + if [[ $(echo "$arg_arrSelect2" | cut -d';' -f1) == "when" ]]; then + strSelect+=" WHEN" $(echo "$arg_arrSelect2" | cut -d';' -f2) "THEN" $(echo "$arg_arrSelect2" | cut -d';' -f3) + else + strSelect+=" ELSE" $(echo "$arg_arrSelect2" | cut -d';' -f3) + fi + if [[ $(echo "$arg_arrSelect3" | cut -d';' -f1) == "when" ]]; then + strSelect+=" WHEN" $(echo "$arg_arrSelect3" | cut -d';' -f2) "THEN" $(echo "$arg_arrSelect3" | cut -d';' -f3) + else + strSelect+=" ELSE" $(echo "$arg_arrSelect3" | cut -d';' -f3) + fi + if [[ $(echo "$arg_arrSelect4" | cut -d';' -f1) == "when" ]]; then + strSelect+=" WHEN" $(echo "$arg_arrSelect4" | cut -d';' -f2) "THEN" $(echo "$arg_arrSelect4" | cut -d';' -f3) + else + strSelect+=" ELSE" $(echo "$arg_arrSelect4" | cut -d';' -f3) + fi + if [[ $(echo "$arg_arrSelect5" | cut -d';' -f1) == "when" ]]; then + strSelect+=" WHEN" $(echo "$arg_arrSelect5" | cut -d';' -f2) "THEN" $(echo "$arg_arrSelect5" | cut -d';' -f3) + else + strSelect+=" ELSE" $(echo "$arg_arrSelect5" | cut -d';' -f3) + fi + + strSelect="CASE" $strSelect "END" + fi + + return $strSelect; } function create_sql_parameters_where() { - #TODO insert cut CLI here - return ""; + local strWhere = "" + + if [[ -n $arg_arrWhere1 ]]; then + if [[ $(echo "$arg_arrWhere1" | cut -d';' -f1) == "when" ]]; then + strWhere+=" WHEN" $(echo "$arg_arrWhere1" | cut -d';' -f2) "THEN" $(echo "$arg_arrWhere1" | cut -d';' -f3) + else + strWhere+="ELSE" $(echo "$arg_arrWhere1" | cut -d';' -f3) + fi + if [[ $(echo "$arg_arrWhere2" | cut -d';' -f1) == "when" ]]; then + strWhere+=" WHEN" $(echo "$arg_arrWhere2" | cut -d';' -f2) "THEN" $(echo "$arg_arrWhere2" | cut -d';' -f3) + else + strWhere+=" ELSE" $(echo "$arg_arrWhere2" | cut -d';' -f3) + fi + if [[ $(echo "$arg_arrWhere3" | cut -d';' -f1) == "when" ]]; then + strWhere+=" WHEN" $(echo "$arg_arrWhere3" | cut -d';' -f2) "THEN" $(echo "$arg_arrWhere3" | cut -d';' -f3) + else + strWhere+=" ELSE" $(echo "$arg_arrWhere3" | cut -d';' -f3) + fi + if [[ $(echo "$arg_arrWhere4" | cut -d';' -f1) == "when" ]]; then + strWhere+=" WHEN" $(echo "$arg_arrWhere4" | cut -d';' -f2) "THEN" $(echo "$arg_arrWhere4" | cut -d';' -f3) + else + strWhere+=" ELSE" $(echo "$arg_arrWhere4" | cut -d';' -f3) + fi + if [[ $(echo "$arg_arrWhere5" | cut -d';' -f1) == "when" ]]; then + strWhere+=" WHEN" $(echo "$arg_arrWhere5" | cut -d';' -f2) "THEN" $(echo "$arg_arrWhere5" | cut -d';' -f3) + else + strWhere+=" ELSE" $(echo "$arg_arrWhere5" | cut -d';' -f3) + fi + + strWhere="CASE" $strWhere "END" + fi + + return $strWhere; }