Filippo Giunchedi has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/199857

Change subject: scap: improve deploy2graphite
......................................................................

scap: improve deploy2graphite

mostly cleaner/saner shell

Bug: T1387
Change-Id: Ice7e95f963b78386189ada37ba88838735fb82d3
---
M modules/scap/files/deploy2graphite
1 file changed, 33 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/57/199857/1

diff --git a/modules/scap/files/deploy2graphite 
b/modules/scap/files/deploy2graphite
index 4dead4a..9895b76 100755
--- a/modules/scap/files/deploy2graphite
+++ b/modules/scap/files/deploy2graphite
@@ -1,28 +1,41 @@
-#! /bin/bash
+#!/bin/bash
+
+set -e
+set -u
 
 . /usr/local/lib/mw-deployment-vars.sh
 
+me=$(readlink -f "$0")
+deploy_type=${1:-}
+deploy_duration=${2:-}
+dry_run=${DOLOGMSGNOLOG:+no}
+
 usage() {
-       echo "Usage: $0 deploy_type [deploy_duration_seconds]"
-       echo "$0 will log an entry at graphite.wikimedia.org indicating that a"
-       echo " deploy event of the type indicated has occurred."
-       echo " Expected deploy events include sync-common, sync-file, scap, 
etc."
-       echo " These messages can be suppressed by setting an environment 
variable $DOLOGMSGNOLOG."
-       echo ""
-       echo "  IF YOU'RE RUNNING THIS BY HAND, PLEASE STOP."
-       echo ""
-       exit
+    echo "Usage: $me deploy_type [deploy_duration_seconds]"
+    echo "$me will log an entry at graphite.wikimedia.org indicating that a"
+    echo " deploy event of the type indicated has occurred."
+    echo " Expected deploy events include sync-common, sync-file, scap, etc."
+    echo " These messages can be suppressed by setting an environment variable 
\$DOLOGMSGNOLOG."
+    echo ""
+    echo "  IF YOU'RE RUNNING THIS BY HAND, PLEASE STOP."
+    echo ""
+    exit
 }
 
-[ "${1/-h}" != "$1" ] && usage
+statsd_send() {
+    echo "$1" | nc -w1 -q0 -u $MW_STATSD_HOST $MW_STATSD_PORT
+}
 
-if [ -z $DOLOGMSGNOLOG ]; then
-       if [ "$1" ] ; then
-               utime="$(date +%s)"
-               echo "deploy.${1}:1|c" | nc -w1 -q0 -u $MW_STATSD_HOST 
$MW_STATSD_PORT || /bin/true
-               echo "deploy.all:1|c" | nc -w1 -q0 -u $MW_STATSD_HOST 
$MW_STATSD_PORT || /bin/true
-               test -n "$2" && echo "deploy.${1}.timing:${2}000|ms" | nc -w1 
-q0 -u $MW_STATSD_HOST $MW_STATSD_PORT || /bin/true
-       else
-               usage
-       fi
+if [ "$deploy_type" = "-h" ] || [ "$deploy_type" = "" ]; then
+    usage
+fi
+
+if [ "$dry_run" != "no" ]; then
+    exit 0
+fi
+
+statsd_send "deploy.${deploy_type}:1|c" || true
+statsd_send "deploy.all:1|c" || true
+if [ -n "$deploy_duration" ]; then
+    statsd_send "deploy.${deploy_type}.timing:${deploy_duration}000|ms" || true
 fi

-- 
To view, visit https://gerrit.wikimedia.org/r/199857
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ice7e95f963b78386189ada37ba88838735fb82d3
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Filippo Giunchedi <fgiunch...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to