fix: rework to implement environment variables handling
Developed environ.sh.jinja and added test pillar data to default Corrected prometheus.config.environ ref #59 Switched default test pillar to use none archive - due to deployment of custom service Disabled a number of exporters following switch from archive due to failing - to be reviewed Corrected prometheus environ_file location Resolves: #59
This commit is contained in:
		
							parent
							
								
									fa96aabba7
								
							
						
					
					
						commit
						eea5b407fa
					
				@ -12,6 +12,7 @@ extends: 'default'
 | 
			
		||||
# 5. Any YAML files under directory `.kitchen/`, introduced during local testing
 | 
			
		||||
# 6. `kitchen.vagrant.yml`, which contains Embedded Ruby (ERB) template syntax
 | 
			
		||||
ignore: |
 | 
			
		||||
  .bundle/
 | 
			
		||||
  .cache/
 | 
			
		||||
  .git/
 | 
			
		||||
  node_modules/
 | 
			
		||||
 | 
			
		||||
@ -7,6 +7,8 @@ driver:
 | 
			
		||||
  use_sudo: false
 | 
			
		||||
  privileged: true
 | 
			
		||||
  run_command: /lib/systemd/systemd
 | 
			
		||||
  forward:
 | 
			
		||||
    - 9090:9090
 | 
			
		||||
 | 
			
		||||
platforms:
 | 
			
		||||
  ## SALT `tiamat`
 | 
			
		||||
@ -350,7 +352,7 @@ suites:
 | 
			
		||||
      state_top:
 | 
			
		||||
        base:
 | 
			
		||||
          '*':
 | 
			
		||||
            - prometheus._mapdata
 | 
			
		||||
            # - prometheus._mapdata
 | 
			
		||||
            - prometheus
 | 
			
		||||
      pillars:
 | 
			
		||||
        top.sls:
 | 
			
		||||
 | 
			
		||||
@ -4,7 +4,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 %}
 | 
			
		||||
{%- from tplroot ~ "/files/macros.jinja" import concat_environ %}
 | 
			
		||||
{%- from tplroot ~ "/files/macros.jinja" import concat_args %}
 | 
			
		||||
{%- set sls_archive_install = tplroot ~ '.archive.install' %}
 | 
			
		||||
{%- set sls_package_install = tplroot ~ '.package.install' %}
 | 
			
		||||
 | 
			
		||||
@ -12,7 +12,8 @@ include:
 | 
			
		||||
  - {{ sls_archive_install if p.pkg.use_upstream_archive else sls_package_install }}
 | 
			
		||||
 | 
			
		||||
    {%- for name in p.wanted.component %}
 | 
			
		||||
        {%- if 'environ' in p.pkg.component[name] and p.pkg.component[name]['environ'] %}
 | 
			
		||||
        {%- if 'environ' in p.pkg.component[name] and 'args' in p.pkg.component[name]['environ'] %}
 | 
			
		||||
            {%- set args = p.pkg.component[name]['environ']['args'] %}
 | 
			
		||||
            {%- if 'environ_file' in p.pkg.component[name] and p.pkg.component[name]['environ_file'] %}
 | 
			
		||||
 | 
			
		||||
prometheus-config-install-{{ name }}-environ_file:
 | 
			
		||||
@ -29,8 +30,10 @@ prometheus-config-install-{{ name }}-environ_file:
 | 
			
		||||
    - user: {{ p.identity.rootuser }}
 | 
			
		||||
    - group: {{ p.identity.rootgroup }}
 | 
			
		||||
                {%- endif %}
 | 
			
		||||
    - contents: |
 | 
			
		||||
       command_args="{{ concat_environ(environ) }}"
 | 
			
		||||
    #- contents: |
 | 
			
		||||
    #   command_args="{{ concat_args(args) }}"
 | 
			
		||||
    - context:
 | 
			
		||||
        args: {{ args }}
 | 
			
		||||
    - watch_in:
 | 
			
		||||
      - service: prometheus-service-running-{{ name }}
 | 
			
		||||
    - require:
 | 
			
		||||
