From 5d2204c2904340e8f090273e8e91f4aefda78e21 Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Sun, 19 Aug 2018 03:11:58 +0200 Subject: [PATCH] don't use pupetlabs-hocon for metrics.conf --- .fixtures.yml | 17 +++--- manifests/server/puppetserver.pp | 34 +---------- metadata.json | 4 -- .../puppet_server_puppetserver_spec.rb | 29 +++------- .../puppetserver/conf.d/metrics.conf.erb | 58 +++++++++++++++++++ 5 files changed, 75 insertions(+), 67 deletions(-) create mode 100644 templates/server/puppetserver/conf.d/metrics.conf.erb diff --git a/.fixtures.yml b/.fixtures.yml index 36536e3e..2a778ac5 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,14 +1,13 @@ fixtures: repositories: - apache: 'https://github.com/puppetlabs/puppetlabs-apache.git' - concat: 'https://github.com/puppetlabs/puppetlabs-concat.git' - extlib: 'https://github.com/voxpupuli/puppet-extlib.git' - foreman: 'https://github.com/theforeman/puppet-foreman.git' - git: 'https://github.com/theforeman/puppet-git.git' - hocon: 'https://github.com/puppetlabs/puppetlabs-hocon.git' - inifile: 'https://github.com/puppetlabs/puppetlabs-inifile.git' - puppetdb: 'https://github.com/puppetlabs/puppetlabs-puppetdb.git' - stdlib: 'https://github.com/puppetlabs/puppetlabs-stdlib.git' + apache: 'https://github.com/puppetlabs/puppetlabs-apache.git' + concat: 'https://github.com/puppetlabs/puppetlabs-concat.git' + extlib: 'https://github.com/voxpupuli/puppet-extlib.git' + foreman: 'https://github.com/theforeman/puppet-foreman.git' + git: 'https://github.com/theforeman/puppet-git.git' + inifile: 'https://github.com/puppetlabs/puppetlabs-inifile.git' + puppetdb: 'https://github.com/puppetlabs/puppetlabs-puppetdb.git' + stdlib: 'https://github.com/puppetlabs/puppetlabs-stdlib.git' symlinks: puppet: "#{source_dir}" diff --git a/manifests/server/puppetserver.pp b/manifests/server/puppetserver.pp index e51bf470..e52a9099 100644 --- a/manifests/server/puppetserver.pp +++ b/manifests/server/puppetserver.pp @@ -300,39 +300,7 @@ file { $metrics_conf: ensure => $metrics_conf_ensure, - } - - $metrics_general_settings = { - 'metrics.server-id' => $metrics_server_id, - 'metrics.registries.puppetserver.reporters.jmx.enabled' => $metrics_jmx_enable, - 'metrics.registries.puppetserver.reporters.graphite.enabled' => $metrics_graphite_enable, - 'metrics.reporters.graphite.host' => $metrics_graphite_host, - 'metrics.reporters.graphite.port' => $metrics_graphite_port, - 'metrics.reporters.graphite.update-interval-seconds' => $metrics_graphite_interval, - } - - $metrics_general_settings.each |$setting, $value| { - hocon_setting { $setting: - ensure => present, - path => $metrics_conf, - setting => $setting, - value => $value, - require => File[$metrics_conf], - } - } - - $metrics_allowed_settings = $metrics_allowed ? { - undef => absent, - default => present, - } - - hocon_setting { 'metrics.registries.puppetserver.metrics-allowed': - ensure => $metrics_allowed_settings, - path => $metrics_conf, - setting => 'metrics.registries.puppetserver.metrics-allowed', - value => $metrics_allowed, - type => 'array', - require => File[$metrics_conf], + content => template('puppet/server/puppetserver/conf.d/metrics.conf.erb'), } } } diff --git a/metadata.json b/metadata.json index fe531d1c..0378d537 100644 --- a/metadata.json +++ b/metadata.json @@ -23,10 +23,6 @@ "name": "puppetlabs/concat", "version_requirement": ">= 1.0.0 < 5.0.0" }, - { - "name": "puppetlabs/hocon", - "version_requirement": ">= 1.0.0 < 2.0.0" - }, { "name": "puppetlabs/stdlib", "version_requirement": ">= 4.13.0 < 5.0.0" diff --git a/spec/classes/puppet_server_puppetserver_spec.rb b/spec/classes/puppet_server_puppetserver_spec.rb index 7b33e057..735895e1 100644 --- a/spec/classes/puppet_server_puppetserver_spec.rb +++ b/spec/classes/puppet_server_puppetserver_spec.rb @@ -568,28 +568,15 @@ with_content(%r{^ # Whether to enable http-client metrics; defaults to 'true'.\n metrics-enabled: true$(.*)}). with_content(%r{^profiler: \{\n # enable or disable profiling for the Ruby code;\n enabled: true}) } - it { should contain_file('/etc/custom/puppetserver/conf.d/metrics.conf').with_ensure('file') } it { - should contain_hocon_setting('metrics.server-id'). - with_path('/etc/custom/puppetserver/conf.d/metrics.conf'). - with_setting('metrics.server-id'). - with_value('puppetserver.example.com'). - with_ensure('present') - } - it { - should contain_hocon_setting('metrics.reporters.graphite.host'). - with_path('/etc/custom/puppetserver/conf.d/metrics.conf'). - with_setting('metrics.reporters.graphite.host'). - with_value('graphitehost.example.com'). - with_ensure('present') - } - it { - should contain_hocon_setting('metrics.registries.puppetserver.metrics-allowed'). - with_path('/etc/custom/puppetserver/conf.d/metrics.conf'). - with_setting('metrics.registries.puppetserver.metrics-allowed'). - with_value(['single.element.array']). - with_type('array'). - with_ensure('present') + should contain_file('/etc/custom/puppetserver/conf.d/metrics.conf'). + with_content(%r{^( *)metrics-allowed: \[\n( *)"single.element.array",\n( *)\]}). + with_content(%r{^( *)server-id: "puppetserver.example.com"}). + with_content(%r{^( *)jmx: \{\n( *)enabled: true}). + with_content(%r{^( *)graphite: \{\n( *)enabled: true}). + with_content(%r{^( *)host: "graphitehost.example.com"}). + with_content(%r{^( *)port: 2003}). + with_content(%r{^( *)update-interval-seconds: 5}) } end diff --git a/templates/server/puppetserver/conf.d/metrics.conf.erb b/templates/server/puppetserver/conf.d/metrics.conf.erb new file mode 100644 index 00000000..60fc3d3b --- /dev/null +++ b/templates/server/puppetserver/conf.d/metrics.conf.erb @@ -0,0 +1,58 @@ +# settings related to metrics +metrics: { + # a server id that will be used as part of the namespace for metrics produced + # by this server + server-id: "<%= @metrics_server_id %>" + registries: { + puppetserver: { + # specify metrics to allow in addition to those in the default list +<% if @metrics_allowed -%> + metrics-allowed: [ +<%- @metrics_allowed.each do |allowed_host| -%> + "<%= allowed_host %>", +<%- end -%> + ] +<%- else -%>> + #metrics-allowed: ["compiler.compile.production"] +<% end -%> + reporters: { + # enable or disable JMX metrics reporter + jmx: { + enabled: <%= @metrics_jmx_enable %> + } + # enable or disable Graphite metrics reporter + graphite: { + enabled: <%= @metrics_graphite_enable %> + } + } + } + } + + # this section is used to configure settings for reporters that will send + # the metrics to various destinations for external viewing + reporters: { + graphite: { + # graphite host + host: "<%= @metrics_graphite_host %>" + # graphite metrics port + port: <%= @metrics_graphite_port %> + # how often to send metrics to graphite + update-interval-seconds: <%= @metrics_graphite_interval %> + } + } + metrics-webservice: { + jolokia: { + # Enable or disable the Jolokia-based metrics/v2 endpoint. + # Default is true. + # enabled: false + + # Configure any of the settings listed at: + # https://jolokia.org/reference/html/agents.html#war-agent-installation + servlet-init-params: { + # Specify a custom security policy: + # https://jolokia.org/reference/html/security.html + # policyLocation: "file:///etc/puppetlabs/puppetserver/jolokia-access.xml" + } + } + } +}