fluentd 0.14.1 → 0.14.2

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 (129) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +110 -1
  3. data/Rakefile +5 -1
  4. data/appveyor.yml +7 -1
  5. data/example/in_forward.conf +4 -0
  6. data/lib/fluent/compat/exec_util.rb +129 -0
  7. data/lib/fluent/compat/file_util.rb +54 -0
  8. data/lib/fluent/compat/filter.rb +21 -3
  9. data/lib/fluent/compat/formatter.rb +4 -2
  10. data/lib/fluent/compat/formatter_utils.rb +85 -0
  11. data/lib/fluent/compat/handle_tag_and_time_mixin.rb +60 -0
  12. data/lib/fluent/compat/input.rb +1 -3
  13. data/lib/fluent/compat/output.rb +95 -39
  14. data/lib/fluent/compat/parser.rb +17 -0
  15. data/lib/fluent/compat/parser_utils.rb +40 -0
  16. data/lib/fluent/compat/socket_util.rb +165 -0
  17. data/lib/fluent/compat/string_util.rb +34 -0
  18. data/lib/fluent/{test/driver/owner.rb → compat/structured_format_mixin.rb} +5 -11
  19. data/lib/fluent/config/element.rb +2 -2
  20. data/lib/fluent/configurable.rb +2 -1
  21. data/lib/fluent/event.rb +61 -7
  22. data/lib/fluent/event_router.rb +1 -1
  23. data/lib/fluent/plugin.rb +7 -7
  24. data/lib/fluent/plugin/buf_file.rb +5 -2
  25. data/lib/fluent/plugin/buffer.rb +194 -64
  26. data/lib/fluent/plugin/buffer/chunk.rb +28 -3
  27. data/lib/fluent/plugin/buffer/file_chunk.rb +5 -21
  28. data/lib/fluent/plugin/buffer/memory_chunk.rb +1 -11
  29. data/lib/fluent/plugin/exec_util.rb +2 -112
  30. data/lib/fluent/plugin/file_util.rb +3 -38
  31. data/lib/fluent/plugin/file_wrapper.rb +1 -1
  32. data/lib/fluent/plugin/filter_grep.rb +3 -7
  33. data/lib/fluent/plugin/filter_record_transformer.rb +5 -5
  34. data/lib/fluent/plugin/filter_stdout.rb +18 -11
  35. data/lib/fluent/plugin/formatter.rb +0 -48
  36. data/lib/fluent/plugin/formatter_csv.rb +7 -8
  37. data/lib/fluent/plugin/formatter_hash.rb +1 -4
  38. data/lib/fluent/plugin/formatter_json.rb +1 -4
  39. data/lib/fluent/plugin/formatter_ltsv.rb +5 -6
  40. data/lib/fluent/plugin/formatter_msgpack.rb +1 -4
  41. data/lib/fluent/plugin/formatter_out_file.rb +36 -3
  42. data/lib/fluent/plugin/formatter_stdout.rb +36 -1
  43. data/lib/fluent/plugin/in_dummy.rb +9 -2
  44. data/lib/fluent/plugin/in_exec.rb +20 -57
  45. data/lib/fluent/plugin/in_forward.rb +4 -3
  46. data/lib/fluent/plugin/in_object_space.rb +8 -44
  47. data/lib/fluent/plugin/in_syslog.rb +13 -24
  48. data/lib/fluent/plugin/in_tail.rb +3 -0
  49. data/lib/fluent/plugin/out_buffered_stdout.rb +14 -4
  50. data/lib/fluent/plugin/out_exec.rb +7 -5
  51. data/lib/fluent/plugin/out_exec_filter.rb +10 -10
  52. data/lib/fluent/plugin/out_file.rb +1 -3
  53. data/lib/fluent/plugin/out_forward.rb +38 -57
  54. data/lib/fluent/plugin/out_stdout.rb +14 -5
  55. data/lib/fluent/plugin/out_stream.rb +3 -0
  56. data/lib/fluent/plugin/output.rb +31 -14
  57. data/lib/fluent/plugin/parser.rb +0 -69
  58. data/lib/fluent/plugin/parser_apache.rb +10 -6
  59. data/lib/fluent/plugin/parser_apache_error.rb +8 -3
  60. data/lib/fluent/plugin/parser_csv.rb +3 -1
  61. data/lib/fluent/plugin/parser_json.rb +1 -1
  62. data/lib/fluent/plugin/parser_multiline.rb +5 -3
  63. data/lib/fluent/plugin/parser_nginx.rb +10 -6
  64. data/lib/fluent/plugin/parser_regexp.rb +73 -0
  65. data/lib/fluent/plugin/socket_util.rb +2 -148
  66. data/lib/fluent/plugin/storage_local.rb +1 -1
  67. data/lib/fluent/plugin/string_util.rb +3 -18
  68. data/lib/fluent/plugin_helper.rb +1 -0
  69. data/lib/fluent/plugin_helper/compat_parameters.rb +166 -41
  70. data/lib/fluent/plugin_helper/formatter.rb +30 -19
  71. data/lib/fluent/plugin_helper/inject.rb +25 -12
  72. data/lib/fluent/plugin_helper/parser.rb +22 -13
  73. data/lib/fluent/plugin_helper/storage.rb +22 -13
  74. data/lib/fluent/registry.rb +19 -6
  75. data/lib/fluent/supervisor.rb +27 -1
  76. data/lib/fluent/test/driver/base.rb +16 -92
  77. data/lib/fluent/test/driver/base_owned.rb +17 -53
  78. data/lib/fluent/test/driver/base_owner.rb +125 -0
  79. data/lib/fluent/test/driver/filter.rb +24 -2
  80. data/lib/fluent/test/driver/input.rb +2 -2
  81. data/lib/fluent/test/driver/multi_output.rb +2 -2
  82. data/lib/fluent/test/driver/output.rb +3 -5
  83. data/lib/fluent/test/helpers.rb +25 -0
  84. data/lib/fluent/test/input_test.rb +4 -4
  85. data/lib/fluent/test/output_test.rb +3 -3
  86. data/lib/fluent/version.rb +1 -1
  87. data/test/config/test_element.rb +135 -6
  88. data/test/plugin/test_buf_file.rb +71 -3
  89. data/test/plugin/test_buffer.rb +305 -86
  90. data/test/plugin/test_buffer_chunk.rb +60 -2
  91. data/test/plugin/test_buffer_file_chunk.rb +4 -3
  92. data/test/plugin/test_filter_grep.rb +25 -21
  93. data/test/plugin/test_filter_record_transformer.rb +75 -67
  94. data/test/plugin/test_filter_stdout.rb +171 -74
  95. data/test/plugin/test_formatter_csv.rb +94 -0
  96. data/test/plugin/test_formatter_json.rb +30 -0
  97. data/test/plugin/test_formatter_ltsv.rb +52 -0
  98. data/test/plugin/test_formatter_msgpack.rb +28 -0
  99. data/test/plugin/test_formatter_out_file.rb +95 -0
  100. data/test/plugin/test_formatter_single_value.rb +38 -0
  101. data/test/plugin/test_in_dummy.rb +95 -0
  102. data/test/plugin/test_in_exec.rb +27 -31
  103. data/test/plugin/test_in_forward.rb +24 -0
  104. data/test/plugin/test_in_gc_stat.rb +5 -5
  105. data/test/plugin/test_in_object_space.rb +4 -4
  106. data/test/plugin/test_in_syslog.rb +60 -35
  107. data/test/plugin/test_out_buffered_stdout.rb +17 -3
  108. data/test/plugin/test_out_forward.rb +93 -5
  109. data/test/plugin/test_out_stdout.rb +14 -3
  110. data/test/plugin/test_output_as_buffered_retries.rb +20 -0
  111. data/test/plugin/test_output_as_buffered_secondary.rb +16 -0
  112. data/test/plugin/test_output_as_standard.rb +22 -22
  113. data/test/plugin/test_parser_apache.rb +13 -9
  114. data/test/plugin/test_parser_apache_error.rb +11 -6
  115. data/test/plugin/test_parser_csv.rb +35 -25
  116. data/test/plugin/test_parser_nginx.rb +11 -5
  117. data/test/plugin/test_parser_regexp.rb +235 -68
  118. data/test/plugin/test_parser_tsv.rb +54 -58
  119. data/test/plugin_helper/test_compat_parameters.rb +111 -46
  120. data/test/plugin_helper/test_formatter.rb +40 -0
  121. data/test/plugin_helper/test_inject.rb +101 -2
  122. data/test/plugin_helper/test_parser.rb +40 -0
  123. data/test/plugin_helper/test_storage.rb +43 -0
  124. data/test/test_event.rb +93 -0
  125. data/test/test_event_router.rb +13 -4
  126. data/test/test_event_time.rb +0 -3
  127. data/test/test_formatter.rb +7 -164
  128. data/test/test_plugin_classes.rb +28 -1
  129. metadata +24 -3
