Puppet Class: profile::restbase

Defined in:
modules/profile/manifests/restbase.pp

Overview

class profile::restbase

sets up a REST API & storage service

Parameters

cassandra_user

Cassandra user name.

cassandra_password

Cassandra password.

seeds

Array of cassandra hosts (IP or host names) to contact.

seeds_ng

Array of cassandra hosts (IP or host names) to contact (next-gen storage module).

cassandra_local_dc

Which DC should be considered local.

cassandra_datacenters

The full list of member datacenters.

cassandra_tls

An associative array of TLS options for the Cassandra driver. See: nodejs.org/api/tls.html#tls_tls_createsecurecontext_options

logging_label

The logging label to use both for logging and statsd.

monitor_restbase

Whether RESTBase HTTP root monitoring is enabled. (true/false)

monitor_domain

The domain to monitor during the service's operation.

hosts

The list of RESTBase hosts used for setting up the rate-limiting DHT.

In production, URIs are looked up automatically. In other environments, you will need to define via hiera the following variables:

parsoid_uri

URI to reach Parsoid. Format: parsoid.svc.eqiad.wmnet:8000

mobileapps_uri

MobileApps service URI. Format: mobileapps.svc.eqiad.wmnet:4102

mathoid_uri

Mathoid service URI. Format: mathoid.svc.eqiad.wmnet:4001

aqs_uri

Analytics Query Service URI. Format: aqs.svc.eqiad.wmnet:7232/analytics.wikimedia.org/v1

event_service_uri

Eventgate service URI. Format: eventgate-main.discovery.wmnet:4492/v1/events

proton_uri

Proton PDF Render service URI. Format: proton.discovery.wmnet:4030

citoid_uri

Citoid service URI. Format: citoid.svc.eqiad.wmnet:1970

cxserver_uri

CXServer service uri. Format: cxserver.discovery.wmnet:4002

recommendation_uri

Recommendation API service URI. Format: recommendation-api.discovery.wmnet:9632

wikifeeds_uri

Wikifeeds service URI. Format: wikifeeds.discovery.wmnet:4101

Parameters:

  • cassandra_user (Any) (defaults to: lookup('profile::restbase::cassandra_user'))
  • cassandra_password (Any) (defaults to: lookup('profile::restbase::cassandra_password'))
  • no_workers (Any) (defaults to: lookup('profile::restbase::no_workers', {'default_value' => 'ncpu'}))
  • seeds_ng (Any) (defaults to: lookup('profile::restbase::seeds_ng', {'default_value' => []}))
  • hosts (Any) (defaults to: lookup('profile::restbase::hosts'))
  • cassandra_local_dc (Any) (defaults to: lookup('profile::restbase::cassandra_local_dc'))
  • cassandra_datacenters (Any) (defaults to: lookup('profile::restbase::cassandra_datacenters'))
  • cassandra_tls (Any) (defaults to: lookup('profile::restbase::cassandra_tls', {'default_value' => {}}))
  • salt_key (Any) (defaults to: lookup('profile::restbase::salt_key'))
  • logging_label (Any) (defaults to: lookup('profile::restbase::logging_label'))
  • listeners (Any) (defaults to: lookup('profile::services_proxy::envoy::listeners'))
  • parsoid_uri (Any) (defaults to: lookup( 'profile::restbase::parsoid_uri', {'default_value' => wmflib::service::get_url('mw-parsoid', '/w/rest.php', $listeners)} ))
  • mobileapps_uri (Any) (defaults to: lookup( 'profile::restbase::mobileapps_uri', {'default_value' => wmflib::service::get_url('mobileapps', '', $listeners)} ))
  • mathoid_uri (Any) (defaults to: lookup( 'profile::restbase::mathoid_uri', {'default_value' => wmflib::service::get_url('mathoid', '', $listeners)} ))
  • aqs_uri (Any) (defaults to: lookup('profile::restbase::aqs_uri'))
  • event_service_uri (Any) (defaults to: lookup( 'profile::restbase::event_service_uri', {'default_value' => wmflib::service::get_url('eventgate-main','/v1/events', $listeners)} ))
  • proton_uri (Any) (defaults to: lookup( 'profile::restbase::proton_uri', {'default_value' => wmflib::service::get_url('proton', '', $listeners)} ))
  • citoid_uri (Any) (defaults to: lookup( 'profile::restbase::citoid_uri', {'default_value' => wmflib::service::get_url('citoid', '', $listeners)} ))
  • cxserver_uri (Any) (defaults to: lookup( 'profile::restbase::cxserver_uri', {'default_value' => wmflib::service::get_url('cxserver', '', $listeners)} ))
  • recommendation_uri (Any) (defaults to: lookup( 'profile::restbase::recommendation_uri', {'default_value' => wmflib::service::get_url('recommendation', '', $listeners)} ))
  • wikifeeds_uri (Any) (defaults to: lookup( 'profile::restbase::wikifeeds_uri', {'default_value' => wmflib::service::get_url('wikifeeds', '', $listeners)} ))
  • monitor_restbase (Any) (defaults to: lookup('profile::restbase::monitor_restbase', {'default_value' => true}))
  • monitor_domain (Any) (defaults to: lookup('profile::restbase::monitor_domain'))


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
# File 'modules/profile/manifests/restbase.pp', line 75

