Skip to content

Commit a5d4d03

Browse files
committed
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
1 parent 219250a commit a5d4d03

File tree

6 files changed

+95
-34
lines changed

6 files changed

+95
-34
lines changed

prometheus/archive/install.sls

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ prometheus-archive-install-{{ name }}-file-directory:
8282
- user: prometheus-config-user-install-{{ name }}-user-present
8383
- group: prometheus-config-user-install-{{ name }}-user-present
8484
85+
{%- if grains.kernel|lower == 'linux' %}
86+
8587
prometheus-archive-install-{{ name }}-managed-service:
8688
file.managed:
8789
- name: {{ p.dir.service }}/{{ p.pkg.component[name]['service'].get('name', name) }}.service
@@ -116,5 +118,6 @@ prometheus-archive-install-{{ name }}-managed-service:
116118
- require:
117119
- archive: prometheus-archive-install-{{ name }}
118120
121+
{%- endif %}
119122
{%- endif %}
120123
{%- endfor %}

test/integration/default/controls/archive_spec.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
control 'prometheus components' do
44
title 'should be installed'
55

6-
service_dir =
7-
case platform[:family]
8-
when 'debian'
9-
'/lib/systemd/system'
10-
else
11-
'/usr/lib/systemd/system'
12-
end
6+
case platform[:family]
7+
when 'debian'
8+
service_dir = '/lib/systemd/system'
9+
alert_manager_service = 'prometheus-alertmanager'
10+
else
11+
service_dir = '/usr/lib/systemd/system'
12+
alert_manager_service = 'alertmanager'
13+
end
1314

1415
# describe package('cron') do
1516
# it { should be_installed } # not available on amazonlinux?
@@ -64,7 +65,7 @@
6465
it { should exist }
6566
its('group') { should eq 'alertmanager' }
6667
end
67-
describe file("#{service_dir}/alertmanager.service") do
68+
describe file("#{service_dir}/#{alert_manager_service}.service") do
6869
it { should exist }
6970
its('group') { should eq 'root' }
7071
its('mode') { should cmp '0644' }

test/integration/default/controls/service_spec.rb

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# frozen_string_literal: true
22

3-
control 'prometheus services' do
3+
control 'services with a consistent service name across distros' do
44
title 'should be running'
55

6+
# we forced node_exporter's service name to `node_exporter` in the pillar,
7+
# so its name will be the same across distros for this test
68
describe service('node_exporter') do
79
it { should be_enabled }
810
it { should be_running }
@@ -13,3 +15,47 @@
1315
it { should be_listening }
1416
end
1517
end
18+
19+
control 'services with a consistent service name on each distro' do
20+
title 'should be running'
21+
22+
# if we don't set a service name in the pillar,
23+
# its name will be the same on each distro, no matter what the
24+
# install method we choose
25+
26+
distro_service =
27+
case platform[:family]
28+
when 'debian'
29+
'prometheus-blackbox-exporter'
30+
else
31+
'blackbox_exporter'
32+
end
33+
34+
describe service(distro_service) do
35+
it { should be_enabled }
36+
it { should be_running }
37+
end
38+
39+
# blackbox_exporter port
40+
describe port(9115) do
41+
it { should be_listening }
42+
end
43+
end
44+
45+
control 'services with any service name we want to give them' do
46+
title 'should be running'
47+
48+
# if we set a service name in the pillar,
49+
# the formula should work, no matter what it is or the
50+
# install method we choose
51+
52+
describe service('my-fancy-consul-exporter-service') do
53+
it { should be_enabled }
54+
it { should be_running }
55+
end
56+
57+
# consul_exporter port
58+
describe port(9107) do
59+
it { should be_listening }
60+
end
61+
end

test/integration/repo/controls/service_spec.rb

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,29 @@
33
control 'prometheus services' do
44
title 'should be running'
55

6-
service =
6+
services =
77
case platform[:family]
88
when 'redhat'
9-
'node_exporter'
9+
%w[
10+
node_exporter
11+
prometheus
12+
blackbox_exporter
13+
alertmanager
14+
]
1015
else
11-
'prometheus-node-exporter'
16+
%w[
17+
prometheus
18+
prometheus-node-exporter
19+
prometheus-blackbox-exporter
20+
prometheus-alertmanager
21+
]
1222
end
1323

14-
describe service(service) do
15-
it { should be_enabled }
16-
it { should be_running }
24+
services.each do |service|
25+
describe service(service) do
26+
it { should be_enabled }
27+
it { should be_running }
28+
end
1729
end
1830

1931
# prometheus-node-exporter port

test/salt/pillar/default.sls

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ prometheus:
1313
- prometheus
1414
- alertmanager
1515
- node_exporter
16+
- blackbox_exporter
17+
- consul_exporter
1618
# - memcached_exporter # not in upstream repo, only archive
1719

1820
exporters:
@@ -93,11 +95,21 @@ prometheus:
9395
archive:
9496
source_hash: b2503fd932f85f4e5baf161268854bf5d22001869b84f00fd2d1f57b51b72424
9597
service:
96-
name: node_exporter
9798
args:
9899
web.listen-address: ":9110"
99100
# collector.textfile.directory: /var/tmp/node_exporter
100101

102+
blackbox_exporter:
103+
service:
104+
args:
105+
web.listen-address: ":9115"
106+
config_file: /opt/prometheus/blackbox_exporter-v0.14.0/blackbox.yml
107+
108+
consul_exporter:
109+
service:
110+
# This is to test that any fancy name we use, will work in archive mode
111+
name: my-fancy-consul-exporter-service
112+
101113
prometheus:
102114
service:
103115
args:

test/salt/pillar/repo.sls

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ prometheus:
1212
- alertmanager
1313
- node_exporter
1414
- blackbox_exporter
15-
# - memcached_exporter # not in upstream repo, only archive
1615

1716
exporters:
1817
node_exporter:
@@ -72,20 +71,6 @@ prometheus:
7271
email_configs:
7372
- to: 'team-X+alerts@example.org'
7473

75-
inhibit_rules:
76-
- name: opsGenie-receiver
77-
opsgenie_configs:
78-
- api_key: mysecret
79-
- name: slack-receiver
80-
slack_configs:
81-
- channel: '#my-channel'
82-
image_url: 'http://some.img.com/img.png'
83-
84-
{% if grains['os_family'] == 'Debian' %}
85-
service:
86-
name: prometheus-alertmanager
87-
{% endif %}
88-
8974
node_exporter:
9075
version: v0.18.1
9176
archive:
@@ -94,9 +79,11 @@ prometheus:
9479
args:
9580
web.listen-address: ":9110"
9681
# collector.textfile.directory: /var/tmp/node_exporter
97-
{% if grains['os_family'] == 'Debian' %}
98-
name: prometheus-node-exporter
99-
{% endif %}
82+
83+
blackbox_exporter:
84+
service:
85+
args:
86+
web.listen-address: ":9115"
10087

10188
prometheus:
10289
service:

0 commit comments

Comments
 (0)