@@ -208,6 +208,8 @@ class BufferedOutputSecondaryTest < Test::Unit::TestCase
208
208
  @i.secondary.register(:write){|chunk| chunk.read.split("\n").each{|line| written << JSON.parse(line) } }
209
209
  @i.start
210
210
 
211
+ @i.interrupt_flushes
212
+
211
213
  now = Time.parse('2016-04-13 18:33:30 -0700')
212
214
  Timecop.freeze( now )
213
215
 
@@ -270,6 +272,8 @@ class BufferedOutputSecondaryTest < Test::Unit::TestCase
270
272
  @i.secondary.register(:write){|chunk| chunk.read.split("\n").each{|line| written << JSON.parse(line) } }
271
273
  @i.start
272
274
 
275
+ @i.interrupt_flushes
276
+
273
277
  now = Time.parse('2016-04-13 18:33:30 -0700')
274
278
  Timecop.freeze( now )
275
279
 
@@ -333,6 +337,8 @@ class BufferedOutputSecondaryTest < Test::Unit::TestCase
333
337
  @i.secondary.register(:try_write){|chunk| chunks << chunk; chunk.read.split("\n").each{|line| written << JSON.parse(line) } }
334
338
  @i.start
335
339
 
340
+ @i.interrupt_flushes
341
+
336
342
  now = Time.parse('2016-04-13 18:33:30 -0700')
