Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/environ correction #60

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
21 changes: 21 additions & 0 deletions pillar.example
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
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: {{ concat_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
14 changes: 10 additions & 4 deletions prometheus/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ 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: {}
# 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
Expand Down Expand Up @@ -131,10 +133,12 @@ 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: {}
# 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
Expand All @@ -152,8 +156,10 @@ prometheus:
version: v2.22.1
config_file: /etc/prometheus/prometheus.yml
config: {}
environ_file: /etc/default/prometheus.sh
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
Expand All @@ -170,7 +176,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: {}
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="{{ args }}"



{{ config|yaml(False) }}
16 changes: 15 additions & 1 deletion test/integration/repo/controls/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,24 @@
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
11 changes: 10 additions & 1 deletion test/salt/pillar/default.sls
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
# Uses the archive install method identified by 'use_upstream_archive: true'
prometheus:
wanted:
clientlibs:
Expand All @@ -18,7 +19,7 @@ prometheus:
- php-fpm_exporter
- postgres_exporter
- mysqld_exporter
# - memcached_exporter # not in upstream repo, only archive
- memcached_exporter # not in upstream repo, only archive

exporters:
node_exporter:
Expand Down Expand Up @@ -85,6 +86,10 @@ prometheus:
- to: 'team-X+alerts@example.org'

node_exporter:
environ:
args:
collector.systemd: true
web.listen-address: ":9110"
service:
args:
collector.systemd: null
Expand Down Expand Up @@ -113,6 +118,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
Expand Down
9 changes: 9 additions & 0 deletions test/salt/pillar/repo.sls
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
# Uses the standard install method from package repo
prometheus:
wanted:
clientlibs:
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down