From eea5b407fa6dee5cdcb7bd951b752beb1833176c Mon Sep 17 00:00:00 2001 From: BlueWolf Date: Thu, 24 Jun 2021 14:55:09 +0100 Subject: [PATCH] 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