Puppet Class: profile::maps::osm_master

Defined in:
modules/profile/manifests/maps/osm_master.pp

Overview

SPDX-License-Identifier: Apache-2.0

Parameters:

  • planet_sync_period (String) (defaults to: lookup('profile::maps::osm_master::planet_sync_period', { 'default_value' => 'hour' }))
  • planet_sync_day (String) (defaults to: lookup('profile::maps::osm_master::planet_sync_day', { 'default_value' => '*' }))
  • planet_sync_hours (Variant[String,Integer]) (defaults to: lookup('profile::maps::osm_master::planet_sync_hours', { 'default_value' => '*' }))
  • planet_sync_minute (Variant[String,Integer]) (defaults to: lookup('profile::maps::osm_master::planet_sync_minute', { 'default_value' => '00' }))
  • maps_hosts (Array[Stdlib::Host]) (defaults to: lookup('profile::maps::hosts'))
  • kartotherian_pass (String) (defaults to: lookup('profile::maps::osm_master::kartotherian_pass'))
  • tilerator_pass (String) (defaults to: lookup('profile::maps::osm_master::tilerator_pass'))
  • replication_pass (String) (defaults to: lookup('profile::maps::osm_master::replication_pass'))
  • swift_key_id (String) (defaults to: lookup('profile::maps::osm_master::swift_key_id'))
  • swift_password (String) (defaults to: lookup('profile::maps::osm_master::swift_password'))
  • tegola_swift_container (String) (defaults to: lookup('profile::maps::osm_master::tegola_swift_container'))
  • postgres_replicas (Hash[String, Struct[{ip_address => Stdlib::IP::Address}]]) (defaults to: lookup('profile::maps::osm_master::replicas', { 'default_value' => {}}))
  • osm_engine (String) (defaults to: lookup('profile::maps::osm_master::engine', { 'default_value' => 'osm2pgsql' }))
  • disable_replication_cron (Boolean) (defaults to: lookup('profile::maps::osm_master::disable_replication_cron', { 'default_value' => false }))
  • disable_tile_generation_cron (Boolean) (defaults to: lookup('profile::maps::osm_master::disable_tile_generation_cron', { 'default_value' => false }))
  • disable_admin_timer (Boolean) (defaults to: lookup('profile::maps::osm_master::disable_admin_timer', { 'default_value' => false }))
  • use_proxy (Boolean) (defaults to: lookup('profile::maps::apps::use_proxy'))
  • eventgate_endpoint (String) (defaults to: lookup('profile::maps::osm_master::eventgate_endpoint'))
  • log_min_duration_statement (Optional[Integer[250]]) (defaults to: lookup('profile::maps::osm_master::log_min_duration_statement', { 'default_value' => undef }))
  • use_replication_slots (Boolean) (defaults to: lookup('profile::maps::osm_master::use_replication_slots'))


2
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
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
# File 'modules/profile/manifests/maps/osm_master.pp', line 2