337
343
  Timecop.freeze( now )
338
344
 
@@ -407,6 +413,8 @@ class BufferedOutputSecondaryTest < Test::Unit::TestCase
407
413
  @i.secondary.register(:try_write){|chunk| chunks << chunk; chunk.read.split("\n").each{|line| written << JSON.parse(line) } }
408
414
  @i.start
409
415
 
416
+ @i.interrupt_flushes
417
+
410
418
  now = Time.parse('2016-04-13 18:33:30 -0700')
411
419
  Timecop.freeze( now )
412
420
 
@@ -482,6 +490,8 @@ class BufferedOutputSecondaryTest < Test::Unit::TestCase
482
490
  @i.secondary.register(:write){|chunk| raise "don't use this" }
483
491
  @i.start
484
492
 
493
+ @i.interrupt_flushes
494
+
485
495
  now = Time.parse('2016-04-13 18:33:30 -0700')
486
496
  Timecop.freeze( now )
487
497
 
@@ -564,6 +574,8 @@ class BufferedOutputSecondaryTest < Test::Unit::TestCase
564
574
  @i.secondary.register(:write){|chunk| raise "your secondary is also useless." }
565
575
  @i.start
566
576
 
577
+ @i.interrupt_flushes
578
+
567
579
  now = Time.parse('2016-04-13 18:33:30 -0700')
568
580
  Timecop.freeze( now )
569
581
 
@@ -632,6 +644,8 @@ class BufferedOutputSecondaryTest < Test::Unit::TestCase
632
644
  @i.secondary.register(:write){|chunk| chunk.read.split("\n").each{|line| written << JSON.parse(line) } }
633
645
  @i.start
634
646
 
647
+ @i.interrupt_flushes
648
+
635
649
  now = Time.parse('2016-04-13 18:33:30 -0700')
636
650
  Timecop.freeze( now )
637
651
 
@@ -700,6 +714,8 @@ class BufferedOutputSecondaryTest < Test::Unit::TestCase
700
714
  @i.secondary.register(:write){|chunk| raise "your secondary is also useless." }
701
715
  @i.start
702
716
 
717
+ @i.interrupt_flushes
718
+
703
719
  now = Time.parse('2016-04-13 18:33:30 -0700')
704
720
  Timecop.freeze( now )
705
721
 
@@ -90,7 +90,7 @@ class StandardBufferedOutputTest < Test::Unit::TestCase
90
90
  es = test_event_stream
91
91
 
92
92
  buffer_mock = flexmock(@i.buffer)
93
- buffer_mock.should_receive(:write).once.with({m => [es.to_msgpack_stream, es.size]}, bulk: true, enqueue: false)
93
+ buffer_mock.should_receive(:write).once.with({m => es}, format: Fluent::Plugin::Output::FORMAT_MSGPACK_STREAM, enqueue: false)
94
94
 
