From 076869a8cdbde4ed1034d98f16cdeaa17906554e Mon Sep 17 00:00:00 2001 From: BlueWolf Date: Sun, 27 Jun 2021 15:04:47 +0100 Subject: [PATCH] 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