Puppet Class: profile::toolforge::checker

Defined in:
modules/profile/manifests/toolforge/checker.pp

Overview

Class: profile::toolforge::checker

Exposes a set of web endpoints that perform an explicit check for a particular set of internal services, and response OK (200) or not (anything else).

Used for external monitoring / collection of availability metrics



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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'modules/profile/manifests/toolforge/checker.pp', line 9

class profile::toolforge::checker {
    include profile::toolforge::grid::base
    include profile::toolforge::k8s::client

    # Packages needed by the uwsgi services
    ensure_packages([
        'python3-flask',
        'python3-ldap3',
        'python3-redis',
        'python3-requests',
        'python3-yaml',
    ])

    # For etcd checks, we need the puppet certs to act as client
    $puppet_cert_pub  = $facts['puppet_config']['hostcert']
    $puppet_cert_priv = $facts['puppet_config']['hostprivkey']
    $puppet_cert_ca   = profile::base::certificates::get_trusted_ca_path()
    $install_dir = '/var/lib/toolschecker'
    $wsgi_file = "${install_dir}/toolschecker.py"
    $etcd_cert_pub    = "${install_dir}/etcd/${facts['networking']['fqdn']}.pem"
    $etcd_cert_priv   = "${install_dir}/etcd/${facts['networking']['fqdn']}.priv"
    $etcd_cert_ca     = "${install_dir}/etcd/ca.pem"

    $checks = {
        'cron'                   => absent,
        'db_toolsdb'             => absent,
        'dns_private'            => '/dns/private',
        'etcd_kubernetes'        => '/etcd/k8s',
        'grid_continuous_buster' => absent,
        'grid_start_buster'      => absent,
        'kubernetes_nodes_ready' => absent,
        'ldap'                   => '/ldap',
        'nfs_dumps'              => '/nfs/dumps',
        'nfs_home'               => '/nfs/home',
        'redis'                  => '/redis',
        'self'                   => '/self',
        'webservice_gridengine'  => absent,
        'webservice_kubernetes'  => absent,
    }

    $checks.each |String $name, Variant[String, Wmflib::Ensure] $path| {
        $ensure = $path ? {
            Wmflib::Ensure => $path,
            default        => 'present',
        }

        # Provision a separate uwsgi service for each check endpoint.
        # This is done so that we can use 'harakiri mode' which will terminate
        # the entire uwsgi process if a request takes longer than the
        # configured maximum response time.
        uwsgi::app { "toolschecker_${name}":
            ensure   => $ensure,
            settings => {
                uwsgi => {
                    need-plugins     => 'python3',
                    master           => true,
                    chdir            => $install_dir,
                    wsgi-file        => $wsgi_file,
                    callable         => 'app',
                    uwsgi-socket     => "/tmp/uwsgi-${name}.sock",
                    chmod-socket     => 664,
                    processes        => 1,
                    harakiri         => 300,
                    harakiri-verbose => true,
                    die-on-term      => true,
                    env              => [
                        'LANG=C.UTF-8',
                        'PYTHONENCODING=utf-8',
                    ],
                },
            },
            require  => File[$wsgi_file],
        }
    }

    $present_checks = $checks.filter |String $name, Variant[String, Wmflib::Ensure] $path| { !($path =~ Wmflib::Ensure) }
    $check_names = keys($present_checks).map |$name| { "toolschecker_${name}" }

    # Reverse proxy in front the collection of uwsgi containers
    nginx::site { 'toolschecker-nginx':
        content => template('profile/toolforge/checker/nginx.erb'),
        require => Uwsgi::App[$check_names],
    }

    file { $install_dir:
        ensure => directory,
        owner  => 'www-data',
        group  => 'www-data',
        mode   => '0755',
        before => File[$wsgi_file],
    }

    file { "${install_dir}/etcd":
        ensure => directory,
        owner  => 'www-data',
        group  => 'www-data',
        mode   => '0500',
    }

    file { $etcd_cert_pub:
        ensure => present,
        source => "file://${puppet_cert_pub}",
        owner  => 'www-data',
        group  => 'www-data',
    }

    file { $etcd_cert_priv:
        ensure    => present,
        source    => "file://${puppet_cert_priv}",
        owner     => 'www-data',
        group     => 'www-data',
        mode      => '0600',
        show_diff => false,
    }

    file { $etcd_cert_ca:
        ensure => present,
        source => "file://${puppet_cert_ca}",
        owner  => 'www-data',
        group  => 'www-data',
    }

    file { $wsgi_file:
        ensure => file,
        owner  => 'root',
        group  => 'root',
        mode   => '0444',
        source => 'puppet:///modules/profile/toolforge/checker/toolschecker.py',
        notify => Uwsgi::App[$check_names],
    }

    $config = {
        'DEBUG'         => true,
        'DUMPS_PATH'    => '/public/dumps/public/enwiki',
        'ETCD_K8S' => wmflib::role::hosts('wmcs::toolforge::k8s::etcd'),
        'ETCD_AUTH' => {
            'KEY'  => $etcd_cert_priv,
            'CERT' => $etcd_cert_pub,
            'CA'   => $etcd_cert_ca,
        },
        'NFS_HOME_PATH' => '/data/project/toolschecker/nfs-test/',
    }
    file { "${install_dir}/config.yaml":
        ensure  => 'present',
        owner   => 'root',
        group   => 'www-data',
        mode    => '0440',
        content => to_yaml($config),
        notify  => Uwsgi::App[$check_names],
    }

    file { "${install_dir}/replica.my.cnf":
        ensure => present,
        owner  => 'www-data',
        group  => 'www-data',
        mode   => '0400',
        source => '/data/project/toolschecker/replica.my.cnf',
        before => File[$wsgi_file],
    }

    file { "${install_dir}/postgres.my.cnf":
        ensure => absent,
    }

    file { [
        "${install_dir}/kubernetes.json",
        "${install_dir}/kube-config.yaml",
        "${install_dir}/client.crt",
        "${install_dir}/client.key",
    ]:
        ensure => absent,
    }

    sudo::user { 'www-data':
        ensure => absent,
    }

    # Configure the $HOME of the toolschecker tool. Assumes that the basic
    # Toolforge tool user and its homedir has already been provisioned by
    # other means.

    # Directory to write NFS read/write check files to
    file { '/data/project/toolschecker/nfs-test':
        ensure => directory,
        owner  => 'www-data',
        group  => "${::wmcs_project}.toolschecker",
        mode   => '0755',
        before => File[$wsgi_file],
    }

    # Configure the $HOME of the toolschecker-ge-ws tool. Assumes that the
    # basic Toolforge tool user and its homedir has already been provisioned
    # by other means.

    file { '/usr/local/sbin/toolscheckerctl':
        ensure => file,
        owner  => 'root',
        group  => 'root',
        mode   => '0655',
        source => 'puppet:///modules/profile/toolforge/checker/toolscheckerctl.py',
    }
}