Bug 1438415 Re-order mbsdiff hook to allow exit values r=catlee draft
authorSimon Fraser <sfraser@mozilla.com>
Thu, 15 Feb 2018 21:59:15 +0000
changeset 755900 241dd8046f9be02e3d86b5a5b6360ed0bca77110
parent 755833 994a8d6eccbcdc6106794705bd77e3ac5f031be2
push id99313
push usersfraser@mozilla.com
push dateThu, 15 Feb 2018 21:59:45 +0000
reviewerscatlee
bugs1438415
milestone60.0a1
Bug 1438415 Re-order mbsdiff hook to allow exit values r=catlee MozReview-Commit-ID: 9Z3DMyarcpt
taskcluster/docker/funsize-update-generator/scripts/mbsdiff_hook.sh
--- a/taskcluster/docker/funsize-update-generator/scripts/mbsdiff_hook.sh
+++ b/taskcluster/docker/funsize-update-generator/scripts/mbsdiff_hook.sh
@@ -7,23 +7,47 @@
 # This tool contains functions that are to be used to handle/enable funsize
 # Author: Mihai Tabara
 #
 
 HOOK=
 AWS_BUCKET_NAME=
 LOCAL_CACHE_DIR=
 
-S3_CACHE_HITS=0
-S3_CACHE_MISSES=0
-
 # Don't cache files smaller than this, as it's slower with S3
 # Bug 1437473
 CACHE_THRESHOLD=500000
 
+
+NAMESPACE='releng.releases.partials'
+if [ -e "${HOME}/.dogrc" ]
+then
+    METRIC_CMD="$(which dog)"
+else
+    METRIC_CMD="echo"
+fi
+METRIC_PARAMS="--type gauge --no_host"
+
+if [ -n "${BRANCH}" ]
+then
+    if [ -n "${TAGS}" ]; then TAGS="${TAGS},"; fi
+    TAGS="${TAGS}branch:${BRANCH}"
+fi
+if [ -n "${PLATFORM}" ]
+then
+    if [ -n "${TAGS}" ]; then TAGS="${TAGS},"; fi
+    TAGS="${TAGS}platform:${PLATFORM}"
+fi
+if [ -n "${TAGS}" ]
+then
+    # We want literal quotes
+    # shellcheck disable=SC2089
+    TAGS="--tags='${TAGS}'"
+fi
+
 getsha512(){
     openssl sha512 "${1}" | awk '{print $2}'
 }
 
 print_usage(){
     echo "$(basename "$0") [-S S3-BUCKET-NAME] [-c LOCAL-CACHE-DIR-PATH] [-g] [-u] PATH-FROM-URL PATH-TO-URL PATH-PATCH"
     echo "Script that saves/retrieves from cache presumptive patches as args"
     echo ""
@@ -87,29 +111,30 @@ get_patch(){
             return 0
         fi
     fi
     # If not in the local cache, we might find it remotely.
 
     if [ -n "${AWS_BUCKET_NAME}" ]; then
         BUCKET_PATH="s3://${AWS_BUCKET_NAME}${sha_from}/${sha_to}/${s3_filename}"
         if aws s3 ls "${BUCKET_PATH}"; then
-            ((S3_CACHE_HITS++))
+            # shellcheck disable=SC2086,SC2090
+            ${METRIC_CMD} metric post "${NAMESPACE}.s3_cache.hit" "${S3_CACHE_HITS}" ${METRIC_PARAMS} ${TAGS}
             echo "s3 cache hits now ${S3_CACHE_HITS}"
             if aws s3 cp "${BUCKET_PATH}" "${destination_file}"; then
                 echo "Successful retrieved ${destination_file} from s3://${AWS_BUCKET_NAME}"
                 return 0
             else
                 echo "Failed to retrieve ${destination_file} from s3://${AWS_BUCKET_NAME}"
                 return 1
             fi
         # Not found, fall through to default error
         else
-            ((S3_CACHE_MISSES++))
-            echo "s3 cache misses now ${S3_CACHE_MISSES}"
+            # shellcheck disable=SC2086,SC2090
+            ${METRIC_CMD} metric post "${NAMESPACE}.s3_cache.miss" "${S3_CACHE_MISSES}" ${METRIC_PARAMS} ${TAGS}
         fi
     fi
     return 1
 }
 
 OPTIND=1
 
 while getopts ":S:c:gu" option; do
@@ -150,40 +175,8 @@ while getopts ":S:c:gu" option; do
 done
 shift $((OPTIND-1))
 
 if [ "$HOOK" == "PRE" ]; then
     get_patch "$1" "$2" "$3"
 elif [ "$HOOK" == "POST" ]; then
     upload_patch "$1" "$2" "$3"
 fi
-
-
-NAMESPACE='releng.releases.partials'
-if [ -e "${HOME}/.dogrc" ]
-then
-    METRIC_CMD="$(which dog)"
-else
-    METRIC_CMD="echo"
-fi
-METRIC_PARAMS="--type gauge --no_host"
-
-if [ -n "${BRANCH}" ]
-then
-    if [ -n "${TAGS}" ]; then TAGS="${TAGS},"; fi
-    TAGS="${TAGS}branch:${BRANCH}"
-fi
-if [ -n "${PLATFORM}" ]
-then
-    if [ -n "${TAGS}" ]; then TAGS="${TAGS},"; fi
-    TAGS="${TAGS}platform:${PLATFORM}"
-fi
-if [ -n "${TAGS}" ]
-then
-    # We want literal quotes
-    # shellcheck disable=SC2089
-    TAGS="--tags='${TAGS}'"
-fi
-
-# shellcheck disable=SC2086,SC2090
-${METRIC_CMD} metric post "${NAMESPACE}.s3_cache.miss" "${S3_CACHE_MISSES}" ${METRIC_PARAMS} ${TAGS}
-# shellcheck disable=SC2086,SC2090
-${METRIC_CMD} metric post "${NAMESPACE}.s3_cache.hit" "${S3_CACHE_HITS}" ${METRIC_PARAMS} ${TAGS}