Puppet Class: profile::logstash::production

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

Overview

SPDX-License-Identifier: Apache-2.0 vim:sw=4 ts=4 sts=4 et:

Class: profile::logstash::production

Provisions a Logstash collector instance for the production environment

Parameters:

  • input_kafka_consumer_group_id (String) (defaults to: lookup('profile::logstash::collector::input_kafka_consumer_group_id', { 'default_value' => 'logstash' }))
  • maintenance_hosts (Array[Stdlib::Host]) (defaults to: lookup('maintenance_hosts', { 'default_value' => [] }))
  • output_public_loki_host (Optional[Stdlib::Fqdn]) (defaults to: lookup('profile::logstash::collector::output_public_loki_host', { 'default_value' => undef }))


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
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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# File 'modules/profile/manifests/logstash/production.pp', line 7

class profile::logstash::production (
  String                 $input_kafka_consumer_group_id = lookup('profile::logstash::collector::input_kafka_consumer_group_id', { 'default_value' => 'logstash' }),
  Array[Stdlib::Host]    $maintenance_hosts             = lookup('maintenance_hosts',                                           { 'default_value' => [] }),
  Optional[Stdlib::Fqdn] $output_public_loki_host       = lookup('profile::logstash::collector::output_public_loki_host',       { 'default_value' => undef }),
) {

  include profile::logstash::common
  include profile::base::certificates
  $ssl_truststore_location = profile::base::certificates::get_trusted_ca_jks_path()
  $ssl_truststore_password = profile::base::certificates::get_trusted_ca_jks_password()
  $manage_truststore = false

  # Allow logstash_checker.py from maintenance hosts.
  $maintenance_hosts_str = join($maintenance_hosts, ' ')
  ferm::service { 'logstash_canary_checker_reporting':
    proto  => 'tcp',
    port   => '9200',
    srange => "(\$DEPLOYMENT_HOSTS ${maintenance_hosts_str})",
  }

  # Inputs (10)
  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_location               => $ssl_truststore_location,
    ssl_truststore_password               => $ssl_truststore_password,
    manage_truststore                     => $manage_truststore,
    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_location               => $ssl_truststore_location,
    ssl_truststore_password               => $ssl_truststore_password,
    manage_truststore                     => $manage_truststore,
    ssl_endpoint_identification_algorithm => '',
  }

  # k8s dedicated topics https://phabricator.wikimedia.org/T366710
  logstash::input::kafka { 'k8s-eqiad':
    kafka_cluster_name                    => 'logging-eqiad',
    topics_pattern                        => 'k8s-.*',
    group_id                              => $input_kafka_consumer_group_id,
    auto_offset_reset                     => 'latest',
    type                                  => 'syslog',
    tags                                  => ['input-kafka-k8s', 'rsyslog-shipper', 'kafka', 'es'],
    codec                                 => 'json',
    security_protocol                     => 'SSL',
    ssl_truststore_location               => $ssl_truststore_location,
    ssl_truststore_password               => $ssl_truststore_password,
    manage_truststore                     => $manage_truststore,
    ssl_endpoint_identification_algorithm => '',
    consumer_threads                      => 3,
  }

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

  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_location               => $ssl_truststore_location,
    ssl_truststore_password               => $ssl_truststore_password,
    manage_truststore                     => $manage_truststore,
    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_location               => $ssl_truststore_location,
    ssl_truststore_password               => $ssl_truststore_password,
    manage_truststore                     => $manage_truststore,
    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_location               => $ssl_truststore_location,
    ssl_truststore_password               => $ssl_truststore_password,
    manage_truststore                     => $manage_truststore,
    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_location               => $ssl_truststore_location,
    ssl_truststore_password               => $ssl_truststore_password,
    manage_truststore                     => $manage_truststore,
    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_location               => $ssl_truststore_location,
    ssl_truststore_password               => $ssl_truststore_password,
    manage_truststore                     => $manage_truststore,
    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_location               => $ssl_truststore_location,
    ssl_truststore_password               => $ssl_truststore_password,
    manage_truststore                     => $manage_truststore,
    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_location               => $ssl_truststore_location,
    ssl_truststore_password               => $ssl_truststore_password,
    manage_truststore                     => $manage_truststore,
    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_location               => $ssl_truststore_location,
    ssl_truststore_password               => $ssl_truststore_password,
    manage_truststore                     => $manage_truststore,
    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_location               => $ssl_truststore_location,
    ssl_truststore_password               => $ssl_truststore_password,
    manage_truststore                     => $manage_truststore,
    ssl_endpoint_identification_algorithm => '',
    consumer_threads                      => 3,
  }

  logstash::input::kafka { 'mediawiki-httpd-accesslog-eqiad-sampled':
    kafka_cluster_name                    => 'logging-eqiad',
    topic                                 => 'mediawiki.httpd.accesslog-sampled',
    group_id                              => $input_kafka_consumer_group_id,
    type                                  => 'mw-accesslog-sampled',
    tags                                  => ['input-kafka-mediawiki-httpd-accesslog-eqiad-sampled', 'kafka', 'es'],
    codec                                 => 'json',
    security_protocol                     => 'SSL',
    ssl_truststore_location               => $ssl_truststore_location,
    ssl_truststore_password               => $ssl_truststore_password,
    manage_truststore                     => $manage_truststore,
    ssl_endpoint_identification_algorithm => '',
    consumer_threads                      => 3,
  }

  logstash::input::kafka { 'mediawiki-httpd-accesslog-codfw-sampled':
    kafka_cluster_name                    => 'logging-codfw',
    topic                                 => 'mediawiki.httpd.accesslog-sampled',
    group_id                              => $input_kafka_consumer_group_id,
    type                                  => 'mw-accesslog-sampled',
    tags                                  => ['input-kafka-mediawiki-httpd-accesslog-codfw-sampled', 'kafka', 'es'],
    codec                                 => 'json',
    security_protocol                     => 'SSL',
    ssl_truststore_location               => $ssl_truststore_location,
    ssl_truststore_password               => $ssl_truststore_password,
    manage_truststore                     => $manage_truststore,
    ssl_endpoint_identification_algorithm => '',
    consumer_threads                      => 3,
  }

  logstash::input::kafka { 'mediawiki-php-fpm-slowlog-eqiad':
    kafka_cluster_name                    => 'logging-eqiad',
    topic                                 => 'mediawiki.php-fpm.slowlog',
    group_id                              => $input_kafka_consumer_group_id,
    tags                                  => ['input-kafka-mediawiki-php-fpm-slowlog-eqiad', 'kafka', 'es'],
    codec                                 => 'json',
    security_protocol                     => 'SSL',
    ssl_truststore_location               => $ssl_truststore_location,
    ssl_truststore_password               => $ssl_truststore_password,
    manage_truststore                     => $manage_truststore,
    ssl_endpoint_identification_algorithm => '',
    consumer_threads                      => 3,
  }

  logstash::input::kafka { 'mediawiki-php-fpm-slowlog-codfw':
    kafka_cluster_name                    => 'logging-codfw',
    topic                                 => 'mediawiki.php-fpm.slowlog',
    group_id                              => $input_kafka_consumer_group_id,
    tags                                  => ['input-kafka-mediawiki-php-fpm-slowlog-codfw', 'kafka', 'es'],
    codec                                 => 'json',
    security_protocol                     => 'SSL',
    ssl_truststore_location               => $ssl_truststore_location,
    ssl_truststore_password               => $ssl_truststore_password,
    manage_truststore                     => $manage_truststore,
    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_location               => $ssl_truststore_location,
      ssl_truststore_password               => $ssl_truststore_password,
      manage_truststore                     => $manage_truststore,
      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 => '',
  }

  # Outputs (90)
  # logstash-* indexes output
  logstash::output::opensearch { 'logstash':
    host            => '127.0.0.1',
    guard_condition => '[@metadata][output] == "logstash"',
    index           => 'logstash-%{[@metadata][partition]}-%{[@metadata][policy_revision]}-7.0.0-1-%{[@metadata][datestamp_format]}',
    priority        => 90,
    template        => '/etc/logstash/templates/logstash_7.0-1.json',
    require         => File['/etc/logstash/templates'],
  }

  # loki output
  if ($output_public_loki_host) {
    logstash::output::loki { 'loki_public':
      host            => $output_public_loki_host,
      guard_condition => '[@metadata][output] == "loki"',
    }
  }

  # 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
  $dlq_versions = {
    # version => revision
    '1.0.0' => '1'
  }
  $dlq_versions.each |String $dlq_version, String $dlq_revision| {
    logstash::output::opensearch { "dlq-${dlq_version}-${dlq_revision}":
      host            => '127.0.0.1',
      guard_condition => "[@metadata][output] == \"dlq\" and [@metadata][template_version] == \"${dlq_version}\"",
      index           => "dlq-%{[@metadata][partition]}-%{[@metadata][policy_revision]}-${dlq_version}-${dlq_revision}-%{[@metadata][datestamp_format]}",
      priority        => 90,
      template        => "/etc/logstash/templates/dlq_${dlq_version}-${dlq_revision}.json",
      require         => File['/etc/logstash/templates'],
    }
  }

  $ecs_versions = {
    # version => revision
    '1.7.0'  => '5',
    '1.11.0' => '7'
  }
  $ecs_versions.each |String $ecs_version, String $ecs_revision| {
    logstash::output::opensearch { "ecs_${ecs_version}-${ecs_revision}":
      host            => '127.0.0.1',
      guard_condition => "[@metadata][output] == \"ecs\" and [@metadata][template_version] == \"${ecs_version}\"",
      index           => "ecs-%{[@metadata][partition]}-%{[@metadata][policy_revision]}-${ecs_version}-${ecs_revision}-%{[@metadata][datestamp_format]}",
      priority        => 90,
      template        => "/etc/logstash/templates/ecs_${ecs_version}-${ecs_revision}.json",
      require         => File['/etc/logstash/templates'],
    }
  }

  $w3creportingapi_versions = {
    # version => revision
    '1.0.0' => '3'
  }
  $w3creportingapi_versions.each |String $w3creportingapi_version, String $w3creportingapi_revision| {
    logstash::output::opensearch { "w3creportingapi-${w3creportingapi_version}-${w3creportingapi_revision}":
      host            => '127.0.0.1',
      guard_condition => "[@metadata][output] == \"w3creportingapi\" and [@metadata][template_version] == \"${w3creportingapi_version}\"",
      index           => "w3creportingapi-%{[@metadata][partition]}-%{[@metadata][policy_revision]}-${w3creportingapi_version}-${w3creportingapi_revision}-%{[@metadata][datestamp_format]}",
      priority        => 90,
      template        => "/etc/logstash/templates/w3creportingapi_${w3creportingapi_version}-${w3creportingapi_revision}.json",
      require         => File['/etc/logstash/templates'],
    }
  }

}