-
Notifications
You must be signed in to change notification settings - Fork 9
/
logs-dispatcher.fluent-conf.configmap.yaml
514 lines (500 loc) · 17.2 KB
/
logs-dispatcher.fluent-conf.configmap.yaml
1
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
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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "lagoon-logging.logsDispatcher.fullname" . }}-fluent-conf
labels:
{{- include "lagoon-logging.logsDispatcher.labels" . | nindent 4 }}
data:
fluent.conf: |
# vi: ft=fluentd
<system>
workers 2
# comment out this line to see warnings
# it is set to error because fluentd is quite chatty
log_level error
</system>
# prometheus metrics
<source>
@type prometheus
</source>
<source>
@type prometheus_monitor
</source>
<source>
@type prometheus_output_monitor
</source>
# container logs collected by the logging-operator
<source>
@type forward
@id in_container
tag process.container
</source>
# application logs emitted by the lagoon_logs drupal module
<source>
@type udp
@id in_application
tag "lagoon.#{ENV['CLUSTER_NAME']}.application"
port 5140
# max IPv4 UDP payload size
message_length_limit 65507
<parse>
@type json
</parse>
</source>
{{- if .Values.openshiftHaproxyLogsCollector.enabled }}
# router logs emitted by the openshift routers
<source>
@type forward
@id in_router_openshift
port 24225
tag "lagoon.#{ENV['CLUSTER_NAME']}.router.openshift"
</source>
{{- end }}
{{- if .Values.cdnLogsCollector.enabled }}
# cdn logs collected via cdn-logs-collector
<source>
@type forward
@id in_cdn
port 24226
tag "lagoon.#{ENV['CLUSTER_NAME']}.cdn"
</source>
{{- end }}
#
# optional sources which can be enabled in the chart
#
@include source.d/*.conf
#
# pre-processing for nginx_router logs
#
# the reason for having the two match blocks is because we have two checks
# to distinguish nginx_router logs:
# * app label is "nginx-ingress"
# * namespace is "syn-nginx-ingress"
# if either of those checks fails the message is tagged as a regular
# container log.
#
# check app name first. if app name didn't match, set tag to container log.
<match process.container>
@type rewrite_tag_filter
<rule>
key $.kubernetes.labels.app
pattern ^nginx-ingress$
tag "process.app_nginx_ingress"
</rule>
<rule>
key $['kubernetes']['labels']['app.kubernetes.io/name']
pattern ^ingress-nginx$
tag "process.app_nginx_ingress"
</rule>
# Last rule: catchall
<rule>
invert true
key $.kubernetes.labels.app
pattern ^nginx-ingress$
tag "lagoon.#{ENV['CLUSTER_NAME']}.container"
</rule>
</match>
# check namespace_name. if it is okay too, tag as router log.
# if namespace didn't match, set tag to container log.
<match process.app_nginx_ingress>
@type rewrite_tag_filter
<rule>
key $.kubernetes.namespace_name
pattern ^syn-nginx-ingress$
tag "lagoon.#{ENV['CLUSTER_NAME']}.router.nginx"
</rule>
<rule>
key $.kubernetes.namespace_name
pattern ^ingress-nginx$
tag "lagoon.#{ENV['CLUSTER_NAME']}.router.nginx"
</rule>
<rule>
key $.kubernetes.namespace_name
pattern ^sigsci-ingress-nginx$
tag "lagoon.#{ENV['CLUSTER_NAME']}.router.nginx"
</rule>
# Last rule: catchall
<rule>
invert true
key $.kubernetes.namespace_name
pattern ^syn-nginx-ingress$
tag "lagoon.#{ENV['CLUSTER_NAME']}.container"
</rule>
</match>
# prometheus monitoring
<filter lagoon.**>
@type prometheus
<metric>
name fluentd_input_status_num_records_total
type counter
desc The total number of incoming records
<labels>
tag ${tag}
hostname ${hostname}
</labels>
</metric>
</filter>
#
# process container logs
#
# restructure so the kubernetes_metadata plugin can find the keys it needs
<filter lagoon.*.container>
@type record_modifier
remove_keys _dummy_
<record>
_dummy_ ${record['docker'] = {'container_id' => "#{record.dig('kubernetes','docker_id')}"}; nil}
</record>
</filter>
# enrich with k8s metadata (will get the namespace labels)
<filter lagoon.*.container>
@type kubernetes_metadata
@log_level warn
skip_container_metadata true
skip_master_url true
</filter>
# strip the duplicate information so that it doesn't appear in logs
<filter lagoon.*.container>
@type record_modifier
remove_keys docker
</filter>
# post-process to try to eke some more structure out of the logs.
# the last "format none" block is a catch-all for unmatched messages.
<filter lagoon.*.container>
@type parser
{{- if eq .Values.containerRuntime "docker" }}
key_name log
{{- else }}
key_name message
{{- end }}
reserve_data true
<parse>
@type multi_format
<pattern>
format regexp
expression /^(?<remote>[^ ]*) (?<host>[^ ]*) (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^\"]*?)(?: +\S*)?)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)"(?:\s+"(?<forwarded_for>[^"]+)")?)?$/
time_format %d/%b/%Y:%H:%M:%S %z
types size:integer
</pattern>
<pattern>
format none
</pattern>
</parse>
</filter>
#
# process application logs
#
# Restructure so the kubernetes_metadata plugin can find the keys it needs.
# Also add some dummy data required by the kubernetes_metadata plugin.
<filter lagoon.*.application>
@type record_modifier
remove_keys _dummy_,type
<record>
# modify the 'type' record before removal to convert underscores to
# hyphens as the former are illegal in k8s names. Lagoon does this same
# modification when creating the namespace.
_dummy_ ${record['openshift_project'] = record['type']&.gsub!('_', '-'); record['kubernetes'] = {'namespace_name' => record['type'], 'pod_name' => record['host'], 'container_name' => 'unknown'}; record['docker'] = {'container_id' => "#{record['type']}_#{record['host']}"}; nil}
</record>
</filter>
# enrich with k8s metadata (will get the namespace labels)
<filter lagoon.*.application>
@type kubernetes_metadata
@log_level warn
skip_container_metadata true
skip_master_url true
</filter>
# strip the dummy information so that it doesn't appear in logs
<filter lagoon.*.application>
@type record_modifier
remove_keys _dummy_,docker
<record>
_dummy_ ${record['kubernetes'].delete('pod_name'); record['kubernetes'].delete('container_name'); record['kubernetes'].delete('pod_id'); nil}
</record>
</filter>
#
# process nginx_router logs
#
# The message field may be json-encoded router logs, so parse that and put the
# keys in the top-level log object.
<filter lagoon.*.router.nginx>
@type parser
{{- if eq .Values.containerRuntime "docker" }}
key_name log
{{- else }}
key_name message
{{- end }}
reserve_time true
reserve_data true
remove_key_name_field true
<parse>
@type multi_format
<pattern>
format json
</pattern>
<pattern>
format none
</pattern>
</parse>
</filter>
# match the nginx router logs here and relabel them based on whether they
# were successfully parsed as json above or not
<match lagoon.*.router.nginx>
@type rewrite_tag_filter
<rule>
# if the host key doesn't exist then this was not parsed as JSON, so we
# just send to @OUTPUT directly because it is an actual nginx
# controller log. These logs will appear in index_name
# router-logs-ingress-nginx_.* if the keepIngressNginxController value
# is set to true.
invert true
key host
pattern /.+/
tag ${tag}
{{- if .Values.keepIngressNginxController }}
label @OUTPUT
{{- else }}
label @DISCARD
{{- end }}
</rule>
<rule>
# host key exists, so this is a HTTP request log
key host
pattern /.+/
tag ${tag}
label @NGINX_ROUTER_OUTPUT
</rule>
</match>
<label @NGINX_ROUTER_OUTPUT>
# Strip the nginx-ingress namespace info and add enough dummy information
# so that kubernetes_metadata plugin can get the namespace labels.
<filter lagoon.*.router.nginx>
@type record_modifier
remove_keys _dummy_
<record>
_dummy_ ${record['kubernetes'] = {'namespace_name' => record['namespace'], 'pod_name' => 'nopod', 'container_name' => 'nocontainer'}; record['docker'] = {'container_id' => "#{record['namespace']}_#{record['ingress_name']}"}; nil}
</record>
</filter>
# enrich with k8s metadata (will get the namespace labels)
<filter lagoon.*.router.nginx>
@type kubernetes_metadata
@log_level warn
skip_container_metadata true
skip_master_url true
</filter>
# strip the dummy information so that it doesn't appear in logs
<filter lagoon.*.router.nginx>
@type record_modifier
remove_keys _dummy_,docker
<record>
_dummy_ ${record['kubernetes'].delete('pod_name'); record['kubernetes'].delete('container_name'); record['kubernetes'].delete('pod_id'); nil}
</record>
</filter>
{{- with .Values.routerLogsPostProcess }}
{{- . | nindent 6 }}
{{- end }}
<match lagoon.*.router.nginx>
@type relabel
@label @OUTPUT
</match>
</label>
{{- if .Values.openshiftHaproxyLogsCollector.enabled }}
#
# process openshift router logs
#
# retructure the record enough for the kubernetes_metadata plugin to get
# namespace labels
<filter lagoon.*.router.openshift.**>
@type record_modifier
remove_keys _dummy_,kubernetes_namespace_name,kubernetes_pod_name,kubernetes_container_name,docker_container_id
<record>
_dummy_ ${record['kubernetes'] = {'namespace_name' => record['kubernetes_namespace_name'], 'pod_name' => record['kubernetes_pod_name'], 'container_name' => record['kubernetes_container_name']}; record['docker'] = {'container_id' => record['docker_container_id']}; nil}
</record>
</filter>
# enrich with k8s metadata
<filter lagoon.*.router.openshift.**>
@type kubernetes_metadata
@log_level warn
skip_container_metadata true
skip_master_url true
</filter>
{{- end }}
<match lagoon.**>
@type relabel
@label @OUTPUT
</match>
<label @OUTPUT>
#
# add cluster identifier
#
<filter lagoon.**>
@type record_modifier
<record>
cluster "#{ENV['CLUSTER_NAME']}"
</record>
</filter>
#
# add the container logs index_name
#
<filter lagoon.*.container>
@type record_modifier
<record>
index_name container-logs-${record.dig('kubernetes','namespace_labels','lagoon.sh/project')&.gsub("_", "-") || "#{record.dig('kubernetes','namespace_name') || 'unknown_project'}_#{ENV['CLUSTER_NAME']}"}-_-${record.dig('kubernetes','namespace_labels','lagoon.sh/environmentType') || "unknown_environmenttype"}-_-${Time.at(time).strftime("%Y.%m")}
log ${record['log'] || ""}
</record>
</filter>
#
# add the application logs index_name
#
<filter lagoon.*.application>
@type record_modifier
<record>
index_name application-logs-${record.dig('kubernetes','namespace_labels','lagoon.sh/project')&.gsub("_", "-") || "#{record.dig('kubernetes','namespace_name') || 'unknown_project'}_#{ENV['CLUSTER_NAME']}"}-_-${record.dig('kubernetes','namespace_labels','lagoon.sh/environmentType') || "unknown_environmenttype"}-_-${Time.at(time).strftime("%Y.%m")}
</record>
</filter>
#
# add the router logs index_name
#
<filter lagoon.*.router.**>
@type record_modifier
<record>
index_name router-logs-${record.dig('kubernetes','namespace_labels','lagoon.sh/project')&.gsub("_", "-") || "#{record.dig('kubernetes','namespace_name') || 'unknown_project'}_#{ENV['CLUSTER_NAME']}"}-_-${record.dig('kubernetes','namespace_labels','lagoon.sh/environmentType') || "unknown_environmenttype"}-_-${Time.at(time).strftime("%Y.%m")}
</record>
</filter>
{{- if .Values.cdnLogsCollector.enabled }}
#
# add the cdn logs index_name
#
<filter lagoon.*.cdn>
@type record_modifier
<record>
index_name cdn-logs-_-${ENV['CLUSTER_NAME']}-_-${Time.at(time).strftime("%Y.%m")}
</record>
</filter>
{{- end }}
{{- if .Values.consolidateServiceIndices }}
# some cluster services generate namespaces with a random suffix, so
# consolidate those in a single index for each service
<filter lagoon.*.router.openshift.**>
@type record_modifier
<replace>
key index_name
expression /^(?<prefix>router-logs-e2e)-[^-]{10}-[^-]{26}_(?<suffix>.+)$/
replace \k<prefix>_\k<suffix>
</replace>
</filter>
<filter lagoon.*.container>
@type record_modifier
<replace>
key index_name
expression /^(?<prefix>container-logs-e2e)-[^-]{10}-[^-]{26}_(?<suffix>.+)$/
replace \k<prefix>_\k<suffix>
</replace>
<replace>
key index_name
expression /^(?<prefix>container-logs-.+-apb)-(?:prov|depr)-[^-]{5}_(?<suffix>.+)$/
replace \k<prefix>_\k<suffix>
</replace>
<replace>
key index_name
expression /^(?<prefix>container-logs-openshift-build-test)-[0-9]+-[^-]{5}$/
replace \k<prefix>
</replace>
</filter>
{{- end }}
#
# add the lagoon logs index_name
# the source for this tag is included when lagoonLogs.enabled is true
#
<filter lagoon.*.lagoon>
@type record_modifier
<record>
index_name lagoon-logs-${record['project']}-_-all_environments-_-${Time.at(time).strftime("%Y.%m")}
</record>
</filter>
#
# exclude the lagoon logs for running builds, and legacy task: updates
#
<filter lagoon.*.lagoon>
@type grep
<or>
<exclude>
key $.meta.buildPhase
pattern ^running$
</exclude>
<exclude>
key $.meta.buildStatus
pattern ^running$
</exclude>
<exclude>
key $.event
pattern ^task:builddeploy-kubernetes:*
</exclude>
</or>
</filter>
#
# forward all to logs-concentrator
#
<match lagoon.**>
@type copy
{{- if .Values.enableDefaultForwarding }}
<store>
@type forward
@id out_forward
# error out early
verify_connection_at_startup {{ .Values.forward.verifyConnectionAtStartup }}
# tls
transport tls
tls_cert_path /fluentd/tls/ca.crt
tls_client_cert_path /fluentd/tls/client.crt
tls_client_private_key_path /fluentd/tls/client.key
tls_verify_hostname {{ .Values.forward.tlsVerifyHostname }}
# endpoint
keepalive true # makes sure the connection is not recreated every second
keepalive_timeout 10m # reconnect after 10mins in order to handle DNS changes, etc.
# avoid persistent DNS cache in case the server IP changes
expire_dns_cache 3600 # refresh cached DNS every hour
<server>
port "#{ENV['LOGS_FORWARD_HOST_PORT']}"
host "#{ENV['LOGS_FORWARD_HOST']}"
name "#{ENV['LOGS_FORWARD_HOSTNAME']}"
username "#{ENV['LOGS_FORWARD_USERNAME']}"
password "#{ENV['LOGS_FORWARD_PASSWORD']}"
</server>
# authentication
<security>
self_hostname "#{ENV['LOGS_FORWARD_SELF_HOSTNAME']}"
shared_key "#{ENV['LOGS_FORWARD_SHARED_KEY']}"
</security>
# buffer chunks by tag
<buffer tag>
@type file
path /fluentd/buffer/forward
# buffer params (per worker)
total_limit_size 7500MB
# flush params
flush_thread_count 8 # 8 threads that flush, makes sure we have enough flushers for all the different buffers
flush_interval 2s # flush every 2 seconds
flush_thread_burst_interval 0 # don't sleep if there is more data to flush
retry_max_interval 30s # limit exponential backoff period
overflow_action drop_oldest_chunk
</buffer>
</store>
{{- end }}
{{- if .Values.extraConf }}
<store>
@type relabel
@label @EXTRACONF
</store>
{{- end }}
@include store.d/*.conf
</match>
</label>
<label @DISCARD>
<match lagoon.**>
@type null
</match>
</label>
{{- with .Values.extraConf }}
<label @EXTRACONF>
{{- . | nindent 6 }}
</label>
{{- end }}