class profile::maps::osm_master (
    String $planet_sync_period                   = lookup('profile::maps::osm_master::planet_sync_period', { 'default_value' => 'hour' }),
    String $planet_sync_day                      = lookup('profile::maps::osm_master::planet_sync_day', { 'default_value' => '*' }),
    Variant[String,Integer]$planet_sync_hours    = lookup('profile::maps::osm_master::planet_sync_hours', { 'default_value' => '*' }),
    Variant[String,Integer] $planet_sync_minute  = lookup('profile::maps::osm_master::planet_sync_minute', { 'default_value' => '00' }),
    Array[Stdlib::Host] $maps_hosts              = lookup('profile::maps::hosts'),
    String $kartotherian_pass                    = lookup('profile::maps::osm_master::kartotherian_pass'),
    String $tilerator_pass                       = lookup('profile::maps::osm_master::tilerator_pass'),
    String $replication_pass                     = lookup('profile::maps::osm_master::replication_pass'),
    String $swift_key_id                         = lookup('profile::maps::osm_master::swift_key_id'),
    String $swift_password                       = lookup('profile::maps::osm_master::swift_password'),
    String $tegola_swift_container               = lookup('profile::maps::osm_master::tegola_swift_container'),
    Hash[String, Struct[{ip_address => Stdlib::IP::Address}]] $postgres_replicas = lookup('profile::maps::osm_master::replicas', { 'default_value' => {}}),
    String $osm_engine                           = lookup('profile::maps::osm_master::engine', { 'default_value' => 'osm2pgsql' }),
    Boolean $disable_replication_cron            = lookup('profile::maps::osm_master::disable_replication_cron', { 'default_value' => false }),
    Boolean $disable_tile_generation_cron        = lookup('profile::maps::osm_master::disable_tile_generation_cron', { 'default_value' => false }),
    Boolean $disable_admin_timer                 = lookup('profile::maps::osm_master::disable_admin_timer', { 'default_value' => false }),
    Boolean $use_proxy                           = lookup('profile::maps::apps::use_proxy'),
    String $eventgate_endpoint                         = lookup('profile::maps::osm_master::eventgate_endpoint'),
    Optional[Integer[250]] $log_min_duration_statement = lookup('profile::maps::osm_master::log_min_duration_statement', { 'default_value' => undef }),
    Boolean $use_replication_slots               = lookup('profile::maps::osm_master::use_replication_slots'),

) {

    require profile::maps::postgresql_common
    include network::constants

    $tegola_networks = flatten([
        $network::constants::services_kubepods_networks,
        $network::constants::staging_kubepods_networks,
    ])

    $maps_hosts_ferm = join($maps_hosts, ' ')

    $db_name = 'gis'

    $pgversion = $::lsbdistcodename ? {
        'bullseye'  => 13,
        'buster'  => 11,
    }

    # We need 1 connection per host that is fully pooled. If we want
    # to pool additional hosts, we need TWO connections per host (one
    # for the backup thread, and one for the streaming of new logs
    # thread). 6 will give us the overhead to allow for 3 new hosts to
    # be added at once in case we need this.
    $max_senders = length($maps_hosts) + 6

    # We iterate through all maps hosts of the DC, and skip ourselves (master)
    $replication_slots = $use_replication_slots ? {
        true    => $maps_hosts.map |$replica| {
                    if $facts['networking']['fqdn'] != $replica {
                        "wal_${replica.regsubst('\.', '_', 'G')}"
                    }
                    else {
                        undef
                    }
                }
                .filter |$replica| {
                        $replica != undef
                },
        default => [],
      }

    class { 'postgresql::master':
        root_dir                   => '/srv/postgresql',
        includes                   => [ 'tuning.conf', 'logging.conf' ],
        checkpoint_segments        => 768,
        wal_keep_segments          => 768,
        max_wal_senders            => $max_senders,
        log_min_duration_statement => $log_min_duration_statement,
        replication_slots          => $replication_slots,

    }

    class { '::osm': }
    class { '::osm::import_waterlines':
        use_proxy  => $use_proxy,
        proxy_host => "webproxy.${::site}.wmnet",
        proxy_port => 8080,
    }

    # Users
    postgresql::user { 'kartotherian':
        user     => 'kartotherian',
        password => $kartotherian_pass,
        database => $db_name,
    }
    postgresql::user { 'osmimporter@localhost':
        user     => 'osmimporter',
        database => $db_name,
        type     => 'local',
        method   => 'peer'
    }
    postgresql::user { 'osmupdater@localhost':
        user     => 'osmupdater',
        database => $db_name,
        type     => 'local',
        method   => 'peer'
    }
    postgresql::user { 'prometheus@localhost':
        user     => 'prometheus',
        database => 'postgres',
        type     => 'local',
        method   => 'peer',
    }

    profile::maps::tilerator_user { 'localhost':
        ip_address => '127.0.0.1/32',
        password   => $tilerator_pass,
    }
    # tegola-vector-tiles will connect as user tilerator from
    # kubernetes pods.
    $tegola_networks.each |String $subnet| {
        if $subnet =~ Stdlib::IP::Address::V4 {
            $_subnet = split($subnet, '/')[0]
            profile::maps::tilerator_user { "${_subnet}_kubepod":
            ip_address => $subnet,
            password   => $tilerator_pass,
            }
        }
    }

    if $postgres_replicas {
        create_resources(
            profile::maps::tilerator_user,
            $postgres_replicas,
            { password => $tilerator_pass }
        )
    }

    # Grants
    file { "/usr/local/bin/maps-grants-${db_name}.sql":
        owner   => 'root',
        group   => 'root',
        mode    => '0400',
        content => template('profile/maps/grants-db.sql.erb'),
    }
    file { '/usr/local/bin/maps-grants-tiles.sql':
        owner   => 'root',
        group   => 'root',
        mode    => '0400',
        content => template('profile/maps/grants-tiles.sql.erb'),
    }

    # DB setup
    postgresql::spatialdb { $db_name: }

    # some additional logging for the postgres master to help diagnose import
    # performance issues
    file { "/etc/postgresql/${pgversion}/main/logging.conf":
        ensure => 'present',
        owner  => 'root',
        group  => 'root',
        mode   => '0444',
        source => 'puppet:///modules/profile/maps/logging.conf',
    }

    file { '/root/.tegola_credentials':
        ensure  => 'present',
        mode    => '0600',
        owner   => 'root',
        group   => 'root',
        content => template('profile/maps/swift_config.erb'),
    }

    if $postgres_replicas {
        $postgres_replicas_defaults = {
            replication_pass => $replication_pass,
        }
        create_resources(postgresql::slave_users, $postgres_replicas, $postgres_replicas_defaults)
    }

    osm::planet_sync { $db_name:
        ensure                       => present,
        engine                       => $osm_engine,
        flat_nodes                   => true,
        expire_levels                => 15,
        num_threads                  => 4,
        use_proxy                    => $use_proxy,
        proxy_host                   => "webproxy.${::site}.wmnet",
        proxy_port                   => 8080,
        period                       => $planet_sync_period,
        day                          => $planet_sync_day,
        hours                        => $planet_sync_hours,
        minute                       => $planet_sync_minute,
        disable_replication_cron     => $disable_replication_cron,
        disable_tile_generation_cron => $disable_tile_generation_cron,
        eventgate_endpoint           => $eventgate_endpoint,
        swift_key_id                 => $swift_key_id,
        swift_password               => $swift_password,
        tegola_swift_container       => $tegola_swift_container
    }

    if ($osm_engine == 'osm2pgsql') {
        file { '/usr/local/bin/grants-populate-admin.sql':
            owner  => 'postgres',
            group  => 'postgres',
            mode   => '0400',
            source => 'puppet:///modules/profile/maps/grants-populate-admin.sql',
        }
        osm::populate_admin { $db_name:
            ensure              => present,
            disable_admin_timer => $disable_admin_timer,
        }
    }

    $state_path = $osm_engine ? {
        'imposm3' => '/srv/osm/diff/last.state.txt',
        'osm2pgsql' => '/srv/osmosis/state.txt'
    }

    class { 'osm::prometheus':
        state_path      => $state_path,
        prometheus_path => '/var/lib/prometheus/node.d/osm_sync_lag.prom',
    }

    # Access to postgres master from postgres replicas
    ferm::service { 'postgres_maps':
        proto  => 'tcp',
        port   => '5432',
        srange => "@resolve((${maps_hosts_ferm}))",
    }

    # Enable venvs for ad-hoc python scripts
    ensure_packages('python3-venv')

    # Install kafkacat and python libs to interract with kafka for dev/debug reasons
    ensure_packages(['kafkacat', 'python3-kafka', 'python3-snappy'])

    # Install dependencies to interract with swift storage
    ensure_packages(['swift', 'python3-swiftclient', 's3cmd', 'python3-boto'])

    # T290982
    ensure_packages('python3-maps-deduped-tilelist')
}