From 263aa363e0ccdde6776b2dcf13afd333bac71703 Mon Sep 17 00:00:00 2001
From: Joe Gordon <joe.gordon0@gmail.com>
Date: Thu, 30 Jan 2014 13:51:34 -0800
Subject: [PATCH] Generate two elastic-recheck-graph json files all, and gate
 only

We want to display the hits for all queues and for just the gate queue.
A parameter was added to elastic-recheck-graph to support this, and a
second patch updates the web page to give the gate queue only option.
This patch updates the usage of elastic-recheck-gate.

Related elastic-recheck patchs:
 * I9217a2ceedf86ffe04851084df78238384fccd51
 * I23ed8d945c9517221622e1ca215c80539bb07bbd

Change-Id: Iac51aeaf152f50f8b9a064cd249b0920bef824df
---
 modules/elastic_recheck/manifests/cron.pp | 17 ++++++++++++++---
 modules/elastic_recheck/manifests/init.pp | 17 ++++++++++++++---
 2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/modules/elastic_recheck/manifests/cron.pp b/modules/elastic_recheck/manifests/cron.pp
index aa1e8a7c3d..137d5015d2 100644
--- a/modules/elastic_recheck/manifests/cron.pp
+++ b/modules/elastic_recheck/manifests/cron.pp
@@ -19,18 +19,29 @@
 
 class elastic_recheck::cron () {
   $er_state_path = $::elastic_recheck::recheck_state_dir
-  $graph_cmd = $::elastic_recheck::graph_cmd
+  $graph_all_cmd = $::elastic_recheck::graph_all_cmd
+  $graph_gate_cmd = $::elastic_recheck::graph_gate_cmd
   $uncat_cmd = $::elastic_recheck::uncat_cmd
 
-  cron { 'elastic-recheck':
+  cron { 'elastic-recheck-all':
     user        => 'recheck',
     minute      => '*/15',
     hour        => '*',
-    command     => "cd ${er_state_path} && er_safe_run.sh ${graph_cmd}",
+    command     => "cd ${er_state_path} && er_safe_run.sh ${graph_all_cmd}",
     environment => 'PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin',
     require     => Class['elastic_recheck']
   }
 
+  cron { 'elastic-recheck-gate':
+    user        => 'recheck',
+    minute      => '*/15',
+    hour        => '*',
+    command     => "sleep $((RANDOM\%60+90)) && cd ${er_state_path} && er_safe_run.sh ${graph_gate_cmd}",
+    environment => 'PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin',
+    require     => Class['elastic_recheck']
+  }
+
+
   cron { 'elastic-recheck-uncat':
     user        => 'recheck',
     minute      => '59',
diff --git a/modules/elastic_recheck/manifests/init.pp b/modules/elastic_recheck/manifests/init.pp
index 6a2a820e9d..b17533147f 100644
--- a/modules/elastic_recheck/manifests/init.pp
+++ b/modules/elastic_recheck/manifests/init.pp
@@ -23,7 +23,8 @@ class elastic_recheck (
   # any commit. So we need to define commands in a way that
   # we can trigger an exec here, as well as on cron.
   $recheck_state_dir = '/var/lib/elastic-recheck'
-  $graph_cmd = 'elastic-recheck-graph /opt/elastic-recheck/queries -o graph-new.json && mv graph-new.json graph.json'
+  $graph_all_cmd = 'elastic-recheck-graph /opt/elastic-recheck/queries -o all-new.json && mv all-new.json all.json'
+  $graph_gate_cmd = 'elastic-recheck-graph /opt/elastic-recheck/queries -o gate-new.json -q gate && mv gate-new.json gate.json'
   $uncat_cmd = 'elastic-recheck-uncategorized -d /opt/elastic-recheck/queries -t /usr/local/share/elastic-recheck/templates -o uncategorized-new.html && mv uncategorized-new.html uncategorized.html'
 
   group { 'recheck':
@@ -45,8 +46,18 @@ class elastic_recheck (
     source   => 'https://git.openstack.org/openstack-infra/elastic-recheck',
   }
 
-  exec { 'run_er_graph':
-    command     => "er_safe_run.sh ${graph_cmd}",
+  exec { 'run_er_graph_all':
+    command     => "er_safe_run.sh ${graph_all_cmd}",
+    path        => '/usr/local/bin:/usr/bin:/bin/',
+    cwd         => $recheck_state_dir,
+    user        => 'recheck',
+    refreshonly => true,
+    require     => File['/usr/local/bin/er_safe_run.sh'],
+    subscribe   => Vcsrepo['/opt/elastic-recheck'],
+  }
+
+  exec { 'run_er_graph_gate_only':
+    command     => "er_safe_run.sh ${graph_gate_cmd}",
     path        => '/usr/local/bin:/usr/bin:/bin/',
     cwd         => $recheck_state_dir,
     user        => 'recheck',