]> review.fuel-infra Code Review - puppet-modules/puppet-ceilometer.git/commitdiff
Support notification/polling full config by hiera
authorAndy Botting <andy@andybotting.com>
Thu, 30 Apr 2020 01:38:13 +0000 (11:38 +1000)
committerAndy Botting <andy@andybotting.com>
Mon, 11 May 2020 01:45:16 +0000 (11:45 +1000)
The existing YAML templates for pipeline, event_pipeline and
polling configurations aren't flexible enough to support more
complex setups.

This commit adds support for allowing the whole YAML config to be
defined in Hiera by adding some new class arguments.

Change-Id: If08d876d659871f02f3ccfd9f20ccb3605f98de1

manifests/agent/notification.pp
manifests/agent/polling.pp
releasenotes/notes/add-agent-notification-polling-config.yaml-7756bf89719cdbcf.yaml [new file with mode: 0644]
spec/classes/ceilometer_agent_notification_spec.rb
spec/classes/ceilometer_agent_polling_spec.rb

index 9514c4246e44fdb88ddff83e459b17929e62449e..032c1bea19214395f5393b128277563cf128d170 100644 (file)
 #   (Optional) Whether to manage event_pipeline.yaml
 #   Defaults to false
 #
+# [*event_pipeline_config*]
+#   (Optional) A hash of the event_pipeline.yaml configuration.
+#   This is used only if manage_event_pipeline is true.
+#   Defaults to undef
+#
 # [*event_pipeline_publishers*]
 #   (Optional) A list of publishers to put in event_pipeline.yaml
 #   Add 'notifier://?topic=alarm.all' to the list if you are using Aodh
 #   (Optional) Whether to manage pipeline.yaml
 #   Defaults to false
 #
+# [*pipeline_config*]
+#   (Optional) A hash of the pipeline.yaml configuration.
+#   This is used only if manage_pipeline is true.
+#   Defaults to undef
+#
 # [*pipeline_publishers*]
 #   (Optional) A list of publishers to put in pipeline.yaml.
 #   By default all the data is dispatched to gnocchi
