fluentd 1.9.3 → 1.11.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fluentd might be problematic. Click here for more details.

Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/issue-auto-closer.yml +12 -0
  3. data/CHANGELOG.md +182 -0
  4. data/CONTRIBUTING.md +1 -1
  5. data/README.md +4 -0
  6. data/docs/SECURITY_AUDIT.pdf +0 -0
  7. data/lib/fluent/command/debug.rb +1 -0
  8. data/lib/fluent/command/fluentd.rb +25 -1
  9. data/lib/fluent/config.rb +1 -0
  10. data/lib/fluent/daemonizer.rb +88 -0
  11. data/lib/fluent/log.rb +45 -6
  12. data/lib/fluent/match.rb +1 -1
  13. data/lib/fluent/msgpack_factory.rb +13 -6
  14. data/lib/fluent/plugin/buffer.rb +2 -2
  15. data/lib/fluent/plugin/in_dummy.rb +3 -3
  16. data/lib/fluent/plugin/in_forward.rb +2 -2
  17. data/lib/fluent/plugin/in_gc_stat.rb +16 -0
  18. data/lib/fluent/plugin/in_http.rb +146 -75
  19. data/lib/fluent/plugin/in_monitor_agent.rb +1 -1
  20. data/lib/fluent/plugin/in_syslog.rb +4 -4
  21. data/lib/fluent/plugin/in_tail.rb +40 -31
  22. data/lib/fluent/plugin/in_tail/position_file.rb +23 -6
  23. data/lib/fluent/plugin/in_unix.rb +77 -77
  24. data/lib/fluent/plugin/out_copy.rb +1 -1
  25. data/lib/fluent/plugin/out_file.rb +1 -1
  26. data/lib/fluent/plugin/out_forward.rb +25 -22
  27. data/lib/fluent/plugin/out_forward/handshake_protocol.rb +4 -0
  28. data/lib/fluent/plugin/out_forward/load_balancer.rb +1 -1
  29. data/lib/fluent/plugin/out_http.rb +15 -2
  30. data/lib/fluent/plugin/parser_multiline.rb +1 -1
  31. data/lib/fluent/plugin/parser_syslog.rb +303 -62
  32. data/lib/fluent/plugin/sd_file.rb +1 -0
  33. data/lib/fluent/plugin/sd_srv.rb +135 -0
  34. data/lib/fluent/plugin_helper/cert_option.rb +15 -2
  35. data/lib/fluent/plugin_helper/child_process.rb +3 -2
  36. data/lib/fluent/plugin_helper/record_accessor.rb +14 -0
  37. data/lib/fluent/plugin_helper/server.rb +3 -1
  38. data/lib/fluent/plugin_helper/service_discovery.rb +7 -0
  39. data/lib/fluent/plugin_helper/service_discovery/manager.rb +8 -0
  40. data/lib/fluent/plugin_helper/socket.rb +20 -2
  41. data/lib/fluent/plugin_helper/socket_option.rb +21 -3
  42. data/lib/fluent/supervisor.rb +21 -9
  43. data/lib/fluent/system_config.rb +2 -1
  44. data/lib/fluent/test/filter_test.rb +2 -2
  45. data/lib/fluent/test/output_test.rb +3 -3
  46. data/lib/fluent/version.rb +1 -1
  47. data/test/command/test_fluentd.rb +71 -12
  48. data/test/config/test_system_config.rb +2 -0
  49. data/test/helper.rb +2 -2
  50. data/test/plugin/in_tail/test_fifo.rb +121 -0
  51. data/test/plugin/in_tail/test_io_handler.rb +132 -0
  52. data/test/plugin/in_tail/test_position_file.rb +25 -1
  53. data/test/plugin/out_forward/test_handshake_protocol.rb +10 -1
  54. data/test/plugin/out_forward/test_load_balancer.rb +46 -0
  55. data/test/plugin/test_buf_file.rb +3 -1
  56. data/test/plugin/test_buffer.rb +20 -0
  57. data/test/plugin/test_compressable.rb +7 -4
  58. data/test/plugin/test_in_dummy.rb +12 -14
  59. data/test/plugin/test_in_forward.rb +2 -2
  60. data/test/plugin/test_in_gc_stat.rb +24 -1
  61. data/test/plugin/test_in_http.rb +57 -0
  62. data/test/plugin/test_in_syslog.rb +16 -1
  63. data/test/plugin/test_in_tail.rb +43 -20
  64. data/test/plugin/test_in_unix.rb +128 -73
  65. data/test/plugin/test_out_forward.rb +39 -3
  66. data/test/plugin/test_out_http.rb +38 -0
  67. data/test/plugin/test_out_null.rb +1 -1
  68. data/test/plugin/test_output_as_buffered_retries.rb +12 -4
  69. data/test/plugin/test_output_as_buffered_secondary.rb +9 -1
  70. data/test/plugin/test_parser_syslog.rb +106 -46
  71. data/test/plugin/test_sd_file.rb +17 -0
  72. data/test/plugin/test_sd_srv.rb +230 -0
  73. data/test/plugin_helper/data/cert/cert-with-CRLF.pem +19 -0
  74. data/test/plugin_helper/data/cert/cert_chains/ca-cert-key.pem +27 -0
  75. data/test/plugin_helper/data/cert/cert_chains/ca-cert.pem +20 -0
  76. data/test/plugin_helper/data/cert/cert_chains/cert-key.pem +27 -0
  77. data/test/plugin_helper/data/cert/cert_chains/cert.pem +40 -0
  78. data/test/plugin_helper/data/cert/generate_cert.rb +38 -0
  79. data/test/plugin_helper/http_server/test_app.rb +1 -1
  80. data/test/plugin_helper/http_server/test_route.rb +1 -1
  81. data/test/plugin_helper/test_cert_option.rb +2 -0
  82. data/test/plugin_helper/test_child_process.rb +20 -3
  83. data/test/plugin_helper/test_http_server_helper.rb +2 -2
  84. data/test/plugin_helper/test_record_accessor.rb +41 -0
  85. data/test/plugin_helper/test_server.rb +1 -1
  86. data/test/plugin_helper/test_service_discovery.rb +37 -4
  87. data/test/plugin_helper/test_socket.rb +131 -0
  88. data/test/test_daemonizer.rb +91 -0
  89. data/test/test_log.rb +44 -0
  90. data/test/test_msgpack_factory.rb +18 -0
  91. metadata +28 -2
