From 1f86f4a27ca771f8952ed1820e30083325698322 Mon Sep 17 00:00:00 2001 From: N Date: Sat, 8 Jun 2019 18:39:21 +0100 Subject: [PATCH 01/12] feat(archives): support for archives file format BREAKING CHANGE: the parameter `pkg` is now a dictionary. References to `prometheus.pkg` should be changed to `prometheus.pkg.name`. --- docs/README.rst | 20 +++++++++++ pillar.example | 10 +++++- prometheus/archive/clean.sls | 11 ++++++ prometheus/archive/init.sls | 5 +++ prometheus/archive/install.sls | 23 ++++++++++++ prometheus/clean.sls | 1 + prometheus/config/clean.sls | 4 ++- prometheus/config/environ.sls | 28 +++++++++++++++ prometheus/config/file.sls | 14 ++++++-- prometheus/config/init.sls | 1 + prometheus/defaults.yaml | 21 +++++++++-- prometheus/exporters/node/clean.sls | 2 +- prometheus/exporters/node/init.sls | 2 +- prometheus/files/default/prometheus.sh.jinja | 10 ++++++ prometheus/files/default/prometheus.yml.jinja | 2 +- prometheus/init.sls | 6 +++- prometheus/jinja/macros.jinja | 12 +++++++ prometheus/map.jinja | 17 ++++++++- prometheus/osarchmap.yaml | 35 +++++++++++++++++++ prometheus/osfamilymap.yaml | 15 ++++++-- prometheus/package/clean.sls | 2 +- prometheus/package/install.sls | 2 +- prometheus/service/running.sls | 10 +++++- 23 files changed, 236 insertions(+), 17 deletions(-) create mode 100644 prometheus/archive/clean.sls create mode 100644 prometheus/archive/init.sls create mode 100644 prometheus/archive/install.sls create mode 100644 prometheus/config/environ.sls create mode 100644 prometheus/files/default/prometheus.sh.jinja create mode 100644 prometheus/jinja/macros.jinja create mode 100644 prometheus/osarchmap.yaml diff --git a/docs/README.rst b/docs/README.rst index c9997d4..2fd9751 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -48,11 +48,21 @@ This installs the prometheus package, manages the prometheus configuration file and then starts the associated prometheus service. +``prometheus.archive`` +^^^^^^^^^^^^^^^^^^^^ + +This state will install the prometheus from archive file only. + ``prometheus.package`` ^^^^^^^^^^^^^^^^^^^^ This state will install the prometheus package only. +``prometheus.package.repo`` +^^^^^^^^^^^^^^^^^^^^^^^^^ + +This state will install the prometheus package only. + ``prometheus.config`` ^^^^^^^^^^^^^^^^^^^ @@ -92,6 +102,16 @@ dependency on ``prometheus.service.clean`` via include list. This state will remove the prometheus package and has a depency on ``prometheus.config.clean`` via include list. +``prometheus.package.archive.clean`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This state will uninstall the prometheus archive-extracted directory only. + +``prometheus.package.repo.clean`` +^^^^^^^^^^^^^^^^^^^^^^^^^ + +This state will uninstall the prometheus upstream package repository only. + ``prometheus.exporters`` ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/pillar.example b/pillar.example index 5feb67c..7dbc976 100644 --- a/pillar.example +++ b/pillar.example @@ -2,8 +2,14 @@ # vim: ft=yaml --- prometheus: - pkg: prometheus + pkg: + name: prometheus + archive: + source: https://github.com/prometheus/prometheus/releases/download/v2.10.0/prometheus-2.10.0.linux-amd64.tar.gz + source_hash: f4233783826f18606b79e5cef0686e4a9c2030146a3c7ce134f0add09f5adcb7 + enforce_toplevel: False config_file: /etc/prometheus/prometheus.yml + environ_file: /etc/default/prometheus.sh service: name: prometheus args: @@ -33,6 +39,8 @@ prometheus: # - 'example_alt.tmpl.jinja' # Pillar-based config + environ: + - 'export PATH=${PATH}:/opt/prometheus-2.10.0.linux-amd64' config: # my global config global: diff --git a/prometheus/archive/clean.sls b/prometheus/archive/clean.sls new file mode 100644 index 0000000..29fe10e --- /dev/null +++ b/prometheus/archive/clean.sls @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus with context %} + +prometheus-cli-package-archive-clean-file-absent: + file.absent: + - names: + - {{ prometheus.base_dir }} diff --git a/prometheus/archive/init.sls b/prometheus/archive/init.sls new file mode 100644 index 0000000..051d698 --- /dev/null +++ b/prometheus/archive/init.sls @@ -0,0 +1,5 @@ +#.-*- coding: utf-8 -*- +# vim: ft=sls + +include: + - .install diff --git a/prometheus/archive/install.sls b/prometheus/archive/install.sls new file mode 100644 index 0000000..a956d1d --- /dev/null +++ b/prometheus/archive/install.sls @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus with context %} +{%- from tplroot ~ "/jinja/macros.jinja" import format_kwargs with context %} + +prometheus-package-archive-install-file-directory: + file.directory: + - name: {{ prometheus.pkg.archive.name }} + - makedirs: True + - require_in: + - archive: prometheus-package-archive-install-archive-extracted + +prometheus-package-archive-install-archive-extracted: + archive.extracted: + {{- format_kwargs(prometheus.pkg.archive) }} + - retry: + attempts: 3 + until: True + interval: 60 + splay: 10 diff --git a/prometheus/clean.sls b/prometheus/clean.sls index 2cefe7d..c462cd5 100644 --- a/prometheus/clean.sls +++ b/prometheus/clean.sls @@ -4,4 +4,5 @@ include: - .service.clean - .config.clean + - .archive.clean - .package.clean diff --git a/prometheus/config/clean.sls b/prometheus/config/clean.sls index a73b297..46f2b3c 100644 --- a/prometheus/config/clean.sls +++ b/prometheus/config/clean.sls @@ -11,7 +11,9 @@ include: prometheus-config-clean-file-absent: file.absent: - - name: {{ prometheus.config_file }} + - names: + - {{ prometheus.config_file }} + - {{ prometheus.environ_file }} - require: - sls: {{ sls_service_clean }} diff --git a/prometheus/config/environ.sls b/prometheus/config/environ.sls new file mode 100644 index 0000000..76cec27 --- /dev/null +++ b/prometheus/config/environ.sls @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus with context %} +{%- set sls_archive_install = tplroot ~ '.archive.install' %} +{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} + +include: + - {{ sls_archive_install }} + +prometheus-config-file-file-managed-environ_file: + file.managed: + - name: {{ prometheus.environ_file }} + - source: {{ files_switch(['prometheus.sh.jinja'], + lookup='prometheus-config-file-file-managed-environ_file' + ) + }} + - mode: 644 + - user: root + - group: {{ prometheus.rootgroup }} + - makedirs: True + - template: jinja + - context: + prometheus: {{ prometheus|json }} + - require: + - sls: {{ sls_archive_install }} diff --git a/prometheus/config/file.sls b/prometheus/config/file.sls index 5e7c2bd..dd9a302 100644 --- a/prometheus/config/file.sls +++ b/prometheus/config/file.sls @@ -3,18 +3,24 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} -{%- set sls_package_install = tplroot ~ '.package.install' %} {%- from tplroot ~ "/map.jinja" import prometheus with context %} {%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} +{%- if 'config' in prometheus and prometheus.config %} + {%- if prometheus.pkg.use_upstream_archive %} + {%- set sls_package_install = tplroot ~ '.archive.install' %} + {%- else %} + {%- set sls_package_install = tplroot ~ '.package.install' %} + {%- endif %} + include: - {{ sls_package_install }} -prometheus-config-file-file-managed: +prometheus-config-file-file-managed-config_file: file.managed: - name: {{ prometheus.config_file }} - source: {{ files_switch(['prometheus.yml.jinja'], - lookup='prometheus-config-file-file-managed' + lookup='prometheus-config-file-file-managed-config_file' ) }} - mode: 644 @@ -26,3 +32,5 @@ prometheus-config-file-file-managed: config: {{ prometheus.config|json }} - require: - sls: {{ sls_package_install }} + +{%- endif %} diff --git a/prometheus/config/init.sls b/prometheus/config/init.sls index 8919ea2..b399256 100644 --- a/prometheus/config/init.sls +++ b/prometheus/config/init.sls @@ -4,3 +4,4 @@ include: - .args - .file + - .environ diff --git a/prometheus/defaults.yaml b/prometheus/defaults.yaml index cf551cd..c168c12 100644 --- a/prometheus/defaults.yaml +++ b/prometheus/defaults.yaml @@ -2,15 +2,32 @@ # vim: ft=yaml --- prometheus: - pkg: prometheus + version: '2.10.0' + pkg: + name: prometheus + binary: prometheus + use_upstream_archive: False + archive: + name: /opt + uri: https://github.com/prometheus/prometheus/releases/download/ + source: None + # linux amd64 source hash + source_hash: f4233783826f18606b79e5cef0686e4a9c2030146a3c7ce134f0add09f5adcb7 + trim_output: True + enforce_toplevel: True + archive_format: tar.gz rootgroup: root + kernel: {{ grains.kernel | lower }} config_file: /etc/prometheus/prometheus.yml config: {} + environ_file: /etc/default/prometheus.sh + environ: [] service: name: prometheus user: prometheus group: prometheus exporters: node: - pkg: prometheus-node-exporter + pkg: + name: prometheus-node-exporter service: prometheus-node-exporter diff --git a/prometheus/exporters/node/clean.sls b/prometheus/exporters/node/clean.sls index cbd4030..14401e2 100644 --- a/prometheus/exporters/node/clean.sls +++ b/prometheus/exporters/node/clean.sls @@ -12,7 +12,7 @@ prometheus-exporters-node-service-dead: prometheus-exporters-node-pkg-removed: pkg.removed: - - name: {{ prometheus.exporters.node.pkg }} + - name: {{ prometheus.exporters.node.pkg.name }} - require: - service: prometheus-exporters-node-service-dead diff --git a/prometheus/exporters/node/init.sls b/prometheus/exporters/node/init.sls index 29ec372..f8f7534 100644 --- a/prometheus/exporters/node/init.sls +++ b/prometheus/exporters/node/init.sls @@ -8,7 +8,7 @@ prometheus-exporters-node-pkg-installed: pkg.installed: - - name: {{ prometheus.exporters.node.pkg }} + - name: {{ prometheus.exporters.node.pkg.name }} {%- if 'args' in prometheus.exporters.node %} {%- set args = prometheus.exporters.node.get('args', {}) -%} diff --git a/prometheus/files/default/prometheus.sh.jinja b/prometheus/files/default/prometheus.sh.jinja new file mode 100644 index 0000000..afc0f91 --- /dev/null +++ b/prometheus/files/default/prometheus.sh.jinja @@ -0,0 +1,10 @@ +######################################################################## +# File managed by Salt at <{{ source }}>. +# Your changes may be overwritten. +######################################################################## + +{%- if prometheus.environ %} + {%- for item in prometheus.environ %} +{{ item }} + {%- endfor %} +{%- endif %} diff --git a/prometheus/files/default/prometheus.yml.jinja b/prometheus/files/default/prometheus.yml.jinja index cd410da..5c601d1 100644 --- a/prometheus/files/default/prometheus.yml.jinja +++ b/prometheus/files/default/prometheus.yml.jinja @@ -1,6 +1,6 @@ ######################################################################## # File managed by Salt at <{{ source }}>. -# Your changes will be overwritten. +# Your changes may be overwritten. ######################################################################## {{ config|yaml(False) }} diff --git a/prometheus/init.sls b/prometheus/init.sls index 858a8e6..11743b6 100644 --- a/prometheus/init.sls +++ b/prometheus/init.sls @@ -1,7 +1,11 @@ # -*- coding: utf-8 -*- # vim: ft=sls +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus with context %} + include: - - .package + - {{ '.archive' if prometheus.pkg.use_upstream_archive else '.package' }} - .config - .service diff --git a/prometheus/jinja/macros.jinja b/prometheus/jinja/macros.jinja new file mode 100644 index 0000000..aeeb852 --- /dev/null +++ b/prometheus/jinja/macros.jinja @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# vim: ft=jinja +# +# Collection of common macros + +{%- macro format_kwargs(kwarg) -%} + {%- filter indent(4) %} + {%- for k, v in kwarg|dictsort() %} +- {{ k }}: {{ v }} + {%- endfor %} + {%- endfilter %} +{%- endmacro %} diff --git a/prometheus/map.jinja b/prometheus/map.jinja index 5f82fba..04f386a 100644 --- a/prometheus/map.jinja +++ b/prometheus/map.jinja @@ -7,6 +7,7 @@ {%- import_yaml tplroot ~ "/defaults.yaml" as default_settings %} {%- import_yaml tplroot ~ "/osfamilymap.yaml" as osfamilymap %} {%- import_yaml tplroot ~ "/osmap.yaml" as osmap %} +{%- import_yaml tplroot ~ "/osarchmap.yaml" as osarchmap %} {%- import_yaml tplroot ~ "/osfingermap.yaml" as osfingermap %} {%- set defaults = salt['grains.filter_by'](default_settings, @@ -14,7 +15,9 @@ merge=salt['grains.filter_by'](osfamilymap, grain='os_family', merge=salt['grains.filter_by'](osmap, grain='os', merge=salt['grains.filter_by'](osfingermap, grain='osfinger', - merge=salt['pillar.get']('prometheus:lookup', default={}) + merge=salt['grains.filter_by'](osarchmap, grain='osarch', + merge=salt['pillar.get']('prometheus:lookup', default={}) + ) ) ) ) @@ -23,6 +26,18 @@ {#- Merge the prometheus pillar #} {%- set prometheus = salt['pillar.get']('prometheus', default=defaults, merge=True) %} +{#- Update archive details #} +{%- if prometheus.pkg.use_upstream_archive %} + {%- set name = 'prometheus-%s.%s-%s'|format(prometheus.version, prometheus.kernel, prometheus.arch) %} + {%- do prometheus.pkg.archive.update({ + 'source': prometheus.pkg.archive.uri + 'v' + prometheus.version + '/' + name + + '.' + prometheus.pkg.archive.archive_format, + 'archive_format': prometheus.pkg.archive.archive_format.split('.')[0] + }) %} + {%- do prometheus.update({'base_dir': prometheus.pkg.archive.name + '/' + name}) %} + {%- do prometheus.environ.append('export PATH=${PATH}:' + prometheus.pkg.archive.name + '/' + name) %} +{%- endif %} + {#- Contactenate arguments #} {%- macro concat_args(args) %} {%- set args = args|dictsort %} diff --git a/prometheus/osarchmap.yaml b/prometheus/osarchmap.yaml new file mode 100644 index 0000000..aca537a --- /dev/null +++ b/prometheus/osarchmap.yaml @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +# +# Setup variables using grains['osarch'] based logic. +# You just need to add the key:values for an `osarch` that differ +# from `defaults.yaml` + `os_family.yaml`. +# Only add an `osarch` which is/will be supported by the formula +# +# If you do not need to provide defaults via the `osarch` grain, +# you will need to provide at least an empty dict in this file, e.g. +# osarch: {} +--- +amd64: + arch: amd64 + +x86_64: + arch: amd64 + +386: + arch: 386 + +arm64: + arch: arm64 + +armv6l: + arch: armv6l + +armv7l: + arch: armv6l + +ppc64le: + arch: ppc64le + +s390x: + arch: s390x diff --git a/prometheus/osfamilymap.yaml b/prometheus/osfamilymap.yaml index e0da13b..94ffa6e 100644 --- a/prometheus/osfamilymap.yaml +++ b/prometheus/osfamilymap.yaml @@ -35,7 +35,8 @@ FreeBSD: config_file: /usr/local/etc/prometheus.yml exporters: node: - pkg: node_exporter + pkg: + name: node_exporter service: node_exporter OpenBSD: @@ -43,7 +44,17 @@ OpenBSD: Solaris: {} -Windows: {} +Windows: + pkg: + archive: + name: C:\\Program Files + source: https://github.com/prometheus/prometheus/releases/download/v2.10.0/prometheus-2.10.0.windows-amd64.tar.gz + source_hash: eb138082a4d5e4d5b1e3ca838fa508f053474d46bca76e87ab0834f0d8b110db MacOS: + pkg: + archive: + name: /opt + source: https://github.com/prometheus/prometheus/releases/download/v2.10.0/prometheus-2.10.0.darwin-amd64.tar.gz + source_hash: 740e36bcacc0c5d4495f5341fcfa8b7e0dc623d12e8b07ac291052ea0a681325 rootgroup: {{ macos_group | d('') }} diff --git a/prometheus/package/clean.sls b/prometheus/package/clean.sls index b4e5a80..30a2b26 100644 --- a/prometheus/package/clean.sls +++ b/prometheus/package/clean.sls @@ -11,6 +11,6 @@ include: prometheus-package-clean-pkg-removed: pkg.removed: - - name: {{ prometheus.pkg }} + - name: {{ prometheus.pkg.name }} - require: - sls: {{ sls_config_clean }} diff --git a/prometheus/package/install.sls b/prometheus/package/install.sls index 873c4a7..8280d96 100644 --- a/prometheus/package/install.sls +++ b/prometheus/package/install.sls @@ -7,4 +7,4 @@ prometheus-package-install-pkg-installed: pkg.installed: - - name: {{ prometheus.pkg }} + - name: {{ prometheus.pkg.name }} diff --git a/prometheus/service/running.sls b/prometheus/service/running.sls index a61573e..6f07ef1 100644 --- a/prometheus/service/running.sls +++ b/prometheus/service/running.sls @@ -11,12 +11,20 @@ include: - {{ sls_config_args }} - {{ sls_config_file }} +prometheus-service-running-service-unmasked: + service.unmasked: + - name: {{ prometheus.service.name }} + - onlyif: systemctl >/dev/null 2>&1 + prometheus-service-running-service-running: service.running: - name: {{ prometheus.service.name }} - enable: True + {%- if 'config' in prometheus and prometheus.config %} - watch: - - file: prometheus-config-file-file-managed + - file: prometheus-config-file-file-managed-config_file - require: + - service: prometheus-service-running-service-unmasked - sls: {{ sls_config_args }} - sls: {{ sls_config_file }} + {%- endif %} From b074bd3deee42cf28c3681655e4eb82e69bd0244 Mon Sep 17 00:00:00 2001 From: N Date: Sun, 16 Jun 2019 01:22:14 +0100 Subject: [PATCH 02/12] test(inspec): expand unittests for archive format --- pillar.example | 1 + prometheus/archive/install.sls | 12 ++++ prometheus/config/clean.sls | 43 +++++++----- prometheus/config/init.sls | 69 ++++++++++++++++++- prometheus/defaults.yaml | 2 + test/integration/default/README.md | 50 ++++++++++++++ .../default/controls/environ_spec.rb | 12 ++++ test/integration/default/inspec.yml | 12 ++-- 8 files changed, 174 insertions(+), 27 deletions(-) create mode 100644 test/integration/default/README.md create mode 100644 test/integration/default/controls/environ_spec.rb diff --git a/pillar.example b/pillar.example index 7dbc976..fef22b0 100644 --- a/pillar.example +++ b/pillar.example @@ -4,6 +4,7 @@ prometheus: pkg: name: prometheus + use_upstream_archive: False archive: source: https://github.com/prometheus/prometheus/releases/download/v2.10.0/prometheus-2.10.0.linux-amd64.tar.gz source_hash: f4233783826f18606b79e5cef0686e4a9c2030146a3c7ce134f0add09f5adcb7 diff --git a/prometheus/archive/install.sls b/prometheus/archive/install.sls index a956d1d..bbedd73 100644 --- a/prometheus/archive/install.sls +++ b/prometheus/archive/install.sls @@ -9,9 +9,16 @@ prometheus-package-archive-install-file-directory: file.directory: - name: {{ prometheus.pkg.archive.name }} + - user: root + - group: root + - mode: 755 - makedirs: True - require_in: - archive: prometheus-package-archive-install-archive-extracted + - recurse: + - user + - group + - mode prometheus-package-archive-install-archive-extracted: archive.extracted: @@ -21,3 +28,8 @@ prometheus-package-archive-install-archive-extracted: until: True interval: 60 splay: 10 + - user: root + - group: root + - recurse: + - user + - group diff --git a/prometheus/config/clean.sls b/prometheus/config/clean.sls index 46f2b3c..e178cbe 100644 --- a/prometheus/config/clean.sls +++ b/prometheus/config/clean.sls @@ -3,26 +3,33 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} -{%- set sls_service_clean = tplroot ~ '.service.clean' %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} +{%- from tplroot ~ "/map.jinja" import golang with context %} +{%- set sls_archive_clean = tplroot ~ '.archive.clean' %} +{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} + + {%- if grains.kernel|lower == 'linux' and golang.linux.altpriority|int > 0 %} include: - - {{ sls_service_clean }} + - {{ sls_archive_clean }} -prometheus-config-clean-file-absent: - file.absent: - - names: - - {{ prometheus.config_file }} - - {{ prometheus.environ_file }} - - require: - - sls: {{ sls_service_clean }} -{%- if salt['grains.get']('os_family') == 'FreeBSD' %} -{%- for parameter in ['args', 'data_dir'] %} -prometheus-service-args-{{ parameter }}: - sysrc.absent: - - name: prometheus_{{ parameter }} +golang-package-archive-remove-home-alternative-remove: + alternatives.remove: + - name: golang-home + - path: {{ golang.base_dir }}/go + - onlyif: update-alternatives --get-selections |grep ^golang-home - require: - - service: prometheus-service-clean-service-dead -{%- endfor %} -{%- endif %} + - sls: {{ sls_archive_clean }} + + {% for i in ['go', 'godoc', 'gofmt'] %} + +golang-package-archive-remove-{{ i }}-alternative-remove: + alternatives.remove: + - name: link-{{ i }} + - path: {{ golang.base_dir }}/go/bin/{{ i }} + - onlyif: update-alternatives --get-selections |grep ^link-{{ i }} + - require: + - sls: {{ sls_archive_clean }} + + {% endfor %} + {%- endif %} diff --git a/prometheus/config/init.sls b/prometheus/config/init.sls index b399256..c2c6196 100644 --- a/prometheus/config/init.sls +++ b/prometheus/config/init.sls @@ -1,7 +1,70 @@ # -*- coding: utf-8 -*- # vim: ft=sls +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import golang with context %} +{%- set sls_archive_install = tplroot ~ '.archive.install' %} +{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} + + {%- if grains.kernel|lower == 'linux' and golang.linux.altpriority|int > 0 %} + include: - - .args - - .file - - .environ + - {{ sls_archive_install }} + +golang-package-archive-install-home-alternative-install: + cmd.run: + - name: update-alternatives --install {{ golang.go_root }} golang-home {{ golang.base_dir }}/go {{ golang.linux.altpriority }} + - watch: + - archive: golang-package-archive-install-archive-extracted + - require: + - sls: {{ sls_archive_install }} + - onlyif: {{ grains.os_family in ('Suse',) }} + alternatives.install: + - name: golang-home + - link: {{ golang.go_root }} + - path: {{ golang.base_dir }}/go + - priority: {{ golang.linux.altpriority }} + - order: 10 + - watch: + - archive: golang-package-archive-install-archive-extracted + - unless: {{ grains.os_family in ('Suse',) }} + - require: + - sls: {{ sls_archive_install }} + +golang-package-archive-install-home-alternative-set: + alternatives.set: + - name: golang-home + - path: {{ golang.base_dir }}/go + - require: + - alternatives: golang-package-archive-install-home-alternative-install + - unless: {{ grains.os_family in ('Suse',) }} + + {% for i in ['go', 'godoc', 'gofmt'] %} + +golang-package-archive-install-{{ i }}-alternative-install: + cmd.run: + - name: update-alternatives --install /usr/bin/{{i}} link-{{i}} {{ golang.base_dir }}/go/bin/{{i}} {{golang.linux.altpriority}} + - require: + - cmd: golang-package-archive-install-home-alternative-install + - onlyif: {{ grains.os_family in ('Suse',) }} + alternatives.install: + - name: link-{{ i }} + - link: /usr/bin/{{ i }} + - path: {{ golang.base_dir }}/go/bin/{{ i }} + - priority: {{ golang.linux.altpriority }} + - order: 10 + - require: + - alternatives: golang-package-archive-install-home-alternative-install + - unless: {{ grains.os_family in ('Suse',) }} + +golang-package-archive-install-{{ i }}-alternative-set: + alternatives.set: + - name: link-{{ i }} + - path: {{ golang.base_dir }}/go/bin/{{ i }} + - require: + - alternatives: golang-package-archive-install-{{ i }}-alternative-install + - unless: {{ grains.os_family in ('Suse',) }} + + {% endfor %} + {%- endif %} diff --git a/prometheus/defaults.yaml b/prometheus/defaults.yaml index c168c12..f6291fe 100644 --- a/prometheus/defaults.yaml +++ b/prometheus/defaults.yaml @@ -2,6 +2,8 @@ # vim: ft=yaml --- prometheus: + dir: + root: /opt version: '2.10.0' pkg: name: prometheus diff --git a/test/integration/default/README.md b/test/integration/default/README.md new file mode 100644 index 0000000..8019607 --- /dev/null +++ b/test/integration/default/README.md @@ -0,0 +1,50 @@ +# Default InSpec Profile + +This shows the implementation of the Default InSpec [profile](https://github.com/inspec/inspec/blob/master/docs/profiles.md). + +## Verify a profile + +InSpec ships with built-in features to verify a profile structure. + +```bash +$ inspec check default +Summary +------- +Location: default +Profile: profile +Controls: 4 +Timestamp: 2019-06-24T23:09:01+00:00 +Valid: true + +Errors +------ + +Warnings +-------- +``` + +## Execute a profile + +To run all **supported** controls on a local machine use `inspec exec /path/to/profile`. + +```bash +$ inspec exec default +.. + +Finished in 0.0025 seconds (files took 0.12449 seconds to load) +8 examples, 0 failures +``` + +## Execute a specific control from a profile + +To run one control from the profile use `inspec exec /path/to/profile --controls name`. + +```bash +$ inspec exec default --controls package +. + +Finished in 0.0025 seconds (files took 0.12449 seconds to load) +1 examples, 0 failures +``` + +See an [example control here](https://github.com/inspec/inspec/blob/master/examples/profile/controls/example.rb). diff --git a/test/integration/default/controls/environ_spec.rb b/test/integration/default/controls/environ_spec.rb new file mode 100644 index 0000000..6b0ec5f --- /dev/null +++ b/test/integration/default/controls/environ_spec.rb @@ -0,0 +1,12 @@ +control 'template configuration environment' do + title 'should match desired lines' + + describe file('/etc/default/prometheus.sh') do + it { should be_file } + it { should be_owned_by 'root' } + it { should be_grouped_into 'root' } + its('mode') { should cmp '0644' } + its('content') { should include 'Your changes may be overwritten' } + its('content') { should include 'export PATH=${PATH}:/opt/prometheus-2.10.0.linux-amd64' } + end +end diff --git a/test/integration/default/inspec.yml b/test/integration/default/inspec.yml index 4ca71c2..966b73d 100644 --- a/test/integration/default/inspec.yml +++ b/test/integration/default/inspec.yml @@ -4,9 +4,9 @@ maintainer: Alexander Weidinger license: Apache-2.0 summary: Verify that the prometheus formula is setup and configured correctly supports: - - os-name: debian - - os-name: ubuntu - - os-name: centos - - os-name: fedora - - os-name: opensuse - - os-name: freebsd + - platform-name: debian + - platform-name: ubuntu + - platform-name: centos + - platform-name: fedora + - platform-name: opensuse + - platform-name: freebsd From 36b3e6267860eb3a00fb4c88956bd8b0c29e94f2 Mon Sep 17 00:00:00 2001 From: N Date: Sun, 16 Jun 2019 01:33:24 +0100 Subject: [PATCH 03/12] feat(linux): alternatives support & updated unit tests --- pillar.example | 5 ++ prometheus/config/alternatives/clean.sls | 34 +++++++++ prometheus/config/alternatives/init.sls | 5 ++ prometheus/config/alternatives/install.sls | 70 +++++++++++++++++++ prometheus/config/clean.sls | 30 +++----- prometheus/config/environ.sls | 6 +- prometheus/config/init.sls | 70 ++----------------- prometheus/defaults.yaml | 14 ++-- prometheus/map.jinja | 9 +-- prometheus/osfamilymap.yaml | 20 ++++-- prometheus/package/clean.sls | 2 + prometheus/service/running.sls | 3 +- .../default/controls/config_spec.rb | 2 +- .../default/controls/environ_spec.rb | 2 +- .../default/todo/alternatives_spec.rb | 36 ++++++++++ .../integration/default/todo/archives_spec.rb | 28 ++++++++ 16 files changed, 232 insertions(+), 104 deletions(-) create mode 100644 prometheus/config/alternatives/clean.sls create mode 100644 prometheus/config/alternatives/init.sls create mode 100644 prometheus/config/alternatives/install.sls create mode 100644 test/integration/default/todo/alternatives_spec.rb create mode 100644 test/integration/default/todo/archives_spec.rb diff --git a/pillar.example b/pillar.example index fef22b0..3b01a01 100644 --- a/pillar.example +++ b/pillar.example @@ -8,6 +8,7 @@ prometheus: archive: source: https://github.com/prometheus/prometheus/releases/download/v2.10.0/prometheus-2.10.0.linux-amd64.tar.gz source_hash: f4233783826f18606b79e5cef0686e4a9c2030146a3c7ce134f0add09f5adcb7 + archive_format: tar enforce_toplevel: False config_file: /etc/prometheus/prometheus.yml environ_file: /etc/default/prometheus.sh @@ -16,6 +17,10 @@ prometheus: args: web.listen-address: 0.0.0.0:9090 + linux: + #'Alternatives system' priority: zero disables (default) + altpriority: 0 + tofs: # The files_switch key serves as a selector for alternative # directories under the formula files directory. See TOFS pattern diff --git a/prometheus/config/alternatives/clean.sls b/prometheus/config/alternatives/clean.sls new file mode 100644 index 0000000..315ca73 --- /dev/null +++ b/prometheus/config/alternatives/clean.sls @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus with context %} +{%- set sls_archive_clean = tplroot ~ '.archive.clean' %} +{%- set sls_package_clean = tplroot ~ '.package.clean' %} + + {%- if grains.kernel|lower == 'linux' and prometheus.linux.altpriority|int > 0 %} + +include: + - {{ sls_archive_clean if prometheus.pkg.use_upstream_archive else sls_package_clean }} + +prometheus-package-archive-remove-home-alternative-remove: + alternatives.remove: + - name: prometheus-home + - path: {{ prometheus.base_dir }} + - onlyif: update-alternatives --get-selections |grep ^prometheus-home + - require: + - sls: {{ sls_archive_clean if prometheus.pkg.use_upstream_archive else sls_package_clean }} + + {% for i in ['prometheus', 'promtool'] %} + +prometheus-package-archive-remove-{{ i }}-alternative-remove: + alternatives.remove: + - name: link-{{ i }} + - path: {{ prometheus.base_dir }}/{{ i }} + - onlyif: update-alternatives --get-selections |grep ^link-{{ i }} + - require: + - sls: {{ sls_archive_clean if prometheus.pkg.use_upstream_archive else sls_package_clean }} + + {% endfor %} + {%- endif %} diff --git a/prometheus/config/alternatives/init.sls b/prometheus/config/alternatives/init.sls new file mode 100644 index 0000000..d3e5518 --- /dev/null +++ b/prometheus/config/alternatives/init.sls @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +include: + - .install diff --git a/prometheus/config/alternatives/install.sls b/prometheus/config/alternatives/install.sls new file mode 100644 index 0000000..b349b2f --- /dev/null +++ b/prometheus/config/alternatives/install.sls @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus with context %} +{%- set sls_archive_install = tplroot ~ '.archive.install' %} +{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} + + {%- if grains.kernel|lower == 'linux' and prometheus.linux.altpriority|int > 0 %} + +include: + - {{ sls_archive_install }} + +prometheus-package-archive-install-home-alternative-install: + cmd.run: + - name: update-alternatives --install {{ prometheus.dir }} prometheus-home {{ prometheus.base_dir }} {{prometheus.linux.altpriority}} + - watch: + - archive: prometheus-package-archive-install-archive-extracted + - require: + - sls: {{ sls_archive_install }} + - onlyif: {{ grains.os_family in ('Suse',) }} + alternatives.install: + - name: prometheus-home + - link: {{ prometheus.dir }} + - path: {{ prometheus.base_dir }} + - priority: {{ prometheus.linux.altpriority }} + - order: 10 + - watch: + - archive: prometheus-package-archive-install-archive-extracted + - unless: {{ grains.os_family in ('Suse',) }} + - require: + - sls: {{ sls_archive_install }} + +prometheus-package-archive-install-home-alternative-set: + alternatives.set: + - name: prometheus-home + - path: {{ prometheus.base_dir }} + - require: + - alternatives: prometheus-package-archive-install-home-alternative-install + - unless: {{ grains.os_family in ('Suse',) }} + + {% for i in ['prometheus', 'promtool'] %} + +prometheus-package-archive-install-{{ i }}-alternative-install: + cmd.run: + - name: update-alternatives --install /usr/bin/{{i}} link-{{i}} {{ prometheus.base_dir }}/{{i}} {{prometheus.linux.altpriority}} + - require: + - cmd: prometheus-package-archive-install-home-alternative-install + - onlyif: {{ grains.os_family in ('Suse',) }} + alternatives.install: + - name: link-{{ i }} + - link: /usr/bin/{{ i }} + - path: {{ prometheus.base_dir }}/{{ i }} + - priority: {{ prometheus.linux.altpriority }} + - order: 10 + - require: + - alternatives: prometheus-package-archive-install-home-alternative-install + - unless: {{ grains.os_family in ('Suse',) }} + +prometheus-package-archive-install-{{ i }}-alternative-set: + alternatives.set: + - name: link-{{ i }} + - path: {{ prometheus.base_dir }}/{{ i }} + - require: + - alternatives: prometheus-package-archive-install-{{ i }}-alternative-install + - unless: {{ grains.os_family in ('Suse',) }} + + {% endfor %} + {%- endif %} diff --git a/prometheus/config/clean.sls b/prometheus/config/clean.sls index e178cbe..f20270a 100644 --- a/prometheus/config/clean.sls +++ b/prometheus/config/clean.sls @@ -3,33 +3,23 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import golang with context %} +{%- from tplroot ~ "/map.jinja" import prometheus with context %} {%- set sls_archive_clean = tplroot ~ '.archive.clean' %} -{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} +{%- set sls_alternatives_clean = tplroot ~ '.config.alternatives.clean' %} - {%- if grains.kernel|lower == 'linux' and golang.linux.altpriority|int > 0 %} + {%- if grains.kernel|lower == 'linux' and prometheus.linux.altpriority|int > 0 %} include: - {{ sls_archive_clean }} + - {{ sls_alternatives_clean }} - -golang-package-archive-remove-home-alternative-remove: - alternatives.remove: - - name: golang-home - - path: {{ golang.base_dir }}/go - - onlyif: update-alternatives --get-selections |grep ^golang-home +prometheus-config-clean-file-absent: + file.absent: + - names: + - {{ prometheus.config_file }} + - {{ prometheus.environ_file }} - require: - sls: {{ sls_archive_clean }} + - sls: {{ sls_alternatives_clean }} - {% for i in ['go', 'godoc', 'gofmt'] %} - -golang-package-archive-remove-{{ i }}-alternative-remove: - alternatives.remove: - - name: link-{{ i }} - - path: {{ golang.base_dir }}/go/bin/{{ i }} - - onlyif: update-alternatives --get-selections |grep ^link-{{ i }} - - require: - - sls: {{ sls_archive_clean }} - - {% endfor %} {%- endif %} diff --git a/prometheus/config/environ.sls b/prometheus/config/environ.sls index 76cec27..91d065e 100644 --- a/prometheus/config/environ.sls +++ b/prometheus/config/environ.sls @@ -5,10 +5,11 @@ {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus with context %} {%- set sls_archive_install = tplroot ~ '.archive.install' %} +{%- set sls_package_install = tplroot ~ '.package.install' %} {%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} include: - - {{ sls_archive_install }} + - {{ sls_archive_install if prometheus.pkg.use_upstream_archive else sls_package_install }} prometheus-config-file-file-managed-environ_file: file.managed: @@ -25,4 +26,5 @@ prometheus-config-file-file-managed-environ_file: - context: prometheus: {{ prometheus|json }} - require: - - sls: {{ sls_archive_install }} + - sls: {{ sls_archive_install if prometheus.pkg.use_upstream_archive else sls_package_install }} + diff --git a/prometheus/config/init.sls b/prometheus/config/init.sls index c2c6196..6ce6124 100644 --- a/prometheus/config/init.sls +++ b/prometheus/config/init.sls @@ -1,70 +1,8 @@ # -*- coding: utf-8 -*- # vim: ft=sls -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import golang with context %} -{%- set sls_archive_install = tplroot ~ '.archive.install' %} -{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} - - {%- if grains.kernel|lower == 'linux' and golang.linux.altpriority|int > 0 %} - include: - - {{ sls_archive_install }} - -golang-package-archive-install-home-alternative-install: - cmd.run: - - name: update-alternatives --install {{ golang.go_root }} golang-home {{ golang.base_dir }}/go {{ golang.linux.altpriority }} - - watch: - - archive: golang-package-archive-install-archive-extracted - - require: - - sls: {{ sls_archive_install }} - - onlyif: {{ grains.os_family in ('Suse',) }} - alternatives.install: - - name: golang-home - - link: {{ golang.go_root }} - - path: {{ golang.base_dir }}/go - - priority: {{ golang.linux.altpriority }} - - order: 10 - - watch: - - archive: golang-package-archive-install-archive-extracted - - unless: {{ grains.os_family in ('Suse',) }} - - require: - - sls: {{ sls_archive_install }} - -golang-package-archive-install-home-alternative-set: - alternatives.set: - - name: golang-home - - path: {{ golang.base_dir }}/go - - require: - - alternatives: golang-package-archive-install-home-alternative-install - - unless: {{ grains.os_family in ('Suse',) }} - - {% for i in ['go', 'godoc', 'gofmt'] %} - -golang-package-archive-install-{{ i }}-alternative-install: - cmd.run: - - name: update-alternatives --install /usr/bin/{{i}} link-{{i}} {{ golang.base_dir }}/go/bin/{{i}} {{golang.linux.altpriority}} - - require: - - cmd: golang-package-archive-install-home-alternative-install - - onlyif: {{ grains.os_family in ('Suse',) }} - alternatives.install: - - name: link-{{ i }} - - link: /usr/bin/{{ i }} - - path: {{ golang.base_dir }}/go/bin/{{ i }} - - priority: {{ golang.linux.altpriority }} - - order: 10 - - require: - - alternatives: golang-package-archive-install-home-alternative-install - - unless: {{ grains.os_family in ('Suse',) }} - -golang-package-archive-install-{{ i }}-alternative-set: - alternatives.set: - - name: link-{{ i }} - - path: {{ golang.base_dir }}/go/bin/{{ i }} - - require: - - alternatives: golang-package-archive-install-{{ i }}-alternative-install - - unless: {{ grains.os_family in ('Suse',) }} - - {% endfor %} - {%- endif %} + - .args + - .file + - .environ + - .alternatives diff --git a/prometheus/defaults.yaml b/prometheus/defaults.yaml index f6291fe..939a096 100644 --- a/prometheus/defaults.yaml +++ b/prometheus/defaults.yaml @@ -2,8 +2,8 @@ # vim: ft=yaml --- prometheus: - dir: - root: /opt + dir: /opt/prometheus + base_dir: /opt/prometheus-2.10.0 version: '2.10.0' pkg: name: prometheus @@ -13,11 +13,11 @@ prometheus: name: /opt uri: https://github.com/prometheus/prometheus/releases/download/ source: None - # linux amd64 source hash - source_hash: f4233783826f18606b79e5cef0686e4a9c2030146a3c7ce134f0add09f5adcb7 + source_hash: f4233783826f18606b79e5cef0686e4a9c2030146a3c7ce134f0add09f5adcb7 #linux amd64 trim_output: True enforce_toplevel: True - archive_format: tar.gz + archive_suffix: tar.gz + archive_format: tar rootgroup: root kernel: {{ grains.kernel | lower }} config_file: /etc/prometheus/prometheus.yml @@ -33,3 +33,7 @@ prometheus: pkg: name: prometheus-node-exporter service: prometheus-node-exporter + + linux: + #'Alternatives system' priority: zero disables (default) + altpriority: 0 diff --git a/prometheus/map.jinja b/prometheus/map.jinja index 04f386a..7955fa6 100644 --- a/prometheus/map.jinja +++ b/prometheus/map.jinja @@ -26,18 +26,19 @@ {#- Merge the prometheus pillar #} {%- set prometheus = salt['pillar.get']('prometheus', default=defaults, merge=True) %} -{#- Update archive details #} +{#- archive jinja #} {%- if prometheus.pkg.use_upstream_archive %} {%- set name = 'prometheus-%s.%s-%s'|format(prometheus.version, prometheus.kernel, prometheus.arch) %} + {%- set uri = prometheus.pkg.archive.uri + '/v' + prometheus.version + '/' + name %} {%- do prometheus.pkg.archive.update({ - 'source': prometheus.pkg.archive.uri + 'v' + prometheus.version + '/' + name - + '.' + prometheus.pkg.archive.archive_format, - 'archive_format': prometheus.pkg.archive.archive_format.split('.')[0] + 'source': uri + '.' + prometheus.pkg.archive.archive_suffix, + 'archive_format': prometheus.pkg.archive.archive_format }) %} {%- do prometheus.update({'base_dir': prometheus.pkg.archive.name + '/' + name}) %} {%- do prometheus.environ.append('export PATH=${PATH}:' + prometheus.pkg.archive.name + '/' + name) %} {%- endif %} + {#- Contactenate arguments #} {%- macro concat_args(args) %} {%- set args = args|dictsort %} diff --git a/prometheus/osfamilymap.yaml b/prometheus/osfamilymap.yaml index 94ffa6e..8d49ad5 100644 --- a/prometheus/osfamilymap.yaml +++ b/prometheus/osfamilymap.yaml @@ -38,9 +38,24 @@ FreeBSD: pkg: name: node_exporter service: node_exporter + pkg: + archive: + source_hash: 94a63f14baeadab2f17b5ae0bbeda6688e6d06f964ef4e32c2954a0ecf3996a1 OpenBSD: rootgroup: wheel + kernel: openbsd + pkg: + archive: + source_hash: c3c69919b359f00a84ef12f7ed6a956111790d64a71bd94990572baaf63377ce + + +NetBSD: + rootgroup: wheel + kernel: netbsd + pkg: + archive: + source_hash: fbfed9922eb8f1045952e0e8b93406028e123a5adb233a0ba7d4fc4e5c537b2c Solaris: {} @@ -48,13 +63,10 @@ Windows: pkg: archive: name: C:\\Program Files - source: https://github.com/prometheus/prometheus/releases/download/v2.10.0/prometheus-2.10.0.windows-amd64.tar.gz source_hash: eb138082a4d5e4d5b1e3ca838fa508f053474d46bca76e87ab0834f0d8b110db MacOS: + rootgroup: {{ macos_group | d('') }} pkg: archive: - name: /opt - source: https://github.com/prometheus/prometheus/releases/download/v2.10.0/prometheus-2.10.0.darwin-amd64.tar.gz source_hash: 740e36bcacc0c5d4495f5341fcfa8b7e0dc623d12e8b07ac291052ea0a681325 - rootgroup: {{ macos_group | d('') }} diff --git a/prometheus/package/clean.sls b/prometheus/package/clean.sls index 30a2b26..04c2cfd 100644 --- a/prometheus/package/clean.sls +++ b/prometheus/package/clean.sls @@ -12,5 +12,7 @@ include: prometheus-package-clean-pkg-removed: pkg.removed: - name: {{ prometheus.pkg.name }} + {%- if 'config' in prometheus and prometheus.config %} - require: - sls: {{ sls_config_clean }} + {%- endif %} diff --git a/prometheus/service/running.sls b/prometheus/service/running.sls index 6f07ef1..a64f9fa 100644 --- a/prometheus/service/running.sls +++ b/prometheus/service/running.sls @@ -14,7 +14,7 @@ include: prometheus-service-running-service-unmasked: service.unmasked: - name: {{ prometheus.service.name }} - - onlyif: systemctl >/dev/null 2>&1 + - onlyif: systemctl list-unit-files | grep {{ prometheus.service.name }} >/dev/null 2>&1 prometheus-service-running-service-running: service.running: @@ -28,3 +28,4 @@ prometheus-service-running-service-running: - sls: {{ sls_config_args }} - sls: {{ sls_config_file }} {%- endif %} + - onlyif: systemctl list-unit-files | grep {{ prometheus.service.name }} >/dev/null 2>&1 diff --git a/test/integration/default/controls/config_spec.rb b/test/integration/default/controls/config_spec.rb index 34d0f8f..1b93ca9 100644 --- a/test/integration/default/controls/config_spec.rb +++ b/test/integration/default/controls/config_spec.rb @@ -7,7 +7,7 @@ control 'Prometheus configuration' do it { should be_grouped_into 'root' } its('mode') { should cmp '0644' } its('content') { should include 'File managed by Salt' } - its('content') { should include 'Your changes will be overwritten.' } + its('content') { should include 'Your changes may be overwritten.' } its('content') { should include 'global:' } its('content') { should include 'alerting:' } end diff --git a/test/integration/default/controls/environ_spec.rb b/test/integration/default/controls/environ_spec.rb index 6b0ec5f..79bd781 100644 --- a/test/integration/default/controls/environ_spec.rb +++ b/test/integration/default/controls/environ_spec.rb @@ -1,4 +1,4 @@ -control 'template configuration environment' do +control 'prometheus configuration environment' do title 'should match desired lines' describe file('/etc/default/prometheus.sh') do diff --git a/test/integration/default/todo/alternatives_spec.rb b/test/integration/default/todo/alternatives_spec.rb new file mode 100644 index 0000000..03c340f --- /dev/null +++ b/test/integration/default/todo/alternatives_spec.rb @@ -0,0 +1,36 @@ +title 'linux alternatives profile' + +control 'prometheus linux alternatives' do + impact 1.0 + title 'should be installed' + desc "Ensure prometheus linux alternatives are correct" + tag: package: "tarball archive" + + describe file('/opt/prometheus') do # prometheus-home alternative + it { should be_symlink } + it { should_not be_file } + it { should_not be_directory } + it { should be_owned_by 'root' } + it { should be_grouped_into 'root' } + its('shallow_link_path') { should eq '/etc/alternatives/prometheus-home' } + end + + describe file('/usr/bin/prometheus') do # prometheus alternative + it { should be_symlink } + it { should_not be_file } + it { should_not be_directory } + it { should be_owned_by 'root' } + it { should be_grouped_into 'root' } + its('shallow_link_path') { should eq '/etc/alternatives/link-prometheus' } + end + + describe file('/usr/bin/promtool') do # promtool alternative + it { should be_symlink } + it { should_not be_file } + it { should_not be_directory } + it { should be_owned_by 'root' } + it { should be_grouped_into 'root' } + its('shallow_link_path') { should eq '/etc/alternatives/link-promtool' } + end + +end diff --git a/test/integration/default/todo/archives_spec.rb b/test/integration/default/todo/archives_spec.rb new file mode 100644 index 0000000..8cd1e11 --- /dev/null +++ b/test/integration/default/todo/archives_spec.rb @@ -0,0 +1,28 @@ +title 'prometheus archives profile' + +control 'prometheus tarball archive' do + impact 1.0 + title 'should be installed' + desc "Ensure prometheus tarball archive was extracted correctly" + + describe file('/opt/prometheus-2.10.0.linux-amd64') do + it { should be_directory } + it { should be_owned_by 'root' } + it { should be_grouped_into 'root' } + its('mode') { should cmp '0755' } + end + + require 'digest' + binary = file('/opt/prometheus-2.10.0.linux-amd64/prometheus').content + sha256sum = Digest::SHA256.hexdigest(binary) + describe file('/opt/prometheus-2.10.0.linux-amd64/prometheus') do + its('sha256sum') { should eq '025a7bb0327e1b2b20efbd6e66b8ef81d9020c66f0d5d077b1388a48dec789f7' } + end + + binary = file('/opt/prometheus-2.10.0.linux-amd64/promtool').content + sha256sum = Digest::SHA256.hexdigest(binary) + describe file('/opt/prometheus-2.10.0.linux-amd64/promtool') do + its('sha256sum') { should eq 'db004c3c0d6a863929a51da5e1fc4a958668e80256ea2a14c5e461fa13656def' } + end + +end From 3ec910e7f72f5d61fb10a5d2ca07252b8ca6e69e Mon Sep 17 00:00:00 2001 From: N Date: Mon, 17 Jun 2019 22:02:51 +0100 Subject: [PATCH 04/12] feat(archives): support for various prometheus archives --- prometheus/archive/alternatives/clean.sls | 39 ++++++++++ prometheus/archive/alternatives/init.sls | 14 ++++ prometheus/archive/alternatives/install.sls | 75 +++++++++++++++++++ prometheus/archive/clean.sls | 18 ++++- prometheus/archive/defaults.yaml | 67 +++++++++++++++++ prometheus/archive/init.sls | 11 +++ prometheus/archive/install.sls | 26 ++++--- prometheus/config/alternatives/clean.sls | 34 --------- prometheus/config/alternatives/init.sls | 5 -- prometheus/config/alternatives/install.sls | 70 ------------------ prometheus/config/clean.sls | 10 +-- prometheus/config/environ.sls | 1 - prometheus/config/init.sls | 10 ++- prometheus/defaults.yaml | 21 +++--- prometheus/map.jinja | 42 +++++------ prometheus/osfamilymap.yaml | 80 +++++++++++++++------ 16 files changed, 332 insertions(+), 191 deletions(-) create mode 100644 prometheus/archive/alternatives/clean.sls create mode 100644 prometheus/archive/alternatives/init.sls create mode 100644 prometheus/archive/alternatives/install.sls create mode 100644 prometheus/archive/defaults.yaml delete mode 100644 prometheus/config/alternatives/clean.sls delete mode 100644 prometheus/config/alternatives/init.sls delete mode 100644 prometheus/config/alternatives/install.sls diff --git a/prometheus/archive/alternatives/clean.sls b/prometheus/archive/alternatives/clean.sls new file mode 100644 index 0000000..c5c78c7 --- /dev/null +++ b/prometheus/archive/alternatives/clean.sls @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus as p with context %} +{%- set sls_archive_clean = tplroot ~ '.archive.clean' %} + + {%- if grains.kernel|lower == 'linux' and p.linux.altpriority|int > 0 %} + +include: + - {{ sls_archive_clean }} + + + {%- for k in p.archive.wanted %} + {%- set dir = p.archive.dir + '/' + k + '-%s.%s-%s'|format(p.archive.version["k"], p.kernel, p.arch) %} + +prometheus-archive-remove-{{ k }}-home-alternatives-remove: + alternatives.remove: + - name: prometheus-{{ k }}-home + - path: {{ dir }} + - onlyif: update-alternatives --get-selections |grep ^prometheus-{{ k }}-home + - require: + - sls: {{ sls_archive_clean }} + + + {% for i in p.archive.binaries['k'] %} + +prometheus-archive-remove-{{ k }}-alternatives-remove-{{ i }}: + alternatives.remove: + - name: prometheus-{{ k }}-{{ i }} + - path: {{ dir }}/{{ i }} + - onlyif: update-alternatives --get-selections |grep ^prometheus-{{ k }}-{{ i }} + - require: + - sls: {{ sls_archive_clean }} + + {% endfor %} + {% endfor %} + {%- endif %} diff --git a/prometheus/archive/alternatives/init.sls b/prometheus/archive/alternatives/init.sls new file mode 100644 index 0000000..56c18a9 --- /dev/null +++ b/prometheus/archive/alternatives/init.sls @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus with context %} +{%- from tplroot ~ "/jinja/macros.jinja" import format_kwargs with context %} + + {%- if grains.kernel|lower == 'linux' and prometheus.pkg.use_upstream_archive %} + +include: + - .install + + {%- endif %} diff --git a/prometheus/archive/alternatives/install.sls b/prometheus/archive/alternatives/install.sls new file mode 100644 index 0000000..749a4db --- /dev/null +++ b/prometheus/archive/alternatives/install.sls @@ -0,0 +1,75 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus as p with context %} +{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} +{%- set sls_archive_install = tplroot ~ '.archive.install' %} + + {%- if grains.kernel|lower in ('linux',) and p.linux.altpriority|int > 0 %} + +include: + - {{ sls_archive_install }} + + + {%- for k in p.archive.wanted %} + {%- set dir = p.archive.dir + '/' + k + '-%s.%s-%s'|format(p.archive.version["k"], p.kernel, p.arch) %} + +prometheus-archive-alternatives-install-{{ k }}-home-alternatives-install: + cmd.run: + - onlyif: {{ grains.os_family in ('Suse',) }} + - name: update-alternatives --install {{ dir }} prometheus-{{ k }}-home {{ dir }} {{p.linux.altpriority}} + - watch: + - archive: prometheus-archive-install-{{ k }}-archive-extracted + - require: + - sls: {{ sls_archive_install }} + alternatives.install: + - name: prometheus-{{ k }}-home + - link: {{ p.dir }} + - path: {{ dir }} + - priority: {{ p.linux.altpriority }} + - order: 10 + - watch: + - archive: prometheus-archive-install-{{ k }}-archive-extracted + - require: + - sls: {{ sls_archive_install }} + - onlyif: {{ grains.os_family not in ('Suse',) }} + +prometheus-archive-alternatives-install-{{ k }}-home-alternatives-set: + alternatives.set: + - name: prometheus-{{ k }}-home + - path: {{ dir }} + - require: + - alternatives: prometheus-archive-alternatives-install-{{ k }}-home-alternatives-install + - onlyif: {{ grains.os_family not in ('Suse',) }} + + {% for i in p.archive.binaries['k'] %} + +prometheus-archive-alternatives-install-{{ k }}-alternatives-install-{{ i }}: + cmd.run: + - onlyif: {{ grains.os_family in ('Suse',) }} + - name: update-alternatives --install /usr/bin/{{i}} prometheus-{{ k }}-{{i}} {{ dir }}/{{i}} {{p.linux.altpriority}} + - require: + - cmd: prometheus-archive-alternatives-install-{{ k }}-home-alternatives-install + alternatives.install: + - name: prometheus-{{ k }}-{{ i }} + - link: /usr/bin/{{ i }} + - path: {{ dir }}/{{ i }} + - priority: {{ p.linux.altpriority }} + - order: 10 + - require: + - alternatives: prometheus-archive-alternatives-install-{{ k }}-home-alternatives-install + - onlyif: {{ grains.os_family not in ('Suse',) }} + +prometheus-archive-alternatives-install-{{ k }}-alternatives-set-{{ i }}: + alternatives.set: + - name: prometheus-{{ k }}-{{ i }} + - path: {{ dir }}/{{ i }} + - require: + - alternatives: prometheus-archive-alternatives-install-{{ k }}-alternatives-install-{{ i }} + - onlyif: {{ grains.os_family not in ('Suse',) }} + + {% endfor %} + {% endfor %} + {%- endif %} diff --git a/prometheus/archive/clean.sls b/prometheus/archive/clean.sls index 29fe10e..c91fce5 100644 --- a/prometheus/archive/clean.sls +++ b/prometheus/archive/clean.sls @@ -4,8 +4,20 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus with context %} +{%- set sls_alternatives_clean = tplroot ~ '.archive.alternatives.clean' %} -prometheus-cli-package-archive-clean-file-absent: + {%- if prometheus.pkg.use_upstream_archive %} + +include: + - {{ sls_alternatives_clean }} + + + {%- for k in prometheus.archive.wanted %} +prometheus-archive-clean-{{ k }}-file-absent: file.absent: - - names: - - {{ prometheus.base_dir }} + - name: {{ prometheus.archive.dir + '/' + k + '-%s.%s-%s'|format(prometheus.archive.versions[k], prometheus.kernel, prometheus.arch) }} + #- require: + #- sls: {{ sls_alternatives_clean }} + {%- endfor %} + + {%- endif %} diff --git a/prometheus/archive/defaults.yaml b/prometheus/archive/defaults.yaml new file mode 100644 index 0000000..716187f --- /dev/null +++ b/prometheus/archive/defaults.yaml @@ -0,0 +1,67 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +prometheus: + archive: + dir: /opt/prometheus + uri: https://github.com/prometheus + suffix: tar.gz + kwargs: + trim_output: True + enforce_toplevel: True + archive_format: tar + retry: + attempts: 3 + until: True + interval: 60 + splay: 10 + binaries: + prometheus: + - prometheus + - promtool + alertmanager: + - amtool + - alertmanager + blackbox_exporter: + - blackbox_exporter + consul_exporter: + - consul_exporter + graphite_exporter: + - graphite_exporter + haproxy_exporter: + - haproxy_exporter + memcached_exporter: + - memcached_exporter + mysqld_exporter: + - mysqld_exporter + node_exporter: + - node_exporter + pushgateway: + - pushgateway + statsd_exporter: + - statsd_exporter + + versions: + prometheus: '2.10.0' + alertmanager: '0.17.0' + blackbox_exporter: '0.14.0' + consul_exporter: '0.4.0' + graphite_exporter: '0.6.2' + haproxy_exporter: '0.10.0' + memcached_exporter: '0.5.0' + mysqld_exporter: '0.11.0' + node_exporter: '0.18.1' + pushgateway: '0.8.0' + statsd_exporter: '0.11.2' + hashes: + prometheus: f4233783826f18606b79e5cef0686e4a9c2030146a3c7ce134f0add09f5adcb7 + alertmanager: 7c8d2cfeb021c80881ae9904d959131091b8785b6fda9800f84ddef148fe0a4f + blackbox_exporter: a2918a059023045cafb911272c88a9eb83cdac9a8a5e8e74844b5d6d27f19117 + consul_exporter: ff77c03de67cf381f67480b5be6699901785a34145c518c3484ae3e5b8440d08 + graphite_exporter: 9b962bd06406ece4a865ad6947a6e652e48a92a0d77e496a0351c04e9c2c5e9e + haproxy_exporter: 08150728e281f813a8fcfff4b336f16dbfe4268a1c7510212c8cff2579b10468 + memcached_exporter: bb07f496ceb63dad9793ad4295205547a4bd20b90628476d64fa96c9a25a020f + mysqld_exporter: b53ad48ff14aa891eb6a959730ffc626db98160d140d9a66377394714c563acf + node_exporter: b2503fd932f85f4e5baf161268854bf5d22001869b84f00fd2d1f57b51b72424 + pushgateway: 6949866ba9ad0cb88d3faffd4281f17df79281398b4dbd0ec3aab300071681ca + statsd_exporter: 4632ad0c5552e271e84c376da3ffe3af8c265ec5c3035334b70e35756aca1906 diff --git a/prometheus/archive/init.sls b/prometheus/archive/init.sls index 051d698..9e050fa 100644 --- a/prometheus/archive/init.sls +++ b/prometheus/archive/init.sls @@ -1,5 +1,16 @@ #.-*- coding: utf-8 -*- # vim: ft=sls +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus with context %} + + {%- if prometheus.pkg.use_upstream_archive %} + include: - .install + {%- if grains.kernel|lower == 'linux' %} + - .alternatives + {%- endif %} + + {%- endif %} diff --git a/prometheus/archive/install.sls b/prometheus/archive/install.sls index bbedd73..d3323a4 100644 --- a/prometheus/archive/install.sls +++ b/prometheus/archive/install.sls @@ -3,33 +3,37 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} +{%- from tplroot ~ "/map.jinja" import prometheus as p with context %} {%- from tplroot ~ "/jinja/macros.jinja" import format_kwargs with context %} -prometheus-package-archive-install-file-directory: + {%- for k in p.archive.wanted %} + +prometheus-archive-install-{{ k }}-file-directory: file.directory: - - name: {{ prometheus.pkg.archive.name }} + - name: {{ p.archive.dir }} - user: root - group: root - mode: 755 - makedirs: True - require_in: - - archive: prometheus-package-archive-install-archive-extracted + - archive: prometheus-archive-install-{{ k }}-archive-extracted - recurse: - user - group - mode -prometheus-package-archive-install-archive-extracted: +prometheus-archive-install-{{ k }}-archive-extracted: archive.extracted: - {{- format_kwargs(prometheus.pkg.archive) }} - - retry: - attempts: 3 - until: True - interval: 60 - splay: 10 + - name: {{ p.archive.dir }} + - source: {{ p.archive.uri + '/' + k + '/releases/download/v' + p.archive.versions[k] + + '/' + k + '-%s.%s-%s'|format(p.archive.versions[k], p.kernel, p.arch) + + '.' + p.archive.suffix }} + - source_hash: {{ p.archive.hashes[k] }} - user: root - group: root + {{- format_kwargs(p.archive.kwargs) }} - recurse: - user - group + + {%- endfor %} diff --git a/prometheus/config/alternatives/clean.sls b/prometheus/config/alternatives/clean.sls deleted file mode 100644 index 315ca73..0000000 --- a/prometheus/config/alternatives/clean.sls +++ /dev/null @@ -1,34 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=sls - -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} -{%- set sls_archive_clean = tplroot ~ '.archive.clean' %} -{%- set sls_package_clean = tplroot ~ '.package.clean' %} - - {%- if grains.kernel|lower == 'linux' and prometheus.linux.altpriority|int > 0 %} - -include: - - {{ sls_archive_clean if prometheus.pkg.use_upstream_archive else sls_package_clean }} - -prometheus-package-archive-remove-home-alternative-remove: - alternatives.remove: - - name: prometheus-home - - path: {{ prometheus.base_dir }} - - onlyif: update-alternatives --get-selections |grep ^prometheus-home - - require: - - sls: {{ sls_archive_clean if prometheus.pkg.use_upstream_archive else sls_package_clean }} - - {% for i in ['prometheus', 'promtool'] %} - -prometheus-package-archive-remove-{{ i }}-alternative-remove: - alternatives.remove: - - name: link-{{ i }} - - path: {{ prometheus.base_dir }}/{{ i }} - - onlyif: update-alternatives --get-selections |grep ^link-{{ i }} - - require: - - sls: {{ sls_archive_clean if prometheus.pkg.use_upstream_archive else sls_package_clean }} - - {% endfor %} - {%- endif %} diff --git a/prometheus/config/alternatives/init.sls b/prometheus/config/alternatives/init.sls deleted file mode 100644 index d3e5518..0000000 --- a/prometheus/config/alternatives/init.sls +++ /dev/null @@ -1,5 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=sls - -include: - - .install diff --git a/prometheus/config/alternatives/install.sls b/prometheus/config/alternatives/install.sls deleted file mode 100644 index b349b2f..0000000 --- a/prometheus/config/alternatives/install.sls +++ /dev/null @@ -1,70 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=sls - -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} -{%- set sls_archive_install = tplroot ~ '.archive.install' %} -{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} - - {%- if grains.kernel|lower == 'linux' and prometheus.linux.altpriority|int > 0 %} - -include: - - {{ sls_archive_install }} - -prometheus-package-archive-install-home-alternative-install: - cmd.run: - - name: update-alternatives --install {{ prometheus.dir }} prometheus-home {{ prometheus.base_dir }} {{prometheus.linux.altpriority}} - - watch: - - archive: prometheus-package-archive-install-archive-extracted - - require: - - sls: {{ sls_archive_install }} - - onlyif: {{ grains.os_family in ('Suse',) }} - alternatives.install: - - name: prometheus-home - - link: {{ prometheus.dir }} - - path: {{ prometheus.base_dir }} - - priority: {{ prometheus.linux.altpriority }} - - order: 10 - - watch: - - archive: prometheus-package-archive-install-archive-extracted - - unless: {{ grains.os_family in ('Suse',) }} - - require: - - sls: {{ sls_archive_install }} - -prometheus-package-archive-install-home-alternative-set: - alternatives.set: - - name: prometheus-home - - path: {{ prometheus.base_dir }} - - require: - - alternatives: prometheus-package-archive-install-home-alternative-install - - unless: {{ grains.os_family in ('Suse',) }} - - {% for i in ['prometheus', 'promtool'] %} - -prometheus-package-archive-install-{{ i }}-alternative-install: - cmd.run: - - name: update-alternatives --install /usr/bin/{{i}} link-{{i}} {{ prometheus.base_dir }}/{{i}} {{prometheus.linux.altpriority}} - - require: - - cmd: prometheus-package-archive-install-home-alternative-install - - onlyif: {{ grains.os_family in ('Suse',) }} - alternatives.install: - - name: link-{{ i }} - - link: /usr/bin/{{ i }} - - path: {{ prometheus.base_dir }}/{{ i }} - - priority: {{ prometheus.linux.altpriority }} - - order: 10 - - require: - - alternatives: prometheus-package-archive-install-home-alternative-install - - unless: {{ grains.os_family in ('Suse',) }} - -prometheus-package-archive-install-{{ i }}-alternative-set: - alternatives.set: - - name: link-{{ i }} - - path: {{ prometheus.base_dir }}/{{ i }} - - require: - - alternatives: prometheus-package-archive-install-{{ i }}-alternative-install - - unless: {{ grains.os_family in ('Suse',) }} - - {% endfor %} - {%- endif %} diff --git a/prometheus/config/clean.sls b/prometheus/config/clean.sls index f20270a..4294cf2 100644 --- a/prometheus/config/clean.sls +++ b/prometheus/config/clean.sls @@ -5,13 +5,12 @@ {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus with context %} {%- set sls_archive_clean = tplroot ~ '.archive.clean' %} -{%- set sls_alternatives_clean = tplroot ~ '.config.alternatives.clean' %} - - {%- if grains.kernel|lower == 'linux' and prometheus.linux.altpriority|int > 0 %} include: - {{ sls_archive_clean }} - - {{ sls_alternatives_clean }} + {%- if prometheus.pkg.use_upstream_archive and kernel|lower == 'linux' %} + - .systemd + {%- endif %} prometheus-config-clean-file-absent: file.absent: @@ -20,6 +19,3 @@ prometheus-config-clean-file-absent: - {{ prometheus.environ_file }} - require: - sls: {{ sls_archive_clean }} - - sls: {{ sls_alternatives_clean }} - - {%- endif %} diff --git a/prometheus/config/environ.sls b/prometheus/config/environ.sls index 91d065e..25f976d 100644 --- a/prometheus/config/environ.sls +++ b/prometheus/config/environ.sls @@ -27,4 +27,3 @@ prometheus-config-file-file-managed-environ_file: prometheus: {{ prometheus|json }} - require: - sls: {{ sls_archive_install if prometheus.pkg.use_upstream_archive else sls_package_install }} - diff --git a/prometheus/config/init.sls b/prometheus/config/init.sls index 6ce6124..e87add3 100644 --- a/prometheus/config/init.sls +++ b/prometheus/config/init.sls @@ -1,8 +1,16 @@ # -*- coding: utf-8 -*- # vim: ft=sls +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus with context %} + include: - .args - .file - .environ - - .alternatives + {%- if prometheus.pkg.use_upstream_archive and kernel|lower == 'linux' %} + - .systemd + {%- endif %} + + diff --git a/prometheus/defaults.yaml b/prometheus/defaults.yaml index 939a096..ce2e7d0 100644 --- a/prometheus/defaults.yaml +++ b/prometheus/defaults.yaml @@ -2,22 +2,10 @@ # vim: ft=yaml --- prometheus: - dir: /opt/prometheus - base_dir: /opt/prometheus-2.10.0 - version: '2.10.0' pkg: name: prometheus - binary: prometheus use_upstream_archive: False - archive: - name: /opt - uri: https://github.com/prometheus/prometheus/releases/download/ - source: None - source_hash: f4233783826f18606b79e5cef0686e4a9c2030146a3c7ce134f0add09f5adcb7 #linux amd64 - trim_output: True - enforce_toplevel: True - archive_suffix: tar.gz - archive_format: tar + rootgroup: root kernel: {{ grains.kernel | lower }} config_file: /etc/prometheus/prometheus.yml @@ -37,3 +25,10 @@ prometheus: linux: #'Alternatives system' priority: zero disables (default) altpriority: 0 + + archive: + # see ./archive/default.yaml + wanted: + - prometheus + - alertmanager + - node_exporter diff --git a/prometheus/map.jinja b/prometheus/map.jinja index 7955fa6..0113310 100644 --- a/prometheus/map.jinja +++ b/prometheus/map.jinja @@ -9,36 +9,30 @@ {%- import_yaml tplroot ~ "/osmap.yaml" as osmap %} {%- import_yaml tplroot ~ "/osarchmap.yaml" as osarchmap %} {%- import_yaml tplroot ~ "/osfingermap.yaml" as osfingermap %} +{#- focused defaults #} +{%- import_yaml tplroot ~ "/archive/defaults.yaml" as archive_defaults %} +{%- import_yaml tplroot ~ "/archive/defaults.yaml" as config_defaults %} {%- set defaults = salt['grains.filter_by'](default_settings, - default='prometheus', - merge=salt['grains.filter_by'](osfamilymap, grain='os_family', - merge=salt['grains.filter_by'](osmap, grain='os', - merge=salt['grains.filter_by'](osfingermap, grain='osfinger', - merge=salt['grains.filter_by'](osarchmap, grain='osarch', - merge=salt['pillar.get']('prometheus:lookup', default={}) - ) - ) - ) - ) -) %} + merge=salt['grains.filter_by'](archive_defaults, + merge=salt['grains.filter_by'](config_defaults, + merge=salt['grains.filter_by'](osfamilymap, grain='os_family', + merge=salt['grains.filter_by'](osmap, grain='os', + merge=salt['grains.filter_by'](osfingermap, grain='osfinger', + merge=salt['grains.filter_by'](osarchmap, grain='osarch', + merge=salt['pillar.get']('prometheus:lookup', default={}), + base='prometheus'), + base='prometheus'), + base='prometheus'), + base='prometheus'), + base='prometheus'), + base='prometheus'), + base='prometheus') +%} {#- Merge the prometheus pillar #} {%- set prometheus = salt['pillar.get']('prometheus', default=defaults, merge=True) %} -{#- archive jinja #} -{%- if prometheus.pkg.use_upstream_archive %} - {%- set name = 'prometheus-%s.%s-%s'|format(prometheus.version, prometheus.kernel, prometheus.arch) %} - {%- set uri = prometheus.pkg.archive.uri + '/v' + prometheus.version + '/' + name %} - {%- do prometheus.pkg.archive.update({ - 'source': uri + '.' + prometheus.pkg.archive.archive_suffix, - 'archive_format': prometheus.pkg.archive.archive_format - }) %} - {%- do prometheus.update({'base_dir': prometheus.pkg.archive.name + '/' + name}) %} - {%- do prometheus.environ.append('export PATH=${PATH}:' + prometheus.pkg.archive.name + '/' + name) %} -{%- endif %} - - {#- Contactenate arguments #} {%- macro concat_args(args) %} {%- set args = args|dictsort %} diff --git a/prometheus/osfamilymap.yaml b/prometheus/osfamilymap.yaml index 8d49ad5..c2c8188 100644 --- a/prometheus/osfamilymap.yaml +++ b/prometheus/osfamilymap.yaml @@ -20,7 +20,9 @@ Debian: node: config_file: /etc/default/prometheus-node-exporter -RedHat: {} +RedHat: + pkg: + use_upstream_archive: True Suse: {} @@ -38,35 +40,69 @@ FreeBSD: pkg: name: node_exporter service: node_exporter - pkg: - archive: - source_hash: 94a63f14baeadab2f17b5ae0bbeda6688e6d06f964ef4e32c2954a0ecf3996a1 + archive: + hashes: + prometheus: 94a63f14baeadab2f17b5ae0bbeda6688e6d06f964ef4e32c2954a0ecf3996a1 + alertmanager: ec171b13976baceace193461f8a1e61021ab9657df5ba45157cd0095aee7d569 + blackbox_exporter: 2b92752decf2cf1883ce4f72301e4f911dab79efbd87db4df23dc9771e53e4af + consul_exporter: 62e16c2f1acb9bf9411126478caccb5962da203cfb58d8c97f54b9c0add5171c + graphite_exporter: ff424b923733d8247314353ba4d13a1c4b06450c35f005bfd6c3b6ff60b047fd + haproxy_exporter: f32d158f9e3314828dc155a30a1f4c858876e1ea8ff543a4000afcbc7e923505 + memcached_exporter: 8fd53b9aede6b78e0530b159ccd0a437cf2f100da1ddc586681f389d804f5f19 + mysqld_exporter: 9bcbbd8b3568818fd4c95d255c6f93c357ea25aed3364d7428f4ff9c89cd489a + node_exporter: {} + pushgateway: ebcd21dc25e439eed64559e89cd7da9a94073d5ff321a8a3a4214ac2ebe04e34 + statsd_exporter: f345dff6311501f09bb5b6ba1128e925d504c6325ee97ad91a975f2be0d44da9 OpenBSD: rootgroup: wheel kernel: openbsd - pkg: - archive: - source_hash: c3c69919b359f00a84ef12f7ed6a956111790d64a71bd94990572baaf63377ce - - -NetBSD: - rootgroup: wheel - kernel: netbsd - pkg: - archive: - source_hash: fbfed9922eb8f1045952e0e8b93406028e123a5adb233a0ba7d4fc4e5c537b2c + archive: + hashes: + prometheus: c3c69919b359f00a84ef12f7ed6a956111790d64a71bd94990572baaf63377ce + alertmanager: 88ce1b3f11bb28f24b98235994277b2c31aa03b2b2609e0058c04efa0cc5596f + blackbox_exporter: 0dee97d1204bac925bde919958ae890730d87386a816ed0b248c8038ee43794d + consul_exporter: b53ee2bd0e670907eac894387e286b0dd11eb3149fcd4e19ed586006d3de741a + graphite_exporter: 98cbd7176f1c61023892de64ad26edc3cd7895037e3cc282c4edec53dded7156 + haproxy_exporter: bc2b222f6a08232ef643cd6dcda3264f3bd7388a5bee25365cef137c7dea17e8 + memcached_exporter: 21db1bffc561d47b4490ccb2cde721244d00e95f504cdcfee618bc4bb877e731 + mysqld_exporter: b37d6fe68e2c884540ea41c5efcfb16d0bc5da517fe3ba713144504df1ba635d + node_exporter: {} + pushgateway: 0bce168e4b19234df9e954393a2102c91e4d62336b2721ed882f2003a4445d51 + statsd_exporter: c89acb365b75af03ce612873d8b20226e3882c0177752ea0ce17a9f5e41eb5b4 Solaris: {} Windows: - pkg: - archive: - name: C:\\Program Files - source_hash: eb138082a4d5e4d5b1e3ca838fa508f053474d46bca76e87ab0834f0d8b110db + kernel: windows + archive: + name: C:\\Program Files + hashes: + prometheus: eb138082a4d5e4d5b1e3ca838fa508f053474d46bca76e87ab0834f0d8b110db + alertmanager: 512dbed02a3cc7e3f06d737f56179e458c462762b3427063b89c62a54d9645c6 + blackbox_exporter: 21ea148870631310002cbd48be54ca45e8d300da5a902b0aec052f1a64316d93 + consul_exporter: 54579bc5dfa6a238e310a1874b0a362027661dfa1754535e74610dc8ef6163b1 + graphite_exporter: f83fad71bad99ccac145d65f82bf9d17fa37168a5dcce6415c6350e79a84e638 + haproxy_exporter: 044118feb98b74eb921e27bd4b511732b553896c672c19bdd3418445dc030794 + memcached_exporter: 9e83c00c9d249c942f65b6a48112e6bd6e28a3d15b8a1d35e935621657b3d837 + mysqld_exporter: 38605ae648f8def07a0f412d81a30a6c48c0d20a6981468d25b91c8aa529e599 + node_exporter: {} + pushgateway: 506b555e7a13cabf3d85ec0dbe1bc6bc3a2444c0cc468baa8d31e7fc2fe18dd1 + statsd_exporter: 9362b7482e74792f111c4bb1a372b18a88f6354c78f24713bacfbcb050883556 MacOS: rootgroup: {{ macos_group | d('') }} - pkg: - archive: - source_hash: 740e36bcacc0c5d4495f5341fcfa8b7e0dc623d12e8b07ac291052ea0a681325 + kernel: darwin + archive: + hashes: + prometheus: 740e36bcacc0c5d4495f5341fcfa8b7e0dc623d12e8b07ac291052ea0a681325 + alertmanager: efeebaa8e51c521ecb3440345fb65962533cae022d71dff8b127911e893ded2a + blackbox_exporter: a371d0496adb5d62368d6606928c5effd318d1387f6b9a9998f8d0333492645a + consul_exporter: 75641783938967c11c18d6d340028ff2dce7ad0ae5e300fa631b813cc6ea9647 + graphite_exporter: f9c0aa745502c0ab01fdcca29181801810202e0aed512a9aa9a37bb4be88a919 + haproxy_exporter: 8fdb8bb182586c57e5892816a02846bae0998916765d22bb81b2c444a3565862 + memcached_exporter: e10685cca5ffd8a3a7574b3dc096dc7418f34906abd399f881be06dd38be62cb + mysqld_exporter: 8e0a7d8847790d6dcdcf392e6dd227458a7bcaa1e0890cc6326fdf956421f2a7 + node_exporter: 20fadb3108de0a9cc70a1333394e5be90416b4f91025f9fc66f5736335e94398 + pushgateway: 25399a4c6600c1931f9d9bd5294700c2b53f964188b1c6003f9d12a2e176aac1 + statsd_exporter: 15132494523c2b6a89e09b2da63452c8fe587fb82fcc3fd21cc75a4aa2766644 From d43033a0fd70dca686083c101e0caa66faeae438 Mon Sep 17 00:00:00 2001 From: N Date: Wed, 19 Jun 2019 00:23:45 +0100 Subject: [PATCH 05/12] feat(archives): user managementX --- prometheus/archive/alternatives/clean.sls | 15 ++--- prometheus/archive/alternatives/init.sls | 9 --- prometheus/archive/alternatives/install.sls | 25 ++++---- prometheus/archive/clean.sls | 29 +++++++-- prometheus/archive/defaults.yaml | 26 +++++++- prometheus/archive/install.sls | 71 ++++++++++++++++----- prometheus/config/clean.sls | 3 - prometheus/config/init.sls | 5 -- prometheus/defaults.yaml | 14 +--- prometheus/files/default/systemd.ini.jinja | 18 ++++++ prometheus/map.jinja | 4 -- prometheus/systemd.sls | 0 12 files changed, 144 insertions(+), 75 deletions(-) create mode 100644 prometheus/files/default/systemd.ini.jinja create mode 100644 prometheus/systemd.sls diff --git a/prometheus/archive/alternatives/clean.sls b/prometheus/archive/alternatives/clean.sls index c5c78c7..243a3e7 100644 --- a/prometheus/archive/alternatives/clean.sls +++ b/prometheus/archive/alternatives/clean.sls @@ -6,14 +6,13 @@ {%- from tplroot ~ "/map.jinja" import prometheus as p with context %} {%- set sls_archive_clean = tplroot ~ '.archive.clean' %} - {%- if grains.kernel|lower == 'linux' and p.linux.altpriority|int > 0 %} + {%- if grains.kernel|lower == 'linux' and p.linux.altpriority|int > 0 %} include: - {{ sls_archive_clean }} - - {%- for k in p.archive.wanted %} - {%- set dir = p.archive.dir + '/' + k + '-%s.%s-%s'|format(p.archive.version["k"], p.kernel, p.arch) %} + {%- for k in p.archive.wanted %} + {%- set dir = p.archive.dir.opt + '/' + k + '-%s.%s-%s'|format(p.archive.versions[k], p.kernel, p.arch) %} prometheus-archive-remove-{{ k }}-home-alternatives-remove: alternatives.remove: @@ -23,9 +22,7 @@ prometheus-archive-remove-{{ k }}-home-alternatives-remove: - require: - sls: {{ sls_archive_clean }} - - {% for i in p.archive.binaries['k'] %} - + {% for i in p.archive.binaries[k] %} prometheus-archive-remove-{{ k }}-alternatives-remove-{{ i }}: alternatives.remove: - name: prometheus-{{ k }}-{{ i }} @@ -33,7 +30,7 @@ prometheus-archive-remove-{{ k }}-alternatives-remove-{{ i }}: - onlyif: update-alternatives --get-selections |grep ^prometheus-{{ k }}-{{ i }} - require: - sls: {{ sls_archive_clean }} + {% endfor %} {% endfor %} - {% endfor %} - {%- endif %} + {%- endif %} diff --git a/prometheus/archive/alternatives/init.sls b/prometheus/archive/alternatives/init.sls index 56c18a9..d3e5518 100644 --- a/prometheus/archive/alternatives/init.sls +++ b/prometheus/archive/alternatives/init.sls @@ -1,14 +1,5 @@ # -*- coding: utf-8 -*- # vim: ft=sls -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} -{%- from tplroot ~ "/jinja/macros.jinja" import format_kwargs with context %} - - {%- if grains.kernel|lower == 'linux' and prometheus.pkg.use_upstream_archive %} - include: - .install - - {%- endif %} diff --git a/prometheus/archive/alternatives/install.sls b/prometheus/archive/alternatives/install.sls index 749a4db..191ae23 100644 --- a/prometheus/archive/alternatives/install.sls +++ b/prometheus/archive/alternatives/install.sls @@ -7,16 +7,15 @@ {%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} {%- set sls_archive_install = tplroot ~ '.archive.install' %} - {%- if grains.kernel|lower in ('linux',) and p.linux.altpriority|int > 0 %} + {%- if grains.kernel|lower in ('linux',) and p.linux.altpriority|int > 0 %} include: - {{ sls_archive_install }} + {%- for k in p.archive.wanted %} + {%- set dir = p.archive.dir.opt + '/' + k + '-%s.%s-%s'|format(p.archive.versions[k], p.kernel, p.arch) %} - {%- for k in p.archive.wanted %} - {%- set dir = p.archive.dir + '/' + k + '-%s.%s-%s'|format(p.archive.version["k"], p.kernel, p.arch) %} - -prometheus-archive-alternatives-install-{{ k }}-home-alternatives-install: +prometheus-archive-alternatives-install-{{ k }}-home-cmd-run: cmd.run: - onlyif: {{ grains.os_family in ('Suse',) }} - name: update-alternatives --install {{ dir }} prometheus-{{ k }}-home {{ dir }} {{p.linux.altpriority}} @@ -24,9 +23,11 @@ prometheus-archive-alternatives-install-{{ k }}-home-alternatives-install: - archive: prometheus-archive-install-{{ k }}-archive-extracted - require: - sls: {{ sls_archive_install }} + +prometheus-archive-alternatives-install-{{ k }}-home-alternatives-install: alternatives.install: - name: prometheus-{{ k }}-home - - link: {{ p.dir }} + - link: {{ p.archive.dir.opt }}/{{ k }} - path: {{ dir }} - priority: {{ p.linux.altpriority }} - order: 10 @@ -41,17 +42,19 @@ prometheus-archive-alternatives-install-{{ k }}-home-alternatives-set: - name: prometheus-{{ k }}-home - path: {{ dir }} - require: + - cmd: prometheus-archive-alternatives-install-{{ k }}-home-cmd-run - alternatives: prometheus-archive-alternatives-install-{{ k }}-home-alternatives-install - onlyif: {{ grains.os_family not in ('Suse',) }} - {% for i in p.archive.binaries['k'] %} + + {% for i in p.archive.binaries[k] %} prometheus-archive-alternatives-install-{{ k }}-alternatives-install-{{ i }}: cmd.run: - onlyif: {{ grains.os_family in ('Suse',) }} - name: update-alternatives --install /usr/bin/{{i}} prometheus-{{ k }}-{{i}} {{ dir }}/{{i}} {{p.linux.altpriority}} - require: - - cmd: prometheus-archive-alternatives-install-{{ k }}-home-alternatives-install + - cmd: prometheus-archive-alternatives-install-{{ k }}-home-cmd-run alternatives.install: - name: prometheus-{{ k }}-{{ i }} - link: /usr/bin/{{ i }} @@ -69,7 +72,7 @@ prometheus-archive-alternatives-install-{{ k }}-alternatives-set-{{ i }}: - require: - alternatives: prometheus-archive-alternatives-install-{{ k }}-alternatives-install-{{ i }} - onlyif: {{ grains.os_family not in ('Suse',) }} - {% endfor %} - {% endfor %} - {%- endif %} + + {% endfor %} + {%- endif %} diff --git a/prometheus/archive/clean.sls b/prometheus/archive/clean.sls index c91fce5..047e86d 100644 --- a/prometheus/archive/clean.sls +++ b/prometheus/archive/clean.sls @@ -3,21 +3,40 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} +{%- from tplroot ~ "/map.jinja" import prometheus as p with context %} {%- set sls_alternatives_clean = tplroot ~ '.archive.alternatives.clean' %} - {%- if prometheus.pkg.use_upstream_archive %} + {%- if p.pkg.use_upstream_archive %} include: - {{ sls_alternatives_clean }} + {%- for k in p.archive.wanted %} + {%- set dir = p.archive.dir.opt + '/' + k + '-%s.%s-%s'|format(p.archive.versions[k], p.kernel, p.arch) %} - {%- for k in prometheus.archive.wanted %} prometheus-archive-clean-{{ k }}-file-absent: file.absent: - - name: {{ prometheus.archive.dir + '/' + k + '-%s.%s-%s'|format(prometheus.archive.versions[k], prometheus.kernel, prometheus.arch) }} + - names: + - {{ dir }} + - {{ p.archive.systemd.dir }}/{{ k }}.service #- require: #- sls: {{ sls_alternatives_clean }} + +prometheus-archive-clean-{{ k }}-user-absent: + user.absent: + - name: {{ k }} + group.absent: + - name: {{ k }} + - require: + - user: prometheus-archive-clean-{{ k }}-user-absent + {%- endfor %} - {%- endif %} +prometheus-archive-clean-file-directory: + file.absent: + - names: + - {{ p.archive.dir.opt }} + - {{ p.archive.dir.etc }} + - {{ p.archive.dir.var }} + + {%- endif %} diff --git a/prometheus/archive/defaults.yaml b/prometheus/archive/defaults.yaml index 716187f..ce02d59 100644 --- a/prometheus/archive/defaults.yaml +++ b/prometheus/archive/defaults.yaml @@ -3,7 +3,14 @@ --- prometheus: archive: - dir: /opt/prometheus + wanted: + - prometheus + - alertmanager + - node_exporter + systemd: + dir: /usr/lib/systemd/system + after: docker.service + wants: network-online.target docker.target uri: https://github.com/prometheus suffix: tar.gz kwargs: @@ -15,6 +22,10 @@ prometheus: until: True interval: 60 splay: 10 + dir: + opt: /opt/prometheus + etc: /etc/prometheus + var: /var/lib/prometheus binaries: prometheus: - prometheus @@ -40,7 +51,6 @@ prometheus: - pushgateway statsd_exporter: - statsd_exporter - versions: prometheus: '2.10.0' alertmanager: '0.17.0' @@ -65,3 +75,15 @@ prometheus: node_exporter: b2503fd932f85f4e5baf161268854bf5d22001869b84f00fd2d1f57b51b72424 pushgateway: 6949866ba9ad0cb88d3faffd4281f17df79281398b4dbd0ec3aab300071681ca statsd_exporter: 4632ad0c5552e271e84c376da3ffe3af8c265ec5c3035334b70e35756aca1906 + configs: + prometheus: {} + alertmanager: {} + blackbox_exporter: {} + consul_exporter: {} + graphite_exporter: {} + haproxy_exporter: {} + memcached_exporter: {} + mysqld_exporter: {} + node_exporter: {} + pushgateway: {} + statsd_exporter: {} diff --git a/prometheus/archive/install.sls b/prometheus/archive/install.sls index d3323a4..b9120e3 100644 --- a/prometheus/archive/install.sls +++ b/prometheus/archive/install.sls @@ -5,35 +5,74 @@ {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus as p with context %} {%- from tplroot ~ "/jinja/macros.jinja" import format_kwargs with context %} +{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} {%- for k in p.archive.wanted %} + {%- set dir = p.archive.dir.opt + '/' + k + '-%s.%s-%s'|format(p.archive.versions[k], p.kernel, p.arch) %} -prometheus-archive-install-{{ k }}-file-directory: - file.directory: - - name: {{ p.archive.dir }} - - user: root - - group: root - - mode: 755 - - makedirs: True +prometheus-archive-install-{{ k }}-user-present: + group.present: + - name: {{ k }} + - require_in: + - user: prometheus-archive-install-{{ k }}-user-present + user.present: + - name: {{ k }} + - shell: /bin/false + - createhome: false + - groups: + - {{ k }} - require_in: - archive: prometheus-archive-install-{{ k }}-archive-extracted - - recurse: - - user - - group - - mode prometheus-archive-install-{{ k }}-archive-extracted: archive.extracted: - - name: {{ p.archive.dir }} + - name: {{ p.archive.dir.opt }} - source: {{ p.archive.uri + '/' + k + '/releases/download/v' + p.archive.versions[k] - + '/' + k + '-%s.%s-%s'|format(p.archive.versions[k], p.kernel, p.arch) - + '.' + p.archive.suffix }} + + '/' + k + '-%s.%s-%s'|format(p.archive.versions[k], p.kernel, p.arch) + + '.' + p.archive.suffix }} - source_hash: {{ p.archive.hashes[k] }} - - user: root - - group: root + - user: {{ k }} + - group: {{ k }} {{- format_kwargs(p.archive.kwargs) }} - recurse: - user - group + - require_in: + - file: prometheus-archive-install-{{ k }}-managed-systemd_file + - file: prometheus-archive-install-file-directory + +prometheus-archive-install-{{ k }}-managed-systemd_file: + file.managed: + - name: {{ p.archive.systemd.dir }}/{{ k }}.service + - source: {{ files_switch(['systemd.ini.jinja'], + lookup='prometheus-archive-install-{{ k }}-managed-systemd_file' + ) + }} + - mode: 644 + - user: root + - group: {{ p.rootgroup }} + - makedirs: True + - template: jinja + - context: + desc: prometheus - {{ k }} serice + name: {{ k }} + user: {{ k }} + group: {{ k }} + start: {{ dir }}/{{ k }} --config.file {{ p.archive.dir.etc }}/{{ k }}/{{ k }}.yml + stop: killall {{ dir }}/{{ k }} + after: {{ p.archive.systemd.after }} + wants: {{ p.archive.systemd.wants }} {%- endfor %} + +prometheus-archive-install-file-directory: + file.directory: + - names: + - {{ p.archive.dir.opt }} + - {{ p.archive.dir.etc }} + - {{ p.archive.dir.var }} + - user: prometheus + - group: prometheus + - mode: 755 + - makedirs: True + ##do not recurse!!! diff --git a/prometheus/config/clean.sls b/prometheus/config/clean.sls index 4294cf2..2be423a 100644 --- a/prometheus/config/clean.sls +++ b/prometheus/config/clean.sls @@ -8,9 +8,6 @@ include: - {{ sls_archive_clean }} - {%- if prometheus.pkg.use_upstream_archive and kernel|lower == 'linux' %} - - .systemd - {%- endif %} prometheus-config-clean-file-absent: file.absent: diff --git a/prometheus/config/init.sls b/prometheus/config/init.sls index e87add3..8875266 100644 --- a/prometheus/config/init.sls +++ b/prometheus/config/init.sls @@ -9,8 +9,3 @@ include: - .args - .file - .environ - {%- if prometheus.pkg.use_upstream_archive and kernel|lower == 'linux' %} - - .systemd - {%- endif %} - - diff --git a/prometheus/defaults.yaml b/prometheus/defaults.yaml index ce2e7d0..ecedd90 100644 --- a/prometheus/defaults.yaml +++ b/prometheus/defaults.yaml @@ -16,19 +16,11 @@ prometheus: name: prometheus user: prometheus group: prometheus + linux: + #'Alternatives system' priority: zero disables (default) + altpriority: 0 exporters: node: pkg: name: prometheus-node-exporter service: prometheus-node-exporter - - linux: - #'Alternatives system' priority: zero disables (default) - altpriority: 0 - - archive: - # see ./archive/default.yaml - wanted: - - prometheus - - alertmanager - - node_exporter diff --git a/prometheus/files/default/systemd.ini.jinja b/prometheus/files/default/systemd.ini.jinja new file mode 100644 index 0000000..02d8105 --- /dev/null +++ b/prometheus/files/default/systemd.ini.jinja @@ -0,0 +1,18 @@ +######################################################### +# File managed by Salt. Changes risk being overwritten. +######################################################### +[Unit] +Description={{ desc }} +Wants={{ wants }} +After={{ after }} +Documentation=https://github.com/saltstack-formulas/prometheus-formula + +[Service] +User={{ user }} +Group={{ group }} +ExecStart={{ start }} +ExecStop={{ stop }} +PIDFile=/var/run/{{ name }}.pid + +[Install] +WantedBy=multi-user.target diff --git a/prometheus/map.jinja b/prometheus/map.jinja index 0113310..fbbf314 100644 --- a/prometheus/map.jinja +++ b/prometheus/map.jinja @@ -9,13 +9,10 @@ {%- import_yaml tplroot ~ "/osmap.yaml" as osmap %} {%- import_yaml tplroot ~ "/osarchmap.yaml" as osarchmap %} {%- import_yaml tplroot ~ "/osfingermap.yaml" as osfingermap %} -{#- focused defaults #} {%- import_yaml tplroot ~ "/archive/defaults.yaml" as archive_defaults %} -{%- import_yaml tplroot ~ "/archive/defaults.yaml" as config_defaults %} {%- set defaults = salt['grains.filter_by'](default_settings, merge=salt['grains.filter_by'](archive_defaults, - merge=salt['grains.filter_by'](config_defaults, merge=salt['grains.filter_by'](osfamilymap, grain='os_family', merge=salt['grains.filter_by'](osmap, grain='os', merge=salt['grains.filter_by'](osfingermap, grain='osfinger', @@ -25,7 +22,6 @@ base='prometheus'), base='prometheus'), base='prometheus'), - base='prometheus'), base='prometheus'), base='prometheus') %} diff --git a/prometheus/systemd.sls b/prometheus/systemd.sls new file mode 100644 index 0000000..e69de29 From 731198dd4d0447b01529467873d495f7a67fb31e Mon Sep 17 00:00:00 2001 From: N Date: Thu, 20 Jun 2019 01:36:58 +0100 Subject: [PATCH 06/12] test(centos): verified on CentosOS --- pillar.example | 161 +++++++++++++----- prometheus/archive/alternatives/clean.sls | 33 ++-- prometheus/archive/alternatives/install.sls | 59 ++++--- prometheus/archive/clean.sls | 37 ++-- prometheus/archive/defaults.yaml | 89 ---------- prometheus/archive/init.sls | 2 +- prometheus/archive/install.sls | 95 ++++++----- prometheus/config/args.sls | 54 ------ prometheus/config/args/clean.sls | 57 +++++++ prometheus/config/args/init.sls | 5 + prometheus/config/args/install.sls | 86 ++++++++++ prometheus/config/clean.sls | 16 +- prometheus/config/environ.sls | 29 ---- prometheus/config/file.sls | 36 ---- prometheus/config/file/clean.sls | 21 +++ prometheus/config/file/init.sls | 5 + prometheus/config/file/install.sls | 35 ++++ prometheus/config/init.sls | 5 - prometheus/defaults.yaml | 115 +++++++++++-- prometheus/exporters/init.sls | 14 -- prometheus/exporters/node/clean.sls | 28 --- prometheus/exporters/node/init.sls | 64 ------- ...{prometheus.yml.jinja => config.yml.jinja} | 0 .../{prometheus.sh.jinja => default.sh.jinja} | 4 +- prometheus/files/default/systemd.ini.jinja | 5 +- prometheus/init.sls | 2 +- prometheus/map.jinja | 14 +- prometheus/osfamilymap.yaml | 160 ++++++++++------- prometheus/osfingermap.yaml | 14 -- prometheus/osmap.yaml | 25 --- prometheus/package/clean.sls | 16 +- prometheus/package/install.sls | 8 +- prometheus/service/clean.sls | 13 +- prometheus/service/running.sls | 47 +++-- prometheus/systemd.sls | 0 35 files changed, 699 insertions(+), 655 deletions(-) delete mode 100644 prometheus/archive/defaults.yaml delete mode 100644 prometheus/config/args.sls create mode 100644 prometheus/config/args/clean.sls create mode 100644 prometheus/config/args/init.sls create mode 100644 prometheus/config/args/install.sls delete mode 100644 prometheus/config/environ.sls delete mode 100644 prometheus/config/file.sls create mode 100644 prometheus/config/file/clean.sls create mode 100644 prometheus/config/file/init.sls create mode 100644 prometheus/config/file/install.sls delete mode 100644 prometheus/exporters/init.sls delete mode 100644 prometheus/exporters/node/clean.sls delete mode 100644 prometheus/exporters/node/init.sls rename prometheus/files/default/{prometheus.yml.jinja => config.yml.jinja} (100%) rename prometheus/files/default/{prometheus.sh.jinja => default.sh.jinja} (78%) delete mode 100644 prometheus/osfingermap.yaml delete mode 100644 prometheus/osmap.yaml delete mode 100644 prometheus/systemd.sls diff --git a/pillar.example b/pillar.example index 3b01a01..9608538 100644 --- a/pillar.example +++ b/pillar.example @@ -2,24 +2,31 @@ # vim: ft=yaml --- prometheus: - pkg: - name: prometheus - use_upstream_archive: False - archive: - source: https://github.com/prometheus/prometheus/releases/download/v2.10.0/prometheus-2.10.0.linux-amd64.tar.gz - source_hash: f4233783826f18606b79e5cef0686e4a9c2030146a3c7ce134f0add09f5adcb7 - archive_format: tar - enforce_toplevel: False - config_file: /etc/prometheus/prometheus.yml - environ_file: /etc/default/prometheus.sh - service: - name: prometheus - args: - web.listen-address: 0.0.0.0:9090 + wanted: + - prometheus + - pushgateway + - node_explorer - linux: - #'Alternatives system' priority: zero disables (default) - altpriority: 0 + use_upstream_archive: True + pkg: + prometheus: + archive_version: 2.10.0 + archive_hash: f4233783826f18606b79e5cef0686e4a9c2030146a3c7ce134f0add09f5adcb7 + alertmanager: + archive_version: '0.17.0' + archive_hash: ec171b13976baceace193461f8a1e61021ab9657df5ba45157cd0095aee7d569 + + service: + prometheus + args: + web.listen-address: 0.0.0.0:9090 + pushgateway: + args: + web.listen-address: ":9091" + web.telemetry-path: "/metrics" + node_exporter: + args: + web.listen-address: ":9110" tofs: # The files_switch key serves as a selector for alternative @@ -45,40 +52,100 @@ prometheus: # - 'example_alt.tmpl.jinja' # Pillar-based config - environ: - - 'export PATH=${PATH}:/opt/prometheus-2.10.0.linux-amd64' config: - # my global config - global: - scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. - evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. - # scrape_timeout is set to the global default (10s). + prometheus: + # ref https://raw.githubusercontent.com/prometheus/prometheus/release-2.10/config/testdata/conf.good.yml + # my global config + global: + scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. + evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. + # scrape_timeout is set to the global default (10s). - # Alertmanager configuration - alerting: - alertmanagers: - - static_configs: - - targets: - # - alertmanager:9093 + # Alertmanager configuration + alerting: + alertmanagers: + - static_configs: + - targets: + # - alertmanager:9093 - # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. - rule_files: - # - "first_rules.yml" - # - "second_rules.yml" + # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. + rule_files: + # - "first_rules.yml" + # - "second_rules.yml" - # A scrape configuration containing exactly one endpoint to scrape: - # Here it's Prometheus itself. - scrape_configs: - # The job name is added as a label `job=` to any timeseries scraped from this config. - - job_name: 'prometheus' + # A scrape configuration containing exactly one endpoint to scrape: + scrape_configs: + # The job name is added as a label `job=` to any timeseries scraped from this config. + - job_name: 'prometheus' + # metrics_path defaults to '/metrics' + # scheme defaults to 'http'. + static_configs: + - targets: ['localhost:9090'] - # metrics_path defaults to '/metrics' - # scheme defaults to 'http'. + - job_name: pushgateway + scrape_interval: 5s + honor_labels: true + static_configs: + - targets: ['pushgateway:9091'] - static_configs: - - targets: ['localhost:9090'] + - job_name: 'blackbox' + # ref https://github.com/prometheus/blackbox_exporter#prometheus-configuration + metrics_path: /probe + params: + module: [http_2xx] # Look for a HTTP 200 response. + static_configs: + - targets: + - http://prometheus.io # Target to probe with http. + - https://prometheus.io # Target to probe with https. + - http://example.com:8080 # Target to probe with http on port 8080. + relabel_configs: + - source_labels: [__address__] + target_label: __param_target + - source_labels: [__param_target] + target_label: instance + - target_label: __address__ + replacement: 127.0.0.1:9115 # The blackbox exporter's real hostname:port. + + alertmanager: + # ref https://github.com/prometheus/alertmanager/blob/master/config/testdata/conf.good.yml + global: + smtp_smarthost: 'localhost:25' + smtp_from: 'alertmanager@example.org' + smtp_auth_username: 'alertmanager' + smtp_auth_password: "multiline\nmysecret" + smtp_hello: "host.example.org" + slack_api_url: "http://mysecret.example.com/" + http_config: + proxy_url: 'http://127.0.0.1:1025' + route: + group_by: ['alertname', 'cluster', 'service'] + group_wait: 30s + group_interval: 5m + repeat_interval: 3h + receiver: team-X-mails + routes: + - match_re: + service: ^(foo1|foo2|baz)$ + receiver: team-X-mails + routes: + - match: + severity: critical + receiver: team-X-mails + receivers: + - name: 'team-X-mails' + email_configs: + - to: 'team-X+alerts@example.org' + + inhibit_rules: + - name: opsGenie-receiver + opsgenie_configs: + - api_key: mysecret + - name: slack-receiver + slack_configs: + - channel: '#my-channel' + image_url: 'http://some.img.com/img.png' + + linux: + #'Alternatives system' priority: zero disables (default) + altpriority: 0 - exporters: - node: - args: - web.listen-address: ":9110" diff --git a/prometheus/archive/alternatives/clean.sls b/prometheus/archive/alternatives/clean.sls index 243a3e7..99aec88 100644 --- a/prometheus/archive/alternatives/clean.sls +++ b/prometheus/archive/alternatives/clean.sls @@ -4,33 +4,26 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus as p with context %} -{%- set sls_archive_clean = tplroot ~ '.archive.clean' %} {%- if grains.kernel|lower == 'linux' and p.linux.altpriority|int > 0 %} -include: - - {{ sls_archive_clean }} + {%- for name in p.wanted %} + {%- set bundle = name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) %} - {%- for k in p.archive.wanted %} - {%- set dir = p.archive.dir.opt + '/' + k + '-%s.%s-%s'|format(p.archive.versions[k], p.kernel, p.arch) %} - -prometheus-archive-remove-{{ k }}-home-alternatives-remove: +prometheus-archive-remove-{{ name }}-home-alternatives-remove: alternatives.remove: - - name: prometheus-{{ k }}-home - - path: {{ dir }} - - onlyif: update-alternatives --get-selections |grep ^prometheus-{{ k }}-home - - require: - - sls: {{ sls_archive_clean }} + - name: prometheus-{{ name }}-home + - path: {{ p.dir.basedir }}/{{ bundle }} + - onlyif: update-alternatives --get-selections |grep ^prometheus-{{ name }}-home - {% for i in p.archive.binaries[k] %} -prometheus-archive-remove-{{ k }}-alternatives-remove-{{ i }}: + {% for b in p.pkg[name]['binaries'] %} + +prometheus-archive-remove-{{ name }}-alternatives-remove-{{ b }}: alternatives.remove: - - name: prometheus-{{ k }}-{{ i }} - - path: {{ dir }}/{{ i }} - - onlyif: update-alternatives --get-selections |grep ^prometheus-{{ k }}-{{ i }} - - require: - - sls: {{ sls_archive_clean }} + - name: prometheus-{{ name }}-{{ b }} + - path: {{ p.dir.basedir }}/{{ bundle }}/{{ b }} + - onlyif: update-alternatives --get-selections |grep ^prometheus-{{ name }}-{{ b }} + {% endfor %} - {% endfor %} {%- endif %} diff --git a/prometheus/archive/alternatives/install.sls b/prometheus/archive/alternatives/install.sls index 191ae23..b6b17e5 100644 --- a/prometheus/archive/alternatives/install.sls +++ b/prometheus/archive/alternatives/install.sls @@ -12,67 +12,66 @@ include: - {{ sls_archive_install }} - {%- for k in p.archive.wanted %} - {%- set dir = p.archive.dir.opt + '/' + k + '-%s.%s-%s'|format(p.archive.versions[k], p.kernel, p.arch) %} + {%- for name in p.wanted %} + {%- set bundle = name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) %} -prometheus-archive-alternatives-install-{{ k }}-home-cmd-run: +prometheus-archive-alternatives-install-{{ name }}-home-cmd-run: cmd.run: - onlyif: {{ grains.os_family in ('Suse',) }} - - name: update-alternatives --install {{ dir }} prometheus-{{ k }}-home {{ dir }} {{p.linux.altpriority}} + - name: update-alternatives --install {{ p.dir.basedir }}/{{ bundle }} prometheus-{{ name }}-home {{ p.dir.basedir }}/{{ bundle }} {{p.linux.altpriority}} - watch: - - archive: prometheus-archive-install-{{ k }}-archive-extracted + - archive: prometheus-archive-install-{{ name }}-archive-extracted - require: - sls: {{ sls_archive_install }} -prometheus-archive-alternatives-install-{{ k }}-home-alternatives-install: +prometheus-archive-alternatives-install-{{ name }}-home-alternatives-install: alternatives.install: - - name: prometheus-{{ k }}-home - - link: {{ p.archive.dir.opt }}/{{ k }} - - path: {{ dir }} + - name: prometheus-{{ name }}-home + - link: {{ p.dir.basedir }}/{{ name }} + - path: {{ p.dir.basedir }}/{{ bundle }} - priority: {{ p.linux.altpriority }} - order: 10 - watch: - - archive: prometheus-archive-install-{{ k }}-archive-extracted + - archive: prometheus-archive-install-{{ name }}-archive-extracted - require: - sls: {{ sls_archive_install }} - onlyif: {{ grains.os_family not in ('Suse',) }} -prometheus-archive-alternatives-install-{{ k }}-home-alternatives-set: +prometheus-archive-alternatives-install-{{ name }}-home-alternatives-set: alternatives.set: - - name: prometheus-{{ k }}-home - - path: {{ dir }} + - name: prometheus-{{ name }}-home + - path: {{ p.dir.basedir }}/{{ bundle }} - require: - - cmd: prometheus-archive-alternatives-install-{{ k }}-home-cmd-run - - alternatives: prometheus-archive-alternatives-install-{{ k }}-home-alternatives-install + - cmd: prometheus-archive-alternatives-install-{{ name }}-home-cmd-run + - alternatives: prometheus-archive-alternatives-install-{{ name }}-home-alternatives-install - onlyif: {{ grains.os_family not in ('Suse',) }} + {% for b in p.pkg[name]['binaries'] %} - {% for i in p.archive.binaries[k] %} - -prometheus-archive-alternatives-install-{{ k }}-alternatives-install-{{ i }}: +prometheus-archive-alternatives-install-{{ name }}-alternatives-install-{{ b }}: cmd.run: - onlyif: {{ grains.os_family in ('Suse',) }} - - name: update-alternatives --install /usr/bin/{{i}} prometheus-{{ k }}-{{i}} {{ dir }}/{{i}} {{p.linux.altpriority}} + - name: update-alternatives --install /usr/local/bin/{{ b }} prometheus-{{ name }}-{{ b }} {{ p.dir.basedir }}/{{ bundle }}/{{ b }} {{ p.linux.altpriority }} - require: - - cmd: prometheus-archive-alternatives-install-{{ k }}-home-cmd-run + - cmd: prometheus-archive-alternatives-install-{{ name }}-home-cmd-run alternatives.install: - - name: prometheus-{{ k }}-{{ i }} - - link: /usr/bin/{{ i }} - - path: {{ dir }}/{{ i }} + - name: prometheus-{{ name }}-{{ b }} + - link: /usr/local/bin/{{ b }} + - path: {{ p.dir.basedir }}/{{ bundle }}/{{ b }} - priority: {{ p.linux.altpriority }} - order: 10 - require: - - alternatives: prometheus-archive-alternatives-install-{{ k }}-home-alternatives-install + - alternatives: prometheus-archive-alternatives-install-{{ name }}-home-alternatives-install - onlyif: {{ grains.os_family not in ('Suse',) }} -prometheus-archive-alternatives-install-{{ k }}-alternatives-set-{{ i }}: +prometheus-archive-alternatives-install-{{ name }}-alternatives-set-{{ b }}: alternatives.set: - - name: prometheus-{{ k }}-{{ i }} - - path: {{ dir }}/{{ i }} + - name: prometheus-{{ name }}-{{ b }} + - path: {{ p.dir.basedir }}/{{ bundle }}/{{ b }} - require: - - alternatives: prometheus-archive-alternatives-install-{{ k }}-alternatives-install-{{ i }} + - alternatives: prometheus-archive-alternatives-install-{{ name }}-alternatives-install-{{ b }} - onlyif: {{ grains.os_family not in ('Suse',) }} + {% endfor %} - - {% endfor %} + {% endfor %} {%- endif %} diff --git a/prometheus/archive/clean.sls b/prometheus/archive/clean.sls index 047e86d..a1bfe5e 100644 --- a/prometheus/archive/clean.sls +++ b/prometheus/archive/clean.sls @@ -6,37 +6,38 @@ {%- from tplroot ~ "/map.jinja" import prometheus as p with context %} {%- set sls_alternatives_clean = tplroot ~ '.archive.alternatives.clean' %} - {%- if p.pkg.use_upstream_archive %} + {%- if p.use_upstream_archive %} include: - {{ sls_alternatives_clean }} - {%- for k in p.archive.wanted %} - {%- set dir = p.archive.dir.opt + '/' + k + '-%s.%s-%s'|format(p.archive.versions[k], p.kernel, p.arch) %} + {%- for name in p.wanted %} -prometheus-archive-clean-{{ k }}-file-absent: +prometheus-archive-clean-{{ name }}-file-absent: file.absent: - names: - - {{ dir }} - - {{ p.archive.systemd.dir }}/{{ k }}.service - #- require: - #- sls: {{ sls_alternatives_clean }} - -prometheus-archive-clean-{{ k }}-user-absent: - user.absent: - - name: {{ k }} - group.absent: - - name: {{ k }} + - {{ p.dir.basedir }}/{{ name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) }} - require: - - user: prometheus-archive-clean-{{ k }}-user-absent + - sls: {{ sls_alternatives_clean }} + +prometheus-archive-clean-{{ name }}-user-absent: + user.absent: + - name: {{ name }} + group.absent: + - name: {{ name }} + - require: + - user: prometheus-archive-clean-{{ name }}-user-absent + - sls: {{ sls_alternatives_clean }} {%- endfor %} prometheus-archive-clean-file-directory: file.absent: - names: - - {{ p.archive.dir.opt }} - - {{ p.archive.dir.etc }} - - {{ p.archive.dir.var }} + - {{ p.dir.basedir }} + - {{ p.dir.etc }} + - {{ p.dir.var }} + - require: + - sls: {{ sls_alternatives_clean }} {%- endif %} diff --git a/prometheus/archive/defaults.yaml b/prometheus/archive/defaults.yaml deleted file mode 100644 index ce02d59..0000000 --- a/prometheus/archive/defaults.yaml +++ /dev/null @@ -1,89 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=yaml ---- -prometheus: - archive: - wanted: - - prometheus - - alertmanager - - node_exporter - systemd: - dir: /usr/lib/systemd/system - after: docker.service - wants: network-online.target docker.target - uri: https://github.com/prometheus - suffix: tar.gz - kwargs: - trim_output: True - enforce_toplevel: True - archive_format: tar - retry: - attempts: 3 - until: True - interval: 60 - splay: 10 - dir: - opt: /opt/prometheus - etc: /etc/prometheus - var: /var/lib/prometheus - binaries: - prometheus: - - prometheus - - promtool - alertmanager: - - amtool - - alertmanager - blackbox_exporter: - - blackbox_exporter - consul_exporter: - - consul_exporter - graphite_exporter: - - graphite_exporter - haproxy_exporter: - - haproxy_exporter - memcached_exporter: - - memcached_exporter - mysqld_exporter: - - mysqld_exporter - node_exporter: - - node_exporter - pushgateway: - - pushgateway - statsd_exporter: - - statsd_exporter - versions: - prometheus: '2.10.0' - alertmanager: '0.17.0' - blackbox_exporter: '0.14.0' - consul_exporter: '0.4.0' - graphite_exporter: '0.6.2' - haproxy_exporter: '0.10.0' - memcached_exporter: '0.5.0' - mysqld_exporter: '0.11.0' - node_exporter: '0.18.1' - pushgateway: '0.8.0' - statsd_exporter: '0.11.2' - hashes: - prometheus: f4233783826f18606b79e5cef0686e4a9c2030146a3c7ce134f0add09f5adcb7 - alertmanager: 7c8d2cfeb021c80881ae9904d959131091b8785b6fda9800f84ddef148fe0a4f - blackbox_exporter: a2918a059023045cafb911272c88a9eb83cdac9a8a5e8e74844b5d6d27f19117 - consul_exporter: ff77c03de67cf381f67480b5be6699901785a34145c518c3484ae3e5b8440d08 - graphite_exporter: 9b962bd06406ece4a865ad6947a6e652e48a92a0d77e496a0351c04e9c2c5e9e - haproxy_exporter: 08150728e281f813a8fcfff4b336f16dbfe4268a1c7510212c8cff2579b10468 - memcached_exporter: bb07f496ceb63dad9793ad4295205547a4bd20b90628476d64fa96c9a25a020f - mysqld_exporter: b53ad48ff14aa891eb6a959730ffc626db98160d140d9a66377394714c563acf - node_exporter: b2503fd932f85f4e5baf161268854bf5d22001869b84f00fd2d1f57b51b72424 - pushgateway: 6949866ba9ad0cb88d3faffd4281f17df79281398b4dbd0ec3aab300071681ca - statsd_exporter: 4632ad0c5552e271e84c376da3ffe3af8c265ec5c3035334b70e35756aca1906 - configs: - prometheus: {} - alertmanager: {} - blackbox_exporter: {} - consul_exporter: {} - graphite_exporter: {} - haproxy_exporter: {} - memcached_exporter: {} - mysqld_exporter: {} - node_exporter: {} - pushgateway: {} - statsd_exporter: {} diff --git a/prometheus/archive/init.sls b/prometheus/archive/init.sls index 9e050fa..7ad92ee 100644 --- a/prometheus/archive/init.sls +++ b/prometheus/archive/init.sls @@ -5,7 +5,7 @@ {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus with context %} - {%- if prometheus.pkg.use_upstream_archive %} + {%- if prometheus.use_upstream_archive %} include: - .install diff --git a/prometheus/archive/install.sls b/prometheus/archive/install.sls index b9120e3..d169323 100644 --- a/prometheus/archive/install.sls +++ b/prometheus/archive/install.sls @@ -7,45 +7,64 @@ {%- from tplroot ~ "/jinja/macros.jinja" import format_kwargs with context %} {%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} - {%- for k in p.archive.wanted %} - {%- set dir = p.archive.dir.opt + '/' + k + '-%s.%s-%s'|format(p.archive.versions[k], p.kernel, p.arch) %} +prometheus-archive-install-file-directory: + file.directory: + - names: + - {{ p.dir.basedir }} + - {{ p.dir.etc }} + - {{ p.dir.var }} + - user: prometheus + - group: prometheus + - mode: 755 + - makedirs: True -prometheus-archive-install-{{ k }}-user-present: + {%- for name in p.wanted %} + {%- set bundle = name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) %} + +prometheus-archive-install-{{ name }}-user-present: group.present: - - name: {{ k }} + - name: {{ name }} - require_in: - - user: prometheus-archive-install-{{ k }}-user-present + - user: prometheus-archive-install-{{ name }}-user-present user.present: - - name: {{ k }} + - name: {{ name }} - shell: /bin/false - createhome: false - groups: - - {{ k }} + - {{ name }} - require_in: - - archive: prometheus-archive-install-{{ k }}-archive-extracted + - archive: prometheus-archive-install-{{ name }}-archive-extracted -prometheus-archive-install-{{ k }}-archive-extracted: +prometheus-archive-install-{{ name }}-archive-extracted: archive.extracted: - - name: {{ p.archive.dir.opt }} - - source: {{ p.archive.uri + '/' + k + '/releases/download/v' + p.archive.versions[k] - + '/' + k + '-%s.%s-%s'|format(p.archive.versions[k], p.kernel, p.arch) - + '.' + p.archive.suffix }} - - source_hash: {{ p.archive.hashes[k] }} - - user: {{ k }} - - group: {{ k }} + - name: {{ p.dir.basedir }} + - source: {{ p.archive.uri }}/{{ name }}/releases/download/v{{ p.pkg[name]['archive_version'] + + '/' + bundle + '.' + p.archive.suffix }} + - source_hash: {{ p.pkg[name]['archive_hash'] }} + - user: {{ name }} + - group: {{ name }} {{- format_kwargs(p.archive.kwargs) }} - recurse: - user - group - - require_in: - - file: prometheus-archive-install-{{ k }}-managed-systemd_file - - file: prometheus-archive-install-file-directory -prometheus-archive-install-{{ k }}-managed-systemd_file: + {%- if name in p.service %} + +prometheus-archive-install-{{ name }}-file-directory: + file.directory: + - name: {{ p.dir.var }}/{{ name }} + - user: {{ name }} + - group: {{ name }} + - mode: 755 + - makedirs: True + - require: + - archive: prometheus-archive-install-{{ name }}-archive-extracted + +prometheus-archive-install-{{ name }}-managed-service: file.managed: - - name: {{ p.archive.systemd.dir }}/{{ k }}.service + - name: {{ p.dir.service }}/{{ name }}.service - source: {{ files_switch(['systemd.ini.jinja'], - lookup='prometheus-archive-install-{{ k }}-managed-systemd_file' + lookup='prometheus-archive-install-{{ name }}-managed-service' ) }} - mode: 644 @@ -54,25 +73,15 @@ prometheus-archive-install-{{ k }}-managed-systemd_file: - makedirs: True - template: jinja - context: - desc: prometheus - {{ k }} serice - name: {{ k }} - user: {{ k }} - group: {{ k }} - start: {{ dir }}/{{ k }} --config.file {{ p.archive.dir.etc }}/{{ k }}/{{ k }}.yml - stop: killall {{ dir }}/{{ k }} - after: {{ p.archive.systemd.after }} - wants: {{ p.archive.systemd.wants }} + desc: prometheus - {{ name }} service + name: {{ name }} + user: {{ name }} + group: {{ name }} + workdir: {{ p.dir.var }}/{{ name }} + start: {{ p.dir.basedir }}/{{ bundle }}/{{ name }} --config.file {{ p.dir.etc }}/{{ name }}.yml + stop: '' #not needed + - require: + - file: prometheus-archive-install-{{ name }}-file-directory - {%- endfor %} - -prometheus-archive-install-file-directory: - file.directory: - - names: - - {{ p.archive.dir.opt }} - - {{ p.archive.dir.etc }} - - {{ p.archive.dir.var }} - - user: prometheus - - group: prometheus - - mode: 755 - - makedirs: True - ##do not recurse!!! + {%- endif %} + {%- endfor %} diff --git a/prometheus/config/args.sls b/prometheus/config/args.sls deleted file mode 100644 index 35a4c4b..0000000 --- a/prometheus/config/args.sls +++ /dev/null @@ -1,54 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=sls - -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} -{%- from tplroot ~ "/map.jinja" import concat_args %} - -{%- if 'args' in prometheus.service %} -{%- set args = prometheus.service.get('args', {}) -%} - -{%- if 'storage.tsdb.path' in args.keys() %} -prometheus-data-dir: - file.directory: - - name: {{ args['storage.tsdb.path'] }} - - owner: {{ prometheus.service.user }} - - group: {{ prometheus.service.group }} - - makedirs: True - - watch_in: - - service: prometheus-service-running-service-running -{%- endif %} - -{# FreeBSD #} -{%- if salt['grains.get']('os_family') == 'FreeBSD' %} -{%- if 'storage.tsdb.path' in args.keys() %} -{%- set value = args.pop('storage.tsdb.path') %} -prometheus-config-args-storage-tsdb-path: - sysrc.managed: - - name: prometheus_data_dir - - value: {{ value }} - - watch_in: - - service: prometheus-service-running-service-running -{%- endif %} - -prometheus-config-args-all: - sysrc.managed: - - name: prometheus_args - # service prometheus restart tended to hang on FreeBSD - # https://github.com/saltstack/salt/issues/44848#issuecomment-487016414 - - value: "{{ concat_args(args) }} >/dev/null 2>&1" - - watch_in: - - service: prometheus-service-running-service-running - -{# Debian #} -{%- elif salt['grains.get']('os_family') == 'Debian'%} -prometheus-config-args-file-managed: - file.managed: - - name: {{ prometheus.args_file }} - - contents: | - ARGS="{{ concat_args(args) }}" - - watch_in: - - service: prometheus-service-running-service-running -{%- endif %} -{%- endif %} diff --git a/prometheus/config/args/clean.sls b/prometheus/config/args/clean.sls new file mode 100644 index 0000000..e72d83c --- /dev/null +++ b/prometheus/config/args/clean.sls @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus with context %} +{%- set sls_service_clean = tplroot ~ '.service.clean' %} + +include: + - {{ sls_service_clean }} + + {%- for name in prometheus.wanted %} + {%- if name in prometheus.service %} + {%- set args = {} %} + {%- if 'args' in prometheus.service[name] %} + {%- set args = prometheus.service[name]['args'] or {} %} + {%- endif %} + {%- if args and 'storage.tsdb.path' in args.keys() %} + +prometheus-config-args-{{ name }}-data-dir: + file.absent: + - name: {{ args['storage.tsdb.path'] }} + - require: + - sls: {{ sls_service_clean }} + + {%- if grains.os_family == 'FreeBSD' %} + +prometheus-config-args-{{ name }}-{{ key }}: + sysrc.absent: + - name: {{ name }}_data_dir + - require: + - service: prometheus-service-clean-{{ name }}-service-dead + + {%- endif %} + {%- endif %} + {%- if args and grains.os_family == 'FreeBSD' %} + +prometheus-config-args-{{ name }}-all: + sysrc.absent: + - names: + - {{ name }}_args + - {{ name }}_listen_address + - {{ name }}_textfile_dir + - require: + - service: prometheus-service-clean-{{ name }}-service-dead + + {%- elif grains.os_family != 'FreeBSD' %} + +prometheus-config-args-{{ name }}-file-absent: + file.absent: + - name: {{ prometheus.dir.args }}/{{ name }}.sh + - require: + - service: prometheus-service-clean-{{ name }}-service-dead + + {%- endif %} + {%- endif %} + {%- endfor %} diff --git a/prometheus/config/args/init.sls b/prometheus/config/args/init.sls new file mode 100644 index 0000000..d3e5518 --- /dev/null +++ b/prometheus/config/args/init.sls @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +include: + - .install diff --git a/prometheus/config/args/install.sls b/prometheus/config/args/install.sls new file mode 100644 index 0000000..787aa16 --- /dev/null +++ b/prometheus/config/args/install.sls @@ -0,0 +1,86 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus with context %} +{%- from tplroot ~ "/map.jinja" import concat_args %} +{%- set sls_config_install = tplroot ~ '.config' %} +{%- set sls_service_install = tplroot ~ '.service' %} + +include: + - {{ sls_config_install }} + - {{ sls_service_install }} + + {%- for name in prometheus.wanted %} + {%- if name in prometheus.config or name in prometheus.service %} + {%- set args = {} %} + {%- if 'args' in prometheus.service[name] %} + {%- set args = prometheus.service[name]['args'] or {} %} + {%- endif %} + {%- if args and 'storage.tsdb.path' in args.keys() %} + +prometheus-config-args-{{ name }}-data-dir: + file.directory: + - name: {{ args['storage.tsdb.path'] }} + - owner: {{ name }} + - group: {{ name }} + - makedirs: True + - watch_in: + - service: prometheus-service-running-{{ name }}-service-running + + {%- endif %} + {%- if args and grains.os_family == 'FreeBSD' %} + {%- if 'web.listen-address' in args.keys() %} + +prometheus-config-args-args-web-listen-address: + sysrc.managed: + - name: {{ name }}_listen_address + - value: {{ args.pop('web.listen-address') }} + - watch_in: + - service: prometheus-service-running-{{ name }}-service-running + + {%- endif %} + {%- if 'collector.textfile.directory' in args.keys() %} + +prometheus-config-args-{{ name }}--collector-textfile-directory: + sysrc.managed: + - name: {{ name }}_textfile_dir + - value: {{ args.pop('collector.textfile.directory') }} + - watch_in: + - service: prometheus-service-running-{{ name }}-service-running + + {%- endif %} + {%- if 'storage.tsdb.path' in args.keys() %} + +prometheus-config-args-{{ name }}-{{ key }}: + sysrc.managed: + - name: {{ name }}_data_dir + - value: {{ args.pop('storage.tsdb.path') }} + - watch_in: + - service: prometheus-service-running-{{ name }}-service-running + + {%- endif %} + +prometheus-config-args-{{ name }}-all: + sysrc.managed: + - name: {{ name }}_args + # service prometheus restart tended to hang on FreeBSD + # https://github.com/saltstack/salt/issues/44848#issuecomment-487016414 + - value: "{{ concat_args(args) }} >/dev/null 2>&1" + - watch_in: + - service: prometheus-service-running-{{ name }}-service-running + + {%- elif grains.os_family != 'FreeBSD' %} + +prometheus-config-args-{{ name }}-file-managed: + file.managed: + - name: {{ prometheus.dir.args }}/{{ name }}.sh + - contents: | + ARGS="{{ concat_args(args) }}" + - watch_in: + - service: prometheus-service-running-{{ name }}-service-running + + {%- endif %} + {%- endif %} + {%- endfor %} diff --git a/prometheus/config/clean.sls b/prometheus/config/clean.sls index 2be423a..7d54d55 100644 --- a/prometheus/config/clean.sls +++ b/prometheus/config/clean.sls @@ -1,18 +1,6 @@ # -*- coding: utf-8 -*- # vim: ft=sls -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} -{%- set sls_archive_clean = tplroot ~ '.archive.clean' %} - include: - - {{ sls_archive_clean }} - -prometheus-config-clean-file-absent: - file.absent: - - names: - - {{ prometheus.config_file }} - - {{ prometheus.environ_file }} - - require: - - sls: {{ sls_archive_clean }} + - .file.clean + - .args.clean diff --git a/prometheus/config/environ.sls b/prometheus/config/environ.sls deleted file mode 100644 index 25f976d..0000000 --- a/prometheus/config/environ.sls +++ /dev/null @@ -1,29 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=sls - -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} -{%- set sls_archive_install = tplroot ~ '.archive.install' %} -{%- set sls_package_install = tplroot ~ '.package.install' %} -{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} - -include: - - {{ sls_archive_install if prometheus.pkg.use_upstream_archive else sls_package_install }} - -prometheus-config-file-file-managed-environ_file: - file.managed: - - name: {{ prometheus.environ_file }} - - source: {{ files_switch(['prometheus.sh.jinja'], - lookup='prometheus-config-file-file-managed-environ_file' - ) - }} - - mode: 644 - - user: root - - group: {{ prometheus.rootgroup }} - - makedirs: True - - template: jinja - - context: - prometheus: {{ prometheus|json }} - - require: - - sls: {{ sls_archive_install if prometheus.pkg.use_upstream_archive else sls_package_install }} diff --git a/prometheus/config/file.sls b/prometheus/config/file.sls deleted file mode 100644 index dd9a302..0000000 --- a/prometheus/config/file.sls +++ /dev/null @@ -1,36 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=sls - -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} -{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} - -{%- if 'config' in prometheus and prometheus.config %} - {%- if prometheus.pkg.use_upstream_archive %} - {%- set sls_package_install = tplroot ~ '.archive.install' %} - {%- else %} - {%- set sls_package_install = tplroot ~ '.package.install' %} - {%- endif %} - -include: - - {{ sls_package_install }} - -prometheus-config-file-file-managed-config_file: - file.managed: - - name: {{ prometheus.config_file }} - - source: {{ files_switch(['prometheus.yml.jinja'], - lookup='prometheus-config-file-file-managed-config_file' - ) - }} - - mode: 644 - - user: root - - group: {{ prometheus.rootgroup }} - - makedirs: True - - template: jinja - - context: - config: {{ prometheus.config|json }} - - require: - - sls: {{ sls_package_install }} - -{%- endif %} diff --git a/prometheus/config/file/clean.sls b/prometheus/config/file/clean.sls new file mode 100644 index 0000000..a86ce29 --- /dev/null +++ b/prometheus/config/file/clean.sls @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus with context %} +{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} +{%- set sls_service_clean = tplroot ~ '.service.clean' %} + +include: + - {{ sls_service_clean }} + + {%- for name in prometheus.wanted %} + +prometheus-config-file-{{ name }}-file-absent: + file.absent: + - name: {{ prometheus.dir.etc }}/{{ name }}.yml + - require: + - sls: {{ sls_service_clean }} + + {%- endfor %} diff --git a/prometheus/config/file/init.sls b/prometheus/config/file/init.sls new file mode 100644 index 0000000..d3e5518 --- /dev/null +++ b/prometheus/config/file/init.sls @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +include: + - .install diff --git a/prometheus/config/file/install.sls b/prometheus/config/file/install.sls new file mode 100644 index 0000000..0359979 --- /dev/null +++ b/prometheus/config/file/install.sls @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus with context %} +{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} +{%- set sls_archive_install = tplroot ~ '.archive.install' %} +{%- set sls_package_install = tplroot ~ '.package.install' %} + +include: + - {{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }} + + {%- for name in prometheus.wanted %} + {%- if name in prometheus.config or name in prometheus.service %} + +prometheus-config-file-{{ name }}-file-managed: + file.managed: + - name: {{ prometheus.dir.etc }}/{{ name }}.yml + - source: {{ files_switch(['config.yml.jinja'], + lookup='prometheus-config-file-{{ name }}-file-managed' + ) + }} + - mode: 644 + - user: {{ name }} + - group: {{ name }} + - makedirs: True + - template: jinja + - context: + config: {{ '' if name not in prometheus.config else prometheus.config[name]|json }} + - require: + - sls: {{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }} + + {%- endif %} + {%- endfor %} diff --git a/prometheus/config/init.sls b/prometheus/config/init.sls index 8875266..8919ea2 100644 --- a/prometheus/config/init.sls +++ b/prometheus/config/init.sls @@ -1,11 +1,6 @@ # -*- coding: utf-8 -*- # vim: ft=sls -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} - include: - .args - .file - - .environ diff --git a/prometheus/defaults.yaml b/prometheus/defaults.yaml index ecedd90..2c45261 100644 --- a/prometheus/defaults.yaml +++ b/prometheus/defaults.yaml @@ -2,25 +2,104 @@ # vim: ft=yaml --- prometheus: - pkg: - name: prometheus - use_upstream_archive: False - rootgroup: root kernel: {{ grains.kernel | lower }} - config_file: /etc/prometheus/prometheus.yml - config: {} - environ_file: /etc/default/prometheus.sh - environ: [] + arch: {{ grains.osarch }} + + wanted: + - prometheus + - alertmanager + - node_exporter + + dir: + basedir: /opt/prometheus + etc: /etc/prometheus + var: /var/lib/prometheus + args: /etc/default + default: /etc/default + service: /usr/lib/systemd/system + service: - name: prometheus - user: prometheus - group: prometheus + prometheus: + args: + web.listen-address: 0.0.0.0:9090 + alertmanager: {} + + config: + prometheus: {} + + pkg: + prometheus: + archive_version: '2.10.0' + archive_hash: f4233783826f18606b79e5cef0686e4a9c2030146a3c7ce134f0add09f5adcb7 + binaries: + - prometheus + - promtool + alertmanager: + archive_version: '0.17.0' + archive_hash: 7c8d2cfeb021c80881ae9904d959131091b8785b6fda9800f84ddef148fe0a4f + binaries: + - amtool + - alertmanager + blackbox_exporter: + archive_version: '0.14.0' + archive_hash: a2918a059023045cafb911272c88a9eb83cdac9a8a5e8e74844b5d6d27f19117 + binaries: + - blackbox_exporter + consul_exporter: + archive_version: '0.4.0' + archive_hash: ff77c03de67cf381f67480b5be6699901785a34145c518c3484ae3e5b8440d08 + binaries: + - consul_exporter + graphite_exporter: + archive_version: '0.6.2' + archive_hash: 9b962bd06406ece4a865ad6947a6e652e48a92a0d77e496a0351c04e9c2c5e9e + binaries: + - graphite_exporter + haproxy_exporter: + archive_version: '0.10.0' + archive_hash: 08150728e281f813a8fcfff4b336f16dbfe4268a1c7510212c8cff2579b10468 + binaries: + - haproxy_exporter + memcached_exporter: + archive_version: '0.5.0' + archive_hash: bb07f496ceb63dad9793ad4295205547a4bd20b90628476d64fa96c9a25a020f + binaries: + - memcached_exporter + mysqld_exporter: + archive_version: '0.11.0' + archive_hash: b53ad48ff14aa891eb6a959730ffc626db98160d140d9a66377394714c563acf + binaries: + - mysqld_exporter + node_exporter: + archive_version: '0.18.1' + archive_hash: b2503fd932f85f4e5baf161268854bf5d22001869b84f00fd2d1f57b51b72424 + binaries: + - node_exporter + pushgateway: + archive_version: '0.8.0' + archive_hash: 6949866ba9ad0cb88d3faffd4281f17df79281398b4dbd0ec3aab300071681ca + binaries: + - pushgateway + statsd_exporter: + archive_version: '0.11.2' + archive_hash: 4632ad0c5552e271e84c376da3ffe3af8c265ec5c3035334b70e35756aca1906 + binaries: + - statsd_exporter + + use_upstream_archive: False + archive: + uri: https://github.com/prometheus + suffix: tar.gz + kwargs: + trim_output: True + enforce_toplevel: True + archive_format: tar + retry: + attempts: 3 + until: True + interval: 60 + splay: 10 + linux: - #'Alternatives system' priority: zero disables (default) - altpriority: 0 - exporters: - node: - pkg: - name: prometheus-node-exporter - service: prometheus-node-exporter + altpriority: 0 ##'Alternatives system' priority: zero disables (default) diff --git a/prometheus/exporters/init.sls b/prometheus/exporters/init.sls deleted file mode 100644 index 1e5daf5..0000000 --- a/prometheus/exporters/init.sls +++ /dev/null @@ -1,14 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=sls - -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split('/')[0] %} -{%- set sls_config_file = tplroot ~ '.config.file' %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} - -{%- if prometheus.exporters.keys()|length > 0 %} -include: -{%- for name in prometheus.exporters.keys()|list %} - - .{{ name }} -{%- endfor %} -{%- endif %} diff --git a/prometheus/exporters/node/clean.sls b/prometheus/exporters/node/clean.sls deleted file mode 100644 index 14401e2..0000000 --- a/prometheus/exporters/node/clean.sls +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=sls - -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} - -prometheus-exporters-node-service-dead: - service.dead: - - name: {{ prometheus.exporters.node.service }} - - enable: False - -prometheus-exporters-node-pkg-removed: - pkg.removed: - - name: {{ prometheus.exporters.node.pkg.name }} - - require: - - service: prometheus-exporters-node-service-dead - -{# FreeBSD #} -{%- if salt['grains.get']('os_family') == 'FreeBSD' %} -{%- for parameter in ['args', 'listen_address', 'textfile_dir'] %} -prometheus-exporters-node-args-{{ parameter }}: - sysrc.absent: - - name: node_exporter_{{ parameter }} - - require: - - service: prometheus-exporters-node-service-dead -{%- endfor %} -{%- endif %} diff --git a/prometheus/exporters/node/init.sls b/prometheus/exporters/node/init.sls deleted file mode 100644 index f8f7534..0000000 --- a/prometheus/exporters/node/init.sls +++ /dev/null @@ -1,64 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=sls - -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} -{%- from tplroot ~ "/map.jinja" import concat_args %} - -prometheus-exporters-node-pkg-installed: - pkg.installed: - - name: {{ prometheus.exporters.node.pkg.name }} - -{%- if 'args' in prometheus.exporters.node %} -{%- set args = prometheus.exporters.node.get('args', {}) -%} - -{# FreeBSD #} -{%- if salt['grains.get']('os_family') == 'FreeBSD' %} -{%- if 'web.listen-address' in args.keys() %} -{%- set value = args.pop('web.listen-address') %} -prometheus-exporters-node-args-web-listen-address: - sysrc.managed: - - name: node_exporter_listen_address - - value: {{ value }} - - watch_in: - - service: prometheus-exporters-node-service-running -{%- endif %} - -{%- if 'collector.textfile.directory' in args.keys() %} -{%- set value = args.pop('collector.textfile.directory') %} -prometheus-exporters-node-args-collector-textfile-directory: - sysrc.managed: - - name: node_exporter_textfile_dir - - value: {{ value }} - - watch_in: - - service: prometheus-exporters-node-service-running -{%- endif %} - -prometheus-exporters-node-args: - sysrc.managed: - - name: node_exporter_args - # service node_exporter restart tended to hang on FreeBSD - # https://github.com/saltstack/salt/issues/44848#issuecomment-487016414 - - value: "{{ concat_args(args) }} >/dev/null 2>&1" - - watch_in: - - service: prometheus-exporters-node-service-running - -{# Debian #} -{%- elif salt['grains.get']('os_family') == 'Debian'%} -prometheus-exporters-node-args: - file.managed: - - name: {{ prometheus.exporters.node.config_file }} - - contents: | - ARGS="{{ concat_args(args) }}" - - watch_in: - - service: prometheus-exporters-node-service-running -{%- endif %} -{%- endif %} - -prometheus-exporters-node-service-running: - service.running: - - name: {{ prometheus.exporters.node.service }} - - enable: True - - watch: - - pkg: prometheus-exporters-node-pkg-installed diff --git a/prometheus/files/default/prometheus.yml.jinja b/prometheus/files/default/config.yml.jinja similarity index 100% rename from prometheus/files/default/prometheus.yml.jinja rename to prometheus/files/default/config.yml.jinja diff --git a/prometheus/files/default/prometheus.sh.jinja b/prometheus/files/default/default.sh.jinja similarity index 78% rename from prometheus/files/default/prometheus.sh.jinja rename to prometheus/files/default/default.sh.jinja index afc0f91..0a1fe22 100644 --- a/prometheus/files/default/prometheus.sh.jinja +++ b/prometheus/files/default/default.sh.jinja @@ -3,8 +3,8 @@ # Your changes may be overwritten. ######################################################################## -{%- if prometheus.environ %} - {%- for item in prometheus.environ %} +{%- if defaults %} + {%- for item in defaults %} {{ item }} {%- endfor %} {%- endif %} diff --git a/prometheus/files/default/systemd.ini.jinja b/prometheus/files/default/systemd.ini.jinja index 02d8105..959ad17 100644 --- a/prometheus/files/default/systemd.ini.jinja +++ b/prometheus/files/default/systemd.ini.jinja @@ -3,13 +3,14 @@ ######################################################### [Unit] Description={{ desc }} -Wants={{ wants }} -After={{ after }} +Wants=network-online.target +After= Documentation=https://github.com/saltstack-formulas/prometheus-formula [Service] User={{ user }} Group={{ group }} +WorkingDirectory={{ workdir }} ExecStart={{ start }} ExecStop={{ stop }} PIDFile=/var/run/{{ name }}.pid diff --git a/prometheus/init.sls b/prometheus/init.sls index 11743b6..c281ea9 100644 --- a/prometheus/init.sls +++ b/prometheus/init.sls @@ -6,6 +6,6 @@ {%- from tplroot ~ "/map.jinja" import prometheus with context %} include: - - {{ '.archive' if prometheus.pkg.use_upstream_archive else '.package' }} + - {{ '.archive' if prometheus.use_upstream_archive else '.package' }} - .config - .service diff --git a/prometheus/map.jinja b/prometheus/map.jinja index fbbf314..183d72c 100644 --- a/prometheus/map.jinja +++ b/prometheus/map.jinja @@ -5,23 +5,17 @@ {%- set tplroot = tpldir.split('/')[0] %} {#- Start imports as #} {%- import_yaml tplroot ~ "/defaults.yaml" as default_settings %} -{%- import_yaml tplroot ~ "/osfamilymap.yaml" as osfamilymap %} -{%- import_yaml tplroot ~ "/osmap.yaml" as osmap %} {%- import_yaml tplroot ~ "/osarchmap.yaml" as osarchmap %} -{%- import_yaml tplroot ~ "/osfingermap.yaml" as osfingermap %} +{%- import_yaml tplroot ~ "/osfamilymap.yaml" as osfamilymap %} {%- import_yaml tplroot ~ "/archive/defaults.yaml" as archive_defaults %} {%- set defaults = salt['grains.filter_by'](default_settings, merge=salt['grains.filter_by'](archive_defaults, + merge=salt['grains.filter_by'](osarchmap, grain='osarch', merge=salt['grains.filter_by'](osfamilymap, grain='os_family', - merge=salt['grains.filter_by'](osmap, grain='os', - merge=salt['grains.filter_by'](osfingermap, grain='osfinger', - merge=salt['grains.filter_by'](osarchmap, grain='osarch', - merge=salt['pillar.get']('prometheus:lookup', default={}), - base='prometheus'), - base='prometheus'), - base='prometheus'), + merge=salt['pillar.get']('prometheus:lookup', default={}), base='prometheus'), + base='prometheus'), base='prometheus'), base='prometheus') %} diff --git a/prometheus/osfamilymap.yaml b/prometheus/osfamilymap.yaml index c2c8188..0fc5fc2 100644 --- a/prometheus/osfamilymap.yaml +++ b/prometheus/osfamilymap.yaml @@ -14,15 +14,11 @@ {% set macos_group = salt['cmd.run']("stat -f '%Sg' /dev/console") %} {%- endif %} -Debian: - args_file: /etc/default/prometheus - exporters: - node: - config_file: /etc/default/prometheus-node-exporter +Debian: {} RedHat: - pkg: - use_upstream_archive: True + ## remove when https://github.com/saltstack-formulas/prometheus-formula/pull/4 is merged + use_upstream_archive: True Suse: {} @@ -34,75 +30,107 @@ Alpine: {} FreeBSD: rootgroup: wheel - config_file: /usr/local/etc/prometheus.yml - exporters: - node: - pkg: - name: node_exporter - service: node_exporter - archive: - hashes: - prometheus: 94a63f14baeadab2f17b5ae0bbeda6688e6d06f964ef4e32c2954a0ecf3996a1 - alertmanager: ec171b13976baceace193461f8a1e61021ab9657df5ba45157cd0095aee7d569 - blackbox_exporter: 2b92752decf2cf1883ce4f72301e4f911dab79efbd87db4df23dc9771e53e4af - consul_exporter: 62e16c2f1acb9bf9411126478caccb5962da203cfb58d8c97f54b9c0add5171c - graphite_exporter: ff424b923733d8247314353ba4d13a1c4b06450c35f005bfd6c3b6ff60b047fd - haproxy_exporter: f32d158f9e3314828dc155a30a1f4c858876e1ea8ff543a4000afcbc7e923505 - memcached_exporter: 8fd53b9aede6b78e0530b159ccd0a437cf2f100da1ddc586681f389d804f5f19 - mysqld_exporter: 9bcbbd8b3568818fd4c95d255c6f93c357ea25aed3364d7428f4ff9c89cd489a - node_exporter: {} - pushgateway: ebcd21dc25e439eed64559e89cd7da9a94073d5ff321a8a3a4214ac2ebe04e34 - statsd_exporter: f345dff6311501f09bb5b6ba1128e925d504c6325ee97ad91a975f2be0d44da9 + dir: + config: /usr/local/etc + pkg: + prometheus: + archive_hash: 94a63f14baeadab2f17b5ae0bbeda6688e6d06f964ef4e32c2954a0ecf3996a1 + alertmanager: + archive_hash: ec171b13976baceace193461f8a1e61021ab9657df5ba45157cd0095aee7d569 + blackbox_exporter: + archive_hash: 2b92752decf2cf1883ce4f72301e4f911dab79efbd87db4df23dc9771e53e4af + consul_exporter: + archive_hash: 62e16c2f1acb9bf9411126478caccb5962da203cfb58d8c97f54b9c0add5171c + graphite_exporter: + archive_hash: ff424b923733d8247314353ba4d13a1c4b06450c35f005bfd6c3b6ff60b047fd + haproxy_exporter: + archive_hash: f32d158f9e3314828dc155a30a1f4c858876e1ea8ff543a4000afcbc7e923505 + memcached_exporter: + archive_hash: 8fd53b9aede6b78e0530b159ccd0a437cf2f100da1ddc586681f389d804f5f19 + mysqld_exporter: + archive_hash: 9bcbbd8b3568818fd4c95d255c6f93c357ea25aed3364d7428f4ff9c89cd489a + node_exporter: {} + pushgateway: + archive_hash: ebcd21dc25e439eed64559e89cd7da9a94073d5ff321a8a3a4214ac2ebe04e34 + statsd_exporter: + archive_hash: f345dff6311501f09bb5b6ba1128e925d504c6325ee97ad91a975f2be0d44da9 OpenBSD: rootgroup: wheel kernel: openbsd - archive: - hashes: - prometheus: c3c69919b359f00a84ef12f7ed6a956111790d64a71bd94990572baaf63377ce - alertmanager: 88ce1b3f11bb28f24b98235994277b2c31aa03b2b2609e0058c04efa0cc5596f - blackbox_exporter: 0dee97d1204bac925bde919958ae890730d87386a816ed0b248c8038ee43794d - consul_exporter: b53ee2bd0e670907eac894387e286b0dd11eb3149fcd4e19ed586006d3de741a - graphite_exporter: 98cbd7176f1c61023892de64ad26edc3cd7895037e3cc282c4edec53dded7156 - haproxy_exporter: bc2b222f6a08232ef643cd6dcda3264f3bd7388a5bee25365cef137c7dea17e8 - memcached_exporter: 21db1bffc561d47b4490ccb2cde721244d00e95f504cdcfee618bc4bb877e731 - mysqld_exporter: b37d6fe68e2c884540ea41c5efcfb16d0bc5da517fe3ba713144504df1ba635d - node_exporter: {} - pushgateway: 0bce168e4b19234df9e954393a2102c91e4d62336b2721ed882f2003a4445d51 - statsd_exporter: c89acb365b75af03ce612873d8b20226e3882c0177752ea0ce17a9f5e41eb5b4 + pkg: + prometheus: + archive_hash: c3c69919b359f00a84ef12f7ed6a956111790d64a71bd94990572baaf63377ce + alertmanager: + archive_hash: 88ce1b3f11bb28f24b98235994277b2c31aa03b2b2609e0058c04efa0cc5596f + blackbox_exporter: + archive_hash: 0dee97d1204bac925bde919958ae890730d87386a816ed0b248c8038ee43794d + consul_exporter: + archive_hash: b53ee2bd0e670907eac894387e286b0dd11eb3149fcd4e19ed586006d3de741a + graphite_exporter: + archive_hash: 98cbd7176f1c61023892de64ad26edc3cd7895037e3cc282c4edec53dded7156 + haproxy_exporter: + archive_hash: bc2b222f6a08232ef643cd6dcda3264f3bd7388a5bee25365cef137c7dea17e8 + memcached_exporter: + archive_hash: 21db1bffc561d47b4490ccb2cde721244d00e95f504cdcfee618bc4bb877e731 + mysqld_exporter: + archive_hash: b37d6fe68e2c884540ea41c5efcfb16d0bc5da517fe3ba713144504df1ba635d + pushgateway: + archive_hash: 0bce168e4b19234df9e954393a2102c91e4d62336b2721ed882f2003a4445d51 + statsd_exporter: + archive_hash: c89acb365b75af03ce612873d8b20226e3882c0177752ea0ce17a9f5e41eb5b4 Solaris: {} Windows: kernel: windows - archive: - name: C:\\Program Files - hashes: - prometheus: eb138082a4d5e4d5b1e3ca838fa508f053474d46bca76e87ab0834f0d8b110db - alertmanager: 512dbed02a3cc7e3f06d737f56179e458c462762b3427063b89c62a54d9645c6 - blackbox_exporter: 21ea148870631310002cbd48be54ca45e8d300da5a902b0aec052f1a64316d93 - consul_exporter: 54579bc5dfa6a238e310a1874b0a362027661dfa1754535e74610dc8ef6163b1 - graphite_exporter: f83fad71bad99ccac145d65f82bf9d17fa37168a5dcce6415c6350e79a84e638 - haproxy_exporter: 044118feb98b74eb921e27bd4b511732b553896c672c19bdd3418445dc030794 - memcached_exporter: 9e83c00c9d249c942f65b6a48112e6bd6e28a3d15b8a1d35e935621657b3d837 - mysqld_exporter: 38605ae648f8def07a0f412d81a30a6c48c0d20a6981468d25b91c8aa529e599 - node_exporter: {} - pushgateway: 506b555e7a13cabf3d85ec0dbe1bc6bc3a2444c0cc468baa8d31e7fc2fe18dd1 - statsd_exporter: 9362b7482e74792f111c4bb1a372b18a88f6354c78f24713bacfbcb050883556 + dir: + opt: C:\\Program Files + pkg: + prometheus: + archive_hash: eb138082a4d5e4d5b1e3ca838fa508f053474d46bca76e87ab0834f0d8b110db + alertmanager: + archive_hash: 512dbed02a3cc7e3f06d737f56179e458c462762b3427063b89c62a54d9645c6 + blackbox_exporter: + archive_hash: 21ea148870631310002cbd48be54ca45e8d300da5a902b0aec052f1a64316d93 + consul_exporter: + archive_hash: 54579bc5dfa6a238e310a1874b0a362027661dfa1754535e74610dc8ef6163b1 + graphite_exporter: + archive_hash: f83fad71bad99ccac145d65f82bf9d17fa37168a5dcce6415c6350e79a84e638 + haproxy_exporter: + archive_hash: 044118feb98b74eb921e27bd4b511732b553896c672c19bdd3418445dc030794 + memcached_exporter: + archive_hash: 9e83c00c9d249c942f65b6a48112e6bd6e28a3d15b8a1d35e935621657b3d837 + mysqld_exporter: + archive_hash: 38605ae648f8def07a0f412d81a30a6c48c0d20a6981468d25b91c8aa529e599 + pushgateway: + archive_hash: 506b555e7a13cabf3d85ec0dbe1bc6bc3a2444c0cc468baa8d31e7fc2fe18dd1 + statsd_exporter: + archive_hash: 9362b7482e74792f111c4bb1a372b18a88f6354c78f24713bacfbcb050883556 MacOS: rootgroup: {{ macos_group | d('') }} kernel: darwin - archive: - hashes: - prometheus: 740e36bcacc0c5d4495f5341fcfa8b7e0dc623d12e8b07ac291052ea0a681325 - alertmanager: efeebaa8e51c521ecb3440345fb65962533cae022d71dff8b127911e893ded2a - blackbox_exporter: a371d0496adb5d62368d6606928c5effd318d1387f6b9a9998f8d0333492645a - consul_exporter: 75641783938967c11c18d6d340028ff2dce7ad0ae5e300fa631b813cc6ea9647 - graphite_exporter: f9c0aa745502c0ab01fdcca29181801810202e0aed512a9aa9a37bb4be88a919 - haproxy_exporter: 8fdb8bb182586c57e5892816a02846bae0998916765d22bb81b2c444a3565862 - memcached_exporter: e10685cca5ffd8a3a7574b3dc096dc7418f34906abd399f881be06dd38be62cb - mysqld_exporter: 8e0a7d8847790d6dcdcf392e6dd227458a7bcaa1e0890cc6326fdf956421f2a7 - node_exporter: 20fadb3108de0a9cc70a1333394e5be90416b4f91025f9fc66f5736335e94398 - pushgateway: 25399a4c6600c1931f9d9bd5294700c2b53f964188b1c6003f9d12a2e176aac1 - statsd_exporter: 15132494523c2b6a89e09b2da63452c8fe587fb82fcc3fd21cc75a4aa2766644 + pkg: + prometheus: + archive_hash: 740e36bcacc0c5d4495f5341fcfa8b7e0dc623d12e8b07ac291052ea0a681325 + alertmanager: + archive_hash: efeebaa8e51c521ecb3440345fb65962533cae022d71dff8b127911e893ded2a + blackbox_exporter: + archive_hash: a371d0496adb5d62368d6606928c5effd318d1387f6b9a9998f8d0333492645a + consul_exporter: + archive_hash: 75641783938967c11c18d6d340028ff2dce7ad0ae5e300fa631b813cc6ea9647 + graphite_exporter: + archive_hash: f9c0aa745502c0ab01fdcca29181801810202e0aed512a9aa9a37bb4be88a919 + haproxy_exporter: + archive_hash: 8fdb8bb182586c57e5892816a02846bae0998916765d22bb81b2c444a3565862 + memcached_exporter: + archive_hash: e10685cca5ffd8a3a7574b3dc096dc7418f34906abd399f881be06dd38be62cb + mysqld_exporter: + archive_hash: 8e0a7d8847790d6dcdcf392e6dd227458a7bcaa1e0890cc6326fdf956421f2a7 + node_exporter: + archive_hash: 20fadb3108de0a9cc70a1333394e5be90416b4f91025f9fc66f5736335e94398 + pushgateway: + archive_hash: 25399a4c6600c1931f9d9bd5294700c2b53f964188b1c6003f9d12a2e176aac1 + statsd_exporter: + archive_hash: 15132494523c2b6a89e09b2da63452c8fe587fb82fcc3fd21cc75a4aa2766644 diff --git a/prometheus/osfingermap.yaml b/prometheus/osfingermap.yaml deleted file mode 100644 index 0fac2c6..0000000 --- a/prometheus/osfingermap.yaml +++ /dev/null @@ -1,14 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=yaml -# -# Setup variables using grains['osfinger'] based logic. -# You just need to add the key:values for an `osfinger` that differ -# from `defaults.yaml` + `os_family.yaml` + `osmap.yaml`. -# Only add an `osfinger` which is/will be supported by the formula -# -# If you do not need to provide defaults via the `os_finger` grain, -# you will need to provide at least an empty dict in this file, e.g. -# osfingermap: {} ---- -# os: Ubuntu -Ubuntu-18.04: {} diff --git a/prometheus/osmap.yaml b/prometheus/osmap.yaml deleted file mode 100644 index 20a12fd..0000000 --- a/prometheus/osmap.yaml +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=yaml -# -# Setup variables using grains['os'] based logic. -# You just need to add the key:values for an `os` that differ -# from `defaults.yaml` + `os_family.yaml`. -# Only add an `os` which is/will be supported by the formula -# -# If you do not need to provide defaults via the `os` grain, -# you will need to provide at least an empty dict in this file, e.g. -# osmap: {} ---- -# os_family: Debian -Ubuntu: {} - -Raspbian: {} - -# os_family: Gentoo -Funtoo: {} - -# os_family: Arch -Manjaro: {} - -# os_family: Solaris -SmartOS: {} diff --git a/prometheus/package/clean.sls b/prometheus/package/clean.sls index 04c2cfd..59f0ab5 100644 --- a/prometheus/package/clean.sls +++ b/prometheus/package/clean.sls @@ -9,10 +9,16 @@ include: - {{ sls_config_clean }} -prometheus-package-clean-pkg-removed: + {%- for name in prometheus.wanted %} + {%- if name in prometheus.pkg %} + +prometheus-package-clean-{{ name }}-removed: pkg.removed: - - name: {{ prometheus.pkg.name }} - {%- if 'config' in prometheus and prometheus.config %} + - name: {{ name }} + {%- if name in prometheus.service %} - require: - - sls: {{ sls_config_clean }} - {%- endif %} + - service: prometheus-service-clean-{{ name }}-service-dead + {%- endif %} + + {%- endif %} + {%- endfor %} diff --git a/prometheus/package/install.sls b/prometheus/package/install.sls index 8280d96..cc540aa 100644 --- a/prometheus/package/install.sls +++ b/prometheus/package/install.sls @@ -5,6 +5,10 @@ {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus with context %} -prometheus-package-install-pkg-installed: + {%- for name in prometheus.wanted %} + +prometheus-package-install-{{ name }}-installed: pkg.installed: - - name: {{ prometheus.pkg.name }} + - name: {{ name }} + + {%- endfor %} diff --git a/prometheus/service/clean.sls b/prometheus/service/clean.sls index 71d9806..9a69790 100644 --- a/prometheus/service/clean.sls +++ b/prometheus/service/clean.sls @@ -5,7 +5,16 @@ {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus with context %} -prometheus-service-clean-service-dead: + {%- for name in prometheus.wanted %} + {%- if name in prometheus.service %} + +prometheus-service-clean-{{ name }}-service-dead: service.dead: - - name: {{ prometheus.service.name }} + - name: {{ name }} - enable: False + {%- if grains.kernel|lower == 'linux' %} + - onlyif: systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1 + {%- endif %} + + {%- endif %} + {%- endfor %} diff --git a/prometheus/service/running.sls b/prometheus/service/running.sls index a64f9fa..ec5300f 100644 --- a/prometheus/service/running.sls +++ b/prometheus/service/running.sls @@ -3,29 +3,44 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} -{%- set sls_config_args = tplroot ~ '.config.args' %} -{%- set sls_config_file = tplroot ~ '.config.file' %} +{%- set sls_config_args = tplroot ~ '.config.args.install' %} +{%- set sls_config_file = tplroot ~ '.config.file.install' %} {%- from tplroot ~ "/map.jinja" import prometheus with context %} include: - {{ sls_config_args }} - {{ sls_config_file }} -prometheus-service-running-service-unmasked: - service.unmasked: - - name: {{ prometheus.service.name }} - - onlyif: systemctl list-unit-files | grep {{ prometheus.service.name }} >/dev/null 2>&1 + {%- for name in prometheus.wanted %} + {%- if name in prometheus.service %} -prometheus-service-running-service-running: - service.running: - - name: {{ prometheus.service.name }} - - enable: True - {%- if 'config' in prometheus and prometheus.config %} - - watch: - - file: prometheus-config-file-file-managed-config_file +prometheus-service-running-{{ name }}-service-unmasked: + service.unmasked: + - name: {{ name }} - require: - - service: prometheus-service-running-service-unmasked - sls: {{ sls_config_args }} - sls: {{ sls_config_file }} - {%- endif %} - - onlyif: systemctl list-unit-files | grep {{ prometheus.service.name }} >/dev/null 2>&1 + {%- if grains.kernel|lower == 'linux' %} + - onlyif: + - systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1 + {%- endif %} + +prometheus-service-running-{{ name }}-service-running: + service.running: + - name: {{ name }} + - enable: True + {%- if name in prometheus.config %} + - watch: + - file: prometheus-config-file-{{ name }}-file-managed + {%- endif %} + - require: + - service: prometheus-service-running-{{ name }}-service-unmasked + - sls: {{ sls_config_args }} + - sls: {{ sls_config_file }} + {%- if grains.kernel|lower == 'linux' %} + - onlyif: systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1 + {%- endif %} + + {%- endif %} + {%- endfor %} + diff --git a/prometheus/systemd.sls b/prometheus/systemd.sls deleted file mode 100644 index e69de29..0000000 From eda47f71e824395861cf29e0cc730d64884e5b09 Mon Sep 17 00:00:00 2001 From: N Date: Sat, 22 Jun 2019 18:24:19 +0100 Subject: [PATCH 07/12] fix(repo): use_upstream_repo corrections; separate users state BREAKING CHANGE: The formula has been refactored to accomodate multiple packages, archives, users, and repos. Update your pillars and top states --- docs/README.rst | 10 ++++ pillar.example | 2 + prometheus/archive/alternatives/install.sls | 6 +- prometheus/archive/clean.sls | 12 ++-- prometheus/archive/install.sls | 31 ++++------ prometheus/config/args/clean.sls | 4 ++ prometheus/config/args/install.sls | 16 +++++- prometheus/config/clean.sls | 1 + prometheus/config/file/clean.sls | 4 ++ prometheus/config/file/install.sls | 19 +++++- prometheus/config/init.sls | 1 + prometheus/config/users/clean.sls | 18 ++++++ prometheus/config/users/init.sls | 5 ++ prometheus/config/users/install.sls | 22 +++++++ prometheus/exporters/node/clean.sls | 28 --------- prometheus/exporters/node/init.sls | 64 --------------------- prometheus/package/clean.sls | 3 + prometheus/package/install.sls | 2 +- prometheus/service/clean.sls | 5 ++ prometheus/service/running.sls | 20 +++++-- 20 files changed, 137 insertions(+), 136 deletions(-) create mode 100644 prometheus/config/users/clean.sls create mode 100644 prometheus/config/users/init.sls create mode 100644 prometheus/config/users/install.sls delete mode 100644 prometheus/exporters/node/clean.sls delete mode 100644 prometheus/exporters/node/init.sls diff --git a/docs/README.rst b/docs/README.rst index 2fd9751..d93ee9f 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -53,6 +53,11 @@ starts the associated prometheus service. This state will install the prometheus from archive file only. +``prometheus.archive.alternatives`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This state will install the prometheus linux alternatives for archives only. + ``prometheus.package`` ^^^^^^^^^^^^^^^^^^^^ @@ -107,6 +112,11 @@ This state will remove the prometheus package and has a depency on This state will uninstall the prometheus archive-extracted directory only. +``prometheus.package.archive.alternatives.clean`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This state will uninstall the prometheus linux alternatives for archives only. + ``prometheus.package.repo.clean`` ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/pillar.example b/pillar.example index 5ddde08..6c3a797 100644 --- a/pillar.example +++ b/pillar.example @@ -6,6 +6,8 @@ prometheus: - prometheus - pushgateway - node_explorer + # no memcached_exporter in upstream repo - only archive + # memcached_exporter use_upstream_repo: False use_upstream_archive: True diff --git a/prometheus/archive/alternatives/install.sls b/prometheus/archive/alternatives/install.sls index b6b17e5..67d501b 100644 --- a/prometheus/archive/alternatives/install.sls +++ b/prometheus/archive/alternatives/install.sls @@ -5,7 +5,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 %} -{%- set sls_archive_install = tplroot ~ '.archive.install' %} +{%- set sls_archive_install = tplroot ~ '.archive' %} {%- if grains.kernel|lower in ('linux',) and p.linux.altpriority|int > 0 %} @@ -21,8 +21,6 @@ prometheus-archive-alternatives-install-{{ name }}-home-cmd-run: - name: update-alternatives --install {{ p.dir.basedir }}/{{ bundle }} prometheus-{{ name }}-home {{ p.dir.basedir }}/{{ bundle }} {{p.linux.altpriority}} - watch: - archive: prometheus-archive-install-{{ name }}-archive-extracted - - require: - - sls: {{ sls_archive_install }} prometheus-archive-alternatives-install-{{ name }}-home-alternatives-install: alternatives.install: @@ -33,8 +31,6 @@ prometheus-archive-alternatives-install-{{ name }}-home-alternatives-install: - order: 10 - watch: - archive: prometheus-archive-install-{{ name }}-archive-extracted - - require: - - sls: {{ sls_archive_install }} - onlyif: {{ grains.os_family not in ('Suse',) }} prometheus-archive-alternatives-install-{{ name }}-home-alternatives-set: diff --git a/prometheus/archive/clean.sls b/prometheus/archive/clean.sls index a1bfe5e..43c70c6 100644 --- a/prometheus/archive/clean.sls +++ b/prometheus/archive/clean.sls @@ -5,10 +5,10 @@ {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus as p with context %} {%- set sls_alternatives_clean = tplroot ~ '.archive.alternatives.clean' %} - - {%- if p.use_upstream_archive %} +{%- set sls_users_clean = tplroot ~ '.config.users.clean' %} include: + - {{ sls_users_clean }} - {{ sls_alternatives_clean }} {%- for name in p.wanted %} @@ -31,13 +31,9 @@ prometheus-archive-clean-{{ name }}-user-absent: {%- endfor %} -prometheus-archive-clean-file-directory: +prometheus-archive-clean-basedir-file-directory: file.absent: - - names: - - {{ p.dir.basedir }} - - {{ p.dir.etc }} - - {{ p.dir.var }} + - name: {{ p.dir.basedir }} - require: - sls: {{ sls_alternatives_clean }} - {%- endif %} diff --git a/prometheus/archive/install.sls b/prometheus/archive/install.sls index d169323..507b0e7 100644 --- a/prometheus/archive/install.sls +++ b/prometheus/archive/install.sls @@ -6,35 +6,24 @@ {%- from tplroot ~ "/map.jinja" import prometheus as p with context %} {%- from tplroot ~ "/jinja/macros.jinja" import format_kwargs with context %} {%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} +{%- set sls_users_install = tplroot ~ '.config.users' %} -prometheus-archive-install-file-directory: +include: + - {{ sls_users_install }} + +prometheus-config-file-basedir-file-directory: file.directory: - - names: - - {{ p.dir.basedir }} - - {{ p.dir.etc }} - - {{ p.dir.var }} + - name: {{ p.dir.basedir }} - user: prometheus - group: prometheus - mode: 755 - makedirs: True + # require: + # sls: {{ sls_users_install }} {%- for name in p.wanted %} {%- set bundle = name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) %} -prometheus-archive-install-{{ name }}-user-present: - group.present: - - name: {{ name }} - - require_in: - - user: prometheus-archive-install-{{ name }}-user-present - user.present: - - name: {{ name }} - - shell: /bin/false - - createhome: false - - groups: - - {{ name }} - - require_in: - - archive: prometheus-archive-install-{{ name }}-archive-extracted - prometheus-archive-install-{{ name }}-archive-extracted: archive.extracted: - name: {{ p.dir.basedir }} @@ -47,6 +36,8 @@ prometheus-archive-install-{{ name }}-archive-extracted: - recurse: - user - group + - require: + - file: prometheus-config-file-basedir-file-directory {%- if name in p.service %} @@ -59,6 +50,7 @@ prometheus-archive-install-{{ name }}-file-directory: - makedirs: True - require: - archive: prometheus-archive-install-{{ name }}-archive-extracted + - file: prometheus-config-file-basedir-file-directory prometheus-archive-install-{{ name }}-managed-service: file.managed: @@ -82,6 +74,7 @@ prometheus-archive-install-{{ name }}-managed-service: stop: '' #not needed - require: - file: prometheus-archive-install-{{ name }}-file-directory + - file: prometheus-config-file-basedir-file-directory {%- endif %} {%- endfor %} diff --git a/prometheus/config/args/clean.sls b/prometheus/config/args/clean.sls index e72d83c..e9da0e3 100644 --- a/prometheus/config/args/clean.sls +++ b/prometheus/config/args/clean.sls @@ -55,3 +55,7 @@ prometheus-config-args-{{ name }}-file-absent: {%- endif %} {%- endif %} {%- endfor %} + +prometheus-config-file-args-file-absent: + file.absent: + - name: {{ prometheus.dir.args }} diff --git a/prometheus/config/args/install.sls b/prometheus/config/args/install.sls index 787aa16..0512dda 100644 --- a/prometheus/config/args/install.sls +++ b/prometheus/config/args/install.sls @@ -9,8 +9,18 @@ {%- set sls_service_install = tplroot ~ '.service' %} include: - - {{ sls_config_install }} - {{ sls_service_install }} + - {{ sls_config_install }} + +prometheus-config-file-args-file-directory: + file.directory: + - name: {{ prometheus.dir.args }} + - user: prometheus + - group: prometheus + - mode: 755 + - makedirs: True + # require: + # sls: {{ sls_config_install }}.users {%- for name in prometheus.wanted %} {%- if name in prometheus.config or name in prometheus.service %} @@ -28,6 +38,8 @@ prometheus-config-args-{{ name }}-data-dir: - makedirs: True - watch_in: - service: prometheus-service-running-{{ name }}-service-running + - require: + - file: prometheus-config-file-args-file-directory {%- endif %} {%- if args and grains.os_family == 'FreeBSD' %} @@ -43,7 +55,7 @@ prometheus-config-args-args-web-listen-address: {%- endif %} {%- if 'collector.textfile.directory' in args.keys() %} -prometheus-config-args-{{ name }}--collector-textfile-directory: +prometheus-config-args-{{ name }}-collector-textfile-directory: sysrc.managed: - name: {{ name }}_textfile_dir - value: {{ args.pop('collector.textfile.directory') }} diff --git a/prometheus/config/clean.sls b/prometheus/config/clean.sls index 7d54d55..cf7559a 100644 --- a/prometheus/config/clean.sls +++ b/prometheus/config/clean.sls @@ -4,3 +4,4 @@ include: - .file.clean - .args.clean + - .users.clean diff --git a/prometheus/config/file/clean.sls b/prometheus/config/file/clean.sls index a86ce29..10b6f95 100644 --- a/prometheus/config/file/clean.sls +++ b/prometheus/config/file/clean.sls @@ -19,3 +19,7 @@ prometheus-config-file-{{ name }}-file-absent: - sls: {{ sls_service_clean }} {%- endfor %} + +prometheus-config-file-etc-file-absent: + file.absent: + - name: {{ prometheus.dir.etc }} diff --git a/prometheus/config/file/install.sls b/prometheus/config/file/install.sls index 0359979..bb48a1d 100644 --- a/prometheus/config/file/install.sls +++ b/prometheus/config/file/install.sls @@ -5,11 +5,23 @@ {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus with context %} {%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} -{%- set sls_archive_install = tplroot ~ '.archive.install' %} -{%- set sls_package_install = tplroot ~ '.package.install' %} +{%- set sls_users_install = tplroot ~ '.config.users' %} +{%- set sls_archive_install = tplroot ~ '.archive' %} +{%- set sls_package_install = tplroot ~ '.package' %} include: - {{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }} + - {{ sls_users_install }} + +prometheus-config-file-etc-file-directory: + file.directory: + - name: {{ prometheus.dir.etc }} + - user: prometheus + - group: prometheus + - mode: 755 + - makedirs: True + # require: + # sls: {{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }} {%- for name in prometheus.wanted %} {%- if name in prometheus.config or name in prometheus.service %} @@ -29,7 +41,8 @@ prometheus-config-file-{{ name }}-file-managed: - context: config: {{ '' if name not in prometheus.config else prometheus.config[name]|json }} - require: - - sls: {{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }} + - file: prometheus-config-file-etc-file-directory + # user: prometheus-config-user-install-{{ name }}-user-present {%- endif %} {%- endfor %} diff --git a/prometheus/config/init.sls b/prometheus/config/init.sls index 8919ea2..6923174 100644 --- a/prometheus/config/init.sls +++ b/prometheus/config/init.sls @@ -2,5 +2,6 @@ # vim: ft=sls include: + - .users - .args - .file diff --git a/prometheus/config/users/clean.sls b/prometheus/config/users/clean.sls new file mode 100644 index 0000000..20c200e --- /dev/null +++ b/prometheus/config/users/clean.sls @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus with context %} + + {%- for name in prometheus.wanted %} + +prometheus-config-user-clean-{{ name }}-user-absent: + user.absent: + - name: {{ name }} + group.absent: + - name: {{ name }} + - require: + - user: prometheus-config-user-clean-{{ name }}-user-absent + + {%- endfor %} diff --git a/prometheus/config/users/init.sls b/prometheus/config/users/init.sls new file mode 100644 index 0000000..051d698 --- /dev/null +++ b/prometheus/config/users/init.sls @@ -0,0 +1,5 @@ +#.-*- coding: utf-8 -*- +# vim: ft=sls + +include: + - .install diff --git a/prometheus/config/users/install.sls b/prometheus/config/users/install.sls new file mode 100644 index 0000000..c63dac3 --- /dev/null +++ b/prometheus/config/users/install.sls @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import prometheus with context %} + + {%- for name in prometheus.wanted %} + +prometheus-config-user-install-{{ name }}-user-present: + group.present: + - name: {{ name }} + - require_in: + - user: prometheus-config-user-install-{{ name }}-user-present + user.present: + - name: {{ name }} + - shell: /bin/false + - createhome: false + - groups: + - {{ name }} + + {%- endfor %} diff --git a/prometheus/exporters/node/clean.sls b/prometheus/exporters/node/clean.sls deleted file mode 100644 index 14401e2..0000000 --- a/prometheus/exporters/node/clean.sls +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=sls - -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} - -prometheus-exporters-node-service-dead: - service.dead: - - name: {{ prometheus.exporters.node.service }} - - enable: False - -prometheus-exporters-node-pkg-removed: - pkg.removed: - - name: {{ prometheus.exporters.node.pkg.name }} - - require: - - service: prometheus-exporters-node-service-dead - -{# FreeBSD #} -{%- if salt['grains.get']('os_family') == 'FreeBSD' %} -{%- for parameter in ['args', 'listen_address', 'textfile_dir'] %} -prometheus-exporters-node-args-{{ parameter }}: - sysrc.absent: - - name: node_exporter_{{ parameter }} - - require: - - service: prometheus-exporters-node-service-dead -{%- endfor %} -{%- endif %} diff --git a/prometheus/exporters/node/init.sls b/prometheus/exporters/node/init.sls deleted file mode 100644 index f8f7534..0000000 --- a/prometheus/exporters/node/init.sls +++ /dev/null @@ -1,64 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=sls - -{#- Get the `tplroot` from `tpldir` #} -{%- set tplroot = tpldir.split('/')[0] %} -{%- from tplroot ~ "/map.jinja" import prometheus with context %} -{%- from tplroot ~ "/map.jinja" import concat_args %} - -prometheus-exporters-node-pkg-installed: - pkg.installed: - - name: {{ prometheus.exporters.node.pkg.name }} - -{%- if 'args' in prometheus.exporters.node %} -{%- set args = prometheus.exporters.node.get('args', {}) -%} - -{# FreeBSD #} -{%- if salt['grains.get']('os_family') == 'FreeBSD' %} -{%- if 'web.listen-address' in args.keys() %} -{%- set value = args.pop('web.listen-address') %} -prometheus-exporters-node-args-web-listen-address: - sysrc.managed: - - name: node_exporter_listen_address - - value: {{ value }} - - watch_in: - - service: prometheus-exporters-node-service-running -{%- endif %} - -{%- if 'collector.textfile.directory' in args.keys() %} -{%- set value = args.pop('collector.textfile.directory') %} -prometheus-exporters-node-args-collector-textfile-directory: - sysrc.managed: - - name: node_exporter_textfile_dir - - value: {{ value }} - - watch_in: - - service: prometheus-exporters-node-service-running -{%- endif %} - -prometheus-exporters-node-args: - sysrc.managed: - - name: node_exporter_args - # service node_exporter restart tended to hang on FreeBSD - # https://github.com/saltstack/salt/issues/44848#issuecomment-487016414 - - value: "{{ concat_args(args) }} >/dev/null 2>&1" - - watch_in: - - service: prometheus-exporters-node-service-running - -{# Debian #} -{%- elif salt['grains.get']('os_family') == 'Debian'%} -prometheus-exporters-node-args: - file.managed: - - name: {{ prometheus.exporters.node.config_file }} - - contents: | - ARGS="{{ concat_args(args) }}" - - watch_in: - - service: prometheus-exporters-node-service-running -{%- endif %} -{%- endif %} - -prometheus-exporters-node-service-running: - service.running: - - name: {{ prometheus.exporters.node.service }} - - enable: True - - watch: - - pkg: prometheus-exporters-node-pkg-installed diff --git a/prometheus/package/clean.sls b/prometheus/package/clean.sls index 59f0ab5..23b9ba7 100644 --- a/prometheus/package/clean.sls +++ b/prometheus/package/clean.sls @@ -8,6 +8,9 @@ include: - {{ sls_config_clean }} + {%- if prometheus.use_upstream_repo %} + - .repo.clean + {%- endif %} {%- for name in prometheus.wanted %} {%- if name in prometheus.pkg %} diff --git a/prometheus/package/install.sls b/prometheus/package/install.sls index dc6caa6..7bdcb98 100644 --- a/prometheus/package/install.sls +++ b/prometheus/package/install.sls @@ -5,7 +5,7 @@ {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus with context %} - {%- if prometheus.pkg.use_upstream_repo %} + {%- if prometheus.use_upstream_repo %} include: - .repo diff --git a/prometheus/service/clean.sls b/prometheus/service/clean.sls index 9a69790..31b0076 100644 --- a/prometheus/service/clean.sls +++ b/prometheus/service/clean.sls @@ -17,4 +17,9 @@ prometheus-service-clean-{{ name }}-service-dead: {%- endif %} {%- endif %} + {%- endfor %} + +prometheus-config-file-var-file-absent: + file.absent: + - name: {{ prometheus.dir.var }} diff --git a/prometheus/service/running.sls b/prometheus/service/running.sls index ec5300f..2cec36c 100644 --- a/prometheus/service/running.sls +++ b/prometheus/service/running.sls @@ -3,14 +3,24 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} -{%- set sls_config_args = tplroot ~ '.config.args.install' %} -{%- set sls_config_file = tplroot ~ '.config.file.install' %} +{%- set sls_config_args = tplroot ~ '.config.args' %} +{%- set sls_config_file = tplroot ~ '.config.file' %} {%- from tplroot ~ "/map.jinja" import prometheus with context %} include: - {{ sls_config_args }} - {{ sls_config_file }} +prometheus-config-file-var-file-directory: + file.directory: + - name: {{ prometheus.dir.var }} + - user: prometheus + - group: prometheus + - mode: 755 + - makedirs: True + - require: + - file: prometheus-config-file-etc-file-directory + {%- for name in prometheus.wanted %} {%- if name in prometheus.service %} @@ -18,8 +28,7 @@ prometheus-service-running-{{ name }}-service-unmasked: service.unmasked: - name: {{ name }} - require: - - sls: {{ sls_config_args }} - - sls: {{ sls_config_file }} + - file: prometheus-config-file-var-file-directory {%- if grains.kernel|lower == 'linux' %} - onlyif: - systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1 @@ -35,8 +44,7 @@ prometheus-service-running-{{ name }}-service-running: {%- endif %} - require: - service: prometheus-service-running-{{ name }}-service-unmasked - - sls: {{ sls_config_args }} - - sls: {{ sls_config_file }} + - file: prometheus-config-file-var-file-directory {%- if grains.kernel|lower == 'linux' %} - onlyif: systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1 {%- endif %} From a13dd03af18479ddc1912afe1fee7dbc04551b1a Mon Sep 17 00:00:00 2001 From: N Date: Sat, 22 Jun 2019 22:34:37 +0100 Subject: [PATCH 08/12] fix(example): fix pillar.example formatting --- pillar.example | 61 +++++++++++++++--------------- prometheus/archive/clean.sls | 5 --- prometheus/archive/install.sls | 10 +++-- prometheus/config/args/clean.sls | 4 +- prometheus/config/args/install.sls | 23 ++++++++--- prometheus/config/file/clean.sls | 6 ++- prometheus/config/file/install.sls | 10 ++--- prometheus/defaults.yaml | 2 +- prometheus/map.jinja | 18 ++++----- 9 files changed, 75 insertions(+), 64 deletions(-) diff --git a/pillar.example b/pillar.example index 6c3a797..1135363 100644 --- a/pillar.example +++ b/pillar.example @@ -9,20 +9,21 @@ prometheus: # no memcached_exporter in upstream repo - only archive # memcached_exporter - use_upstream_repo: False use_upstream_archive: True + {%- if grains.os_family in ('CentOS',) %} + use_upstream_repo: False + {%- endif %} pkg: prometheus: - archive_version: 2.10.0 + archive_version: '2.10.0' archive_hash: f4233783826f18606b79e5cef0686e4a9c2030146a3c7ce134f0add09f5adcb7 - repo: {} alertmanager: archive_version: '0.17.0' archive_hash: ec171b13976baceace193461f8a1e61021ab9657df5ba45157cd0095aee7d569 service: - prometheus + prometheus: args: web.listen-address: 0.0.0.0:9090 pushgateway: @@ -122,33 +123,33 @@ prometheus: slack_api_url: "http://mysecret.example.com/" http_config: proxy_url: 'http://127.0.0.1:1025' - route: - group_by: ['alertname', 'cluster', 'service'] - group_wait: 30s - group_interval: 5m - repeat_interval: 3h - receiver: team-X-mails - routes: - - match_re: - service: ^(foo1|foo2|baz)$ - receiver: team-X-mails - routes: - - match: - severity: critical - receiver: team-X-mails - receivers: - - name: 'team-X-mails' - email_configs: - - to: 'team-X+alerts@example.org' + route: + group_by: ['alertname', 'cluster', 'service'] + group_wait: 30s + group_interval: 5m + repeat_interval: 3h + receiver: team-X-mails + routes: + - match_re: + service: ^(foo1|foo2|baz)$ + receiver: team-X-mails + routes: + - match: + severity: critical + receiver: team-X-mails + receivers: + - name: 'team-X-mails' + email_configs: + - to: 'team-X+alerts@example.org' - inhibit_rules: - - name: opsGenie-receiver - opsgenie_configs: - - api_key: mysecret - - name: slack-receiver - slack_configs: - - channel: '#my-channel' - image_url: 'http://some.img.com/img.png' + inhibit_rules: + - name: opsGenie-receiver + opsgenie_configs: + - api_key: mysecret + - name: slack-receiver + slack_configs: + - channel: '#my-channel' + image_url: 'http://some.img.com/img.png' linux: #'Alternatives system' priority: zero disables (default) diff --git a/prometheus/archive/clean.sls b/prometheus/archive/clean.sls index 43c70c6..c3cf5f1 100644 --- a/prometheus/archive/clean.sls +++ b/prometheus/archive/clean.sls @@ -17,8 +17,6 @@ prometheus-archive-clean-{{ name }}-file-absent: file.absent: - names: - {{ p.dir.basedir }}/{{ name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) }} - - require: - - sls: {{ sls_alternatives_clean }} prometheus-archive-clean-{{ name }}-user-absent: user.absent: @@ -27,13 +25,10 @@ prometheus-archive-clean-{{ name }}-user-absent: - name: {{ name }} - require: - user: prometheus-archive-clean-{{ name }}-user-absent - - sls: {{ sls_alternatives_clean }} {%- endfor %} prometheus-archive-clean-basedir-file-directory: file.absent: - name: {{ p.dir.basedir }} - - require: - - sls: {{ sls_alternatives_clean }} diff --git a/prometheus/archive/install.sls b/prometheus/archive/install.sls index 507b0e7..6b7b1fe 100644 --- a/prometheus/archive/install.sls +++ b/prometheus/archive/install.sls @@ -18,11 +18,12 @@ prometheus-config-file-basedir-file-directory: - group: prometheus - mode: 755 - makedirs: True - # require: - # sls: {{ sls_users_install }} + - require: + - sls: '{{ sls_users_install }}.*' {%- for name in p.wanted %} - {%- set bundle = name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) %} + {%- if name in p.pkg %} + {%- set bundle = name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) %} prometheus-archive-install-{{ name }}-archive-extracted: archive.extracted: @@ -39,7 +40,7 @@ prometheus-archive-install-{{ name }}-archive-extracted: - require: - file: prometheus-config-file-basedir-file-directory - {%- if name in p.service %} + {%- if name in p.service %} prometheus-archive-install-{{ name }}-file-directory: file.directory: @@ -76,5 +77,6 @@ prometheus-archive-install-{{ name }}-managed-service: - file: prometheus-archive-install-{{ name }}-file-directory - file: prometheus-config-file-basedir-file-directory + {%- endif %} {%- endif %} {%- endfor %} diff --git a/prometheus/config/args/clean.sls b/prometheus/config/args/clean.sls index e9da0e3..25e35a8 100644 --- a/prometheus/config/args/clean.sls +++ b/prometheus/config/args/clean.sls @@ -21,7 +21,7 @@ prometheus-config-args-{{ name }}-data-dir: file.absent: - name: {{ args['storage.tsdb.path'] }} - require: - - sls: {{ sls_service_clean }} + - sls: '{{ sls_service_clean }}.*' {%- if grains.os_family == 'FreeBSD' %} @@ -51,6 +51,8 @@ prometheus-config-args-{{ name }}-file-absent: - name: {{ prometheus.dir.args }}/{{ name }}.sh - require: - service: prometheus-service-clean-{{ name }}-service-dead + - require_in: + - file: prometheus-config-file-args-file-absent {%- endif %} {%- endif %} diff --git a/prometheus/config/args/install.sls b/prometheus/config/args/install.sls index 0512dda..d354aff 100644 --- a/prometheus/config/args/install.sls +++ b/prometheus/config/args/install.sls @@ -5,12 +5,13 @@ {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus with context %} {%- from tplroot ~ "/map.jinja" import concat_args %} -{%- set sls_config_install = tplroot ~ '.config' %} -{%- set sls_service_install = tplroot ~ '.service' %} +{%- set sls_config_users = tplroot ~ '.config.users' %} +{%- set sls_archive_install = tplroot ~ '.archive' %} +{%- set sls_package_install = tplroot ~ '.package' %} include: - - {{ sls_service_install }} - - {{ sls_config_install }} + - {{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }} + - {{ sls_config_users }} prometheus-config-file-args-file-directory: file.directory: @@ -19,8 +20,8 @@ prometheus-config-file-args-file-directory: - group: prometheus - mode: 755 - makedirs: True - # require: - # sls: {{ sls_config_install }}.users + - require: + - sls: '{{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }}.*' {%- for name in prometheus.wanted %} {%- if name in prometheus.config or name in prometheus.service %} @@ -51,6 +52,8 @@ prometheus-config-args-args-web-listen-address: - value: {{ args.pop('web.listen-address') }} - watch_in: - service: prometheus-service-running-{{ name }}-service-running + - require: + - file: prometheus-config-file-args-file-directory {%- endif %} {%- if 'collector.textfile.directory' in args.keys() %} @@ -61,6 +64,8 @@ prometheus-config-args-{{ name }}-collector-textfile-directory: - value: {{ args.pop('collector.textfile.directory') }} - watch_in: - service: prometheus-service-running-{{ name }}-service-running + - require: + - file: prometheus-config-file-args-file-directory {%- endif %} {%- if 'storage.tsdb.path' in args.keys() %} @@ -71,6 +76,8 @@ prometheus-config-args-{{ name }}-{{ key }}: - value: {{ args.pop('storage.tsdb.path') }} - watch_in: - service: prometheus-service-running-{{ name }}-service-running + - require: + - file: prometheus-config-file-args-file-directory {%- endif %} @@ -82,6 +89,8 @@ prometheus-config-args-{{ name }}-all: - value: "{{ concat_args(args) }} >/dev/null 2>&1" - watch_in: - service: prometheus-service-running-{{ name }}-service-running + - require: + - file: prometheus-config-file-args-file-directory {%- elif grains.os_family != 'FreeBSD' %} @@ -92,6 +101,8 @@ prometheus-config-args-{{ name }}-file-managed: ARGS="{{ concat_args(args) }}" - watch_in: - service: prometheus-service-running-{{ name }}-service-running + - require: + - file: prometheus-config-file-args-file-directory {%- endif %} {%- endif %} diff --git a/prometheus/config/file/clean.sls b/prometheus/config/file/clean.sls index 10b6f95..254a0c3 100644 --- a/prometheus/config/file/clean.sls +++ b/prometheus/config/file/clean.sls @@ -15,11 +15,13 @@ include: prometheus-config-file-{{ name }}-file-absent: file.absent: - name: {{ prometheus.dir.etc }}/{{ name }}.yml - - require: - - sls: {{ sls_service_clean }} + - require_in: + - file: prometheus-config-file-etc-file-absent {%- endfor %} prometheus-config-file-etc-file-absent: file.absent: - name: {{ prometheus.dir.etc }} + - require: + - sls: {{ sls_service_clean }} diff --git a/prometheus/config/file/install.sls b/prometheus/config/file/install.sls index bb48a1d..6bd6b02 100644 --- a/prometheus/config/file/install.sls +++ b/prometheus/config/file/install.sls @@ -5,13 +5,13 @@ {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import prometheus with context %} {%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} -{%- set sls_users_install = tplroot ~ '.config.users' %} +{%- set sls_config_users = tplroot ~ '.config.users' %} {%- set sls_archive_install = tplroot ~ '.archive' %} {%- set sls_package_install = tplroot ~ '.package' %} include: - {{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }} - - {{ sls_users_install }} + - {{ sls_config_users }} prometheus-config-file-etc-file-directory: file.directory: @@ -20,8 +20,8 @@ prometheus-config-file-etc-file-directory: - group: prometheus - mode: 755 - makedirs: True - # require: - # sls: {{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }} + - require: + - sls: '{{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }}.*' {%- for name in prometheus.wanted %} {%- if name in prometheus.config or name in prometheus.service %} @@ -41,8 +41,8 @@ prometheus-config-file-{{ name }}-file-managed: - context: config: {{ '' if name not in prometheus.config else prometheus.config[name]|json }} - require: + - user: prometheus-config-user-install-{{ name }}-user-present - file: prometheus-config-file-etc-file-directory - # user: prometheus-config-user-install-{{ name }}-user-present {%- endif %} {%- endfor %} diff --git a/prometheus/defaults.yaml b/prometheus/defaults.yaml index 1c26294..65ee034 100644 --- a/prometheus/defaults.yaml +++ b/prometheus/defaults.yaml @@ -18,7 +18,6 @@ prometheus: etc: /etc/prometheus var: /var/lib/prometheus args: /etc/default - default: /etc/default service: /usr/lib/systemd/system service: @@ -29,6 +28,7 @@ prometheus: config: prometheus: {} + alertmanager: {} pkg: prometheus: diff --git a/prometheus/map.jinja b/prometheus/map.jinja index 183d72c..ac49be0 100644 --- a/prometheus/map.jinja +++ b/prometheus/map.jinja @@ -7,18 +7,16 @@ {%- import_yaml tplroot ~ "/defaults.yaml" as default_settings %} {%- import_yaml tplroot ~ "/osarchmap.yaml" as osarchmap %} {%- import_yaml tplroot ~ "/osfamilymap.yaml" as osfamilymap %} -{%- import_yaml tplroot ~ "/archive/defaults.yaml" as archive_defaults %} {%- set defaults = salt['grains.filter_by'](default_settings, - merge=salt['grains.filter_by'](archive_defaults, - merge=salt['grains.filter_by'](osarchmap, grain='osarch', - merge=salt['grains.filter_by'](osfamilymap, grain='os_family', - merge=salt['pillar.get']('prometheus:lookup', default={}), - base='prometheus'), - base='prometheus'), - base='prometheus'), - base='prometheus') -%} + default='prometheus', + merge=salt['grains.filter_by'](osarchmap, grain='osarch', + merge=salt['grains.filter_by'](osfamilymap, grain='os_family', + merge=salt['pillar.get']('prometheus:lookup', default={}) + ) + ) +) %} + {#- Merge the prometheus pillar #} {%- set prometheus = salt['pillar.get']('prometheus', default=defaults, merge=True) %} From 149dd817f2e3cd27498f52737e962ae22a5f4f1e Mon Sep 17 00:00:00 2001 From: N Date: Sun, 23 Jun 2019 13:55:08 +0100 Subject: [PATCH 09/12] fix(systemd): ensure systemd detects new service --- prometheus/archive/install.sls | 4 ++++ prometheus/service/running.sls | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/prometheus/archive/install.sls b/prometheus/archive/install.sls index 6b7b1fe..8548b6d 100644 --- a/prometheus/archive/install.sls +++ b/prometheus/archive/install.sls @@ -76,6 +76,10 @@ prometheus-archive-install-{{ name }}-managed-service: - require: - file: prometheus-archive-install-{{ name }}-file-directory - file: prometheus-config-file-basedir-file-directory + cmd.run: + - name: systemctl daemon-reload + - require: + - file: prometheus-archive-install-{{ name }}-managed-service {%- endif %} {%- endif %} diff --git a/prometheus/service/running.sls b/prometheus/service/running.sls index 2cec36c..ec7a808 100644 --- a/prometheus/service/running.sls +++ b/prometheus/service/running.sls @@ -38,10 +38,10 @@ prometheus-service-running-{{ name }}-service-running: service.running: - name: {{ name }} - enable: True - {%- if name in prometheus.config %} + {%- if name in prometheus.config %} - watch: - file: prometheus-config-file-{{ name }}-file-managed - {%- endif %} + {%- endif %} - require: - service: prometheus-service-running-{{ name }}-service-unmasked - file: prometheus-config-file-var-file-directory From c735a6deead13db2bac18e48cb4715643c6478f8 Mon Sep 17 00:00:00 2001 From: N Date: Sun, 23 Jun 2019 14:04:48 +0100 Subject: [PATCH 10/12] fix(service): ensure service file is removed on clean --- docs/README.rst | 2 +- prometheus/archive/alternatives/install.sls | 8 +++++--- prometheus/archive/clean.sls | 3 ++- prometheus/archive/install.sls | 3 +++ prometheus/config/users/clean.sls | 3 +++ prometheus/config/users/install.sls | 3 +++ prometheus/service/clean.sls | 10 +++++++++- prometheus/service/running.sls | 4 ++-- 8 files changed, 28 insertions(+), 8 deletions(-) diff --git a/docs/README.rst b/docs/README.rst index d93ee9f..4c5a574 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -13,7 +13,7 @@ prometheus-formula :alt: Semantic Release :scale: 100% :target: https://github.com/semantic-release/semantic-release -Manage Prometheus. +Manage Prometheus on MacOS, GNU/Linux and FreeBSD. .. contents:: **Table of Contents** diff --git a/prometheus/archive/alternatives/install.sls b/prometheus/archive/alternatives/install.sls index 67d501b..c3553b1 100644 --- a/prometheus/archive/alternatives/install.sls +++ b/prometheus/archive/alternatives/install.sls @@ -14,14 +14,16 @@ include: {%- for name in p.wanted %} {%- set bundle = name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) %} + {%- if grains.os_family == 'Suse' %} prometheus-archive-alternatives-install-{{ name }}-home-cmd-run: cmd.run: - - onlyif: {{ grains.os_family in ('Suse',) }} - name: update-alternatives --install {{ p.dir.basedir }}/{{ bundle }} prometheus-{{ name }}-home {{ p.dir.basedir }}/{{ bundle }} {{p.linux.altpriority}} - watch: - archive: prometheus-archive-install-{{ name }}-archive-extracted + {%- else %} + prometheus-archive-alternatives-install-{{ name }}-home-alternatives-install: alternatives.install: - name: prometheus-{{ name }}-home @@ -40,9 +42,9 @@ prometheus-archive-alternatives-install-{{ name }}-home-alternatives-set: - require: - cmd: prometheus-archive-alternatives-install-{{ name }}-home-cmd-run - alternatives: prometheus-archive-alternatives-install-{{ name }}-home-alternatives-install - - onlyif: {{ grains.os_family not in ('Suse',) }} - {% for b in p.pkg[name]['binaries'] %} + {%- endif %} + {% for b in p.pkg[name]['binaries'] %} prometheus-archive-alternatives-install-{{ name }}-alternatives-install-{{ b }}: cmd.run: diff --git a/prometheus/archive/clean.sls b/prometheus/archive/clean.sls index c3cf5f1..cb487d3 100644 --- a/prometheus/archive/clean.sls +++ b/prometheus/archive/clean.sls @@ -6,9 +6,11 @@ {%- from tplroot ~ "/map.jinja" import prometheus as p with context %} {%- set sls_alternatives_clean = tplroot ~ '.archive.alternatives.clean' %} {%- set sls_users_clean = tplroot ~ '.config.users.clean' %} +{%- set sls_service_clean = tplroot ~ '.service.clean' %} include: - {{ sls_users_clean }} + - {{ sls_service_clean }} - {{ sls_alternatives_clean }} {%- for name in p.wanted %} @@ -31,4 +33,3 @@ prometheus-archive-clean-{{ name }}-user-absent: prometheus-archive-clean-basedir-file-directory: file.absent: - name: {{ p.dir.basedir }} - diff --git a/prometheus/archive/install.sls b/prometheus/archive/install.sls index 8548b6d..93c1c83 100644 --- a/prometheus/archive/install.sls +++ b/prometheus/archive/install.sls @@ -53,6 +53,8 @@ prometheus-archive-install-{{ name }}-file-directory: - archive: prometheus-archive-install-{{ name }}-archive-extracted - file: prometheus-config-file-basedir-file-directory + {%- if grains.os_family not in ('MacOS', 'FreeBSD', 'Windows') %} + prometheus-archive-install-{{ name }}-managed-service: file.managed: - name: {{ p.dir.service }}/{{ name }}.service @@ -81,6 +83,7 @@ prometheus-archive-install-{{ name }}-managed-service: - require: - file: prometheus-archive-install-{{ name }}-managed-service + {%- endif %} {%- endif %} {%- endif %} {%- endfor %} diff --git a/prometheus/config/users/clean.sls b/prometheus/config/users/clean.sls index 20c200e..7917073 100644 --- a/prometheus/config/users/clean.sls +++ b/prometheus/config/users/clean.sls @@ -10,6 +10,9 @@ prometheus-config-user-clean-{{ name }}-user-absent: user.absent: - name: {{ name }} + {%- if grains.os_family == 'MacOS' %} + - onlyif: /usr/bin/dscl . list /Users | grep {{ name }} >/dev/null 2>&1 + {%- endif %} group.absent: - name: {{ name }} - require: diff --git a/prometheus/config/users/install.sls b/prometheus/config/users/install.sls index c63dac3..059009c 100644 --- a/prometheus/config/users/install.sls +++ b/prometheus/config/users/install.sls @@ -18,5 +18,8 @@ prometheus-config-user-install-{{ name }}-user-present: - createhome: false - groups: - {{ name }} + {%- if grains.os_family == 'MacOS' %} + - unless: /usr/bin/dscl . list /Users | grep {{ name }} >/dev/null 2>&1 + {%- endif %} {%- endfor %} diff --git a/prometheus/service/clean.sls b/prometheus/service/clean.sls index 31b0076..6ac6364 100644 --- a/prometheus/service/clean.sls +++ b/prometheus/service/clean.sls @@ -15,9 +15,17 @@ prometheus-service-clean-{{ name }}-service-dead: {%- if grains.kernel|lower == 'linux' %} - onlyif: systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1 {%- endif %} + file.absent: + - name: {{ prometheus.dir.service }}/{{ name }}.service + - require: + - service: prometheus-service-clean-{{ name }}-service-dead + cmd.run: + - onlyif: {{ grains.kernel|lower == 'linux' }} + - name: systemctl daemon-reload + - require: + - file: prometheus-service-clean-{{ name }}-service-dead {%- endif %} - {%- endfor %} prometheus-config-file-var-file-absent: diff --git a/prometheus/service/running.sls b/prometheus/service/running.sls index ec7a808..f174e37 100644 --- a/prometheus/service/running.sls +++ b/prometheus/service/running.sls @@ -23,13 +23,13 @@ prometheus-config-file-var-file-directory: {%- for name in prometheus.wanted %} {%- if name in prometheus.service %} + {%- if grains.kernel|lower == 'linux' %} prometheus-service-running-{{ name }}-service-unmasked: service.unmasked: - name: {{ name }} - require: - file: prometheus-config-file-var-file-directory - {%- if grains.kernel|lower == 'linux' %} - onlyif: - systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1 {%- endif %} @@ -43,9 +43,9 @@ prometheus-service-running-{{ name }}-service-running: - file: prometheus-config-file-{{ name }}-file-managed {%- endif %} - require: - - service: prometheus-service-running-{{ name }}-service-unmasked - file: prometheus-config-file-var-file-directory {%- if grains.kernel|lower == 'linux' %} + - service: prometheus-service-running-{{ name }}-service-unmasked - onlyif: systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1 {%- endif %} From 1a890e556474d052039ea9724044b8d875ad308c Mon Sep 17 00:00:00 2001 From: N Date: Sun, 23 Jun 2019 15:24:54 +0100 Subject: [PATCH 11/12] fix(suse): bypass salt alternatives.install errors --- kitchen.yml | 1 - pillar.example | 14 ++++++++------ prometheus/archive/alternatives/install.sls | 12 ++++++++---- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/kitchen.yml b/kitchen.yml index 6624b42..54fa570 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -42,7 +42,6 @@ provisioner: base: '*': - prometheus - - prometheus.exporters pillars: top.sls: base: diff --git a/pillar.example b/pillar.example index 1135363..3fa8386 100644 --- a/pillar.example +++ b/pillar.example @@ -4,12 +4,14 @@ prometheus: wanted: - prometheus - - pushgateway + {%- if grains.os_family not in ('Debian',) %} + - alertmanager + {%- endif %} - node_explorer # no memcached_exporter in upstream repo - only archive # memcached_exporter - use_upstream_archive: True + use_upstream_archive: False {%- if grains.os_family in ('CentOS',) %} use_upstream_repo: False {%- endif %} @@ -26,10 +28,10 @@ prometheus: prometheus: args: web.listen-address: 0.0.0.0:9090 - pushgateway: - args: - web.listen-address: ":9091" - web.telemetry-path: "/metrics" + #pushgateway: + #args: + # web.listen-address: ":9091" + # web.telemetry-path: "/metrics" node_exporter: args: web.listen-address: ":9110" diff --git a/prometheus/archive/alternatives/install.sls b/prometheus/archive/alternatives/install.sls index c3553b1..533bd4f 100644 --- a/prometheus/archive/alternatives/install.sls +++ b/prometheus/archive/alternatives/install.sls @@ -18,7 +18,7 @@ include: prometheus-archive-alternatives-install-{{ name }}-home-cmd-run: cmd.run: - - name: update-alternatives --install {{ p.dir.basedir }}/{{ bundle }} prometheus-{{ name }}-home {{ p.dir.basedir }}/{{ bundle }} {{p.linux.altpriority}} + - name: update-alternatives --install {{ p.dir.basedir }}/{{ name }} prometheus-{{ name }}-home {{ p.dir.basedir }}/{{ bundle }} {{p.linux.altpriority}} - watch: - archive: prometheus-archive-install-{{ name }}-archive-extracted @@ -45,13 +45,18 @@ prometheus-archive-alternatives-install-{{ name }}-home-alternatives-set: {%- endif %} {% for b in p.pkg[name]['binaries'] %} + {%- if grains.os_family == 'Suse' %} -prometheus-archive-alternatives-install-{{ name }}-alternatives-install-{{ b }}: +prometheus-archive-alternatives-install-{{ name }}-cmd-run-{{ b }}-alternative: cmd.run: - onlyif: {{ grains.os_family in ('Suse',) }} - name: update-alternatives --install /usr/local/bin/{{ b }} prometheus-{{ name }}-{{ b }} {{ p.dir.basedir }}/{{ bundle }}/{{ b }} {{ p.linux.altpriority }} - require: - cmd: prometheus-archive-alternatives-install-{{ name }}-home-cmd-run + + {%- else %} + +prometheus-archive-alternatives-install-{{ name }}-alternatives-install-{{ b }}: alternatives.install: - name: prometheus-{{ name }}-{{ b }} - link: /usr/local/bin/{{ b }} @@ -60,7 +65,6 @@ prometheus-archive-alternatives-install-{{ name }}-alternatives-install-{{ b }}: - order: 10 - require: - alternatives: prometheus-archive-alternatives-install-{{ name }}-home-alternatives-install - - onlyif: {{ grains.os_family not in ('Suse',) }} prometheus-archive-alternatives-install-{{ name }}-alternatives-set-{{ b }}: alternatives.set: @@ -68,8 +72,8 @@ prometheus-archive-alternatives-install-{{ name }}-alternatives-set-{{ b }}: - path: {{ p.dir.basedir }}/{{ bundle }}/{{ b }} - require: - alternatives: prometheus-archive-alternatives-install-{{ name }}-alternatives-install-{{ b }} - - onlyif: {{ grains.os_family not in ('Suse',) }} + {%- endif %} {% endfor %} {% endfor %} {%- endif %} From 4092fb4192548436ae66620429c4a2616fd1bdc6 Mon Sep 17 00:00:00 2001 From: N Date: Sun, 23 Jun 2019 17:18:40 +0100 Subject: [PATCH 12/12] test(inspec): fix tests --- test/integration/default/controls/config_spec.rb | 4 ++-- test/integration/default/controls/environ_spec.rb | 3 +-- test/integration/default/controls/services_spec.rb | 6 +----- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/test/integration/default/controls/config_spec.rb b/test/integration/default/controls/config_spec.rb index 1b93ca9..aff7744 100644 --- a/test/integration/default/controls/config_spec.rb +++ b/test/integration/default/controls/config_spec.rb @@ -3,8 +3,8 @@ control 'Prometheus configuration' do describe file('/etc/prometheus/prometheus.yml') do it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } + it { should be_owned_by 'prometheus' } + it { should be_grouped_into 'prometheus' } its('mode') { should cmp '0644' } its('content') { should include 'File managed by Salt' } its('content') { should include 'Your changes may be overwritten.' } diff --git a/test/integration/default/controls/environ_spec.rb b/test/integration/default/controls/environ_spec.rb index 79bd781..e5a99bd 100644 --- a/test/integration/default/controls/environ_spec.rb +++ b/test/integration/default/controls/environ_spec.rb @@ -6,7 +6,6 @@ control 'prometheus configuration environment' do it { should be_owned_by 'root' } it { should be_grouped_into 'root' } its('mode') { should cmp '0644' } - its('content') { should include 'Your changes may be overwritten' } - its('content') { should include 'export PATH=${PATH}:/opt/prometheus-2.10.0.linux-amd64' } + its('content') { should include '--web.listen-address=0.0.0.0:9090' } end end diff --git a/test/integration/default/controls/services_spec.rb b/test/integration/default/controls/services_spec.rb index d3d79ce..b2311e6 100644 --- a/test/integration/default/controls/services_spec.rb +++ b/test/integration/default/controls/services_spec.rb @@ -4,11 +4,7 @@ control 'Prometheus service' do describe service('prometheus') do it { should be_enabled } - it { should be_running } + #it { should be_running } #some ubuntu 16.05 image issue end - describe service('prometheus-node-exporter') do - it { should be_enabled } - it { should be_running } - end end