@@ -83,8 +93,10 @@ class ceilometer::agent::notification (
   $package_ensure            = 'present',
   $manage_event_pipeline     = false,
   $event_pipeline_publishers = ['gnocchi://'],
+  $event_pipeline_config     = undef,
   $manage_pipeline           = false,
   $pipeline_publishers       = ['gnocchi://'],
+  $pipeline_config           = undef,
 ) {
 
   include ceilometer::deps
@@ -114,13 +126,19 @@ class ceilometer::agent::notification (
     tag        => 'ceilometer-service'
   }
 
-  if ($manage_event_pipeline) {
-    validate_legacy(Array, 'validate_array', $event_pipeline_publishers)
+  if $manage_event_pipeline {
+    if $event_pipeline_config {
+      validate_legacy(Hash, 'validate_hash', $event_pipeline_config)
+      $event_pipeline_content = to_yaml($event_pipeline_config)
+    } else {
+      validate_legacy(Array, 'validate_array', $event_pipeline_publishers)
+      $event_pipeline_content = template('ceilometer/event_pipeline.yaml.erb')
+    }
 
     file { 'event_pipeline':
       ensure                  => present,
       path                    => $::ceilometer::params::event_pipeline,
-      content                 => template('ceilometer/event_pipeline.yaml.erb'),
+      content                 => $event_pipeline_content,
       selinux_ignore_defaults => true,
       mode                    => '0640',
       owner                   => 'root',
@@ -129,13 +147,19 @@ class ceilometer::agent::notification (
     }
   }
 
-  if ($manage_pipeline) {
-    validate_legacy(Array, 'validate_array', $pipeline_publishers)
+  if $manage_pipeline {
+    if $pipeline_config {
+      validate_legacy(Hash, 'validate_hash', $pipeline_config)
+      $pipeline_content = to_yaml($pipeline_config)
+    } else {
+      validate_legacy(Array, 'validate_array', $pipeline_publishers)
+      $pipeline_content = template('ceilometer/pipeline.yaml.erb')
+    }
 
     file { 'pipeline':
       ensure                  => present,
       path                    => $::ceilometer::params::pipeline,
-      content                 => template('ceilometer/pipeline.yaml.erb'),
+      content                 => $pipeline_content,
       selinux_ignore_defaults => true,
       mode                    => '0640',
       owner                   => 'root',
index 9f1f24085753208ba29f474bbce56d5c187b42c7..804fec9c3dfe2d15af27e1cefadfd7a128b1c882 100644 (file)
 #   the polling.yaml file, used only if manage_polling is true.
 #   Defaults to $::ceilometer::params::polling_meters
 #
+# [*polling_config*]
+#   (Optional) A hash of the polling.yaml configuration.
+#   This is used only if manage_polling is true.
+#   Defaults to undef
+#
 class ceilometer::agent::polling (
   $manage_service            = true,
   $enabled                   = true,
@@ -65,6 +70,7 @@ class ceilometer::agent::polling (
   $manage_polling            = false,
   $polling_interval          = 600,
   $polling_meters            = $::ceilometer::params::polling_meters,
+  $polling_config            = undef,
 ) inherits ceilometer {
 
   include ceilometer::deps
@@ -145,10 +151,17 @@ class ceilometer::agent::polling (
   }
 
   if $manage_polling {
+    if $polling_config {
+      validate_legacy(Hash, 'validate_hash', $polling_config)
+      $polling_content = to_yaml($polling_config)
+    } else {
+      $polling_content = template('ceilometer/polling.yaml.erb')
+    }
+
     file { 'polling':
       ensure                  => present,
       path                    => $::ceilometer::params::polling,
-      content                 => template('ceilometer/polling.yaml.erb'),
+      content                 => $polling_content,
       selinux_ignore_defaults => true,
       tag                     => 'ceilometer-yamls',
     }
diff --git a/releasenotes/notes/add-agent-notification-polling-config.yaml-7756bf89719cdbcf.yaml b/releasenotes/notes/add-agent-notification-polling-config.yaml-7756bf89719cdbcf.yaml
new file mode 100644 (file)
index 0000000..b745a5d
--- /dev/null
@@ -0,0 +1,5 @@
+---
+features:
+  - Add pipeline_config, event_pipeline_config and polling_config agent
+    parameters to support setting the whole configuration for these file
+    by hashes.
index 83a5e4dfe97652ca1bd2ce42fcba2548a5086d2a..b47a65b7c81a20e34b8cd840efb9a03856d2e6e6 100644 (file)
@@ -165,6 +165,42 @@ describe 'ceilometer::agent::notification' do
       ])}
     end
 
+    context 'with event_pipeline and custom config' do
+      before { params.merge!(
+        :manage_event_pipeline => true,
+        :event_pipeline_config => {
+          'sources' => [
+            'name'   => 'my_event_source',
+            'events' => ['*'],
+            'sinks'  => ['my_event_sink'],
+          ],
+          'sinks'   => [
+            'name'         => 'my_event_sink',
+            'transformers' => [],
+            'triggers'     => [],
+            'publishers'   => ['gnocchi://'],
+          ],
+        }
+      )}
+
+      it { should contain_file('event_pipeline').with(
+        :content                 => '---
+sources:
+- name: my_event_source
+  events:
+  - "*"
+  sinks:
+  - my_event_sink
+sinks:
+- name: my_event_sink
+  transformers: []
+  triggers: []
+  publishers:
+  - gnocchi://
+',
+      )}
+    end
+
     context "with event_pipeline management disabled" do
       before { params.merge!(
         :manage_event_pipeline => false
@@ -185,6 +221,40 @@ describe 'ceilometer::agent::notification' do
       ) }
     end
 
+    context 'with pipeline and custom config' do
+      before { params.merge!(
+        :manage_pipeline => true,
+        :pipeline_config => {
+          'sources' => [
+            'name'   => 'my_source',
+            'meters' => ['*'],
+            'sinks'  => ['my_sink'],
+          ],
+          'sinks'   => [
+            'name'         => 'my_sink',
+            'transformers' => [],
+            'publishers'   => ['gnocchi://'],
+          ],
+        }
+      )}
+
+      it { should contain_file('pipeline').with(
+        :content                 => '---
+sources:
+- name: my_source
+  meters:
+  - "*"
+  sinks:
+  - my_sink
+sinks:
+- name: my_sink
+  transformers: []
+  publishers:
+  - gnocchi://
+',
+      )}
+    end
+
     context "with pipeline management disabled" do
       before { params.merge!(
         :manage_pipeline => false
index 4e2575540fbaa672c1d2b072118f618c1c359bb0..e2e2a827187a1513e29913a497416b874ba33fcc 100644 (file)
@@ -139,7 +139,7 @@ sources:
       )}
     end
 
-    context 'with polling and custom config' do
+    context 'with polling and basic custom settings' do
       before do
         params.merge!( :manage_polling   => true,
                        :polling_interval => 30,
@@ -162,6 +162,35 @@ sources:
       )}
     end
 
+    context 'with polling and custom config' do
+      before do
+        params.merge!( :manage_polling => true,
+                       :polling_config => {
+          'sources' => [
+            'name'     => 'my_pollsters',
+            'interval' => 60,
+            'meters'   => [
+              'meterfoo',
+              'meterbar',
+            ],
+          ],
+        } )
+      end
+
+      it { should contain_file('polling').with(
+        :ensure  => 'present',
+        :path    => '/etc/ceilometer/polling.yaml',
+        :content                 => '---
+sources:
+- name: my_pollsters
+  interval: 60
+  meters:
+  - meterfoo
+  - meterbar
+',
+      )}
+    end
+
     context 'with polling management disabled' do
       before do
         params.merge!( :manage_polling => false )