From 346894e2ef914f3918079c48fe80faad9f7b6115 Mon Sep 17 00:00:00 2001
From: Glauco Oliveira <gvinici@thoughtworks.com>
Date: Thu, 19 Nov 2015 11:12:15 -0200
Subject: [PATCH] Update default api configurations

OpenStack Health api has a new functionality that allows users to
retrieve the grouping keys used on the dashboard page.

A few of them simply don't make sense for the users, since they
are too granular.

This commit includes a new default configuration that will ignore
these keys. In case you are interested on how I come up with these keys,
please check this patch: https://review.openstack.org/#/c/240453/

Change-Id: Ibe591d9af94c1cd8d5c1d4956c1c82b4a764b5b7
---
 manifests/api.pp                    | 18 ++++++++++++++++++
 spec/acceptance/api_spec.rb         |  4 ++++
 templates/openstack-health.conf.erb |  6 ++++++
 3 files changed, 28 insertions(+)

diff --git a/manifests/api.pp b/manifests/api.pp
index 86f67b3..9c40193 100644
--- a/manifests/api.pp
+++ b/manifests/api.pp
@@ -14,10 +14,28 @@ class openstack_health::api(
   $server_admin = "webmaster@${::fqdn}",
   $vhost_name = 'localhost',
   $vhost_port = 5000,
+  $ignored_run_metadata_keys = undef,
 ) {
 
   include ::httpd::mod::wsgi
 
+  $default_ignored_run_metadata_keys = ['build_change', 'build_node',
+                                        'build_patchset', 'build_ref',
+                                        'build_short_uuid', 'build_uuid',
+                                        'build_zuul_url', 'filename']
+
+  if $ignored_run_metadata_keys {
+    # In case it was defined, ensure the value provided is an array
+    if is_array($ignored_run_metadata_keys) {
+      $ignored_keys = $ignored_run_metadata_keys
+    } else {
+      fail('$ignored_run_metadata_keys parameter should be an array of strings')
+    }
+  } else {
+    # In case it was not defined, use the default value
+    $ignored_keys = $default_ignored_run_metadata_keys
+  }
+
   $api_dir = "${source_dir}/openstack_health"
   $virtualenv_dir = "${source_dir}/.venv"
 
diff --git a/spec/acceptance/api_spec.rb b/spec/acceptance/api_spec.rb
index f111799..f893b0f 100644
--- a/spec/acceptance/api_spec.rb
+++ b/spec/acceptance/api_spec.rb
@@ -43,6 +43,10 @@ describe 'puppet-openstack_health::api manifest', :if => ['debian', 'ubuntu'].in
       it { should be_file }
       it { should be_owned_by 'openstack_health' }
       it { should be_grouped_into 'openstack_health' }
+      its(:content) { should contain 'db_uri' }
+      its(:content) { should contain 'ignored_run_metadata_keys' }
+      its(:content) { should contain 'build_change' }
+      its(:content) { should contain 'build_zuul_url' }
     end
   end
 
diff --git a/templates/openstack-health.conf.erb b/templates/openstack-health.conf.erb
index c84d971..5eca1ae 100644
--- a/templates/openstack-health.conf.erb
+++ b/templates/openstack-health.conf.erb
@@ -1,2 +1,8 @@
 [default]
 db_uri = <%= scope.lookupvar("openstack_health::api::db_uri") %>
+<% if @ignored_keys.length > 0 -%>
+ignored_run_metadata_keys =
+  <% @ignored_keys.each do |ignored_key| -%>
+    <%= ignored_key %>
+  <% end -%>
+<% end -%>