Skip to content

Commit

Permalink
feat(archives): support for various prometheus archives
Browse files Browse the repository at this point in the history
  • Loading branch information
noelmcloughlin committed Jun 18, 2019
1 parent 36b3e62 commit 3ec910e
Show file tree
Hide file tree
Showing 16 changed files with 332 additions and 191 deletions.
39 changes: 39 additions & 0 deletions prometheus/archive/alternatives/clean.sls
Original file line number Diff line number Diff line change
@@ -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 %}
14 changes: 14 additions & 0 deletions prometheus/archive/alternatives/init.sls
Original file line number Diff line number Diff line change
@@ -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 %}
75 changes: 75 additions & 0 deletions prometheus/archive/alternatives/install.sls
Original file line number Diff line number Diff line change
@@ -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 %}
18 changes: 15 additions & 3 deletions prometheus/archive/clean.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
67 changes: 67 additions & 0 deletions prometheus/archive/defaults.yaml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions prometheus/archive/init.sls
Original file line number Diff line number Diff line change
@@ -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 %}
26 changes: 15 additions & 11 deletions prometheus/archive/install.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
34 changes: 0 additions & 34 deletions prometheus/config/alternatives/clean.sls

This file was deleted.

5 changes: 0 additions & 5 deletions prometheus/config/alternatives/init.sls

This file was deleted.

Loading

0 comments on commit 3ec910e

Please sign in to comment.