@@ -21,7 +21,7 @@ class SyslogParserTest < ::Test::Unit::TestCase
21
21
  assert_equal(event_time('Feb 28 12:00:00', format: '%b %d %H:%M:%S'), time)
22
22
  assert_equal(@expected, record)
23
23
  }
24
- assert_equal(Fluent::Plugin::SyslogParser::REGEXP, @parser.instance.patterns['format'])
24
+ assert_equal(Fluent::Plugin::SyslogParser::RFC3164_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
25
25
  assert_equal("%b %d %H:%M:%S", @parser.instance.patterns['time_format'])
26
26
  end
27
27
 
@@ -35,6 +35,25 @@ class SyslogParserTest < ::Test::Unit::TestCase
35
35
  assert_equal('%b %d %M:%S:%H', @parser.instance.patterns['time_format'])
36
36
  end
37
37
 
38
+ data('regexp' => 'regexp', 'string' => 'string')
39
+ def test_parse_with_time_format2(param)
40
+ @parser.configure('time_format' => '%Y-%m-%dT%H:%M:%SZ', 'parser_type' => param)
41
+ @parser.instance.parse('2020-03-03T10:14:29Z 192.168.0.1 fluentd[11111]: [error] Syslog test') { |time, record|
42
+ assert_equal(event_time('Mar 03 10:14:29', format: '%b %d %H:%M:%S'), time)
43
+ assert_equal(@expected, record)
44
+ }
45
+ assert_equal('%Y-%m-%dT%H:%M:%SZ', @parser.instance.patterns['time_format'])
46
+ end
47
+
48
+ def test_parse_with_time_format_rfc5424
49
+ @parser.configure('time_format' => '%Y-%m-%dT%H:%M:%SZ', 'message_format' => 'rfc5424')
50
+ @parser.instance.parse('2020-03-03T10:14:29Z 192.168.0.1 fluentd 11111 - - [error] Syslog test') { |time, record|
51
+ assert_equal(event_time('Mar 03 10:14:29', format: '%b %d %H:%M:%S'), time)
52
+ assert_equal(@expected.merge('host' => '192.168.0.1', 'msgid' => '-', 'extradata' => '-'), record)
53
+ }
54
+ assert_equal('%Y-%m-%dT%H:%M:%SZ', @parser.instance.patterns['time_format'])
55
+ end
56
+
38
57
  data('regexp' => 'regexp', 'string' => 'string')
39
58
  def test_parse_with_subsecond_time(param)
40
59
  @parser.configure('time_format' => '%b %d %H:%M:%S.%N', 'parser_type' => param)
@@ -51,10 +70,20 @@ class SyslogParserTest < ::Test::Unit::TestCase
51
70
  assert_equal(event_time('Feb 28 12:00:00', format: '%b %d %H:%M:%S'), time)
52
71
  assert_equal(@expected.merge('pri' => 6), record)
53
72
  }
54
- assert_equal(Fluent::Plugin::SyslogParser::REGEXP_WITH_PRI, @parser.instance.patterns['format'])
73
+ assert_equal(Fluent::Plugin::SyslogParser::RFC3164_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
55
74
  assert_equal("%b %d %H:%M:%S", @parser.instance.patterns['time_format'])
56
75
  end
57
76
 
77
+ data('regexp' => 'regexp', 'string' => 'string')
78
+ def test_parse_rfc5452_with_priority(param)
79
+ @parser.configure('with_priority' => true, 'parser_type' => param, 'message_format' => 'rfc5424')
80
+ @parser.instance.parse('<30>1 2020-03-31T20:32:54Z myhostname 02abaf0687f5 10339 02abaf0687f5 - method=POST db=0.00') do |time, record|
81
+ assert_equal(event_time('2020-03-31T20:32:54Z', format: '%Y-%m-%dT%H:%M:%S%z'), time)
82
+ expected = { 'extradata' => '-', 'host' => 'myhostname', 'ident' => '02abaf0687f5', 'message' => 'method=POST db=0.00', 'msgid' => '02abaf0687f5', 'pid' => '10339', 'pri' => 30 }
83
+ assert_equal(expected, record)
84
+ end
85
+ end
86
+
58
87
  data('regexp' => 'regexp', 'string' => 'string')
59
88
  def test_parse_with_empty_priority(param)
60
89
  @parser.configure('with_priority' => true, 'parser_type' => param)
@@ -71,7 +100,7 @@ class SyslogParserTest < ::Test::Unit::TestCase
71
100
  assert_equal(event_time('Feb 28 12:00:00', format: '%b %d %H:%M:%S'), time)
72
101
  assert_equal(@expected, record)
73
102
  }