@ -43,7 +46,7 @@ prometheus-config-environ-{{ name }}-all:
 | 
			
		||||
    - name: {{ name }}_environ
 | 
			
		||||
    # service prometheus restart tends to hang on FreeBSD
 | 
			
		||||
    # https://github.com/saltstack/salt/issues/44848#issuecomment-487016414
 | 
			
		||||
    - value: "{{ concat_environ(p.pkg.component[name]['environ']) }} >/dev/null 2>&1"
 | 
			
		||||
    - value: "{{ concat_args(p.pkg.component[name]['environ']) }} >/dev/null 2>&1"
 | 
			
		||||
    - watch_in:
 | 
			
		||||
      - service: prometheus-service-running-{{ name }}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -152,7 +152,7 @@ prometheus:
 | 
			
		||||
        version: v2.22.1
 | 
			
		||||
        config_file: /etc/prometheus/prometheus.yml
 | 
			
		||||
        config: {}
 | 
			
		||||
        environ_file: /etc/default/prometheus.sh
 | 
			
		||||
        environ_file: /etc/default/prometheus
 | 
			
		||||
        environ: {}
 | 
			
		||||
        service:
 | 
			
		||||
          args:
 | 
			
		||||
 | 
			
		||||
@ -2,5 +2,8 @@
 | 
			
		||||
# File managed by Salt at <{{ source }}>.
 | 
			
		||||
# Your changes may be overwritten.
 | 
			
		||||
########################################################################
 | 
			
		||||
# Set the command-line arguments to pass to the server.
 | 
			
		||||
ARGS="{%- for arg, value in args.items() %}--{{ arg }}={{ value }}{{ " " if not loop.last else "" }}{% endfor %}"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
{{ config|yaml(False) }}
 | 
			
		||||
 | 
			
		||||
@ -14,10 +14,10 @@ prometheus:
 | 
			
		||||
      - alertmanager
 | 
			
		||||
      - node_exporter
 | 
			
		||||
      - blackbox_exporter
 | 
			
		||||
      - consul_exporter
 | 
			
		||||
      - php-fpm_exporter
 | 
			
		||||
      # - consul_exporter
 | 
			
		||||
      # - php-fpm_exporter
 | 
			
		||||
      - postgres_exporter
 | 
			
		||||
      - mysqld_exporter
 | 
			
		||||
      # - mysqld_exporter
 | 
			
		||||
      # - memcached_exporter  # not in upstream repo, only archive
 | 
			
		||||
 | 
			
		||||
  exporters:
 | 
			
		||||
@ -36,7 +36,9 @@ prometheus:
 | 
			
		||||
          smartctl: /usr/sbin/smartctl
 | 
			
		||||
  pkg:
 | 
			
		||||
    use_upstream_repo: false
 | 
			
		||||
    use_upstream_archive: true
 | 
			
		||||
    # Changed to use non archive install as default (the archive includes a bespoke
 | 
			
		||||
    # implementation of service thats needs updating)
 | 
			
		||||
    use_upstream_archive: false
 | 
			
		||||
 | 
			
		||||
    clientlibs:
 | 
			
		||||
      # https://prometheus.io/docs/instrumenting/clientlibs
 | 
			
		||||
@ -102,17 +104,21 @@ prometheus:
 | 
			
		||||
          # This is to test that any fancy name we use, will work in archive mode
 | 
			
		||||
          name: my-fancy-consul-exporter-service
 | 
			
		||||
 | 
			
		||||
      mysqld_exporter:
 | 
			
		||||
        service:
 | 
			
		||||
          args:
 | 
			
		||||
            web.listen-address: 0.0.0.0:9192
 | 
			
		||||
          env:
 | 
			
		||||
            - 'DATA_SOURCE_NAME=foo:bar@/'
 | 
			
		||||
      # mysqld_exporter:
 | 
			
		||||
      #   service:
 | 
			
		||||
      #     args:
 | 
			
		||||
      #       web.listen-address: 0.0.0.0:9192
 | 
			
		||||
      #     env:
 | 
			
		||||
      #       - 'DATA_SOURCE_NAME=foo:bar@/'
 | 
			
		||||
 | 
			
		||||
      prometheus:
 | 
			
		||||
        service:
 | 
			
		||||
          args:
 | 
			
		||||
            web.listen-address: 0.0.0.0:9090
 | 
			
		||||
        environ:
 | 
			
		||||
          args:
 | 
			
		||||
            web.listen-address: 0.0.0.0:9090
 | 
			
		||||
            log.level: debug
 | 
			
		||||
        config:
 | 
			
		||||
          # yamllint disable-line rule:line-length
 | 
			
		||||
          # ref https://raw.githubusercontent.com/prometheus/prometheus/release-2.10/config/testdata/conf.good.yml
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user