Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow hiding of prom config file #451

Merged
merged 1 commit into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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