95
95
  @i.execute_chunking("mytag.test", es)
96
96
  end
@@ -104,7 +104,7 @@ class StandardBufferedOutputTest < Test::Unit::TestCase
104
104
  es = test_event_stream
105
105
 
106
106
  buffer_mock = flexmock(@i.buffer)
107
- buffer_mock.should_receive(:write).once.with({m => [es.to_msgpack_stream(time_int: true), es.size]}, bulk: true, enqueue: false)
107
+ buffer_mock.should_receive(:write).once.with({m => es}, format: Fluent::Plugin::Output::FORMAT_MSGPACK_STREAM_TIME_INT, enqueue: false)
108
108
 
109
109
  @i.execute_chunking("mytag.test", es)
110
110
  end
@@ -120,7 +120,7 @@ class StandardBufferedOutputTest < Test::Unit::TestCase
120
120
  es = test_event_stream
121
121
 
122
122
  buffer_mock = flexmock(@i.buffer)
123
- buffer_mock.should_receive(:write).once.with({m => [es.to_msgpack_stream, es.size]}, bulk: true, enqueue: false)
123
+ buffer_mock.should_receive(:write).once.with({m => es}, format: Fluent::Plugin::Output::FORMAT_MSGPACK_STREAM, enqueue: false)
124
124
 
125
125
  @i.execute_chunking("mytag.test", es)
126
126
  end
@@ -134,7 +134,7 @@ class StandardBufferedOutputTest < Test::Unit::TestCase
134
134
  es = test_event_stream
135
135
 
136
136
  buffer_mock = flexmock(@i.buffer)
137
- buffer_mock.should_receive(:write).once.with({m => [es.to_msgpack_stream(time_int: true), es.size]}, bulk: true, enqueue: false)
137
+ buffer_mock.should_receive(:write).once.with({m => es}, format: Fluent::Plugin::Output::FORMAT_MSGPACK_STREAM_TIME_INT, enqueue: false)
138
138
 
139
139
  @i.execute_chunking("mytag.test", es)
140
140
  end
@@ -164,10 +164,10 @@ class StandardBufferedOutputTest < Test::Unit::TestCase
164
164
 
165
165
  buffer_mock = flexmock(@i.buffer)
166
166
  buffer_mock.should_receive(:write).once.with({
167
- m1 => [es1.to_msgpack_stream, 3],
168
- m2 => [es2.to_msgpack_stream, 2],
169
- m3 => [es3.to_msgpack_stream, 1],
170
- }, bulk: true, enqueue: false)
167
+ m1 => es1,
168
+ m2 => es2,
169
+ m3 => es3,
170
+ }, format: Fluent::Plugin::Output::FORMAT_MSGPACK_STREAM, enqueue: false)
171
171
 
172
172
  es = test_event_stream
173
173
  @i.execute_chunking("mytag.test", es)
@@ -196,10 +196,10 @@ class StandardBufferedOutputTest < Test::Unit::TestCase
196
196
 
197
197
  buffer_mock = flexmock(@i.buffer)
198
198
  buffer_mock.should_receive(:write).with({
199
- m1 => [es1.to_msgpack_stream(time_int: true), 3],
200
- m2 => [es2.to_msgpack_stream(time_int: true), 2],
201
- m3 => [es3.to_msgpack_stream(time_int: true), 1],
202
- }, bulk: true, enqueue: false)
199
+ m1 => es1,
200
+ m2 => es2,
201
+ m3 => es3,
202
+ }, format: Fluent::Plugin::Output::FORMAT_MSGPACK_STREAM_TIME_INT, enqueue: false)
203
203
 
204
204
  es = test_event_stream
205
205
  @i.execute_chunking("mytag.test", es)
@@ -226,9 +226,9 @@ class StandardBufferedOutputTest < Test::Unit::TestCase
226
226
 
227
227
  buffer_mock = flexmock(@i.buffer)
228
228
  buffer_mock.should_receive(:write).with({
229
- m1 => [es1.to_msgpack_stream, 5],
230
- m2 => [es2.to_msgpack_stream, 1],
231
- }, bulk: true, enqueue: false).once
229
+ m1 => es1,
230
+ m2 => es2,
231
+ }, format: Fluent::Plugin::Output::FORMAT_MSGPACK_STREAM, enqueue: false).once
232
232
 