74
- assert_equal(Fluent::Plugin::SyslogParser::REGEXP, @parser.instance.patterns['format'])
103
+ assert_equal(Fluent::Plugin::SyslogParser::RFC3164_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
75
104
  assert_equal("%b %d %H:%M:%S", @parser.instance.patterns['time_format'])
76
105
  end
77
106
 
@@ -170,11 +199,13 @@ class SyslogParserTest < ::Test::Unit::TestCase
170
199
  end
171
200
 
172
201
  class TestRFC5424Regexp < self
173
- def test_parse_with_rfc5424_message
202
+ data('regexp' => 'regexp', 'string' => 'string')
203
+ def test_parse_with_rfc5424_message(param)
174
204
  @parser.configure(
175
205
  'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
176
206
  'message_format' => 'rfc5424',
177
207
  'with_priority' => true,
208
+ 'parser_type' => param
178
209
  )
179
210
  text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
180
211
  @parser.instance.parse(text) do |time, record|
@@ -184,15 +215,16 @@ class SyslogParserTest < ::Test::Unit::TestCase
184
215
  assert_equal "-", record["extradata"]
185
216
  assert_equal "Hi, from Fluentd!", record["message"]
186
217
  end
187
- assert_equal(Fluent::Plugin::SyslogParser::REGEXP_RFC5424_WITH_PRI,
188
- @parser.instance.patterns['format'])
218
+ assert_equal(Fluent::Plugin::SyslogParser::RFC5424_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
189
219
  end
190
220
 
191
- def test_parse_with_rfc5424_message_trailing_eol
221
+ data('regexp' => 'regexp', 'string' => 'string')
222
+ def test_parse_with_rfc5424_message_trailing_eol(param)
192
223
  @parser.configure(
193
224
  'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
194
225
  'message_format' => 'rfc5424',
195
226
  'with_priority' => true,
227
+ 'parser_type' => param
196
228
  )
197
229
  text = "<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!\n"
198
230
  @parser.instance.parse(text) do |time, record|
@@ -202,15 +234,16 @@ class SyslogParserTest < ::Test::Unit::TestCase
202
234
  assert_equal "-", record["extradata"]
203
235
  assert_equal "Hi, from Fluentd!", record["message"]
204
236
  end
205
- assert_equal(Fluent::Plugin::SyslogParser::REGEXP_RFC5424_WITH_PRI,
206
- @parser.instance.patterns['format'])
237
+ assert_equal(Fluent::Plugin::SyslogParser::RFC5424_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
207
238
  end
208
239
 
209
- def test_parse_with_rfc5424_multiline_message
240
+ data('regexp' => 'regexp', 'string' => 'string')
241
+ def test_parse_with_rfc5424_multiline_message(param)
210
242
  @parser.configure(
211
243
  'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
212
244
  'message_format' => 'rfc5424',
213
245
  'with_priority' => true,
246
+ 'parser_type' => param
214
247
  )
215
248
  text = "<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi,\nfrom\nFluentd!"
216
249
  @parser.instance.parse(text) do |time, record|
@@ -220,14 +253,15 @@ class SyslogParserTest < ::Test::Unit::TestCase
220
253
  assert_equal "-", record["extradata"]
221
254
  assert_equal "Hi,\nfrom\nFluentd!", record["message"]
222
255
  end
223
- assert_equal(Fluent::Plugin::SyslogParser::REGEXP_RFC5424_WITH_PRI,
224
- @parser.instance.patterns['format'])
256
+ assert_equal(Fluent::Plugin::SyslogParser::RFC5424_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
225
257
  end
226
258
 
227
- def test_parse_with_rfc5424_message_and_without_priority
259
+ data('regexp' => 'regexp', 'string' => 'string')
260
+ def test_parse_with_rfc5424_message_and_without_priority(param)
228
261
  @parser.configure(
229
262
  'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
230
263
  'message_format' => 'rfc5424',
264
+ 'parser_type' => param
231
265
  )
232
266
  text = '2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
233
267
  @parser.instance.parse(text) do |time, record|
@@ -237,14 +271,15 @@ class SyslogParserTest < ::Test::Unit::TestCase
237
271
  assert_equal "-", record["extradata"]
238
272
  assert_equal "Hi, from Fluentd!", record["message"]
239
273
  end
240
- assert_equal(Fluent::Plugin::SyslogParser::REGEXP_RFC5424_NO_PRI,
241
- @parser.instance.patterns['format'])
274
+ assert_equal(Fluent::Plugin::SyslogParser::RFC5424_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
242
275
  end
243
276
 
244
- def test_parse_with_rfc5424_empty_message_and_without_priority
277
+ data('regexp' => 'regexp', 'string' => 'string')
278
+ def test_parse_with_rfc5424_empty_message_and_without_priority(param)
245
279
  @parser.configure(
246
280
  'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
247
281
  'message_format' => 'rfc5424',
282
+ 'parser_type' => param
248
283
  )
249
284
  text = '2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - -'
250
285
  @parser.instance.parse(text) do |time, record|
@@ -254,14 +289,15 @@ class SyslogParserTest < ::Test::Unit::TestCase
254
289
  assert_equal "-", record["extradata"]
255
290
  assert_nil record["message"]
256
291
  end
257
- assert_equal(Fluent::Plugin::SyslogParser::REGEXP_RFC5424_NO_PRI,
258
- @parser.instance.patterns['format'])
292
+ assert_equal(Fluent::Plugin::SyslogParser::RFC5424_WITHOUT_TIME_AND_PRI_REGEXP, @parser.instance.patterns['format'])
259
293
  end
260
294
 
261
- def test_parse_with_rfc5424_message_without_time_format
295
+ data('regexp' => 'regexp', 'string' => 'string')
296
+ def test_parse_with_rfc5424_message_without_time_format(param)
262
297
  @parser.configure(
263
298
  'message_format' => 'rfc5424',
264
299
  'with_priority' => true,
300
+ 'parser_type' => param
265
301
  )
266
302
  text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
267
303
  @parser.instance.parse(text) do |time, record|
@@ -273,10 +309,12 @@ class SyslogParserTest < ::Test::Unit::TestCase
273
309
  end
274
310
  end
275
311
 
276
- def test_parse_with_rfc5424_message_with_priority_and_pid
312
+ data('regexp' => 'regexp', 'string' => 'string')
313
+ def test_parse_with_rfc5424_message_with_priority_and_pid(param)
277
314
  @parser.configure(
278
315
  'message_format' => 'rfc5424',
279
316
  'with_priority' => true,
317
+ 'parser_type' => param
280
318
  )
281
319
  text = '<28>1 2018-09-26T15:54:26.620412+09:00 machine minissdpd 1298 - - peer 192.168.0.5:50123 is not from a LAN'
282
320
  @parser.instance.parse(text) do |time, record|
@@ -288,11 +326,13 @@ class SyslogParserTest < ::Test::Unit::TestCase
288
326
  end
289
327
  end
290
328
 
291
- def test_parse_with_rfc5424_structured_message
329
+ data('regexp' => 'regexp', 'string' => 'string')
330
+ def test_parse_with_rfc5424_structured_message(param)
292
331
  @parser.configure(
293
332
  'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
294
333
  'message_format' => 'rfc5424',
295
334
  'with_priority' => true,
335
+ 'parser_type' => param
296
336
  )
297
337
  text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd 11111 ID24224 [exampleSDID@20224 iut="3" eventSource="Application" eventID="11211"] [Hi] from Fluentd!'
298
338
  @parser.instance.parse(text) do |time, record|
@@ -305,11 +345,13 @@ class SyslogParserTest < ::Test::Unit::TestCase
305
345
  end
306
346
  end
307
347
 
308
- def test_parse_with_rfc5424_multiple_structured_message
348
+ data('regexp' => 'regexp', 'string' => 'string')
349
+ def test_parse_with_rfc5424_multiple_structured_message(param)
309
350
  @parser.configure(
310
351
  'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
311
352
  'message_format' => 'rfc5424',
312
353
  'with_priority' => true,
354
+ 'parser_type' => param
313
355
  )
314
356
  text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd 11111 ID24224 [exampleSDID@20224 iut="3" eventSource="Application" eventID="11211"][exampleSDID@20224 class="high"] Hi, from Fluentd!'
315
357
  @parser.instance.parse(text) do |time, record|
@@ -322,11 +364,13 @@ class SyslogParserTest < ::Test::Unit::TestCase
322
364
  end
323
365
  end
324
366
 
325
- def test_parse_with_rfc5424_message_includes_right_bracket
367
+ data('regexp' => 'regexp', 'string' => 'string')
368
+ def test_parse_with_rfc5424_message_includes_right_bracket(param)
326
369
  @parser.configure(
327
370
  'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
328
371
  'message_format' => 'rfc5424',
329
372
  'with_priority' => true,
373
+ 'parser_type' => param
330
374
  )
331
375
  text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd 11111 ID24224 [exampleSDID@20224 iut="3" eventSource="Application" eventID="11211"] [Hi] from Fluentd]!'
332
376
  @parser.instance.parse(text) do |time, record|
@@ -339,11 +383,13 @@ class SyslogParserTest < ::Test::Unit::TestCase
339
383
  end
340
384
  end
341
385
 
342
- def test_parse_with_rfc5424_empty_message
386
+ data('regexp' => 'regexp', 'string' => 'string')
387
+ def test_parse_with_rfc5424_empty_message(param)
343
388
  @parser.configure(
344
389
  'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
345
390
  'message_format' => 'rfc5424',
346
391
  'with_priority' => true,
392
+ 'parser_type' => param
347
393
  )
348
394
  text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd 11111 ID24224 [exampleSDID@20224 iut="3" eventSource="Application" eventID="11211"]'
349
395
  @parser.instance.parse(text) do |time, record|
@@ -356,10 +402,35 @@ class SyslogParserTest < ::Test::Unit::TestCase
356
402
  end
357
403
  end
358
404
 
359
- def test_parse_with_rfc5424_message_without_subseconds
405
+ data('regexp' => 'regexp', 'string' => 'string')
406
+ def test_parse_with_rfc5424_space_empty_message(param)
407
+ @parser.configure(
408
+ 'message_format' => 'rfc5424',
409
+ 'with_priority' => true,
410
+ 'parser_type' => param
411
+ )
412
+ text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd 11111 ID24224 [exampleSDID@20224 iut="3" eventSource="Application" eventID="11211"] '
413
+ @parser.instance.parse(text) do |time, record|
414
+ if param == 'string'
415
+ assert_equal(event_time("2017-02-06T13:14:15.003Z", format: '%Y-%m-%dT%H:%M:%S.%L%z'), time)
416
+ assert_equal "11111", record["pid"]
417
+ assert_equal "ID24224", record["msgid"]
418
+ assert_equal "[exampleSDID@20224 iut=\"3\" eventSource=\"Application\" eventID=\"11211\"]",
419
+ record["extradata"]
420
+ assert_equal '', record["message"]
421
+ else
422
+ assert_nil time
423
+ assert_nil record
424
+ end
425
+ end
426
+ end
427
+
428
+ data('regexp' => 'regexp', 'string' => 'string')
429
+ def test_parse_with_rfc5424_message_without_subseconds(param)
360
430
  @parser.configure(
361
431
  'message_format' => 'rfc5424',
362
432
  'with_priority' => true,
433
+ 'parser_type' => param
363
434
  )
364
435
  text = '<16>1 2017-02-06T13:14:15Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
365
436
  @parser.instance.parse(text) do |time, record|
@@ -371,10 +442,12 @@ class SyslogParserTest < ::Test::Unit::TestCase
371
442
  end
372
443
  end
373
444
 
374
- def test_parse_with_rfc5424_message_both_timestamp
445
+ data('regexp' => 'regexp', 'string' => 'string')
446
+ def test_parse_with_rfc5424_message_both_timestamp(param)
375
447
  @parser.configure(
376
448
  'message_format' => 'rfc5424',
377
449
  'with_priority' => true,
450
+ 'parser_type' => param
378
451
  )
379
452
  text = '<16>1 2017-02-06T13:14:15Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
380
453
  @parser.instance.parse(text) do |time, record|
@@ -408,7 +481,6 @@ class SyslogParserTest < ::Test::Unit::TestCase
408
481
  assert_equal(event_time("Feb 28 00:00:12", format: '%b %d %M:%S:%H'), time)
409
482
  assert_equal(@expected, record)
410
483
  end
411
- assert_equal(Fluent::Plugin::SyslogParser::REGEXP, @parser.instance.patterns['format'])
412
484
  end
413
485
 
414
486
  data('regexp' => 'regexp', 'string' => 'string')
@@ -424,7 +496,6 @@ class SyslogParserTest < ::Test::Unit::TestCase
424
496
  assert_equal(event_time("Feb 28 12:00:00", format: '%b %d %M:%S:%H'), time)
425
497
  assert_equal(@expected.merge('pri' => 6), record)
426
498
  end
427
- assert_equal(Fluent::Plugin::SyslogParser::REGEXP_WITH_PRI, @parser.instance.patterns['format'])
428
499
  end
429
500
 
430
501
  data('regexp' => 'regexp', 'string' => 'string')
@@ -441,10 +512,9 @@ class SyslogParserTest < ::Test::Unit::TestCase
441
512
  assert_equal "-", record["pid"]
442
513
  assert_equal "-", record["msgid"]
443
514
  assert_equal "-", record["extradata"]
515
+ assert_equal 16, record["pri"]
444
516
  assert_equal "Hi, from Fluentd!", record["message"]
445
517
  end
446
- assert_equal(Fluent::Plugin::SyslogParser::REGEXP_RFC5424_WITH_PRI,
447
- @parser.instance.patterns['format'])
448
518
  end
449
519
 
450
520
  data('regexp' => 'regexp', 'string' => 'string')
@@ -464,8 +534,6 @@ class SyslogParserTest < ::Test::Unit::TestCase
464
534
  record["extradata"]
465
535
  assert_equal "Hi, from Fluentd!", record["message"]
466
536
  end
467
- assert_equal(Fluent::Plugin::SyslogParser::REGEXP_RFC5424_WITH_PRI,
468
- @parser.instance.patterns['format'])
469
537
  end
470
538
 
471
539
  data('regexp' => 'regexp', 'string' => 'string')
@@ -482,7 +550,6 @@ class SyslogParserTest < ::Test::Unit::TestCase
482
550
  assert_equal(event_time("Feb 28 12:00:00", format: '%b %d %M:%S:%H'), time)
483
551
  assert_equal(@expected.merge('pri' => 1), record)
484
552
  end
485
- assert_equal(Fluent::Plugin::SyslogParser::REGEXP_WITH_PRI, @parser.instance.patterns['format'])
486
553
 
487
554
  text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd 11111 ID24224 [exampleSDID@20224 iut="3" eventSource="Application" eventID="11211"] Hi, from Fluentd!'
488
555
  @parser.instance.parse(text) do |time, record|
@@ -493,15 +560,18 @@ class SyslogParserTest < ::Test::Unit::TestCase
493
560
  record["extradata"]
494
561
  assert_equal "Hi, from Fluentd!", record["message"]
495
562
  end
496
- assert_equal(Fluent::Plugin::SyslogParser::REGEXP_RFC5424_WITH_PRI,
497
- @parser.instance.patterns['format'])
563
+
564
+ text = '<1>Feb 28 12:00:02 192.168.0.1 fluentd[11111]: [error] Syslog test 2>1'
565
+ @parser.instance.parse(text) do |time, record|
566
+ assert_equal(event_time("Feb 28 12:00:02", format: '%b %d %M:%S:%H'), time)
567
+ assert_equal(@expected.merge('pri' => 1, 'message'=> '[error] Syslog test 2>1'), record)
568
+ end
498
569
 
499
570
  text = '<1>Feb 28 12:00:02 192.168.0.1 fluentd[11111]: [error] Syslog test'
500
571
  @parser.instance.parse(text) do |time, record|
501
572
  assert_equal(event_time("Feb 28 12:00:02", format: '%b %d %M:%S:%H'), time)
502
573
  assert_equal(@expected.merge('pri' => 1), record)
503
574
  end
504
- assert_equal(Fluent::Plugin::SyslogParser::REGEXP_WITH_PRI, @parser.instance.patterns['format'])
505
575
 
506
576
  text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
507
577
  @parser.instance.parse(text) do |time, record|
@@ -511,8 +581,6 @@ class SyslogParserTest < ::Test::Unit::TestCase
511
581
  assert_equal "-", record["extradata"]
512
582
  assert_equal "Hi, from Fluentd!", record["message"]
513
583
  end
514
- assert_equal(Fluent::Plugin::SyslogParser::REGEXP_RFC5424_WITH_PRI,
515
- @parser.instance.patterns['format'])
516
584
  end
517
585
 
518
586
  data('regexp' => 'regexp', 'string' => 'string')
@@ -529,7 +597,6 @@ class SyslogParserTest < ::Test::Unit::TestCase
529
597
  assert_equal(event_time("Feb 28 12:00:00", format: '%b %d %M:%S:%H'), time)
530
598
  assert_equal(@expected.merge('pri' => 6), record)
531
599
  end
532
- assert_equal(Fluent::Plugin::SyslogParser::REGEXP_WITH_PRI, @parser.instance.patterns['format'])
533
600
 
534
601
  text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd 11111 ID24224 [exampleSDID@20224 iut="3" eventSource="Application" eventID="11211"] Hi, from Fluentd!'
535
602
  @parser.instance.parse(text) do |time, record|
@@ -540,15 +607,12 @@ class SyslogParserTest < ::Test::Unit::TestCase
540
607
  record["extradata"]
541
608
  assert_equal "Hi, from Fluentd!", record["message"]
542
609
  end
543
- assert_equal(Fluent::Plugin::SyslogParser::REGEXP_RFC5424_WITH_PRI,
544
- @parser.instance.patterns['format'])
545
610
 
546
611
  text = '<16>Feb 28 12:00:02 192.168.0.1 fluentd[11111]: [error] Syslog test'
547
612
  @parser.instance.parse(text) do |time, record|
548
613
  assert_equal(event_time("Feb 28 12:00:02", format: '%b %d %M:%S:%H'), time)
549
614
  assert_equal(@expected.merge('pri' => 16), record)
550
615
  end
551
- assert_equal(Fluent::Plugin::SyslogParser::REGEXP_WITH_PRI, @parser.instance.patterns['format'])
552
616
 
553
617
  text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
554
618
  @parser.instance.parse(text) do |time, record|
@@ -558,8 +622,6 @@ class SyslogParserTest < ::Test::Unit::TestCase
558
622
  assert_equal "-", record["extradata"]
559
623
  assert_equal "Hi, from Fluentd!", record["message"]
560
624
  end
561
- assert_equal(Fluent::Plugin::SyslogParser::REGEXP_RFC5424_WITH_PRI,
562
- @parser.instance.patterns['format'])
563
625
 
564
626
  text = '<16>1 2017-02-06T13:14:15Z 192.168.0.1 fluentd - - - Hi, from Fluentd without subseconds!'
565
627
  @parser.instance.parse(text) do |time, record|
@@ -569,8 +631,6 @@ class SyslogParserTest < ::Test::Unit::TestCase
569
631
  assert_equal "-", record["extradata"]
570
632
  assert_equal "Hi, from Fluentd without subseconds!", record["message"]
571
633
  end
572
- assert_equal(Fluent::Plugin::SyslogParser::REGEXP_RFC5424_WITH_PRI,
573
- @parser.instance.patterns['format'])
574
634
  end
575
635
  end
576
636
  end
@@ -149,6 +149,23 @@ class FileServiceDiscoveryTest < ::Test::Unit::TestCase
149
149
  assert_empty queue
150
150
  end
151
151
 
152
+ test 'Skip if error is occured' do
153
+ @sd_file.extend(TestStatEventHelperWrapper)
154
+
155
+ create_tmp_config('config.json', JSON.generate([{ port: 1233, host: '127.0.0.1' }]))
156
+ @sd_file.configure(config_element('service_discovery', '', { 'path' => File.join(@dir, 'config.yml') }))
157
+ queue = []
158
+
159
+ FileUtils.rm_r(File.join(@dir, 'tmp', 'config.json'))
160
+ mock.proxy(@sd_file).refresh_file(queue).twice
161
+
162
+ @sd_file.start(queue)
163
+ assert_empty queue
164
+
165
+ @sd_file.resume
166
+ assert_empty queue
167
+ end
168
+
152
169
  test 'if service is updated, service_in and service_out event happen' do
153
170
  @sd_file.extend(TestStatEventHelperWrapper)
154
171
 
@@ -0,0 +1,230 @@
1
+ require_relative '../helper'
2
+ require 'fluent/plugin/sd_srv'
3
+ require 'fileutils'
4
+ require 'flexmock/test_unit'
5
+ require 'json'
6
+
7
+ class SrvServiceDiscoveryTest < ::Test::Unit::TestCase
8
+ SRV_RECORD1 = Resolv::DNS::Resource::IN::SRV.new(1, 10, 8081, 'service1.example.com')
9
+ SRV_RECORD2 = Resolv::DNS::Resource::IN::SRV.new(2, 20, 8082, 'service2.example.com')
10
+
11
+ sub_test_case 'configure' do
12
+ test 'set services ordered by priority' do
13
+ sdf = Fluent::Plugin::SrvServiceDiscovery.new
14
+ mock(Resolv::DNS).new { flexmock('dns_resolver', getresources: [SRV_RECORD2, SRV_RECORD1], getaddress: '127.0.0.1') }
15
+
16
+ sdf.configure(config_element('service_discovery', '', { 'service' => 'service1', 'hostname' => 'example.com' }))
17
+ assert_equal Fluent::Plugin::ServiceDiscovery::Service.new(:srv, '127.0.0.1', 8081, 'service1.example.com', 10, false, '', '', nil), sdf.services[0]
18
+ assert_equal Fluent::Plugin::ServiceDiscovery::Service.new(:srv, '127.0.0.1', 8082, 'service2.example.com', 20, false, '', '', nil), sdf.services[1]
19
+ end
20
+
21
+ test 'reuturn host name without revolving name when dns_lookup is flase' do
22
+ sdf = Fluent::Plugin::SrvServiceDiscovery.new
23
+ mock(Resolv::DNS).new { flexmock('dns_resolver', getresources: [SRV_RECORD1, SRV_RECORD2], getaddress: '127.0.0.1') }
24
+
25
+ sdf.configure(config_element('service_discovery', '', { 'service' => 'service1', 'hostname' => 'example.com', 'dns_lookup' => false }))
26
+ assert_equal Fluent::Plugin::ServiceDiscovery::Service.new(:srv, 'service1.example.com', 8081, 'service1.example.com', 10, false, '', '', nil), sdf.services[0]
27
+ assert_equal Fluent::Plugin::ServiceDiscovery::Service.new(:srv, 'service2.example.com', 8082, 'service2.example.com', 20, false, '', '', nil), sdf.services[1]
28
+ end
29
+
30
+ test 'pass a value as :nameserver to Resolve::DNS when dns_server_host is given' do
31
+ sdf = Fluent::Plugin::SrvServiceDiscovery.new
32
+ mock(Resolv::DNS).new(nameserver: '8.8.8.8') { flexmock('dns_resolver', getresources: [SRV_RECORD1, SRV_RECORD2], getaddress: '127.0.0.1') }
33
+
34
+ sdf.configure(config_element('service_discovery', '', { 'service' => 'service1', 'hostname' => 'example.com', 'dns_server_host' => '8.8.8.8' }))
35
+ assert_equal Fluent::Plugin::ServiceDiscovery::Service.new(:srv, '127.0.0.1', 8081, 'service1.example.com', 10, false, '', '', nil), sdf.services[0]
36
+ assert_equal Fluent::Plugin::ServiceDiscovery::Service.new(:srv, '127.0.0.1', 8082, 'service2.example.com', 20, false, '', '', nil), sdf.services[1]
37
+ end
38
+
39
+ test 'pass a value as :nameserver_port to Resolve::DNS when dns_server_host has port' do
40
+ sdf = Fluent::Plugin::SrvServiceDiscovery.new
41
+ mock(Resolv::DNS).new(nameserver_port: [['8.8.8.8', 8080]]) { flexmock('dns_resolver', getresources: [SRV_RECORD1, SRV_RECORD2], getaddress: '127.0.0.1') }
42
+
43
+ sdf.configure(config_element('service_discovery', '', { 'service' => 'service1', 'hostname' => 'example.com', 'dns_server_host' => '8.8.8.8:8080' }))
44
+ assert_equal Fluent::Plugin::ServiceDiscovery::Service.new(:srv, '127.0.0.1', 8081, 'service1.example.com', 10, false, '', '', nil), sdf.services[0]
45
+ assert_equal Fluent::Plugin::ServiceDiscovery::Service.new(:srv, '127.0.0.1', 8082, 'service2.example.com', 20, false, '', '', nil), sdf.services[1]
46
+ end
47
+
48
+ test 'target follows RFC2782' do
49
+ sdf = Fluent::Plugin::SrvServiceDiscovery.new
50
+ mock = flexmock('dns_resolver', getaddress: '127.0.0.1')
51
+ .should_receive(:getresources).with("_service1._tcp.example.com", Resolv::DNS::Resource::IN::SRV)
52
+ .and_return([SRV_RECORD1, SRV_RECORD2])
53
+ .mock
54
+
55
+ mock(Resolv::DNS).new { mock }
56
+ sdf.configure(config_element('service_discovery', '', { 'service' => 'service1', 'hostname' => 'example.com' }))
57
+ assert_equal Fluent::Plugin::ServiceDiscovery::Service.new(:srv, '127.0.0.1', 8081, 'service1.example.com', 10, false, '', '', nil), sdf.services[0]
58
+ assert_equal Fluent::Plugin::ServiceDiscovery::Service.new(:srv, '127.0.0.1', 8082, 'service2.example.com', 20, false, '', '', nil), sdf.services[1]
59
+ end
60
+
61
+ test 'can change protocol' do
62
+ sdf = Fluent::Plugin::SrvServiceDiscovery.new
63
+ mock = flexmock('dns_resolver', getaddress: '127.0.0.1')
64
+ .should_receive(:getresources).with("_service1._udp.example.com", Resolv::DNS::Resource::IN::SRV)
65
+ .and_return([SRV_RECORD1, SRV_RECORD2])
66
+ .mock
67
+
68
+ mock(Resolv::DNS).new { mock }
69
+ sdf.configure(config_element('service_discovery', '', { 'service' => 'service1', 'hostname' => 'example.com', 'proto' => 'udp' }))
70
+ assert_equal Fluent::Plugin::ServiceDiscovery::Service.new(:srv, '127.0.0.1', 8081, 'service1.example.com', 10, false, '', '', nil), sdf.services[0]
71
+ assert_equal Fluent::Plugin::ServiceDiscovery::Service.new(:srv, '127.0.0.1', 8082, 'service2.example.com', 20, false, '', '', nil), sdf.services[1]
72
+ end
73
+
74
+ test 'can set password, username, password' do
75
+ sdf = Fluent::Plugin::SrvServiceDiscovery.new
76
+ mock(Resolv::DNS).new { flexmock('dns_resolver', getresources: [SRV_RECORD2, SRV_RECORD1], getaddress: '127.0.0.1') }
77
+
78
+ sdf.configure(config_element('service_discovery', '', { 'service' => 'service1', 'hostname' => 'example.com', 'shared_key' => 'key', 'username' => 'user', 'password' => 'pass' }))
79
+ assert_equal Fluent::Plugin::ServiceDiscovery::Service.new(:srv, '127.0.0.1', 8081, 'service1.example.com', 10, false, 'user', 'pass', 'key'), sdf.services[0]
80
+ assert_equal Fluent::Plugin::ServiceDiscovery::Service.new(:srv, '127.0.0.1', 8082, 'service2.example.com', 20, false, 'user', 'pass', 'key'), sdf.services[1]
81
+ end
82
+ end
83
+
84
+ sub_test_case '#start' do
85
+ module TestTimerEventHelperWrapper
86
+ # easy to control statsevent
87
+ def timer_execute(_name, _interval, &block)
88
+ @test_timer_event_helper_wrapper_context = Fiber.new do
89
+ loop do
90
+ block.call
91
+
92
+ if Fiber.yield == :finish
93
+ break
94
+ end
95
+ end
96
+ end
97
+
98
+ resume
99
+ end
100
+
101
+ def resume
102
+ @test_timer_event_helper_wrapper_context.resume(:resume)
103
+ end
104
+
105
+ def shutdown
106
+ super
107
+
108
+ if @test_timer_event_helper_wrapper_context
109
+ @test_timer_event_helper_wrapper_context.resume(:finish)
110
+ end
111
+
112
+ end
113
+ end
114
+
115
+ setup do
116
+ sds = Fluent::Plugin::SrvServiceDiscovery.new
117
+ @sd_srv = sds
118
+ end
119
+
120
+ teardown do
121
+ if @sd_srv
122
+ @sd_srv.stop unless @sd_srv.stopped?
123
+ @sd_srv.before_shutdown unless @sd_srv.before_shutdown?
124
+ @sd_srv.shutdown unless @sd_srv.shutdown?
125
+ @sd_srv.after_shutdown unless @sd_srv.after_shutdown?
126
+ @sd_srv.close unless @sd_srv.closed?
127
+ @sd_srv.terminate unless @sd_srv.terminated?
128
+ end
129
+ end
130
+
131
+ test 'Skip if srv record is not updated' do
132
+ @sd_srv.extend(TestTimerEventHelperWrapper)
133
+ mock(Resolv::DNS).new { flexmock('dns_resolver', getresources: [SRV_RECORD2, SRV_RECORD1], getaddress: '127.0.0.1') }
134
+ @sd_srv.configure(config_element('service_discovery', '', { 'service' => 'service1', 'hostname' => 'example.com' }))
135
+ queue = []
136
+
137
+ @sd_srv.start(queue)
138
+ assert_empty queue
139
+
140
+ @sd_srv.resume
141
+ assert_empty queue
142
+ end
143
+
144
+ test 'Skip if DNS resolver raise an error' do
145
+ @sd_srv.extend(TestTimerEventHelperWrapper)
146
+ mock = flexmock('dns_resolver', getaddress: '127.0.0.1')
147
+ .should_receive(:getresources)
148
+ .and_return([SRV_RECORD1, SRV_RECORD2])
149
+ .and_return { raise 'some error' } # for start
150
+ .and_return { raise 'some error' } # for resume
151
+ .mock
152
+
153
+ mock(Resolv::DNS).new { mock }
154
+ @sd_srv.configure(config_element('service_discovery', '', { 'service' => 'service1', 'hostname' => 'example.com' }))
155
+ queue = []
156
+
157
+ @sd_srv.start(queue)
158
+ assert_empty queue
159
+
160
+ @sd_srv.resume
161
+ assert_empty queue
162
+ end
163
+
164
+ test 'if service is updated, service_in and service_out event happen' do
165
+ @sd_srv.extend(TestTimerEventHelperWrapper)
166
+ mock = flexmock('dns_resolver', getaddress: '127.0.0.1')
167
+ .should_receive(:getresources)
168
+ .and_return([SRV_RECORD1])
169
+ .and_return([SRV_RECORD2])
170
+ .mock
171
+
172
+ mock(Resolv::DNS).new { mock }
173
+ @sd_srv.configure(config_element('service_discovery', '', { 'service' => 'service1', 'hostname' => 'example.com', 'dns_lookup' => false }))
174
+ queue = []
175
+
176
+ @sd_srv.start(queue)
177
+ join = queue.shift
178
+ drain = queue.shift
179
+ assert_equal Fluent::Plugin::ServiceDiscovery::SERVICE_IN, join.type
180
+ assert_equal 8082, join.service.port
181
+ assert_equal 'service2.example.com', join.service.host
182
+
183
+ assert_equal Fluent::Plugin::ServiceDiscovery::SERVICE_OUT, drain.type
184
+ assert_equal 8081, drain.service.port
185
+ assert_equal 'service1.example.com', drain.service.host
186
+ end
187
+
188
+ test 'if service is deleted, service_out event happens' do
189
+ @sd_srv.extend(TestTimerEventHelperWrapper)
190
+ mock = flexmock('dns_resolver', getaddress: '127.0.0.1')
191
+ .should_receive(:getresources)
192
+ .and_return([SRV_RECORD1, SRV_RECORD2])
193
+ .and_return([SRV_RECORD2])
194
+ .mock
195
+
196
+ mock(Resolv::DNS).new { mock }
197
+ @sd_srv.configure(config_element('service_discovery', '', { 'service' => 'service1', 'hostname' => 'example.com', 'dns_lookup' => false }))
198
+ queue = []
199
+
200
+ @sd_srv.start(queue)
201
+
202
+ assert_equal 1, queue.size
203
+ drain = queue.shift
204
+ assert_equal Fluent::Plugin::ServiceDiscovery::SERVICE_OUT, drain.type
205
+ assert_equal 8081, drain.service.port
206
+ assert_equal 'service1.example.com', drain.service.host
207
+ end
208
+
209
+ test 'if new service is added, service_in event happens' do
210
+ @sd_srv.extend(TestTimerEventHelperWrapper)
211
+ mock = flexmock('dns_resolver', getaddress: '127.0.0.1')
212
+ .should_receive(:getresources)
213
+ .and_return([SRV_RECORD2])
214
+ .and_return([SRV_RECORD1, SRV_RECORD2])
215
+ .mock
216
+
217
+ mock(Resolv::DNS).new { mock }
218
+ @sd_srv.configure(config_element('service_discovery', '', { 'service' => 'service1', 'hostname' => 'example.com', 'dns_lookup' => false }))
219
+ queue = []
220
+
221
+ @sd_srv.start(queue)
222
+
223
+ assert_equal 1, queue.size
224
+ join = queue.shift
225
+ assert_equal Fluent::Plugin::ServiceDiscovery::SERVICE_IN, join.type
226
+ assert_equal 8081, join.service.port
227
+ assert_equal 'service1.example.com', join.service.host
228
+ end
229
+ end
230
+ end