test(archive): add tests to check service names
this commit makes `service name` to consider pillar provided values, fallback to a consistent `service name` when {archive|package} is available for the component, or to `service name == name` when no other value is provided
This commit is contained in:
parent
219250a215
commit
a5d4d03f8d
@ -82,6 +82,8 @@ prometheus-archive-install-{{ name }}-file-directory:
|
|||||||
- user: prometheus-config-user-install-{{ name }}-user-present
|
- user: prometheus-config-user-install-{{ name }}-user-present
|
||||||
- group: prometheus-config-user-install-{{ name }}-user-present
|
- group: prometheus-config-user-install-{{ name }}-user-present
|
||||||
|
|
||||||
|
{%- if grains.kernel|lower == 'linux' %}
|
||||||
|
|
||||||
prometheus-archive-install-{{ name }}-managed-service:
|
prometheus-archive-install-{{ name }}-managed-service:
|
||||||
file.managed:
|
file.managed:
|
||||||
- name: {{ p.dir.service }}/{{ p.pkg.component[name]['service'].get('name', name) }}.service
|
- name: {{ p.dir.service }}/{{ p.pkg.component[name]['service'].get('name', name) }}.service
|
||||||
@ -117,4 +119,5 @@ prometheus-archive-install-{{ name }}-managed-service:
|
|||||||
- archive: prometheus-archive-install-{{ name }}
|
- archive: prometheus-archive-install-{{ name }}
|
||||||
|
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
{%- endif %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
@ -3,12 +3,13 @@
|
|||||||
control 'prometheus components' do
|
control 'prometheus components' do
|
||||||
title 'should be installed'
|
title 'should be installed'
|
||||||
|
|
||||||
service_dir =
|
|
||||||
case platform[:family]
|
case platform[:family]
|
||||||
when 'debian'
|
when 'debian'
|
||||||
'/lib/systemd/system'
|
service_dir = '/lib/systemd/system'
|
||||||
|
alert_manager_service = 'prometheus-alertmanager'
|
||||||
else
|
else
|
||||||
'/usr/lib/systemd/system'
|
service_dir = '/usr/lib/systemd/system'
|
||||||
|
alert_manager_service = 'alertmanager'
|
||||||
end
|
end
|
||||||
|
|
||||||
# describe package('cron') do
|
# describe package('cron') do
|
||||||
@ -64,7 +65,7 @@ control 'prometheus components' do
|
|||||||
it { should exist }
|
it { should exist }
|
||||||
its('group') { should eq 'alertmanager' }
|
its('group') { should eq 'alertmanager' }
|
||||||
end
|
end
|
||||||
describe file("#{service_dir}/alertmanager.service") do
|
describe file("#{service_dir}/#{alert_manager_service}.service") do
|
||||||
it { should exist }
|
it { should exist }
|
||||||
its('group') { should eq 'root' }
|
its('group') { should eq 'root' }
|
||||||
its('mode') { should cmp '0644' }
|
its('mode') { should cmp '0644' }
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
control 'prometheus services' do
|
control 'services with a consistent service name across distros' do
|
||||||
title 'should be running'
|
title 'should be running'
|
||||||
|
|
||||||
|
# we forced node_exporter's service name to `node_exporter` in the pillar,
|
||||||
|
# so its name will be the same across distros for this test
|
||||||
describe service('node_exporter') do
|
describe service('node_exporter') do
|
||||||
it { should be_enabled }
|
it { should be_enabled }
|
||||||
it { should be_running }
|
it { should be_running }
|
||||||
@ -13,3 +15,47 @@ control 'prometheus services' do
|
|||||||
it { should be_listening }
|
it { should be_listening }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
control 'services with a consistent service name on each distro' do
|
||||||
|
title 'should be running'
|
||||||
|
|
||||||
|
# if we don't set a service name in the pillar,
|
||||||
|
# its name will be the same on each distro, no matter what the
|
||||||
|
# install method we choose
|
||||||
|
|
||||||
|
distro_service =
|
||||||
|
case platform[:family]
|
||||||
|
when 'debian'
|
||||||
|
'prometheus-blackbox-exporter'
|
||||||
|
else
|
||||||
|
'blackbox_exporter'
|
||||||
|
end
|
||||||
|
|
||||||
|
describe service(distro_service) do
|
||||||
|
it { should be_enabled }
|
||||||
|
it { should be_running }
|
||||||
|
end
|
||||||
|
|
||||||
|
# blackbox_exporter port
|
||||||
|
describe port(9115) do
|
||||||
|
it { should be_listening }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
control 'services with any service name we want to give them' do
|
||||||
|
title 'should be running'
|
||||||
|
|
||||||
|
# if we set a service name in the pillar,
|
||||||
|
# the formula should work, no matter what it is or the
|
||||||
|
# install method we choose
|
||||||
|
|
||||||
|
describe service('my-fancy-consul-exporter-service') do
|
||||||
|
it { should be_enabled }
|
||||||
|
it { should be_running }
|
||||||
|
end
|
||||||
|
|
||||||
|
# consul_exporter port
|
||||||
|
describe port(9107) do
|
||||||
|
it { should be_listening }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@ -3,18 +3,30 @@
|
|||||||
control 'prometheus services' do
|
control 'prometheus services' do
|
||||||
title 'should be running'
|
title 'should be running'
|
||||||
|
|
||||||
service =
|
services =
|
||||||
case platform[:family]
|
case platform[:family]
|
||||||
when 'redhat'
|
when 'redhat'
|
||||||
'node_exporter'
|
%w[
|
||||||
|
node_exporter
|
||||||
|
prometheus
|
||||||
|
blackbox_exporter
|
||||||
|
alertmanager
|
||||||
|
]
|
||||||
else
|
else
|
||||||
'prometheus-node-exporter'
|
%w[
|
||||||
|
prometheus
|
||||||
|
prometheus-node-exporter
|
||||||
|
prometheus-blackbox-exporter
|
||||||
|
prometheus-alertmanager
|
||||||
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
services.each do |service|
|
||||||
describe service(service) do
|
describe service(service) do
|
||||||
it { should be_enabled }
|
it { should be_enabled }
|
||||||
it { should be_running }
|
it { should be_running }
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# prometheus-node-exporter port
|
# prometheus-node-exporter port
|
||||||
describe port(9100) do
|
describe port(9100) do
|
||||||
|
@ -13,6 +13,8 @@ prometheus:
|
|||||||
- prometheus
|
- prometheus
|
||||||
- alertmanager
|
- alertmanager
|
||||||
- node_exporter
|
- node_exporter
|
||||||
|
- blackbox_exporter
|
||||||
|
- consul_exporter
|
||||||
# - memcached_exporter # not in upstream repo, only archive
|
# - memcached_exporter # not in upstream repo, only archive
|
||||||
|
|
||||||
exporters:
|
exporters:
|
||||||
@ -93,11 +95,21 @@ prometheus:
|
|||||||
archive:
|
archive:
|
||||||
source_hash: b2503fd932f85f4e5baf161268854bf5d22001869b84f00fd2d1f57b51b72424
|
source_hash: b2503fd932f85f4e5baf161268854bf5d22001869b84f00fd2d1f57b51b72424
|
||||||
service:
|
service:
|
||||||
name: node_exporter
|
|
||||||
args:
|
args:
|
||||||
web.listen-address: ":9110"
|
web.listen-address: ":9110"
|
||||||
# collector.textfile.directory: /var/tmp/node_exporter
|
# collector.textfile.directory: /var/tmp/node_exporter
|
||||||
|
|
||||||
|
blackbox_exporter:
|
||||||
|
service:
|
||||||
|
args:
|
||||||
|
web.listen-address: ":9115"
|
||||||
|
config_file: /opt/prometheus/blackbox_exporter-v0.14.0/blackbox.yml
|
||||||
|
|
||||||
|
consul_exporter:
|
||||||
|
service:
|
||||||
|
# This is to test that any fancy name we use, will work in archive mode
|
||||||
|
name: my-fancy-consul-exporter-service
|
||||||
|
|
||||||
prometheus:
|
prometheus:
|
||||||
service:
|
service:
|
||||||
args:
|
args:
|
||||||
|
@ -12,7 +12,6 @@ prometheus:
|
|||||||
- alertmanager
|
- alertmanager
|
||||||
- node_exporter
|
- node_exporter
|
||||||
- blackbox_exporter
|
- blackbox_exporter
|
||||||
# - memcached_exporter # not in upstream repo, only archive
|
|
||||||
|
|
||||||
exporters:
|
exporters:
|
||||||
node_exporter:
|
node_exporter:
|
||||||
@ -72,20 +71,6 @@ prometheus:
|
|||||||
email_configs:
|
email_configs:
|
||||||
- to: 'team-X+alerts@example.org'
|
- to: 'team-X+alerts@example.org'
|
||||||
|
|
||||||
inhibit_rules:
|
|
||||||
- name: opsGenie-receiver
|
|
||||||
opsgenie_configs:
|
|
||||||
- api_key: mysecret
|
|
||||||
- name: slack-receiver
|
|
||||||
slack_configs:
|
|
||||||
- channel: '#my-channel'
|
|
||||||
image_url: 'http://some.img.com/img.png'
|
|
||||||
|
|
||||||
{% if grains['os_family'] == 'Debian' %}
|
|
||||||
service:
|
|
||||||
name: prometheus-alertmanager
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
node_exporter:
|
node_exporter:
|
||||||
version: v0.18.1
|
version: v0.18.1
|
||||||
archive:
|
archive:
|
||||||
@ -94,9 +79,11 @@ prometheus:
|
|||||||
args:
|
args:
|
||||||
web.listen-address: ":9110"
|
web.listen-address: ":9110"
|
||||||
# collector.textfile.directory: /var/tmp/node_exporter
|
# collector.textfile.directory: /var/tmp/node_exporter
|
||||||
{% if grains['os_family'] == 'Debian' %}
|
|
||||||
name: prometheus-node-exporter
|
blackbox_exporter:
|
||||||
{% endif %}
|
service:
|
||||||
|
args:
|
||||||
|
web.listen-address: ":9115"
|
||||||
|
|
||||||
prometheus:
|
prometheus:
|
||||||
service:
|
service:
|
||||||
|
Loading…
Reference in New Issue
Block a user