diff --git a/prometheus/archive/install.sls b/prometheus/archive/install.sls index 1173ec8..64dfb7b 100644 --- a/prometheus/archive/install.sls +++ b/prometheus/archive/install.sls @@ -82,6 +82,8 @@ prometheus-archive-install-{{ name }}-file-directory: - user: 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: file.managed: - name: {{ p.dir.service }}/{{ p.pkg.component[name]['service'].get('name', name) }}.service @@ -116,5 +118,6 @@ prometheus-archive-install-{{ name }}-managed-service: - require: - archive: prometheus-archive-install-{{ name }} + {%- endif %} {%- endif %} {%- endfor %} diff --git a/test/integration/default/controls/archive_spec.rb b/test/integration/default/controls/archive_spec.rb index fc4bcdb..f12d61c 100644 --- a/test/integration/default/controls/archive_spec.rb +++ b/test/integration/default/controls/archive_spec.rb @@ -3,13 +3,14 @@ control 'prometheus components' do title 'should be installed' - service_dir = - case platform[:family] - when 'debian' - '/lib/systemd/system' - else - '/usr/lib/systemd/system' - end + case platform[:family] + when 'debian' + service_dir = '/lib/systemd/system' + alert_manager_service = 'prometheus-alertmanager' + else + service_dir = '/usr/lib/systemd/system' + alert_manager_service = 'alertmanager' + end # describe package('cron') do # it { should be_installed } # not available on amazonlinux? @@ -64,7 +65,7 @@ control 'prometheus components' do it { should exist } its('group') { should eq 'alertmanager' } end - describe file("#{service_dir}/alertmanager.service") do + describe file("#{service_dir}/#{alert_manager_service}.service") do it { should exist } its('group') { should eq 'root' } its('mode') { should cmp '0644' } diff --git a/test/integration/default/controls/service_spec.rb b/test/integration/default/controls/service_spec.rb index 42bd360..8a57f63 100644 --- a/test/integration/default/controls/service_spec.rb +++ b/test/integration/default/controls/service_spec.rb @@ -1,8 +1,10 @@ # frozen_string_literal: true -control 'prometheus services' do +control 'services with a consistent service name across distros' do 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 it { should be_enabled } it { should be_running } @@ -13,3 +15,47 @@ control 'prometheus services' do it { should be_listening } 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 diff --git a/test/integration/repo/controls/service_spec.rb b/test/integration/repo/controls/service_spec.rb index 063795a..274fd2d 100644 --- a/test/integration/repo/controls/service_spec.rb +++ b/test/integration/repo/controls/service_spec.rb @@ -3,17 +3,29 @@ control 'prometheus services' do title 'should be running' - service = + services = case platform[:family] when 'redhat' - 'node_exporter' + %w[ + node_exporter + prometheus + blackbox_exporter + alertmanager + ] else - 'prometheus-node-exporter' + %w[ + prometheus + prometheus-node-exporter + prometheus-blackbox-exporter + prometheus-alertmanager + ] end - describe service(service) do - it { should be_enabled } - it { should be_running } + services.each do |service| + describe service(service) do + it { should be_enabled } + it { should be_running } + end end # prometheus-node-exporter port diff --git a/test/salt/pillar/default.sls b/test/salt/pillar/default.sls index 1dee3c9..0d60991 100644 --- a/test/salt/pillar/default.sls +++ b/test/salt/pillar/default.sls @@ -13,6 +13,8 @@ prometheus: - prometheus - alertmanager - node_exporter + - blackbox_exporter + - consul_exporter # - memcached_exporter # not in upstream repo, only archive exporters: @@ -93,11 +95,21 @@ prometheus: archive: source_hash: b2503fd932f85f4e5baf161268854bf5d22001869b84f00fd2d1f57b51b72424 service: - name: node_exporter args: web.listen-address: ":9110" # 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: service: args: diff --git a/test/salt/pillar/repo.sls b/test/salt/pillar/repo.sls index 284b5cc..f9bdd15 100644 --- a/test/salt/pillar/repo.sls +++ b/test/salt/pillar/repo.sls @@ -12,7 +12,6 @@ prometheus: - alertmanager - node_exporter - blackbox_exporter - # - memcached_exporter # not in upstream repo, only archive exporters: node_exporter: @@ -72,20 +71,6 @@ prometheus: email_configs: - 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: version: v0.18.1 archive: @@ -94,9 +79,11 @@ prometheus: args: web.listen-address: ":9110" # collector.textfile.directory: /var/tmp/node_exporter - {% if grains['os_family'] == 'Debian' %} - name: prometheus-node-exporter - {% endif %} + + blackbox_exporter: + service: + args: + web.listen-address: ":9115" prometheus: service: