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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'modules/profile/manifests/toolforge/checker.pp', line 9

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

    # Packages needed by the uwsgi services
    require_package(
        'python3-flask',
        'python3-ldap3',
        'python3-psycopg2',
        'python3-pymysql',
        'python3-redis',
        'python3-requests',
        'python3-yaml',
    )

    # For etcd checks, we need the puppet certs to act as client
    $puppet_cert_pub  = "/var/lib/puppet/ssl/certs/${::fqdn}.pem"
    $puppet_cert_priv = "/var/lib/puppet/ssl/private_keys/${::fqdn}.pem"
    $puppet_cert_ca   = '/var/lib/puppet/ssl/certs/ca.pem'
    $install_dir = '/var/lib/toolschecker'
    $wsgi_file = "${install_dir}/toolschecker.py"
    $etcd_cert_pub    = "${install_dir}/etcd/${::fqdn}.pem"
    $etcd_cert_priv   = "${install_dir}/etcd/${::fqdn}.priv"
    $etcd_cert_ca     = "${install_dir}/etcd/ca.pem"

    $checks = {
        'cron'                            => '/cron',
        'db_toolsdb'                      => '/db/toolsdb',
        'db_wikilabelsrw'                 => '/db/wikilabelsrw',
        'dns_private'                     => '/dns/private',
        'etcd_kubernetes'                 => '/etcd/k8s',
        'grid_continuous_stretch'         => '/grid/continuous/stretch',
        'grid_start_stretch'              => '/grid/start/stretch',
        'kubernetes_nodes_ready'          => '/k8s/nodes/ready',
        'ldap'                            => '/ldap',
        'nfs_dumps'                       => '/nfs/dumps',
        'nfs_home'                        => '/nfs/home',
        'nfs_secondary_cluster_showmount' => '/nfs/secondary_cluster_showmount',
        'redis'                           => '/redis',
        'self'                            => '/self',
        'webservice_gridengine'           => '/webservice/gridengine',
        'webservice_kubernetes'           => '/webservice/kubernetes',
    }

    $check_names = keys($checks).map |$name| { "toolschecker_${name}" }

    $checks.each |String $name, String $path| {
        # 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}":
            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],
        }
    }

    # 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],
    }

    # TODO: move to hiera?
    $config = {
        'CRON_PATH'     => '/data/project/toolschecker/crontest.txt',
        'DEBUG'         => true,
        'DUMPS_PATH'    => '/public/dumps/public/enwiki',
        'ETCD_K8S' => [
            "tools-k8s-etcd-4.${::labsproject}.eqiad.wmflabs",
            "tools-k8s-etcd-5.${::labsproject}.eqiad.wmflabs",
            "tools-k8s-etcd-6.${::labsproject}.eqiad.wmflabs",
        ],
        'ETCD_AUTH' => {
            'KEY'  => $etcd_cert_priv,
            'CERT' => $etcd_cert_pub,
            'CA'   => $etcd_cert_ca,
        },
        'NFS_HOME_PATH' => '/data/project/toolschecker/nfs-test/',
        'PROJECT'       => $::labsproject,
        'TOOLS_DOMAIN'  => 'tools.wmflabs.org',
    }
    file { "${install_dir}/config.yaml":
        ensure  => 'present',
        owner   => 'root',
        group   => 'www-data',
        mode    => '0440',
        content => ordered_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 => present,
        owner  => 'www-data',
        group  => 'www-data',
        mode   => '0400',
        source => '/data/project/toolschecker/postgres.my.cnf',
        before => File[$wsgi_file],
    }

    file { "${install_dir}/kubernetes.json":
        ensure => absent,
    }
    file { "${install_dir}/kube-config.yaml":
        ensure => present,
        owner  => 'www-data',
        group  => 'www-data',
        mode   => '0400',
        source => '/data/project/toolschecker/.kube/config',
        before => File[$wsgi_file],
    }
    file { "${install_dir}/client.crt":
        ensure => present,
        owner  => 'www-data',
        group  => 'www-data',
        mode   => '0400',
        source => '/data/project/toolschecker/.toolskube/client.crt',
        before => File[$wsgi_file],
    }
    file { "${install_dir}/client.key":
        ensure => present,
        owner  => 'www-data',
        group  => 'www-data',
        mode   => '0400',
        source => '/data/project/toolschecker/.toolskube/client.key',
        before => File[$wsgi_file],
    }

    # Allow the www-data user to perform actions as related tools.
    sudo::user { 'www-data':
        privileges => [
            "ALL=(${::labsproject}.toolschecker) NOPASSWD: ALL",
            "ALL=(${::labsproject}.toolschecker-k8s-ws) NOPASSWD: ALL",
            "ALL=(${::labsproject}.toolschecker-ge-ws) NOPASSWD: ALL",
        ],
    }

    # 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  => "${::labsproject}.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.

    # "Hello world" php app
    file { '/data/project/toolschecker-ge-ws/public_html/index.php':
        ensure => file,
        owner  => 'root',
        group  => 'root',
        mode   => '0555',
        source => 'puppet:///modules/profile/toolforge/checker/service.php',
        before => File[$wsgi_file],
    }

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

    # "Hello world" php app
    file { '/data/project/toolschecker-k8s-ws/public_html/index.php':
        ensure => file,
        owner  => 'root',
        group  => 'root',
        mode   => '0555',
        source => 'puppet:///modules/profile/toolforge/checker/service.php',
        before => File[$wsgi_file],
    }

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