From eea5b407fa6dee5cdcb7bd951b752beb1833176c Mon Sep 17 00:00:00 2001 From: BlueWolf Date: Thu, 24 Jun 2021 14:55:09 +0100 Subject: [PATCH 1/6] fix: rework to implement environment variables handling Developed environ.sh.jinja and added test pillar data to default Corrected prometheus.config.environ ref #59 Switched default test pillar to use none archive - due to deployment of custom service Disabled a number of exporters following switch from archive due to failing - to be reviewed Corrected prometheus environ_file location Resolves: #59 --- .yamllint | 1 + kitchen.yml | 4 +++- prometheus/config/environ.sls | 13 +++++++----- prometheus/defaults.yaml | 2 +- prometheus/files/default/environ.sh.jinja | 5 ++++- test/salt/pillar/default.sls | 26 ++++++++++++++--------- 6 files changed, 33 insertions(+), 18 deletions(-) diff --git a/.yamllint b/.yamllint index 224d0b9..14197a1 100644 --- a/.yamllint +++ b/.yamllint @@ -12,6 +12,7 @@ extends: 'default' # 5. Any YAML files under directory `.kitchen/`, introduced during local testing # 6. `kitchen.vagrant.yml`, which contains Embedded Ruby (ERB) template syntax ignore: | + .bundle/ .cache/ .git/ node_modules/ diff --git a/kitchen.yml b/kitchen.yml index 637ae30..e7cf266 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -7,6 +7,8 @@ driver: use_sudo: false privileged: true run_command: /lib/systemd/systemd + forward: + - 9090:9090 platforms: ## SALT `tiamat` @@ -350,7 +352,7 @@ suites: state_top: base: '*': - - prometheus._mapdata + # - prometheus._mapdata - prometheus pillars: top.sls: diff --git a/prometheus/config/environ.sls b/prometheus/config/environ.sls index 0aaf6ee..f5edfd8 100644 --- a/prometheus/config/environ.sls +++ b/prometheus/config/environ.sls @@ -4,7 +4,7 @@ {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus as p with context %} {%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} -{%- from tplroot ~ "/files/macros.jinja" import concat_environ %} +{%- from tplroot ~ "/files/macros.jinja" import concat_args %} {%- set sls_archive_install = tplroot ~ '.archive.install' %} {%- set sls_package_install = tplroot ~ '.package.install' %} @@ -12,7 +12,8 @@ include: - {{ sls_archive_install if p.pkg.use_upstream_archive else sls_package_install }} {%- for name in p.wanted.component %} - {%- if 'environ' in p.pkg.component[name] and p.pkg.component[name]['environ'] %} + {%- if 'environ' in p.pkg.component[name] and 'args' in p.pkg.component[name]['environ'] %} + {%- set args = p.pkg.component[name]['environ']['args'] %} {%- if 'environ_file' in p.pkg.component[name] and p.pkg.component[name]['environ_file'] %} prometheus-config-install-{{ name }}-environ_file: @@ -29,8 +30,10 @@ prometheus-config-install-{{ name }}-environ_file: - user: {{ p.identity.rootuser }} - group: {{ p.identity.rootgroup }} {%- endif %} - - contents: | - command_args="{{ concat_environ(environ) }}" + #- contents: | + # command_args="{{ concat_args(args) }}" + - context: + args: {{ args }} - watch_in: - service: prometheus-service-running-{{ name }} - require: @@ -43,7 +46,7 @@ prometheus-config-environ-{{ name }}-all: - name: {{ name }}_environ # service prometheus restart tends to hang on FreeBSD # https://github.com/saltstack/salt/issues/44848#issuecomment-487016414 - - value: "{{ concat_environ(p.pkg.component[name]['environ']) }} >/dev/null 2>&1" + - value: "{{ concat_args(p.pkg.component[name]['environ']) }} >/dev/null 2>&1" - watch_in: - service: prometheus-service-running-{{ name }} diff --git a/prometheus/defaults.yaml b/prometheus/defaults.yaml index 974fff1..b05c14d 100644 --- a/prometheus/defaults.yaml +++ b/prometheus/defaults.yaml @@ -152,7 +152,7 @@ prometheus: version: v2.22.1 config_file: /etc/prometheus/prometheus.yml config: {} - environ_file: /etc/default/prometheus.sh + environ_file: /etc/default/prometheus environ: {} service: args: diff --git a/prometheus/files/default/environ.sh.jinja b/prometheus/files/default/environ.sh.jinja index 5c601d1..a8e4cc4 100644 --- a/prometheus/files/default/environ.sh.jinja +++ b/prometheus/files/default/environ.sh.jinja @@ -2,5 +2,8 @@ # File managed by Salt at <{{ source }}>. # Your changes may be overwritten. ######################################################################## +# Set the command-line arguments to pass to the server. +ARGS="{%- for arg, value in args.items() %}--{{ arg }}={{ value }}{{ " " if not loop.last else "" }}{% endfor %}" + + -{{ config|yaml(False) }} diff --git a/test/salt/pillar/default.sls b/test/salt/pillar/default.sls index 902dc9f..e299a61 100644 --- a/test/salt/pillar/default.sls +++ b/test/salt/pillar/default.sls @@ -14,10 +14,10 @@ prometheus: - alertmanager - node_exporter - blackbox_exporter - - consul_exporter - - php-fpm_exporter + # - consul_exporter + # - php-fpm_exporter - postgres_exporter - - mysqld_exporter + # - mysqld_exporter # - memcached_exporter # not in upstream repo, only archive exporters: @@ -36,7 +36,9 @@ prometheus: smartctl: /usr/sbin/smartctl pkg: use_upstream_repo: false - use_upstream_archive: true + # Changed to use non archive install as default (the archive includes a bespoke + # implementation of service thats needs updating) + use_upstream_archive: false clientlibs: # https://prometheus.io/docs/instrumenting/clientlibs @@ -102,17 +104,21 @@ prometheus: # This is to test that any fancy name we use, will work in archive mode name: my-fancy-consul-exporter-service - mysqld_exporter: - service: - args: - web.listen-address: 0.0.0.0:9192 - env: - - 'DATA_SOURCE_NAME=foo:bar@/' + # mysqld_exporter: + # service: + # args: + # web.listen-address: 0.0.0.0:9192 + # env: + # - 'DATA_SOURCE_NAME=foo:bar@/' prometheus: service: args: web.listen-address: 0.0.0.0:9090 + environ: + args: + web.listen-address: 0.0.0.0:9090 + log.level: debug config: # yamllint disable-line rule:line-length # ref https://raw.githubusercontent.com/prometheus/prometheus/release-2.10/config/testdata/conf.good.yml From 696bee0522b9e37befbe76728c2d3211f25b8a68 Mon Sep 17 00:00:00 2001 From: BlueWolf Date: Thu, 24 Jun 2021 17:25:35 +0100 Subject: [PATCH 2/6] fix: revert to use of macro.jinja for arg handling The previous additions to environ.sh.jinja were fixing something that wasnt broken. --- kitchen.yml | 1 + prometheus/config/environ.sls | 2 +- prometheus/defaults.yaml | 6 ++--- prometheus/files/default/environ.sh.jinja | 4 +-- test/salt/pillar/default.sls | 32 +++++++++++++---------- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/kitchen.yml b/kitchen.yml index e7cf266..59ce615 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -9,6 +9,7 @@ driver: run_command: /lib/systemd/systemd forward: - 9090:9090 + - 9110:9110 platforms: ## SALT `tiamat` diff --git a/prometheus/config/environ.sls b/prometheus/config/environ.sls index f5edfd8..5f8b0c9 100644 --- a/prometheus/config/environ.sls +++ b/prometheus/config/environ.sls @@ -33,7 +33,7 @@ prometheus-config-install-{{ name }}-environ_file: #- contents: | # command_args="{{ concat_args(args) }}" - context: - args: {{ args }} + args: {{ concat_args(args) }} - watch_in: - service: prometheus-service-running-{{ name }} - require: diff --git a/prometheus/defaults.yaml b/prometheus/defaults.yaml index b05c14d..023c360 100644 --- a/prometheus/defaults.yaml +++ b/prometheus/defaults.yaml @@ -44,7 +44,7 @@ prometheus: version: v0.21.0 config_file: /etc/prometheus/alertmanager.yml config: {} - environ_file: /etc/default/prometheus-alertmanager.sh + environ_file: /etc/default/prometheus-alertmanager environ: {} service: args: @@ -131,7 +131,7 @@ prometheus: - tcp/9207 node_exporter: version: v1.0.1 - environ_file: /etc/default/prometheus-node-exporter.sh + environ_file: /etc/default/prometheus-node-exporter environ: {} config_file: /etc/prometheus/node_exporter.yml config: {} @@ -170,7 +170,7 @@ prometheus: - tcp/9090 pushgateway: version: v1.3.0 - environ_file: /etc/default/prometheus-pushgateway.sh + environ_file: /etc/default/prometheus-pushgateway environ: {} config_file: /etc/prometheus/pushgateway.yml config: {} diff --git a/prometheus/files/default/environ.sh.jinja b/prometheus/files/default/environ.sh.jinja index a8e4cc4..296e406 100644 --- a/prometheus/files/default/environ.sh.jinja +++ b/prometheus/files/default/environ.sh.jinja @@ -2,8 +2,8 @@ # File managed by Salt at <{{ source }}>. # Your changes may be overwritten. ######################################################################## -# Set the command-line arguments to pass to the server. -ARGS="{%- for arg, value in args.items() %}--{{ arg }}={{ value }}{{ " " if not loop.last else "" }}{% endfor %}" +# Set the command-line arguments to pass to the server.%}" +ARGS="{{ args }}" diff --git a/test/salt/pillar/default.sls b/test/salt/pillar/default.sls index e299a61..ec9fd1d 100644 --- a/test/salt/pillar/default.sls +++ b/test/salt/pillar/default.sls @@ -20,20 +20,20 @@ prometheus: # - mysqld_exporter # - memcached_exporter # not in upstream repo, only archive - exporters: - node_exporter: - textfile_collectors_dependencies: [] - textfile_collectors: - ipmitool: - enable: false - remove: false - pkg: ipmitool - smartmon: - enable: false - remove: false - pkg: smartmontools - bash_pkg: bash - smartctl: /usr/sbin/smartctl + # exporters: + # node_exporter: + # textfile_collectors_dependencies: [] + # textfile_collectors: + # ipmitool: + # enable: false + # remove: false + # pkg: ipmitool + # smartmon: + # enable: false + # remove: false + # pkg: smartmontools + # bash_pkg: bash + # smartctl: /usr/sbin/smartctl pkg: use_upstream_repo: false # Changed to use non archive install as default (the archive includes a bespoke @@ -87,6 +87,10 @@ prometheus: - to: 'team-X+alerts@example.org' node_exporter: + environ: + args: + collector.systemd: true + web.listen-address: ":9110" service: args: collector.systemd: null From a4dfb87554b9a5d35fe5654698940380cc5fadee Mon Sep 17 00:00:00 2001 From: BlueWolf Date: Fri, 25 Jun 2021 10:51:30 +0100 Subject: [PATCH 3/6] fix: added guidance and reverted incorrected changes from prior commits Added inspec checks for environment files and specifically prometheus and node_exporter args. Provided comments throughout the key reference points for users to signpost the differing approaches to args used along with more clearly identifying the difference between archive and repo approach. Tests appear to be working on both approaches though updates have been focused at repo install method. Fixes: #59 --- kitchen.yml | 5 +- pillar.example | 21 ++++++++ prometheus/defaults.yaml | 6 +++ .../integration/repo/controls/service_spec.rb | 16 +++++- test/salt/pillar/default.sls | 53 +++++++++---------- test/salt/pillar/repo.sls | 9 ++++ 6 files changed, 78 insertions(+), 32 deletions(-) diff --git a/kitchen.yml b/kitchen.yml index 59ce615..637ae30 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -7,9 +7,6 @@ driver: use_sudo: false privileged: true run_command: /lib/systemd/systemd - forward: - - 9090:9090 - - 9110:9110 platforms: ## SALT `tiamat` @@ -353,7 +350,7 @@ suites: state_top: base: '*': - # - prometheus._mapdata + - prometheus._mapdata - prometheus pillars: top.sls: diff --git a/pillar.example b/pillar.example index 748a151..b193b3f 100644 --- a/pillar.example +++ b/pillar.example @@ -1,6 +1,17 @@ # -*- coding: utf-8 -*- # vim: ft=yaml --- +# Prometheus has two approaches to handling config arguments, through an environment +# file or directly adding to the service file. +# This formular takes both approaches in seperate circumstances, with the archive +# install approach implementing a custom service file, and the repo (default) approach +# using an environ file with the standard package provided service file. +# As a result, depending on the install method used, the environ:args or service:args +# pillars need to be set appropriately. +# The default options given under service in the default.yaml may not therefore apply +# depending on the install method, and in some cases they are no longer consistent +# with the default configuration in the latest package. +# This applies to all components with an example provided for node_exporter. prometheus: wanted: clientlibs: @@ -33,6 +44,12 @@ prometheus: smartctl: /usr/sbin/smartctl pkg: use_upstream_repo: false + # Uses the archive install method with true or repo method with false. Default is + # false. + # The archive and repo methods use completely different approaches to + # / service arguments handling, with different required pillar values. + # The repo method uses the package service config, the archive method uses a custom + # service config. use_upstream_archive: true clientlibs: @@ -94,6 +111,10 @@ prometheus: version: v0.18.1 archive: source_hash: b2503fd932f85f4e5baf161268854bf5d22001869b84f00fd2d1f57b51b72424 + environ: + args: + collector.systemd: null + web.listen-address: ":9110" service: name: prometheus-node-exporter args: diff --git a/prometheus/defaults.yaml b/prometheus/defaults.yaml index 023c360..400b76c 100644 --- a/prometheus/defaults.yaml +++ b/prometheus/defaults.yaml @@ -46,6 +46,8 @@ prometheus: config: {} environ_file: /etc/default/prometheus-alertmanager environ: {} + # These service args will not impact installs using the non archive method and + # instead should be added as environ args in such a case service: args: config.file: /etc/prometheus/alertmanager.yml @@ -135,6 +137,8 @@ prometheus: environ: {} config_file: /etc/prometheus/node_exporter.yml config: {} + # These service args will not impact installs using the non archive method and + # instead should be added as environ args in such a case service: args: collector.textfile.directory: /var/tmp/node_exporter @@ -154,6 +158,8 @@ prometheus: config: {} environ_file: /etc/default/prometheus environ: {} + # These service args will not impact installs using the non archive method and + # instead should be added as environ args in such a case service: args: config.file: /etc/prometheus/prometheus.yml diff --git a/test/integration/repo/controls/service_spec.rb b/test/integration/repo/controls/service_spec.rb index 274fd2d..2382004 100644 --- a/test/integration/repo/controls/service_spec.rb +++ b/test/integration/repo/controls/service_spec.rb @@ -26,10 +26,24 @@ control 'prometheus services' do it { should be_enabled } it { should be_running } end + + describe file("/etc/default/#{service}") do + it { should exist } + end end # prometheus-node-exporter port - describe port(9100) do + describe port(9110) do it { should be_listening } end + + # environ args check + describe file('/etc/default/prometheus') do + its('content') { should include '--log.level=debug' } + end + + describe file('/etc/default/prometheus-node-exporter') do + its('content') { should include '--web.listen-address=:9110' } + its('content') { should include '--collector.systemd' } + end end diff --git a/test/salt/pillar/default.sls b/test/salt/pillar/default.sls index ec9fd1d..486b2d8 100644 --- a/test/salt/pillar/default.sls +++ b/test/salt/pillar/default.sls @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # vim: ft=yaml --- +# Uses the archive install method identified by 'use_upstream_archive: true' prometheus: wanted: clientlibs: @@ -14,31 +15,29 @@ prometheus: - alertmanager - node_exporter - blackbox_exporter - # - consul_exporter - # - php-fpm_exporter + - consul_exporter + - php-fpm_exporter - postgres_exporter - # - mysqld_exporter - # - memcached_exporter # not in upstream repo, only archive + - mysqld_exporter + - memcached_exporter # not in upstream repo, only archive - # exporters: - # node_exporter: - # textfile_collectors_dependencies: [] - # textfile_collectors: - # ipmitool: - # enable: false - # remove: false - # pkg: ipmitool - # smartmon: - # enable: false - # remove: false - # pkg: smartmontools - # bash_pkg: bash - # smartctl: /usr/sbin/smartctl + exporters: + node_exporter: + textfile_collectors_dependencies: [] + textfile_collectors: + ipmitool: + enable: false + remove: false + pkg: ipmitool + smartmon: + enable: false + remove: false + pkg: smartmontools + bash_pkg: bash + smartctl: /usr/sbin/smartctl pkg: use_upstream_repo: false - # Changed to use non archive install as default (the archive includes a bespoke - # implementation of service thats needs updating) - use_upstream_archive: false + use_upstream_archive: true clientlibs: # https://prometheus.io/docs/instrumenting/clientlibs @@ -108,12 +107,12 @@ prometheus: # This is to test that any fancy name we use, will work in archive mode name: my-fancy-consul-exporter-service - # mysqld_exporter: - # service: - # args: - # web.listen-address: 0.0.0.0:9192 - # env: - # - 'DATA_SOURCE_NAME=foo:bar@/' + mysqld_exporter: + service: + args: + web.listen-address: 0.0.0.0:9192 + env: + - 'DATA_SOURCE_NAME=foo:bar@/' prometheus: service: diff --git a/test/salt/pillar/repo.sls b/test/salt/pillar/repo.sls index 72b4de0..2ee3790 100644 --- a/test/salt/pillar/repo.sls +++ b/test/salt/pillar/repo.sls @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # vim: ft=yaml --- +# Uses the standard install method from package repo prometheus: wanted: clientlibs: @@ -78,6 +79,10 @@ prometheus: version: v0.18.1 archive: source_hash: b2503fd932f85f4e5baf161268854bf5d22001869b84f00fd2d1f57b51b72424 + environ: + args: + collector.systemd: true + web.listen-address: ":9110" service: args: web.listen-address: ":9110" @@ -92,6 +97,10 @@ prometheus: service: args: web.listen-address: 0.0.0.0:9090 + environ: + args: + web.listen-address: 0.0.0.0:9090 + log.level: debug config: # yamllint disable-line rule:line-length # ref https://raw.githubusercontent.com/prometheus/prometheus/release-2.10/config/testdata/conf.good.yml From 4635ca70702a05bf5db24df54956c175d0cd3e18 Mon Sep 17 00:00:00 2001 From: BlueWolf Date: Fri, 25 Jun 2021 13:17:41 +0100 Subject: [PATCH 4/6] fix: switched test config entry that wasnt available for deb9 The --collector.systemd config argument is unavailable in the older packages. The formula handles either scenario so switching the check out from the test pillar for --log.level=debug instead Resolved issue identified in pull request check for debian --- test/integration/repo/controls/service_spec.rb | 2 +- test/salt/pillar/repo.sls | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/repo/controls/service_spec.rb b/test/integration/repo/controls/service_spec.rb index 2382004..fc33756 100644 --- a/test/integration/repo/controls/service_spec.rb +++ b/test/integration/repo/controls/service_spec.rb @@ -44,6 +44,6 @@ control 'prometheus services' do describe file('/etc/default/prometheus-node-exporter') do its('content') { should include '--web.listen-address=:9110' } - its('content') { should include '--collector.systemd' } + its('content') { should include '--log.level=debug' } end end diff --git a/test/salt/pillar/repo.sls b/test/salt/pillar/repo.sls index 2ee3790..e2cdd27 100644 --- a/test/salt/pillar/repo.sls +++ b/test/salt/pillar/repo.sls @@ -81,7 +81,7 @@ prometheus: source_hash: b2503fd932f85f4e5baf161268854bf5d22001869b84f00fd2d1f57b51b72424 environ: args: - collector.systemd: true + log.level: debug web.listen-address: ":9110" service: args: From 4de3ebd24196c347ae1ebba88d754c9dd535cf74 Mon Sep 17 00:00:00 2001 From: BlueWolf Date: Sun, 27 Jun 2021 15:04:47 +0100 Subject: [PATCH 5/6] fix: added handle for alternative argument opts header Centos and oraclelinux repositories for prometheus include bespoke headers in the environment files (e.g. Debian: ARGS=, Centos: PROMETHEUS_OPTS= ALERTMANAGER_OPTS=). This has been added as a default pillar with osmap variances. Additionally archlinux repo install was failing so added basic support - an issue still remains for the prometheus app itself due to the service file included in the arch repo hardcoding some config options - resulting in the possibility to duplicate arguments resulting in a service error. The prometheus service currently does not start due to permissions not being applied to a data folder. The added config.storage begins to solve this and ensures alignment on all platforms but would result in a duplicate config entry as above. Prometheus on arch therefore needs more work but the exporter installs now work. Resolves: #59 --- prometheus/config/environ.sls | 6 +- prometheus/config/init.sls | 1 + prometheus/config/storage.sls | 33 +++++++++ prometheus/defaults.yaml | 16 +++-- prometheus/files/default/environ.sh.jinja | 2 +- prometheus/osfamilymap.yaml | 72 +++++++++++++++++-- .../repo/controls/packages_spec.rb | 11 ++- .../integration/repo/controls/service_spec.rb | 10 ++- 8 files changed, 134 insertions(+), 17 deletions(-) create mode 100644 prometheus/config/storage.sls diff --git a/prometheus/config/environ.sls b/prometheus/config/environ.sls index 5f8b0c9..bf61233 100644 --- a/prometheus/config/environ.sls +++ b/prometheus/config/environ.sls @@ -7,13 +7,16 @@ {%- from tplroot ~ "/files/macros.jinja" import concat_args %} {%- set sls_archive_install = tplroot ~ '.archive.install' %} {%- set sls_package_install = tplroot ~ '.package.install' %} +{%- set sls_service_running = tplroot ~ '.service.running' %} include: - {{ sls_archive_install if p.pkg.use_upstream_archive else sls_package_install }} + - {{ sls_service_running }} {%- for name in p.wanted.component %} {%- if 'environ' in p.pkg.component[name] and 'args' in p.pkg.component[name]['environ'] %} {%- set args = p.pkg.component[name]['environ']['args'] %} + {%- set arg_name = p.pkg.component[name]['environ']['environ_arg_name'] %} {%- if 'environ_file' in p.pkg.component[name] and p.pkg.component[name]['environ_file'] %} prometheus-config-install-{{ name }}-environ_file: @@ -30,10 +33,9 @@ prometheus-config-install-{{ name }}-environ_file: - user: {{ p.identity.rootuser }} - group: {{ p.identity.rootgroup }} {%- endif %} - #- contents: | - # command_args="{{ concat_args(args) }}" - context: args: {{ concat_args(args) }} + arg_name: {{ arg_name }} - watch_in: - service: prometheus-service-running-{{ name }} - require: diff --git a/prometheus/config/init.sls b/prometheus/config/init.sls index 71fe77c..66fe664 100644 --- a/prometheus/config/init.sls +++ b/prometheus/config/init.sls @@ -4,3 +4,4 @@ include: - .file - .environ + - .storage diff --git a/prometheus/config/storage.sls b/prometheus/config/storage.sls new file mode 100644 index 0000000..b3d09a9 --- /dev/null +++ b/prometheus/config/storage.sls @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus as p with context %} +{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} +{%- from tplroot ~ "/files/macros.jinja" import concat_args %} +{%- set sls_archive_install = tplroot ~ '.archive.install' %} +{%- set sls_package_install = tplroot ~ '.package.install' %} + +include: + - {{ sls_archive_install if p.pkg.use_upstream_archive else sls_package_install }} + + {%- for name in p.wanted.component %} + {%- if 'environ' in p.pkg.component[name] and 'args' in p.pkg.component[name]['environ'] %} + {%- set args = p.pkg.component[name]['environ']['args'] %} + {%- if 'storage.tsdb.path' in args.keys() %} + +prometheus-service-args-{{ name }}-data-dir: + file.directory: + - name: {{ args['storage.tsdb.path'] }} + - owner: {{ name }} + - group: {{ name }} + - makedirs: True + - watch_in: + - service: prometheus-service-running-{{ name }} + - require: + - user: prometheus-config-users-install-{{ name }}-user-present + - group: prometheus-config-users-install-{{ name }}-group-present + + {%- endif %} + {% endif %} + {% endfor %} \ No newline at end of file diff --git a/prometheus/defaults.yaml b/prometheus/defaults.yaml index 400b76c..e938222 100644 --- a/prometheus/defaults.yaml +++ b/prometheus/defaults.yaml @@ -45,7 +45,8 @@ prometheus: config_file: /etc/prometheus/alertmanager.yml config: {} environ_file: /etc/default/prometheus-alertmanager - environ: {} + environ: + environ_arg_name: ARGS # These service args will not impact installs using the non archive method and # instead should be added as environ args in such a case service: @@ -67,6 +68,9 @@ prometheus: version: v0.18.0 config_file: /etc/prometheus/blackbox_exporter.yml config: {} + environ_file: /etc/default/prometheus-blackbox-exporter + environ: + environ_arg_name: ARGS archive: source_hash: a87f9530e31e2b20d03a6d941f6f051c57ee724f24b38f2615b8580ca63966dc commands: @@ -134,7 +138,8 @@ prometheus: node_exporter: version: v1.0.1 environ_file: /etc/default/prometheus-node-exporter - environ: {} + environ: + environ_arg_name: ARGS config_file: /etc/prometheus/node_exporter.yml config: {} # These service args will not impact installs using the non archive method and @@ -157,7 +162,8 @@ prometheus: config_file: /etc/prometheus/prometheus.yml config: {} environ_file: /etc/default/prometheus - environ: {} + environ: + environ_arg_name: ARGS # These service args will not impact installs using the non archive method and # instead should be added as environ args in such a case service: @@ -177,7 +183,8 @@ prometheus: pushgateway: version: v1.3.0 environ_file: /etc/default/prometheus-pushgateway - environ: {} + environ: + environ_arg_name: ARGS config_file: /etc/prometheus/pushgateway.yml config: {} service: {} @@ -201,7 +208,6 @@ prometheus: - tcp/4505 - tcp/4506 - tcp/9102 - clientlibs: # https://prometheus.io/docs/instrumenting/clientlibs # no bash & perl client tarballs are available diff --git a/prometheus/files/default/environ.sh.jinja b/prometheus/files/default/environ.sh.jinja index 296e406..4632e80 100644 --- a/prometheus/files/default/environ.sh.jinja +++ b/prometheus/files/default/environ.sh.jinja @@ -3,7 +3,7 @@ # Your changes may be overwritten. ######################################################################## # Set the command-line arguments to pass to the server.%}" -ARGS="{{ args }}" +{{ arg_name }}="{{ args }}" diff --git a/prometheus/osfamilymap.yaml b/prometheus/osfamilymap.yaml index 75a77ec..27acf9d 100644 --- a/prometheus/osfamilymap.yaml +++ b/prometheus/osfamilymap.yaml @@ -15,7 +15,22 @@ {%- set macos_rootgroup = salt['cmd.run']("stat -f '%Sg' /dev/console") %} {%- endif %} -Arch: {} +Arch: + pkg: + component: + alertmanager: + name: alertmanager + blackbox_exporter: + name: prometheus-blackbox-exporter + prometheus: + environ_file: /etc/conf.d/prometheus + environ: + environ_arg_name: PROMETHEUS_ARGS + node_exporter: + name: prometheus-node-exporter + environ_file: /etc/conf.d/prometheus-node-exporter + environ: + environ_arg_name: NODE_EXPORTER_ARGS Alpine: {} @@ -29,8 +44,6 @@ Debian: use_upstream_package: false use_upstream_archive: false component: - prometheus: - name: prometheus alertmanager: name: prometheus-alertmanager service: @@ -47,11 +60,20 @@ Debian: bird_exporter: name: prometheus-bird-exporter args_file: /etc/default/prometheus-bird-exporter + prometheus: + name: prometheus blackbox_exporter: name: prometheus-blackbox-exporter + config_file: /etc/prometheus/blackbox.yml + environ_file: /etc/default/prometheus-blackbox-exporter + environ: + environ_arg_name: ARGS service: name: prometheus-blackbox-exporter - config_file: /etc/prometheus/blackbox.yml + consul_exporter: + name: prometheus-consul-exporter + graphite_exporter: + name: prometheus-graphite-exporter hacluster_exporter: name: prometheus-hacluster-exporter args_file: /etc/default/prometheus-hacluster-exporter @@ -70,6 +92,8 @@ Debian: mailexporter: name: prometheus-mailexporter args_file: /etc/default/prometheus-mailexporter + memcached_exporter: + name: prometheus-memcached-exporter mongodb_exporter: name: prometheus-mongodb-exporter args_file: /etc/default/prometheus-mongodb-exporter @@ -85,7 +109,7 @@ Debian: args_file: /etc/default/prometheus-nginx-exporter nginx_vts_exporter: name: prometheus-nginx-vts-exporter - args_file: /etc/default/prometheus-nginx-vts-exporter + args_file: /etc/default/prometheus-nginx-vts-export node_exporter: name: prometheus-node-exporter service: @@ -113,7 +137,11 @@ Debian: args_file: /etc/default/prometheus-process-exporter pushgateway: name: prometheus-pushgateway + service: + name: prometheus-pushgateway args_file: /etc/default/prometheus-pushgateway + statsd_exporter: + name: prometheus-statsd-exporter snmp_exporter: name: prometheus-snmp-exporter args_file: /etc/default/prometheus-snmp-exporter @@ -122,7 +150,7 @@ Debian: args_file: /etc/default/prometheus-sql-exporter squid_exporter: name: prometheus-squid-exporter - args_file: /etc/default/prometheus-squid-exporter + args_file: /etc/default/prometheus-squid- tplink_plug_exporter: name: prometheus-tplink-plug-exporter args_file: /etc/default/prometheus-tplink-plug-exporter @@ -135,7 +163,7 @@ Debian: xmpp_alerts: name: prometheus-xmpp-alerts args_file: /etc/default/prometheus-xmpp-alerts - + exporters: node_exporter: textfile_collectors_dependencies: @@ -148,6 +176,35 @@ RedHat: component: prometheus: name: prometheus2 + environ_file: /etc/default/prometheus + environ: + environ_arg_name: PROMETHEUS_OPTS + args: + config.file: /etc/prometheus/prometheus.yml + storage.tsdb.path: /var/lib/prometheus/data + web.console.libraries: /usr/share/prometheus/console_libraries + web.console.templates: /usr/share/prometheus/consoles + alertmanager: + environ_file: /etc/default/alertmanager + environ: + environ_arg_name: ALERTMANAGER_OPTS + args: + config.file: /etc/prometheus/alertmanager.yml + storage.path: /var/lib/prometheus/alertmanager + node_exporter: + environ_file: /etc/default/node_exporter + environ: + environ_arg_name: NODE_EXPORTER_OPTS + pushgateway: + environ_file: /etc/default/pushgateway + environ: + environ_arg_name: PUSHGATEWAY_OPTS + blackbox_exporter: + environ_file: /etc/default/blackbox_exporter + environ: + environ_arg_name: BLACKBOX_EXPORTER_OPTS + args: + config.file: /etc/prometheus/blackbox.yml repo: # https://akai-tsuki.hatenablog.com/entry/2017/12/03/000000 # yamllint disable rule:line-length @@ -385,3 +442,4 @@ MacOS: statsd_exporter: archive: source_hash: 15132494523c2b6a89e09b2da63452c8fe587fb82fcc3fd21cc75a4aa2766644 + diff --git a/test/integration/repo/controls/packages_spec.rb b/test/integration/repo/controls/packages_spec.rb index 1481bb8..d4ae732 100644 --- a/test/integration/repo/controls/packages_spec.rb +++ b/test/integration/repo/controls/packages_spec.rb @@ -11,7 +11,16 @@ control 'prometheus packages' do alertmanager node_exporter ] - when 'debian' + when 'linux' + case platform[:name] + when 'arch' + %w[ + prometheus + alertmanager + prometheus-node-exporter + ] + end + else %w[ prometheus prometheus-alertmanager diff --git a/test/integration/repo/controls/service_spec.rb b/test/integration/repo/controls/service_spec.rb index fc33756..61d18a3 100644 --- a/test/integration/repo/controls/service_spec.rb +++ b/test/integration/repo/controls/service_spec.rb @@ -21,6 +21,14 @@ control 'prometheus services' do ] end + node_exporter = + case platform[:family] + when 'redhat' + 'node_exporter' + else + 'prometheus-node-exporter' + end + services.each do |service| describe service(service) do it { should be_enabled } @@ -42,7 +50,7 @@ control 'prometheus services' do its('content') { should include '--log.level=debug' } end - describe file('/etc/default/prometheus-node-exporter') do + describe file("/etc/default/#{node_exporter}") do its('content') { should include '--web.listen-address=:9110' } its('content') { should include '--log.level=debug' } end From 52845bb534ba98947ee161e7fb745489b2ad57da Mon Sep 17 00:00:00 2001 From: BlueWolf Date: Tue, 29 Jun 2021 12:40:39 +0100 Subject: [PATCH 6/6] fix: removed erroneus dash (-) Dash was incorrectly left alongside squid_exporter entry in osfamilymap. Resolves: #59 --- prometheus/osfamilymap.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prometheus/osfamilymap.yaml b/prometheus/osfamilymap.yaml index 27acf9d..4baeb32 100644 --- a/prometheus/osfamilymap.yaml +++ b/prometheus/osfamilymap.yaml @@ -150,7 +150,7 @@ Debian: args_file: /etc/default/prometheus-sql-exporter squid_exporter: name: prometheus-squid-exporter - args_file: /etc/default/prometheus-squid- + args_file: /etc/default/prometheus-squid tplink_plug_exporter: name: prometheus-tplink-plug-exporter args_file: /etc/default/prometheus-tplink-plug-exporter