Puppet Class: thanos::rule

Defined in:
modules/thanos/manifests/rule.pp

Overview

Parameters:

  • rule_hosts (Hash[Stdlib::Fqdn, Hash])
  • objstore_account (Hash[String, String])
  • objstore_password (String)
  • alertmanagers (Array[Stdlib::Host])
  • rule_files (Array[String])
  • ensure (Wmflib::Ensure) (defaults to: present)
  • query_port (Stdlib::Port::Unprivileged) (defaults to: 10902)
  • http_port (Stdlib::Port::Unprivileged) (defaults to: 17902)
  • grpc_port (Stdlib::Port::Unprivileged) (defaults to: 17901)


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
104
105
106
107
108
109
110
111
112
113
114
115
# File 'modules/thanos/manifests/rule.pp', line 28

class thanos::rule (
    Hash[Stdlib::Fqdn, Hash] $rule_hosts,
    Hash[String, String] $objstore_account,
    String $objstore_password,
    Array[Stdlib::Host] $alertmanagers,
    Array[String] $rule_files,
    Wmflib::Ensure $ensure = present,
    Stdlib::Port::Unprivileged $query_port = 10902,
    Stdlib::Port::Unprivileged $http_port = 17902,
    Stdlib::Port::Unprivileged $grpc_port = 17901,
) {
    ensure_packages(['thanos'])

    $http_address = "0.0.0.0:${http_port}"
    $grpc_address = "0.0.0.0:${grpc_port}"
    $service_name = 'thanos-rule'
    $data_dir = '/srv/thanos-rule'
    $objstore_config_file = '/etc/thanos-rule/objstore.yaml'
    $am_config_file = '/etc/thanos-rule/alertmanagers.yaml'
    $am_config = { 'alertmanagers' => [
        { 'static_configs' => $alertmanagers.map |$a| { "${a}:9093" } }
    ]}
    $replica = $::fqdn in $rule_hosts ? {
        true  => $rule_hosts[$::fqdn]['replica'],
        false => 'unset'
    }

    file { $data_dir:
        ensure => directory,
        mode   => '0750',
        owner  => 'thanos',
        group  => 'thanos',
    }

    file { '/etc/thanos-rule':
        ensure => directory,
        mode   => '0555',
        owner  => 'root',
        group  => 'root',
    }

    file { '/etc/thanos-rule/rules':
        ensure => directory,
        mode   => '0555',
        owner  => 'root',
        group  => 'root',
    }

    file { $objstore_config_file:
        ensure    => $ensure,
        mode      => '0440',
        owner     => 'thanos',
        group     => 'root',
        show_diff => false,
        content   => template('thanos/objstore.yaml.erb'),
    }

    file { $am_config_file:
        ensure  => $ensure,
        mode    => '0444',
        owner   => 'thanos',
        group   => 'root',
        content => ordered_yaml($am_config),
    }

    if $ensure != present {
        $service_ensure = $ensure
    } else { # handle fqdn-based service running/stopped status
        if $::fqdn in $rule_hosts {
            $service_ensure = 'present'
            $service_enable = true
        } else {
            $service_ensure = 'absent'
            $service_enable = false
        }
    }

    systemd::service { $service_name:
        ensure         => $service_ensure,
        restart        => true,
        override       => true,
        content        => systemd_template('thanos-rule'),
        service_params => {
            enable     => $service_enable,
            hasrestart => true,
        },
    }
}