Puppet Class: ores::web

Defined in:
modules/ores/manifests/web.pp

Overview

Class: ores::web

Sets up a uwsgi based web server for ORES running python3

Parameters:

  • web_workers (Any) (defaults to: 48)
  • redis_host (Any) (defaults to: '127.0.0.1')
  • redis_password (Any) (defaults to: undef)
  • redis_queue_port (Any) (defaults to: 6379)
  • redis_cache_port (Any) (defaults to: 6380)
  • port (Any) (defaults to: 8081)
  • statsd_host (Any) (defaults to: 'localhost')
  • statsd_port (Any) (defaults to: '8125')
  • deployment (Any) (defaults to: 'scap3')
  • celery_workers (Any) (defaults to: 35)
  • extra_config (Any) (defaults to: undef)
  • ores_config_user (Any) (defaults to: 'deploy-service')
  • ores_config_group (Any) (defaults to: 'deploy-service')
  • celery_queue_maxsize (Any) (defaults to: 100)
  • poolcounter_nodes (Any) (defaults to: [])
  • logstash_host (Any) (defaults to: undef)
  • logstash_port (Any) (defaults to: undef)


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
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
# File 'modules/ores/manifests/web.pp', line 3

class ores::web(
    $web_workers = 48,
    $redis_host = '127.0.0.1',
    $redis_password = undef,
    $redis_queue_port = 6379,
    $redis_cache_port = 6380,
    $port = 8081,
    $statsd_host = 'localhost',
    $statsd_port = '8125',
    $deployment = 'scap3',
    $celery_workers = 35,
    $extra_config = undef,
    $ores_config_user = 'deploy-service',
    $ores_config_group = 'deploy-service',
    $celery_queue_maxsize = 100,
    $poolcounter_nodes = [],
    $logstash_host = undef,
    $logstash_port = undef,
) {
    require ::ores::base

    # Need to be able to also restart the worker. The uwsgi service is
    # hopefully temporary
    # lsof is temporary, to diagnose T174402
    $sudo_rules = [
        'ALL=(root) NOPASSWD: /usr/sbin/service uwsgi-ores *',
        'ALL=(root) NOPASSWD: /usr/sbin/service celery-ores-worker *',
    ]


    # Ores is controlled via a custom systemd unit (uwsgi-ores),
    # so avoid the generic uwsgi sysvinit script shipped in the
    # Debian package
    exec { 'mask_default_uwsgi_ores':
        command => '/bin/systemctl mask uwsgi.service',
        creates => '/etc/systemd/system/uwsgi.service',
    }

    service::uwsgi { 'ores':
        port            => $port,
        sudo_rules      => $sudo_rules,
        healthcheck_url => '/',
        deployment      => $deployment,
        config          => {
            'wsgi-file'          => "${ores::base::config_path}/ores_wsgi.py",
            chdir                => $ores::base::config_path,
            need-plugins         => 'python3,stats_pusher_statsd',
            venv                 => $ores::base::venv_path,
            logformat            => '[pid: %(pid)] %(addr) (%(user)) {%(vars) vars in %(pktsize) bytes} [%(ctime)] %(method) %(uri) => generated %(rsize) bytes in %(msecs) msecs (%(proto) %(status)) %(headers) headers in %(hsize) bytes (%(switches) switches on core %(core)) user agent "%(uagent)"',
            processes            => $web_workers,
            add-header           => [ 'Access-Control-Allow-Origin: *', "Server: ${::fqdn}", 'Access-Control-Allow-Headers: X-Wikimedia-Debug' ],
            max-requests         => 200,
            stats-push           => "statsd:${statsd_host}:${statsd_port},ores.${::hostname}.uwsgi",
            memory-report        => true,
            skip-atexit-teardown => true,
        },
    }

    # lint:ignore:arrow_alignment
    $base_config = {
        'metrics_collectors' => {
            'wmflabs_statsd' => {
                'host' => $statsd_host,
                'port' => $statsd_port,
            },
        },
        'ores' => {
            'data_paths' => {
                'nltk' => "${::ores::base::config_path}/submodules/wheels/nltk/",
            },
        },
        'score_caches' => {
            'ores_redis' => {
                'host' => $redis_host,
                'port' => $redis_cache_port,
            },
        },
        'task_trackers' => {
            'redis' => {
                'host' => $redis_host,
                'port' => $redis_cache_port,
            },
        },
        'scoring_systems' => {
            'celery_queue' => {
                'broker_url'                 => "redis://${redis_host}:${redis_queue_port}",
                'result_backend'             => "redis://${redis_host}:${redis_queue_port}",
                'worker_concurrency'         => $celery_workers,
                'queue_maxsize'              => $celery_queue_maxsize,
                'lock_manager'               => 'pool_counter',
                'task_tracker'               => 'redis',
                'task_create_missing_queues' => true,
                # T210103: Temporarily whitelist fu-berlin.de
                'whitelisted_ips'            => [
                    '87.77.0.0/16',
                    '160.45.0.0/16',
                ],
                'worker_max_tasks_per_child' => '100',
            },
        },
        'lock_managers' => {
            'pool_counter' => $poolcounter_nodes,
        },
        'logging' => {
            'handlers' => {
                'logstash' => {
                    'host' => $logstash_host,
                    'port' => $logstash_port,
                },
            },
        },
    }
    if $redis_password {
        $pass_config = {
            'score_caches' => {
                'ores_redis' => {
                    'password' => $redis_password,
                },
            },
            'task_trackers' => {
                'redis' => {
                    'password' => $redis_password,
                },
            },
            'scoring_systems' => {
                'celery_queue' => {
                    'broker_url'     => "redis://:${redis_password}@${redis_host}:${redis_queue_port}",
                    'result_backend' => "redis://:${redis_password}@${redis_host}:${redis_queue_port}",
                },
            },
        }
        $config = deep_merge($base_config, $pass_config)
    } else {
        $config = $base_config
    }
    # lint:endignore

    if $extra_config {
        $final_config = deep_merge($config, $extra_config)
    } else {
        $final_config = $config
    }

    # For now puppet ships the config until we migrate it to scap3 as well
    ores::config { 'main':
        config   => $final_config,
        priority => '99',
        mode     => '0444',
        owner    => $ores_config_user,
        group    => $ores_config_group,
    }

}