Puppet Class: profile::wmcs::metricsinfra::prometheus_configurator

Defined in:
modules/profile/manifests/wmcs/metricsinfra/prometheus_configurator.pp

Overview

SPDX-License-Identifier: Apache-2.0

Parameters:

  • config_manager_url (Stdlib::HTTPUrl) (defaults to: lookup('profile::wmcs::metricsinfra::config_manager_url', {default_value => 'http://config-manager.svc.metricsinfra.eqiad1.wikimedia.cloud'}))
  • alertmanager_hosts (Array[Stdlib::Fqdn]) (defaults to: lookup('profile::wmcs::metricsinfra::prometheus_alertmanager_hosts'))
  • global_jobs (Array[Hash]) (defaults to: lookup('profile::wmcs::metricsinfra::global_jobs'))
  • alertmanager_active_host (Stdlib::Fqdn) (defaults to: lookup('profile::wmcs::metricsinfra::alertmanager_active_host'))


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'modules/profile/manifests/wmcs/metricsinfra/prometheus_configurator.pp', line 2

class profile::wmcs::metricsinfra::prometheus_configurator (
    Stdlib::HTTPUrl     $config_manager_url       = lookup('profile::wmcs::metricsinfra::config_manager_url', {default_value => 'http://config-manager.svc.metricsinfra.eqiad1.wikimedia.cloud'}),
    Array[Stdlib::Fqdn] $alertmanager_hosts       = lookup('profile::wmcs::metricsinfra::prometheus_alertmanager_hosts'),
    Array[Hash]         $global_jobs              = lookup('profile::wmcs::metricsinfra::global_jobs'),
    Stdlib::Fqdn        $alertmanager_active_host = lookup('profile::wmcs::metricsinfra::alertmanager_active_host'),
) {
    $gitdir = '/var/lib/git'
    $clone_dir = "${gitdir}/cloud/metricsinfra/prometheus-configurator"

    group { 'prometheus-configurator':
        ensure => present,
        system => true,
    }

    user { 'prometheus-configurator':
        ensure => present,
        system => true,
        gid    => 'prometheus-configurator',
        home   => '/nonexistent',
        # add to prometheus group for access to edit its configuration
        groups => ['prometheus'],
    }

    # at least this time the dependencies are packaged, so no need
    # to do venv tricks here!
    ensure_packages(['python3-requests', 'python3-yaml'])

    wmflib::dir::mkdir_p("${gitdir}/cloud/metricsinfra")

    # TODO: better deployment model (scap, debian, so on) - T288052
    git::clone { 'cloud/metricsinfra/prometheus-configurator':
        ensure    => latest,
        directory => $clone_dir,
        owner     => 'prometheus-configurator',
        group     => 'prometheus-configurator',
        require   => User['prometheus-configurator'],
    }

    file { '/etc/prometheus-configurator':
        ensure => directory,
        owner  => 'prometheus-configurator',
        group  => 'prometheus-configurator',
    }

    $config = {
        manager => {
            url => $config_manager_url,
        },
        openstack => {
            credentials => '/etc/novaobserver.yaml',
        },
        alertmanager_hosts => $alertmanager_hosts.map |Stdlib::Fqdn $host| {
            "${host}:9093"
        },
        alert_routing => {
            irc_base => "http://${alertmanager_active_host}:19190/",
        },
        global_jobs => $global_jobs,
        outputs => [],
        external_rules_files => [
            'alerts_default.yml',
        ],
        external_labels => {
            replica => $::facts['networking']['hostname'],
        },
    }

    file { '/etc/prometheus-configurator/config.yaml':
        ensure  => present,
        owner   => 'prometheus-configurator',
        group   => 'prometheus-configurator',
        content => to_yaml($config),
        mode    => '0440',
    }

    file { '/etc/prometheus-configurator/config.d/':
        ensure => directory,
        owner  => 'prometheus-configurator',
        group  => 'prometheus-configurator',
    }

    systemd::timer::job { 'prometheus-configurator':
        ensure            => present,
        description       => 'Update prometheus configuration from the controller server',
        working_directory => $clone_dir,
        command           => '/usr/bin/python3 scripts/create-prometheus-config --config /etc/prometheus-configurator/config.yaml --config "/etc/prometheus-configurator/config.d/*.yaml"',
        user              => 'prometheus-configurator',
        interval          => [
            {
                'start'    => 'OnBootSec',
                'interval' => '30s',
            },
            {
                'start'    => 'OnUnitInactiveSec',
                'interval' => '300s',
            },
        ],
        environment       => {
            'PYTHONPATH' => $clone_dir,
        },
    }
}