Skip to content

Commit

Permalink
Support prometheus >= 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sathieu committed Oct 24, 2017
1 parent 2c3baf3 commit c091cf0
Show file tree
Hide file tree
Showing 16 changed files with 563 additions and 198 deletions.
15 changes: 15 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@
) {

if $prometheus::init_style {
if( versioncmp($::prometheus::version, '2.0.0') < 0 ){
$daemon_flags = [
"-config.file=${::prometheus::config_dir}/prometheus.yaml",
"-storage.local.path=${::prometheus::localstorage}",
"-web.console.templates=${::prometheus::shared_dir}/consoles",
"-web.console.libraries=${::prometheus::shared_dir}/console_libraries",
]
} else {
$daemon_flags = [
"--config.file=${::prometheus::config_dir}/prometheus.yaml",
"--storage.tsdb.path=${::prometheus::localstorage}",
"--web.console.templates=${::prometheus::shared_dir}/consoles",
"--web.console.libraries=${::prometheus::shared_dir}/console_libraries",
]
}

# the vast majority of files here are init-files
# so any change there should trigger a full service restart
Expand Down
326 changes: 170 additions & 156 deletions spec/classes/prometheus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,183 +7,197 @@
facts
end

context 'without parameters' do
# prometheus::install
it {
is_expected.to contain_file('/var/lib/prometheus').with(
'ensure' => 'directory',
'owner' => 'prometheus',
'group' => 'prometheus',
'mode' => '0755'
)
}

prom_version = '1.5.2'
prom_os = facts[:kernel].downcase
prom_arch = facts[:architecture] == 'i386' ? '386' : 'amd64'

it {
is_expected.to contain_archive("/tmp/prometheus-#{prom_version}.tar.gz").with(
'ensure' => 'present',
'extract' => true,
'extract_path' => '/opt',
'source' => "https://github.com/prometheus/prometheus/releases/download/v#{prom_version}/prometheus-#{prom_version}.#{prom_os}-#{prom_arch}.tar.gz",
'checksum_verify' => false,
'creates' => "/opt/prometheus-#{prom_version}.#{prom_os}-#{prom_arch}/prometheus",
'cleanup' => true
).that_comes_before("File[/opt/prometheus-#{prom_version}.#{prom_os}-#{prom_arch}/prometheus]")
}

it {
is_expected.to contain_file("/opt/prometheus-#{prom_version}.#{prom_os}-#{prom_arch}/prometheus").with(
'owner' => 'root',
'group' => 0,
'mode' => '0555'
)
}

it {
is_expected.to contain_file('/usr/local/bin/prometheus').with(
'ensure' => 'link',
'target' => "/opt/prometheus-#{prom_version}.#{prom_os}-#{prom_arch}/prometheus"
).that_notifies('Service[prometheus]')
}

it {
is_expected.to contain_file('/usr/local/share/prometheus').with(
'ensure' => 'directory',
'owner' => 'prometheus',
'group' => 'prometheus',
'mode' => '0755'
)
}

it {
is_expected.to contain_file('/usr/local/share/prometheus/consoles').with(
'ensure' => 'link',
'target' => "/opt/prometheus-#{prom_version}.#{prom_os}-#{prom_arch}/consoles"
).that_notifies('Service[prometheus]')
}

it {
is_expected.to contain_file('/usr/local/share/prometheus/console_libraries').with(
'ensure' => 'link',
'target' => "/opt/prometheus-#{prom_version}.#{prom_os}-#{prom_arch}/console_libraries"
).that_notifies('Service[prometheus]')
}

it {
is_expected.to contain_user('prometheus').with(
'ensure' => 'present',
'system' => true,
'groups' => []
)
}

it {
is_expected.to contain_group('prometheus').with(
'ensure' => 'present',
'system' => true
)
}

# prometheus::config
if ['debian-7-x86_64'].include?(os)
# init_style = 'debian'
[{}, { version: '2.0.0-rc.1' }].each do |parameters|
context "with parameters #{parameters}" do
let(:params) do
parameters
end

# prometheus::install
it {
is_expected.to contain_file('/etc/init.d/prometheus').with(
'mode' => '0555',
'owner' => 'root',
'group' => 'root',
'content' => File.read(fixtures('files', 'prometheus.debian'))
is_expected.to contain_file('/var/lib/prometheus').with(
'ensure' => 'directory',
'owner' => 'prometheus',
'group' => 'prometheus',
'mode' => '0755'
)
}
elsif ['centos-6-x86_64', 'redhat-6-x86_64'].include?(os)
# init_style = 'sysv'

prom_version = parameters[:version] || '1.5.2'
prom_major = prom_version[0]
prom_os = facts[:kernel].downcase
prom_arch = facts[:architecture] == 'i386' ? '386' : 'amd64'

it {
is_expected.to contain_archive("/tmp/prometheus-#{prom_version}.tar.gz").with(
'ensure' => 'present',
'extract' => true,
'extract_path' => '/opt',
'source' => "https://github.com/prometheus/prometheus/releases/download/v#{prom_version}/prometheus-#{prom_version}.#{prom_os}-#{prom_arch}.tar.gz",
'checksum_verify' => false,
'creates' => "/opt/prometheus-#{prom_version}.#{prom_os}-#{prom_arch}/prometheus",
'cleanup' => true
).that_comes_before("File[/opt/prometheus-#{prom_version}.#{prom_os}-#{prom_arch}/prometheus]")
}

it {
is_expected.to contain_file('/etc/init.d/prometheus').with(
'mode' => '0555',
is_expected.to contain_file("/opt/prometheus-#{prom_version}.#{prom_os}-#{prom_arch}/prometheus").with(
'owner' => 'root',
'group' => 'root',
'content' => File.read(fixtures('files', 'prometheus.sysv'))
'group' => 0,
'mode' => '0555'
)
}
elsif ['centos-7-x86_64', 'debian-8-x86_64', 'redhat-7-x86_64', 'ubuntu-16.04-x86_64'].include?(os)
# init_style = 'systemd'
it { is_expected.to contain_systemd__unit_file('prometheus.service') }
elsif ['ubuntu-14.04-x86_64'].include?(os)
# init_style = 'upstart'

it {
is_expected.to contain_file('/etc/init/prometheus.conf').with(
'mode' => '0444',
'owner' => 'root',
'group' => 'root',
'content' => File.read(fixtures('files', 'prometheus.upstart'))
is_expected.to contain_file('/usr/local/bin/prometheus').with(
'ensure' => 'link',
'target' => "/opt/prometheus-#{prom_version}.#{prom_os}-#{prom_arch}/prometheus"
).that_notifies('Service[prometheus]')
}

it {
is_expected.to contain_file('/usr/local/share/prometheus').with(
'ensure' => 'directory',
'owner' => 'prometheus',
'group' => 'prometheus',
'mode' => '0755'
)
}

it {
is_expected.to contain_file('/etc/init.d/prometheus').with(
is_expected.to contain_file('/usr/local/share/prometheus/consoles').with(
'ensure' => 'link',
'target' => '/lib/init/upstart-job',
'owner' => 'root',
'group' => 'root',
'mode' => '0755'
'target' => "/opt/prometheus-#{prom_version}.#{prom_os}-#{prom_arch}/consoles"
).that_notifies('Service[prometheus]')
}

it {
is_expected.to contain_file('/usr/local/share/prometheus/console_libraries').with(
'ensure' => 'link',
'target' => "/opt/prometheus-#{prom_version}.#{prom_os}-#{prom_arch}/console_libraries"
).that_notifies('Service[prometheus]')
}

it {
is_expected.to contain_user('prometheus').with(
'ensure' => 'present',
'system' => true,
'groups' => []
)
}
else

it {
is_expected.to raise_error(Puppet::Error, %r{I don.t know how to create an init script for style})
is_expected.to contain_group('prometheus').with(
'ensure' => 'present',
'system' => true
)
}
end

it {
is_expected.to contain_file('/etc/prometheus').with(
'ensure' => 'directory',
'owner' => 'prometheus',
'group' => 'prometheus',
'purge' => true,
'recurse' => true
)
}

it {
is_expected.to contain_file('prometheus.yaml').with(
'ensure' => 'present',
'path' => '/etc/prometheus/prometheus.yaml',
'owner' => 'prometheus',
'group' => 'prometheus',
'mode' => '0660',
'content' => File.read(fixtures('files', 'prometheus.yaml'))
).that_notifies('Class[prometheus::service_reload]')
}

# prometheus::alerts
it {
is_expected.not_to contain_file('/etc/prometheus/alert.rules')
}

# prometheus::run_service
it {
is_expected.to contain_service('prometheus').with(
'ensure' => 'running',
'name' => 'prometheus',
'enable' => true,
'hasrestart' => true
)
}

# prometheus::service_reload
it {
is_expected.to contain_exec('prometheus-reload').with(
# 'command' => 'systemctl reload prometheus',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin'],
'refreshonly' => true
)
}
# prometheus::config
if ['debian-7-x86_64'].include?(os)
# init_style = 'debian'

it {
is_expected.to contain_file('/etc/init.d/prometheus').with(
'mode' => '0555',
'owner' => 'root',
'group' => 'root',
'content' => File.read(fixtures('files', "prometheus#{prom_major}.debian"))
)
}
elsif ['centos-6-x86_64', 'redhat-6-x86_64'].include?(os)
# init_style = 'sysv'

it {
is_expected.to contain_file('/etc/init.d/prometheus').with(
'mode' => '0555',
'owner' => 'root',
'group' => 'root',
'content' => File.read(fixtures('files', "prometheus#{prom_major}.sysv"))
)
}
elsif ['centos-7-x86_64', 'debian-8-x86_64', 'redhat-7-x86_64', 'ubuntu-16.04-x86_64'].include?(os)
# init_style = 'systemd'

it { is_expected.to contain_class('systemd') }

it {
is_expected.to contain_systemd__unit_file('prometheus.service').with(
'content' => File.read(fixtures('files', "prometheus#{prom_major}.systemd"))
)
}
elsif ['ubuntu-14.04-x86_64'].include?(os)
# init_style = 'upstart'

it {
is_expected.to contain_file('/etc/init/prometheus.conf').with(
'mode' => '0444',
'owner' => 'root',
'group' => 'root',
'content' => File.read(fixtures('files', "prometheus#{prom_major}.upstart"))
)
}

it {
is_expected.to contain_file('/etc/init.d/prometheus').with(
'ensure' => 'link',
'target' => '/lib/init/upstart-job',
'owner' => 'root',
'group' => 'root',
'mode' => '0755'
)
}
else
it {
is_expected.to raise_error(Puppet::Error, %r{I don.t know how to create an init script for style})
}
end

it {
is_expected.to contain_file('/etc/prometheus').with(
'ensure' => 'directory',
'owner' => 'prometheus',
'group' => 'prometheus',
'purge' => true,
'recurse' => true
)
}

it {
is_expected.to contain_file('prometheus.yaml').with(
'ensure' => 'present',
'path' => '/etc/prometheus/prometheus.yaml',
'owner' => 'prometheus',
'group' => 'prometheus',
'mode' => '0660',
'content' => File.read(fixtures('files', 'prometheus.yaml'))
).that_notifies('Class[prometheus::service_reload]')
}

# prometheus::alerts
it {
is_expected.not_to contain_file('/etc/prometheus/alert.rules')
}

# prometheus::run_service
it {
is_expected.to contain_service('prometheus').with(
'ensure' => 'running',
'name' => 'prometheus',
'enable' => true,
'hasrestart' => true
)
}

# prometheus::service_reload
it {
is_expected.to contain_exec('prometheus-reload').with(
# 'command' => 'systemctl reload prometheus',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin'],
'refreshonly' => true
)
}
end
end
end
end
Expand Down
Loading

0 comments on commit c091cf0

Please sign in to comment.