Puppet Class: profile::logstash::collector7

Defined in:
modules/profile/manifests/logstash/collector7.pp

Overview

vim:sw=4 ts=4 sts=4 et:

Class: profile::logstash::collector7

Provisions Logstash and an Elasticsearch node to proxy requests to ELK stack Elasticsearch cluster.

Parameters:

  • $input_kafka_ssl_truststore_passwords: Hash of kafka cluster name to password for jks truststore used by logstash kafka input plugin, e.g. $input_kafka_ssl_truststore_passwords == 'XXXXXX', etc.

Parameters:

  • input_kafka_ssl_truststore_passwords (Hash[String, String]) (defaults to: lookup('profile::logstash::collector::input_kafka_ssl_truststore_passwords'))
  • input_kafka_consumer_group_id (Optional[String]) (defaults to: lookup('profile::logstash::collector::input_kafka_consumer_group_id', {'default_value' => undef}))
  • jmx_exporter_port (Stdlib::Port) (defaults to: lookup('profile::logstash::collector::jmx_exporter_port', {'default_value' => 7800}))
  • maintenance_hosts (Array[Stdlib::Host]) (defaults to: lookup('maintenance_hosts', {'default_value' => []}))
  • dc_settings (Elasticsearch::InstanceParams) (defaults to: lookup('profile::elasticsearch::dc_settings'))


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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'modules/profile/manifests/logstash/collector7.pp', line 12

