Skip to content

Commit

Permalink
fix: rework to implement environment variables handling
Browse files Browse the repository at this point in the history
Developed environ.sh.jinja and added test pillar data to default
Corrected prometheus.config.environ ref saltstack-formulas#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: saltstack-formulas#59
  • Loading branch information
BlueWolf committed Jun 24, 2021
1 parent fa96aab commit eea5b40
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 18 deletions.
1 change: 1 addition & 0 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
4 changes: 3 additions & 1 deletion kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ driver:
use_sudo: false
privileged: true
run_command: /lib/systemd/systemd
forward:
- 9090:9090

platforms:
## SALT `tiamat`
Expand Down Expand Up @@ -350,7 +352,7 @@ suites:
state_top:
base:
'*':
- prometheus._mapdata
# - prometheus._mapdata
- prometheus
pillars:
top.sls:
Expand Down
13 changes: 8 additions & 5 deletions prometheus/config/environ.sls
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
{%- 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' %}
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:
Expand All @@ -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:
Expand All @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion prometheus/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion prometheus/files/default/environ.sh.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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) }}
26 changes: 16 additions & 10 deletions test/salt/pillar/default.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit eea5b40

Please sign in to comment.