233
233
  es = test_event_stream
234
234
  @i.execute_chunking("mytag.test", es)
@@ -253,9 +253,9 @@ class StandardBufferedOutputTest < Test::Unit::TestCase
253
253
 
254
254
  buffer_mock = flexmock(@i.buffer)
255
255
  buffer_mock.should_receive(:write).with({
256
- m1 => [es1.to_msgpack_stream(time_int: true), 5],
257
- m2 => [es2.to_msgpack_stream(time_int: true), 1],
258
- }, bulk: true, enqueue: false).once
256
+ m1 => es1,
257
+ m2 => es2,
258
+ }, format: Fluent::Plugin::Output::FORMAT_MSGPACK_STREAM_TIME_INT, enqueue: false).once
259
259
 
260
260
  es = test_event_stream
261
261
  @i.execute_chunking("mytag.test", es)
@@ -273,7 +273,7 @@ class StandardBufferedOutputTest < Test::Unit::TestCase
273
273
  es = test_event_stream
274
274
 
275
275
  buffer_mock = flexmock(@i.buffer)
276
- buffer_mock.should_receive(:write).once.with({m => [es.map{|t,r| [t,r].to_json }.join, es.size]}, bulk: true, enqueue: false)
276
+ buffer_mock.should_receive(:write).once.with({m => es.map{|t,r| [t,r].to_json }}, format: nil, enqueue: false)
277
277
 
278
278
  @i.execute_chunking("mytag.test", es)
279
279
  end
@@ -290,7 +290,7 @@ class StandardBufferedOutputTest < Test::Unit::TestCase
290
290
  es = test_event_stream
291
291
 
292
292
  buffer_mock = flexmock(@i.buffer)
293
- buffer_mock.should_receive(:write).once.with({m => [es.map{|t,r| [t,r].to_json }.join, es.size]}, bulk: true, enqueue: false)
293
+ buffer_mock.should_receive(:write).once.with({m => es.map{|t,r| [t,r].to_json}}, format: nil, enqueue: false)
294
294
 
295
295
  @i.execute_chunking("mytag.test", es)
296
296
  end
@@ -323,7 +323,7 @@ class StandardBufferedOutputTest < Test::Unit::TestCase
323
323
  m1 => es1.map{|t,r| [t,r].to_json },
324
324
  m2 => es2.map{|t,r| [t,r].to_json },
325
325
  m3 => es3.map{|t,r| [t,r].to_json },
326
- }, bulk: false, enqueue: false).once
326
+ }, enqueue: false).once
327
327
 
328
328
  es = test_event_stream
329
329
  @i.execute_chunking("mytag.test", es)
@@ -353,7 +353,7 @@ class StandardBufferedOutputTest < Test::Unit::TestCase
353
353
  buffer_mock.should_receive(:write).with({
354
354
  m1 => es1.map{|t,r| [t,r].to_json },
355
355
  m2 => es2.map{|t,r| [t,r].to_json },
356
- }, bulk: false, enqueue: false).once
356
+ }, enqueue: false).once
357
357
 
358
358
  es = test_event_stream
359
359
  @i.execute_chunking("mytag.test", es)
@@ -1,16 +1,20 @@
1
1
  require_relative '../helper'
2
2
  require 'fluent/test/driver/parser'
3
- require 'fluent/plugin/parser'
3
+ require 'fluent/plugin/parser_apache'
4
4
 
5
5
  class ApacheParserTest < ::Test::Unit::TestCase
6
6
  def setup
7
7
  Fluent::Test.setup
8
- @parser = Fluent::Test::Driver::Parser.new(Fluent::Plugin.new_parser('apache'))
8
+ end
9
+
10
+ def create_driver(conf = {})
11
+ Fluent::Test::Driver::Parser.new(Fluent::Plugin::ApacheParser.new).configure(conf)
9
12
  end
10
13
 
11
14
  data('parse' => :parse, 'call' => :call)
12
15
  def test_call(method_name)