class profile::restbase(
    $cassandra_user = lookup('profile::restbase::cassandra_user'),
    $cassandra_password = lookup('profile::restbase::cassandra_password'),
    $no_workers = lookup('profile::restbase::no_workers', {'default_value' => 'ncpu'}),
    $seeds_ng = lookup('profile::restbase::seeds_ng', {'default_value' => []}),
    $hosts = lookup('profile::restbase::hosts'),
    $cassandra_local_dc = lookup('profile::restbase::cassandra_local_dc'),
    $cassandra_datacenters = lookup('profile::restbase::cassandra_datacenters'),
    $cassandra_tls = lookup('profile::restbase::cassandra_tls', {'default_value' => {}}),
    $salt_key = lookup('profile::restbase::salt_key'),
    $logging_label = lookup('profile::restbase::logging_label'),
    $listeners  = lookup('profile::services_proxy::envoy::listeners'),
    $parsoid_uri = lookup(
        'profile::restbase::parsoid_uri',
        {'default_value' => wmflib::service::get_url('mw-parsoid', '/w/rest.php', $listeners)}
    ),
    $mobileapps_uri = lookup(
        'profile::restbase::mobileapps_uri',
        {'default_value' => wmflib::service::get_url('mobileapps', '', $listeners)}
    ),
    $mathoid_uri    = lookup(
        'profile::restbase::mathoid_uri',
        {'default_value' => wmflib::service::get_url('mathoid', '', $listeners)}
    ),
    $aqs_uri        = lookup('profile::restbase::aqs_uri'),
    $event_service_uri = lookup(
        'profile::restbase::event_service_uri',
        {'default_value' => wmflib::service::get_url('eventgate-main','/v1/events', $listeners)}
    ),
    $proton_uri     = lookup(
        'profile::restbase::proton_uri',
        {'default_value' => wmflib::service::get_url('proton', '', $listeners)}
    ),
    $citoid_uri     = lookup(
        'profile::restbase::citoid_uri',
        {'default_value' => wmflib::service::get_url('citoid', '', $listeners)}
    ),
    $cxserver_uri   = lookup(
        'profile::restbase::cxserver_uri',
        {'default_value' => wmflib::service::get_url('cxserver', '', $listeners)}
    ),
    $recommendation_uri = lookup(
        'profile::restbase::recommendation_uri',
        {'default_value' => wmflib::service::get_url('recommendation', '', $listeners)}
    ),
    $wikifeeds_uri  = lookup(
        'profile::restbase::wikifeeds_uri',
        {'default_value' => wmflib::service::get_url('wikifeeds', '', $listeners)}
    ),
    $monitor_restbase = lookup('profile::restbase::monitor_restbase', {'default_value' => true}),
    $monitor_domain = lookup('profile::restbase::monitor_domain'),
) {
    # Default values that need no overriding
    $port = 7231
    $page_size = 250

    require ::service::configuration
    $local_logfile = "${service::configuration::log_dir}/${title}/main.log"

    # Uris
    service::node { 'restbase':
        port              => $port,
        no_workers        => $no_workers,
        no_file           => 200000,
        healthcheck_url   => "/${monitor_domain}/v1",
        icinga_check      => false, # done via service::catalog 'probes'
        has_spec          => true,
        starter_script    => 'restbase/server.js',
        auto_refresh      => false,
        deployment        => 'scap3',
        deployment_config => true,
        deployment_vars   => {
            ipaddress             => $::ipaddress,
            rl_seeds              => reject(reject($hosts, $::hostname), $::ipaddress),
            seeds_ng              => $seeds_ng,
            cassandra_local_dc    => $cassandra_local_dc,
            cassandra_datacenters => $cassandra_datacenters,
            cassandra_user        => $cassandra_user,
            cassandra_password    => $cassandra_password,
            cassandra_tls         => $cassandra_tls,
            parsoid_uri           => $parsoid_uri,
            mathoid_uri           => $mathoid_uri,
            mobileapps_uri        => $mobileapps_uri,
            citoid_uri            => $citoid_uri,
            event_service_uri     => $event_service_uri,
            proton_uri            => $proton_uri,
            cxserver_uri          => $cxserver_uri,
            recommendation_uri    => $recommendation_uri,
            wikifeeds_uri         => $wikifeeds_uri,
            aqs_uri               => $aqs_uri,
            salt_key              => $salt_key,
            page_size             => $page_size,
        },
        logging_name      => $logging_label,
        statsd_prefix     => $logging_label,
    }

    sysctl::parameters { 'tcp_performance':
        values => {
            # Allow TIME_WAIT connection reuse state as attempt to
            # reduce the usage of ephemeral ports.
            # See <http://vincent.bernat.im/en/blog/2014-tcp-time-wait-state-linux.html>
            'net.ipv4.tcp_tw_reuse' => 1,
        },
    }

    $ensure_monitor_restbase = $monitor_restbase ? {
        true    => present,
        false   => absent,
        default => present,
    }

    monitoring::service { 'restbase_http_root':
        ensure        => $ensure_monitor_restbase,
        description   => 'Restbase root url',
        check_command => "check_http_port_url!${port}!/",
        contact_group => 'admins,team-services',
        notes_url     => 'https://wikitech.wikimedia.org/wiki/RESTBase',
    }


    nrpe::monitor_service { 'restbase_instance_space':
        ensure       => $ensure_monitor_restbase,
        description  => 'Cassandra instance data free space',
        notes_url    => 'https://wikitech.wikimedia.org/wiki/RESTBase#instance-data',
        nrpe_command => '/usr/lib/nagios/plugins/check_disk -w 30% -c 20% -p /srv/cassandra/instance-data',
    }


    # RESTBase rate limiting DHT firewall rule
    $rb_hosts_ferm = join($hosts, ' ')
    ferm::service { 'restbase-ratelimit':
        proto  => 'tcp',
        port   => '3050',
        srange => "@resolve((${rb_hosts_ferm}))",
    }

    # TEMP for T223953
    # Allow access to 7233 as well. Once RESTRouter is used, remove
    # this block and entirely and change the port to 7233
    ferm::service {'restbase_web':
        proto => 'tcp',
        port  => '7233',
    }
    # END TEMP

}