Skip to content

Commit

Permalink
Allow hiding of prom config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin Hooten committed May 21, 2020
1 parent 612b0db commit 4d0c546
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
1 change: 1 addition & 0 deletions data/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ prometheus::alertmanager::version: '0.18.0'
prometheus::alerts: {}
prometheus::config_dir: '/etc/prometheus'
prometheus::config_mode: '0640'
prometheus::config_show_diff: true
prometheus::config_template: 'prometheus/prometheus.yaml.erb'
prometheus::consul_exporter::consul_health_summary: true
prometheus::consul_exporter::consul_server: 'localhost:8500'
Expand Down
1 change: 1 addition & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@
group => $prometheus::server::group,
mode => $prometheus::server::config_mode,
notify => Class['prometheus::service_reload'],
show_diff => $prometheus::config_show_diff,
content => template($prometheus::server::config_template),
validate_cmd => "${prometheus::server::bin_dir}/promtool ${cfg_verify_cmd} %",
}
Expand Down
3 changes: 3 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@
# @param log_format
# --log.format=logfmt
# Output format of log messages. One of: [logfmt, json]
# @param config_show_diff
# Whether to show prometheus configuration file diff in the Puppet logs.
class prometheus (
String $user,
String $group,
Expand Down Expand Up @@ -291,6 +293,7 @@
Boolean $manage_group = true,
Boolean $purge_config_dir = true,
Boolean $manage_user = true,
Boolean $config_show_diff = true,
) {

case $arch {
Expand Down
54 changes: 43 additions & 11 deletions spec/classes/prometheus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,13 @@

it {
is_expected.to contain_file('prometheus.yaml').with(
'ensure' => 'file',
'path' => configpath,
'owner' => 'root',
'group' => 'prometheus',
'mode' => '0640',
'content' => File.read(fixtures('files', "prometheus#{prom_major}.yaml"))
'ensure' => 'file',
'path' => configpath,
'owner' => 'root',
'group' => 'prometheus',
'mode' => '0640',
'show_diff' => true,
'content' => File.read(fixtures('files', "prometheus#{prom_major}.yaml"))
).that_notifies('Class[prometheus::service_reload]')
}

Expand Down Expand Up @@ -300,11 +301,12 @@
it { is_expected.to compile.with_all_deps }
it {
is_expected.to contain_file('prometheus.yaml').with(
'ensure' => 'file',
'path' => configpath,
'owner' => 'root',
'group' => 'prometheus',
'content' => %r{http://domain.tld/path}
'ensure' => 'file',
'path' => configpath,
'owner' => 'root',
'group' => 'prometheus',
'show_diff' => true,
'content' => %r{http://domain.tld/path}
)
}
end
Expand Down Expand Up @@ -333,6 +335,36 @@
end
end
end

context 'with config_show_diff set' do
[
{
manage_prometheus_server: true,
config_show_diff: true
},
{
manage_prometheus_server: true,
config_show_diff: false
}
].each do |parameters|
context "to #{parameters[:config_show_diff]}" do
let(:params) do
parameters
end

it { is_expected.to compile.with_all_deps }
it {
is_expected.to contain_file('prometheus.yaml').with(
'ensure' => 'file',
'path' => configpath,
'owner' => 'root',
'group' => 'prometheus',
'show_diff' => parameters[:config_show_diff]
)
}
end
end
end
context 'command-line flags' do
context 'prometheus v2' do
version = '2.13.0'
Expand Down

0 comments on commit 4d0c546

Please sign in to comment.