From 20aad64409204110962f5fad76212cfd37cc0635 Mon Sep 17 00:00:00 2001 From: Radhika Pai Date: Wed, 11 Mar 2020 15:49:40 -0500 Subject: [PATCH] [Update] Grafana: add home dashboard script Adding a loop to wait for the grafana dashboard to be up and contain the OSH Home dashboard before running the script. This should resolve the job completing before the OSH Home dashboard is in the grafana pod. Change-Id: I7ab20fad3ce7f7216e2b2679d863f02f97ef1ff4 --- .../templates/bin/_add-home-dashboard.sh.tpl | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/grafana/templates/bin/_add-home-dashboard.sh.tpl b/grafana/templates/bin/_add-home-dashboard.sh.tpl index a4ce099cb..d7bfe9b85 100644 --- a/grafana/templates/bin/_add-home-dashboard.sh.tpl +++ b/grafana/templates/bin/_add-home-dashboard.sh.tpl @@ -15,15 +15,25 @@ # under the License. set -xe +home_dashboard_id=[] +counter=0 -home_dashboard_id=$(curl -K- <<< "--user ${GF_SECURITY_ADMIN_USER}:${GF_SECURITY_ADMIN_PASSWORD}" -XGET "${GRAFANA_URI}api/search?query=OSH%20Home" | sed 's/\[{.id":"*\([0-9a-zA-Z]*\)*,*.*}[]]/\1/') +#Loop until home_dashboard_id value is not null. If null sleep for 15s. Retry for 5 times. +until [ $home_dashboard_id != "[]" ] +do + echo "Waiting for Home Dashboard to load in Grafana" + sleep 15s + home_dashboard_id=$(curl -K- <<< "--user ${GF_SECURITY_ADMIN_USER}:${GF_SECURITY_ADMIN_PASSWORD}" -XGET "${GRAFANA_URI}api/search?query=OSH%20Home" | sed 's/\[{.id":"*\([0-9a-zA-Z]*\)*,*.*}[]]/\1/') + echo $home_dashboard_id + if [ $counter -ge 5 ]; then + echo "Exiting.. Exceeded the wait." + break + fi + counter=$((counter + 1)); +done -echo $home_dashboard_id - -if [ $home_dashboard_id == "[]" ] +if [ $home_dashboard_id != "[]" ] then - echo "Failed. Verify Home Dashboard is present in Grafana" -else #Set Customized Home Dashboard id as Org preference curl -K- <<< "--user ${GF_SECURITY_ADMIN_USER}:${GF_SECURITY_ADMIN_PASSWORD}" \ -XPUT "${GRAFANA_URI}api/org/preferences" -H "Content-Type: application/json" \