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
This commit is contained in:
BlueWolf 2021-06-24 14:55:09 +01:00
parent fa96aabba7
commit eea5b407fa
6 changed files with 33 additions and 18 deletions

View File

@ -12,6 +12,7 @@ extends: 'default'
# 5. Any YAML files under directory `.kitchen/`, introduced during local testing # 5. Any YAML files under directory `.kitchen/`, introduced during local testing
# 6. `kitchen.vagrant.yml`, which contains Embedded Ruby (ERB) template syntax # 6. `kitchen.vagrant.yml`, which contains Embedded Ruby (ERB) template syntax
ignore: | ignore: |
.bundle/
.cache/ .cache/
.git/ .git/
node_modules/ node_modules/

View File

@ -7,6 +7,8 @@ driver:
use_sudo: false use_sudo: false
privileged: true privileged: true
run_command: /lib/systemd/systemd run_command: /lib/systemd/systemd
forward:
- 9090:9090
platforms: platforms:
## SALT `tiamat` ## SALT `tiamat`
@ -350,7 +352,7 @@ suites:
state_top: state_top:
base: base:
'*': '*':
- prometheus._mapdata # - prometheus._mapdata
- prometheus - prometheus
pillars: pillars:
top.sls: top.sls:

View File

@ -4,7 +4,7 @@
{%- set tplroot = tpldir.split('/')[0] %} {%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import prometheus as p with context %} {%- from tplroot ~ "/map.jinja" import prometheus as p with context %}
{%- from tplroot ~ "/libtofs.jinja" import files_switch 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_archive_install = tplroot ~ '.archive.install' %}
{%- set sls_package_install = tplroot ~ '.package.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 }} - {{ sls_archive_install if p.pkg.use_upstream_archive else sls_package_install }}
{%- for name in p.wanted.component %} {%- 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'] %} {%- if 'environ_file' in p.pkg.component[name] and p.pkg.component[name]['environ_file'] %}
prometheus-config-install-{{ name }}-environ_file: prometheus-config-install-{{ name }}-environ_file:
@ -29,8 +30,10 @@ prometheus-config-install-{{ name }}-environ_file:
- user: {{ p.identity.rootuser }} - user: {{ p.identity.rootuser }}
- group: {{ p.identity.rootgroup }} - group: {{ p.identity.rootgroup }}
{%- endif %} {%- endif %}
- contents: | #- contents: |
command_args="{{ concat_environ(environ) }}" # command_args="{{ concat_args(args) }}"
- context:
args: {{ args }}
- watch_in: - watch_in:
- service: prometheus-service-running-{{ name }} - service: prometheus-service-running-{{ name }}
- require: - require:
@ -43,7 +46,7 @@ prometheus-config-environ-{{ name }}-all:
- name: {{ name }}_environ - name: {{ name }}_environ
# service prometheus restart tends to hang on FreeBSD # service prometheus restart tends to hang on FreeBSD
# https://github.com/saltstack/salt/issues/44848#issuecomment-487016414 # 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: - watch_in:
- service: prometheus-service-running-{{ name }} - service: prometheus-service-running-{{ name }}

View File

@ -152,7 +152,7 @@ prometheus:
version: v2.22.1 version: v2.22.1
config_file: /etc/prometheus/prometheus.yml config_file: /etc/prometheus/prometheus.yml
config: {} config: {}
environ_file: /etc/default/prometheus.sh environ_file: /etc/default/prometheus
environ: {} environ: {}
service: service:
args: args:

View File

@ -2,5 +2,8 @@
# File managed by Salt at <{{ source }}>. # File managed by Salt at <{{ source }}>.
# Your changes may be overwritten. # 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) }}

View File

@ -14,10 +14,10 @@ prometheus:
- alertmanager - alertmanager
- node_exporter - node_exporter
- blackbox_exporter - blackbox_exporter
- consul_exporter # - consul_exporter
- php-fpm_exporter # - php-fpm_exporter
- postgres_exporter - postgres_exporter
- mysqld_exporter # - mysqld_exporter
# - memcached_exporter # not in upstream repo, only archive # - memcached_exporter # not in upstream repo, only archive
exporters: exporters:
@ -36,7 +36,9 @@ prometheus:
smartctl: /usr/sbin/smartctl smartctl: /usr/sbin/smartctl
pkg: pkg:
use_upstream_repo: false 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: clientlibs:
# https://prometheus.io/docs/instrumenting/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 # This is to test that any fancy name we use, will work in archive mode
name: my-fancy-consul-exporter-service name: my-fancy-consul-exporter-service
mysqld_exporter: # mysqld_exporter:
service: # service:
args: # args:
web.listen-address: 0.0.0.0:9192 # web.listen-address: 0.0.0.0:9192
env: # env:
- 'DATA_SOURCE_NAME=foo:bar@/' # - 'DATA_SOURCE_NAME=foo:bar@/'
prometheus: prometheus:
service: service:
args: args:
web.listen-address: 0.0.0.0:9090 web.listen-address: 0.0.0.0:9090
environ:
args:
web.listen-address: 0.0.0.0:9090
log.level: debug
config: config:
# yamllint disable-line rule:line-length # yamllint disable-line rule:line-length
# ref https://raw.githubusercontent.com/prometheus/prometheus/release-2.10/config/testdata/conf.good.yml # ref https://raw.githubusercontent.com/prometheus/prometheus/release-2.10/config/testdata/conf.good.yml