class profile::logstash::collector7 (
    Hash[String, String] $input_kafka_ssl_truststore_passwords = lookup('profile::logstash::collector::input_kafka_ssl_truststore_passwords'),
    Optional[String] $input_kafka_consumer_group_id = lookup('profile::logstash::collector::input_kafka_consumer_group_id', {'default_value' => undef}),
    Stdlib::Port $jmx_exporter_port = lookup('profile::logstash::collector::jmx_exporter_port', {'default_value' => 7800}),
    Array[Stdlib::Host] $maintenance_hosts = lookup('maintenance_hosts', {'default_value' => []}),
    Elasticsearch::InstanceParams $dc_settings = lookup('profile::elasticsearch::dc_settings'),
) {

    require ::profile::java

    $config_dir = '/etc/prometheus'
    $jmx_exporter_config_file = "${config_dir}/logstash_jmx_exporter.yaml"

    # Prometheus JVM metrics
    profile::prometheus::jmx_exporter { "logstash_collector_${::hostname}":
        hostname    => $::hostname,
        port        => $jmx_exporter_port,
        config_file => $jmx_exporter_config_file,
        config_dir  => $config_dir,
        source      => 'puppet:///modules/profile/logstash/jmx_exporter.yaml',
    }

    class { '::logstash':
        jmx_exporter_port   => $jmx_exporter_port,
        jmx_exporter_config => $jmx_exporter_config_file,
        pipeline_workers    => $::processorcount * 2,
        manage_service      => false,
        log_format          => 'json',
        enable_dlq          => true,
        dlq_hosts           => $dc_settings['cluster_hosts'],
    }

    sysctl::parameters { 'logstash_receive_skbuf':
        values => {
            'net.core.rmem_default' => 8388608,
        },
    }

    systemd::service { 'logstash':
        ensure   => present,
        content  => init_template('logstash', 'systemd_override'),
        override => true,
        restart  => true,
    }

    ## Inputs (10)

    ferm::service { 'grafana_dashboard_definition_storage':
        proto  => 'tcp',
        port   => '9200',
        srange => '@resolve((grafana1002.eqiad.wmnet))',
    }

    $maintenance_hosts_str = join($maintenance_hosts, ' ')
    ferm::service { 'logstash_canary_checker_reporting':
        proto  => 'tcp',
        port   => '9200',
        srange => "(\$DEPLOYMENT_HOSTS ${maintenance_hosts_str})",
    }

    logstash::input::dlq { 'main': }

    # Logstash collectors in both sites pull messages
    # from logging kafka clusters in both DCs.
    logstash::input::kafka { 'rsyslog-shipper-eqiad':
        kafka_cluster_name                    => 'logging-eqiad',
        topics_pattern                        => 'rsyslog-.*',
        group_id                              => $input_kafka_consumer_group_id,
        type                                  => 'syslog',
        tags                                  => ['input-kafka-rsyslog-shipper', 'rsyslog-shipper', 'kafka', 'es'],
        codec                                 => 'json',
        security_protocol                     => 'SSL',
        ssl_truststore_password               => $input_kafka_ssl_truststore_passwords['logging-eqiad'],
        ssl_endpoint_identification_algorithm => '',
        consumer_threads                      => 3,
    }

    logstash::input::kafka { 'rsyslog-shipper-codfw':
        kafka_cluster_name                    => 'logging-codfw',
        topics_pattern                        => 'rsyslog-.*',
        group_id                              => $input_kafka_consumer_group_id,
        type                                  => 'syslog',
        tags                                  => ['rsyslog-shipper','kafka', 'es'],
        codec                                 => 'json',
        security_protocol                     => 'SSL',
        ssl_truststore_password               => $input_kafka_ssl_truststore_passwords['logging-codfw'],
        ssl_endpoint_identification_algorithm => '',
    }

    logstash::input::kafka { 'rsyslog-udp-localhost-eqiad':
        kafka_cluster_name                    => 'logging-eqiad',
        topics_pattern                        => 'udp_localhost-.*',
        group_id                              => $input_kafka_consumer_group_id,
        type                                  => 'syslog',
        tags                                  => ['input-kafka-rsyslog-udp-localhost', 'rsyslog-udp-localhost', 'kafka', 'es'],
        codec                                 => 'json',
        security_protocol                     => 'SSL',
        ssl_truststore_password               => $input_kafka_ssl_truststore_passwords['logging-eqiad'],
        ssl_endpoint_identification_algorithm => '',
    }

    logstash::input::kafka { 'rsyslog-udp-localhost-codfw':
        kafka_cluster_name                    => 'logging-codfw',
        topics_pattern                        => 'udp_localhost-.*',
        group_id                              => $input_kafka_consumer_group_id,
        type                                  => 'syslog',
        tags                                  => ['rsyslog-udp-localhost','kafka', 'es'],
        codec                                 => 'json',
        security_protocol                     => 'SSL',
        ssl_truststore_password               => $input_kafka_ssl_truststore_passwords['logging-codfw'],
        ssl_endpoint_identification_algorithm => '',
        consumer_threads                      => 3,
    }

    logstash::input::kafka { 'rsyslog-logback-eqiad':
        kafka_cluster_name                    => 'logging-eqiad',
        topics_pattern                        => 'logback.*',
        group_id                              => $input_kafka_consumer_group_id,
        type                                  => 'logback',
        tags                                  => ['input-kafka-rsyslog-logback', 'kafka-logging-eqiad', 'kafka', 'es'],
        codec                                 => 'json',
        security_protocol                     => 'SSL',
        ssl_truststore_password               => $input_kafka_ssl_truststore_passwords['logging-eqiad'],
        ssl_endpoint_identification_algorithm => '',
        consumer_threads                      => 3,
    }

    logstash::input::kafka { 'deprecated-eqiad':
        kafka_cluster_name                    => 'logging-eqiad',
        topics_pattern                        => 'deprecated.*',
        group_id                              => $input_kafka_consumer_group_id,
        tags                                  => ['input-kafka-deprecated', 'kafka-logging-eqiad', 'kafka', 'es'],
        codec                                 => 'json',
        security_protocol                     => 'SSL',
        ssl_truststore_password               => $input_kafka_ssl_truststore_passwords['logging-eqiad'],
        ssl_endpoint_identification_algorithm => '',
        consumer_threads                      => 3,
    }

    logstash::input::kafka { 'rsyslog-logback-codfw':
        kafka_cluster_name                    => 'logging-codfw',
        topics_pattern                        => 'logback.*',
        group_id                              => $input_kafka_consumer_group_id,
        type                                  => 'logback',
        tags                                  => ['input-kafka-rsyslog-logback', 'kafka-logging-codfw', 'kafka', 'es'],
        codec                                 => 'json',
        security_protocol                     => 'SSL',
        ssl_truststore_password               => $input_kafka_ssl_truststore_passwords['logging-codfw'],
        ssl_endpoint_identification_algorithm => '',
        consumer_threads                      => 3,
    }

    logstash::input::kafka { 'clienterror-eqiad':
        kafka_cluster_name                    => 'logging-eqiad',
        topics_pattern                        => 'eqiad\.mediawiki\.client\.error|eqiad\.kaios_app\.error',
        group_id                              => $input_kafka_consumer_group_id,
        type                                  => 'clienterror',
        tags                                  => ['input-kafka-clienterror-eqiad', 'kafka', 'es'],
        codec                                 => 'json',
        security_protocol                     => 'SSL',
        ssl_truststore_password               => $input_kafka_ssl_truststore_passwords['logging-eqiad'],
        ssl_endpoint_identification_algorithm => '',
        consumer_threads                      => 3,
    }

    logstash::input::kafka { 'clienterror-codfw':
        kafka_cluster_name                    => 'logging-codfw',
        topics_pattern                        => 'codfw\.mediawiki\.client\.error|codfw\.kaios_app\.error',
        group_id                              => $input_kafka_consumer_group_id,
        type                                  => 'clienterror',
        tags                                  => ['input-kafka-clienterror-codfw', 'kafka', 'es'],
        codec                                 => 'json',
        security_protocol                     => 'SSL',
        ssl_truststore_password               => $input_kafka_ssl_truststore_passwords['logging-codfw'],
        ssl_endpoint_identification_algorithm => '',
        consumer_threads                      => 3,
    }

    logstash::input::kafka { 'networkerror-eqiad':
        kafka_cluster_name                    => 'logging-eqiad',
        topic                                 => 'eqiad.w3c.reportingapi.network_error',
        group_id                              => $input_kafka_consumer_group_id,
        tags                                  => ['input-kafka-networkerror-eqiad', 'kafka', 'throttle-exempt'],
        codec                                 => 'json',
        security_protocol                     => 'SSL',
        ssl_truststore_password               => $input_kafka_ssl_truststore_passwords['logging-eqiad'],
        ssl_endpoint_identification_algorithm => '',
        consumer_threads                      => 3,
    }

    logstash::input::kafka { 'networkerror-codfw':
        kafka_cluster_name                    => 'logging-codfw',
        topic                                 => 'codfw.w3c.reportingapi.network_error',
        group_id                              => $input_kafka_consumer_group_id,
        tags                                  => ['input-kafka-networkerror-codfw', 'kafka', 'throttle-exempt'],
        codec                                 => 'json',
        security_protocol                     => 'SSL',
        ssl_truststore_password               => $input_kafka_ssl_truststore_passwords['logging-codfw'],
        ssl_endpoint_identification_algorithm => '',
        consumer_threads                      => 3,
    }

    # Collect all EventGate instance error.validation topics into logstash.
    # Maps logstash::input::kafka title to a kafka cluster and topic to consume.
    $eventgate_validation_error_logstash_inputs = {

        # eventgate-main uses both Kafka main-eqiad and main-codfw
        'eventgate-main-validation-error-eqiad' => {
            'kafka_cluster_name' => 'main-eqiad',
            'topic' => 'eqiad.eventgate-main.error.validation'
        },
        'eventgate-main-validation-error-codfw' => {
            'kafka_cluster_name' => 'main-codfw',
            'topic' => 'codfw.eventgate-main.error.validation'
        },

        # eventgate-analytics uses only Kafka jumbo-eqiad
        'eventgate-analytics-validation-error-eqiad' => {
            'kafka_cluster_name' => 'jumbo-eqiad',
            'topic' => 'eqiad.eventgate-analytics.error.validation'
        },
        'eventgate-analytics-validation-error-codfw' => {
            'kafka_cluster_name' => 'jumbo-eqiad',
            'topic' => 'codfw.eventgate-analytics.error.validation'
        },

        # eventgate-analytics-external uses only Kafka jumbo-eqiad
        'eventgate-analytics-external-validation-error-eqiad' => {
            'kafka_cluster_name' => 'jumbo-eqiad',
            'topic' => 'eqiad.eventgate-analytics-external.error.validation'
        },
        'eventgate-analytics-external-validation-error-codfw' => {
            'kafka_cluster_name' => 'jumbo-eqiad',
            'topic' => 'codfw.eventgate-analytics-external.error.validation'
        },

        # eventgate-logging-external uses both Kafka logging-eqiad and logging-codfw
        'eventgate-logging-external-validation-error-eqiad' => {
            'kafka_cluster_name' => 'logging-eqiad',
            'topic' => 'eqiad.eventgate-logging-external.error.validation'
        },
        'eventgate-logging-external-validation-error-codfw' => {
            'kafka_cluster_name' => 'logging-codfw',
            'topic' => 'codfw.eventgate-logging-external.error.validation'
        },
    }
    $eventgate_validation_error_logstash_inputs.each |String $input_title, $input_params| {
        logstash::input::kafka { $input_title:
            kafka_cluster_name                    => $input_params['kafka_cluster_name'],
            topic                                 => $input_params['topic'],
            group_id                              => $input_kafka_consumer_group_id,
            type                                  => 'eventgate_validation_error',
            tags                                  => ["input-kafka-${input_title}", 'kafka', 'es', 'eventgate'],
            codec                                 => 'json',
            security_protocol                     => 'SSL',
            ssl_truststore_password               => $input_kafka_ssl_truststore_passwords[$input_params['kafka_cluster_name']],
            ssl_endpoint_identification_algorithm => '',
            consumer_threads                      => 3,
        }
    }

    # TODO: Rename this, this is the EventLogging event error topic input.
    $kafka_topic_eventlogging        = 'eventlogging_EventError'
    logstash::input::kafka { $kafka_topic_eventlogging:
        kafka_cluster_name                    => 'jumbo-eqiad',
        topic                                 => $kafka_topic_eventlogging,
        group_id                              => $input_kafka_consumer_group_id,
        tags                                  => [$kafka_topic_eventlogging, 'kafka', 'input-kafka-eventlogging', 'es'],
        type                                  => 'eventlogging',
        codec                                 => 'json',
        ssl_endpoint_identification_algorithm => '',
    }

    ## Global pre-processing (15)

    # move files into module?
    # lint:ignore:puppet_url_without_modules
    file { '/etc/logstash/conf.d':
      ensure  => directory,
      source  => 'puppet:///modules/profile/logstash/filters',
      owner   => 'logstash',
      group   => 'logstash',
      mode    => '0440',
      recurse => true,
      purge   => true,
      force   => true,
    }

    file { '/etc/logstash/filter_scripts':
        ensure  => directory,
        source  => 'puppet:///modules/profile/logstash/filter_scripts',
        owner   => 'logstash',
        group   => 'logstash',
        mode    => '0444',
        recurse => true,
        purge   => true,
        force   => true,
    }

    file { '/etc/logstash/templates':
        ensure  => directory,
        source  => 'puppet:///modules/profile/logstash/templates',
        owner   => 'logstash',
        group   => 'logstash',
        mode    => '0444',
        recurse => true,
        purge   => true,
        force   => true,
    }
    # lint:endignore

    ## Outputs (90)
    logstash::output::elasticsearch { 'logstash':
        host            => '127.0.0.1',
        guard_condition => '"es" in [tags] and ![ecs]',
        index           => '%{[@metadata][index_name]}-%{+YYYY.MM.dd}',
        priority        => 90,
        template        => '/etc/logstash/templates/logstash_7.0-1.json',
        require         => File['/etc/logstash/templates'],
    }

    # Generate a logstash output for each supported version.
    #
    # Installing a new template requires a new index in order for the changes to take effect.
    # Depending on the index pattern rotation schedule, the new index could take an inordinate amount
    # of time to actually rotate.  With a "%{YYYY.MM.dd}" date pattern, this means
    # rotation occurs each day at 00:00 UTC.
    # The concept of revision here works around this constraint to facilitate a shortened
    # "deploy to observable effects" turnaround time and does not restrict us to frequent index rotations.
    #
    # Expects a template file conforming to "ecs_<VERSION>-<REVISION>.json" in "profile/files/logstash/templates/"
    # The most recently built template can be found here: https://doc.wikimedia.org/ecs/#downloads
    #
    # Date templates for indexes use Joda Time pattern syntax (T298619):
    # https://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html
    #   x = weekyear
    #   Y = year of era
    #   M = month of year
    #   w = week of weekyear
    #   d = day of month
    #
    # NOTE: Week of weekyear (x) and year of era (Y) desynchronize when the new year does not fall on ISO first week [0].
    #       Only combine weekyear (x) with week of weekyear (w) when managing weekly indexes.
    #
    # [0] https://en.wikipedia.org/wiki/ISO_week_date#First_week
    $ecs_versions = {
        # version => revision
        '1.7.0'  => '5',
        '1.11.0' => '2'
    }
    $ecs_versions.each |String $ecs_version, String $ecs_revision| {
        logstash::output::elasticsearch { "ecs_${ecs_version}-${ecs_revision}":
          host            => '127.0.0.1',
          guard_condition => "\"es\" in [tags] and [ecs][version] == \"${ecs_version}\"",
          index           => "ecs-${ecs_version}-${ecs_revision}-%{[@metadata][partition]}-%{+xxxx.ww}",
          priority        => 90,
          template        => "/etc/logstash/templates/ecs_${ecs_version}-${ecs_revision}.json",
          require         => File['/etc/logstash/templates'],
        }
    }

    $w3creportingapi_versions = {
        # version => revision
        '1.0.0' => '2'
    }
    $w3creportingapi_versions.each |String $w3creportingapi_version, String $w3creportingapi_revision| {
        logstash::output::elasticsearch { "w3creportingapi-${w3creportingapi_version}-${w3creportingapi_revision}":
          host            => '127.0.0.1',
          guard_condition => "[\$schema] == \"/w3c/reportingapi/network_error/${w3creportingapi_version}\"",
          index           => "w3creportingapi-${w3creportingapi_version}-${w3creportingapi_revision}-%{+xxxx.ww}",
          priority        => 90,
          template        => "/etc/logstash/templates/w3creportingapi_${w3creportingapi_version}-${w3creportingapi_revision}.json",
          require         => File['/etc/logstash/templates'],
        }
    }

    logstash::output::elasticsearch { 'dlq-1.0.0-1':
      host            => '127.0.0.1',
      guard_condition => '[type] == "dlq"',
      index           => 'dlq-1.0.0-1-%{+YYYY.MM.dd}',
      priority        => 90,
      template        => '/etc/logstash/templates/dlq_1.0.0-1.json',
      require         => File['/etc/logstash/templates'],
    }

    # TODO: cleanup -- T256418
    package { 'prometheus-statsd-exporter':
        ensure => 'absent'
    }

    # Ship logstash service logs to ELK
    rsyslog::input::file { 'logstash-json':
        path => '/var/log/logstash/logstash-json.log'
    }

    # TODO: cleanup -- T277080
    mtail::program { 'logstash':
        ensure => absent,
        notify => Service['mtail'],
        source => 'puppet:///modules/mtail/programs/logstash.mtail',
    }
}