13
- m = @parser.instance.method(method_name)
16
+ d = create_driver
17
+ m = d.instance.method(method_name)
14
18
  m.call('192.168.0.1 - - [28/Feb/2013:12:00:00 +0900] "GET / HTTP/1.1" 200 777') { |time, record|
15
19
  assert_equal(event_time('28/Feb/2013:12:00:00 +0900', format: '%d/%b/%Y:%H:%M:%S %z'), time)
16
20
  assert_equal({
@@ -25,13 +29,13 @@ class ApacheParserTest < ::Test::Unit::TestCase
25
29
  end
26
30
 
27
31
  def test_parse_with_keep_time_key
28
- parser = Fluent::Test::Driver::Parser.new(Fluent::Plugin.new_parser('apache'))
29
- parser.instance.configure(
30
- 'time_format'=>"%d/%b/%Y:%H:%M:%S %z",
31
- 'keep_time_key'=>'true',
32
- )
32
+ conf = {
33
+ 'time_format' => "%d/%b/%Y:%H:%M:%S %z",
34
+ 'keep_time_key' => 'true',
35
+ }
36
+ d = create_driver(conf)
33
37
  text = '192.168.0.1 - - [28/Feb/2013:12:00:00 +0900] "GET / HTTP/1.1" 200 777'
34
- parser.instance.parse(text) do |time, record|
38
+ d.instance.parse(text) do |_time, record|
35
39
  assert_equal "28/Feb/2013:12:00:00 +0900", record['time']
36
40
  end
37
41
  end
@@ -1,12 +1,10 @@
1
1
  require_relative '../helper'
2
2
  require 'fluent/test/driver/parser'
3
- require 'fluent/plugin/parser'
3
+ require 'fluent/plugin/parser_apache_error'
4
4
 
5
5
  class ApacheErrorParserTest < ::Test::Unit::TestCase
6
6
  def setup
7
7
  Fluent::Test.setup
8
- @parser = Fluent::Test::Driver::Parser.new(Fluent::Plugin.new_parser('apache_error'))
9
- @parser.configure({})
10
8
  @expected = {
11
9
  'level' => 'error',
12
10
  'client' => '127.0.0.1',
@@ -14,22 +12,29 @@ class ApacheErrorParserTest < ::Test::Unit::TestCase
14
12
  }
15
13
  end
16
14
 
15
+ def create_driver
16
+ Fluent::Test::Driver::Parser.new(Fluent::Plugin::ApacheErrorParser.new).configure({})
17
+ end
18
+
17
19
  def test_parse
18
- @parser.instance.parse('[Wed Oct 11 14:32:52 2000] [error] [client 127.0.0.1] client denied by server configuration') { |time, record|
20
+ d = create_driver
21
+ d.instance.parse('[Wed Oct 11 14:32:52 2000] [error] [client 127.0.0.1] client denied by server configuration') { |time, record|
19
22
  assert_equal(event_time('Wed Oct 11 14:32:52 2000'), time)
20
23
  assert_equal(@expected, record)
21
24
  }
22
25
  end
23
26
 
24
27
  def test_parse_with_pid
25
- @parser.instance.parse('[Wed Oct 11 14:32:52 2000] [error] [pid 1000] [client 127.0.0.1] client denied by server configuration') { |time, record|
28
+ d = create_driver
29
+ d.instance.parse('[Wed Oct 11 14:32:52 2000] [error] [pid 1000] [client 127.0.0.1] client denied by server configuration') { |time, record|
26
30
  assert_equal(event_time('Wed Oct 11 14:32:52 2000'), time)
27
31
  assert_equal(@expected.merge('pid' => '1000'), record)
28
32
  }
29
33
  end
30
34
 
31
35
  def test_parse_without_client
32
- @parser.instance.parse('[Wed Oct 11 14:32:52 2000] [notice] Apache/2.2.15 (Unix) DAV/2 configured -- resuming normal operations') { |time, record|
36
+ d = create_driver
37
+ d.instance.parse('[Wed Oct 11 14:32:52 2000] [notice] Apache/2.2.15 (Unix) DAV/2 configured -- resuming normal operations') { |time, record|
33
38
  assert_equal(event_time('Wed Oct 11 14:32:52 2000'), time)
34
39
  assert_equal({
35
40
  'level' => 'notice',
@@ -1,17 +1,20 @@
1
1
  require_relative '../helper'
2
2
  require 'fluent/test/driver/parser'
3
- require 'fluent/plugin/parser'
3
+ require 'fluent/plugin/parser_csv'
4
4
 
5
5
  class CSVParserTest < ::Test::Unit::TestCase
6
6
  def setup
7
7
  Fluent::Test.setup
8
8
  end
9
9
 
10
+ def create_driver(conf={})
11
+ Fluent::Test::Driver::Parser.new(Fluent::Plugin::CSVParser).configure(conf)
12
+ end
13
+
10
14
  data('array param' => '["time","c","d"]', 'string param' => 'time,c,d')
11
15
  def test_parse(param)
12
- parser = Fluent::Test::Driver::Parser.new(Fluent::Plugin::CSVParser)
13
- parser.configure('keys' => param, 'time_key' => 'time')
14
- parser.instance.parse("2013/02/28 12:00:00,192.168.0.1,111") { |time, record|
16
+ d = create_driver('keys' => param, 'time_key' => 'time')
17
+ d.instance.parse("2013/02/28 12:00:00,192.168.0.1,111") { |time, record|
15
18
  assert_equal(event_time('2013/02/28 12:00:00', format: '%Y/%m/%d %H:%M:%S'), time)
16
19
  assert_equal({
17
20
  'c' => '192.168.0.1',
@@ -24,9 +27,8 @@ class CSVParserTest < ::Test::Unit::TestCase
24
27
  def test_parse_without_time(param)
25
28
  time_at_start = Time.now.to_i
26
29
 
27
- parser = Fluent::Test::Driver::Parser.new(Fluent::Plugin::CSVParser)
28
- parser.configure('keys' => param)
29
- parser.instance.parse("192.168.0.1,111") { |time, record|
30
+ d = create_driver('keys' => param)
31
+ d.instance.parse("192.168.0.1,111") { |time, record|
30
32
  assert time && time >= time_at_start, "parser puts current time without time input"
31
33
  assert_equal({
32
34
  'c' => '192.168.0.1',
@@ -34,10 +36,10 @@ class CSVParserTest < ::Test::Unit::TestCase
34
36
  }, record)
35
37
  }
36
38
 
37
- parser = Fluent::Test::Driver::Parser.new(Fluent::Plugin::CSVParser)
38
- parser.instance.estimate_current_event = false
39
- parser.configure('keys' => param, 'time_key' => 'time')
40
- parser.instance.parse("192.168.0.1,111") { |time, record|
39
+ d = Fluent::Test::Driver::Parser.new(Fluent::Plugin::CSVParser)
40
+ d.instance.estimate_current_event = false
41
+ d.configure('keys' => param)
42
+ d.instance.parse("192.168.0.1,111") { |time, record|
41
43
  assert_equal({
42
44
  'c' => '192.168.0.1',
43
45
  'd' => '111',
@@ -47,48 +49,56 @@ class CSVParserTest < ::Test::Unit::TestCase
47
49
  end
48
50
 
49
51
  def test_parse_with_keep_time_key
50
- parser = Fluent::Test::Driver::Parser.new(Fluent::Plugin::CSVParser)
51
- parser.configure(
52
+ d = create_driver(
52
53
  'keys'=>'time',
53
54
  'time_key'=>'time',
54
55
  'time_format'=>"%d/%b/%Y:%H:%M:%S %z",
55
56
  'keep_time_key'=>'true',
56
57
  )
57
58
  text = '28/Feb/2013:12:00:00 +0900'
58
- parser.instance.parse(text) do |time, record|
59
+ d.instance.parse(text) do |time, record|
59
60
  assert_equal text, record['time']
60
61
  end
61
62
  end
62
63
 
63
64
  data('array param' => '["a","b","c","d","e","f"]', 'string param' => 'a,b,c,d,e,f')
64
- def test_parse_with_null_value_pattern
65
- parser = Fluent::Test::Driver::Parser.new(Fluent::Plugin::CSVParser)
66
- parser.configure(
65
+ def test_parse_with_null_value_pattern(param)
66
+ d = create_driver(
67
67
  'keys'=>param,
68
- 'time_key'=>'time',
69
68
  'null_value_pattern'=>'^(-|null|NULL)$'
70
69
  )
71
- parser.instance.parse("-,null,NULL,,--,nuLL") do |time, record|
70
+ d.instance.parse("-,null,NULL,,--,nuLL") do |time, record|
72
71
  assert_nil record['a']
73
72
  assert_nil record['b']
74
73
  assert_nil record['c']
75
- assert_equal record['d'], ''
74
+ assert_nil record['d']
76
75
  assert_equal record['e'], '--'
77
76
  assert_equal record['f'], 'nuLL'
78
77
  end
79
78
  end
80
79
 
81
80
  data('array param' => '["a","b"]', 'string param' => 'a,b')
82
- def test_parse_with_null_empty_string
83
- parser = Fluent::Test::Driver::Parser.new(Fluent::Plugin::CSVParser)
84
- parser.configure(
81
+ def test_parse_with_null_empty_string(param)
82
+ d = create_driver(
85
83
  'keys'=>param,
86
- 'time_key'=>'time',
87
84
  'null_empty_string'=>true
88
85
  )
89
- parser.instance.parse(", ") do |time, record|
86
+ d.instance.parse(", ") do |time, record|
90
87
  assert_nil record['a']
91
88
  assert_equal record['b'], ' '
92
89
  end
93
90
  end
91
+
92
+ data('array param' => '["a","b","c"]', 'string param' => 'a,b,c')
93
+ def test_parse_with_option_delimiter(param)
94
+ d = create_driver(
95
+ 'keys'=>param,
96
+ 'delimiter'=>' ',
97
+ )
98
+ d.instance.parse("123 456 789") do |time, record|
99
+ assert_equal record['a'], '123'
100
+ assert_equal record['b'], '456'
101
+ assert_equal record['c'], '789'
102
+ end
103
+ end
94
104
  end
@@ -1,11 +1,10 @@
1
1
  require_relative '../helper'
2
2
  require 'fluent/test/driver/parser'
3
- require 'fluent/plugin/parser'
3
+ require 'fluent/plugin/parser_nginx'
4
4
 
5
5
  class NginxParserTest < ::Test::Unit::TestCase
6
6
  def setup
7
7
  Fluent::Test.setup
8
- @parser = Fluent::Test::Driver::Parser.new(Fluent::Plugin.new_parser('nginx'))
9
8
  @expected = {
10
9
  'remote' => '127.0.0.1',
11
10
  'host' => '192.168.0.1',
@@ -19,22 +18,29 @@ class NginxParserTest < ::Test::Unit::TestCase
19
18
  }
20
19
  end
21
20
 
21
+ def create_driver
22
+ Fluent::Test::Driver::Parser.new(Fluent::Plugin::NginxParser.new).configure({})
23
+ end
24
+
22
25
  def test_parse
23
- @parser.instance.parse('127.0.0.1 192.168.0.1 - [28/Feb/2013:12:00:00 +0900] "GET / HTTP/1.1" 200 777 "-" "Opera/12.0"') { |time, record|
26
+ d = create_driver
27
+ d.instance.parse('127.0.0.1 192.168.0.1 - [28/Feb/2013:12:00:00 +0900] "GET / HTTP/1.1" 200 777 "-" "Opera/12.0"') { |time, record|
24
28
  assert_equal(event_time('28/Feb/2013:12:00:00 +0900', format: '%d/%b/%Y:%H:%M:%S %z'), time)
25
29
  assert_equal(@expected, record)
26
30
  }
27
31
  end
28
32
 
29
33
  def test_parse_with_empty_included_path
30
- @parser.instance.parse('127.0.0.1 192.168.0.1 - [28/Feb/2013:12:00:00 +0900] "GET /a[ ]b HTTP/1.1" 200 777 "-" "Opera/12.0"') { |time, record|
34
+ d = create_driver
35
+ d.instance.parse('127.0.0.1 192.168.0.1 - [28/Feb/2013:12:00:00 +0900] "GET /a[ ]b HTTP/1.1" 200 777 "-" "Opera/12.0"') { |time, record|
31
36
  assert_equal(event_time('28/Feb/2013:12:00:00 +0900', format: '%d/%b/%Y:%H:%M:%S %z'), time)
32
37
  assert_equal(@expected.merge('path' => '/a[ ]b'), record)
33
38
  }
34
39
  end
35
40
 
36
41
  def test_parse_without_http_version
37
- @parser.instance.parse('127.0.0.1 192.168.0.1 - [28/Feb/2013:12:00:00 +0900] "GET /" 200 777 "-" "Opera/12.0"') { |time, record|
42
+ d = create_driver
43
+ d.instance.parse('127.0.0.1 192.168.0.1 - [28/Feb/2013:12:00:00 +0900] "GET /" 200 777 "-" "Opera/12.0"') { |time, record|
38
44
  assert_equal(event_time('28/Feb/2013:12:00:00 +0900', format: '%d/%b/%Y:%H:%M:%S %z'), time)
39
45
  assert_equal(@expected, record)
40
46
  }