fluentd 0.12.43 → 0.14.0

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 (253) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +6 -0
  3. data/.gitignore +2 -0
  4. data/.travis.yml +33 -21
  5. data/CONTRIBUTING.md +1 -0
  6. data/ChangeLog +1239 -0
  7. data/README.md +0 -25
  8. data/Rakefile +2 -1
  9. data/Vagrantfile +17 -0
  10. data/appveyor.yml +35 -0
  11. data/example/filter_stdout.conf +5 -5
  12. data/example/in_forward.conf +2 -2
  13. data/example/in_http.conf +2 -2
  14. data/example/in_out_forward.conf +17 -0
  15. data/example/in_syslog.conf +2 -2
  16. data/example/in_tail.conf +2 -2
  17. data/example/in_tcp.conf +2 -2
  18. data/example/in_udp.conf +2 -2
  19. data/example/out_copy.conf +4 -4
  20. data/example/out_file.conf +2 -2
  21. data/example/out_forward.conf +2 -2
  22. data/example/out_forward_buf_file.conf +23 -0
  23. data/example/v0_12_filter.conf +8 -8
  24. data/fluent.conf +29 -0
  25. data/fluentd.gemspec +18 -11
  26. data/lib/fluent/agent.rb +60 -58
  27. data/lib/fluent/command/cat.rb +1 -1
  28. data/lib/fluent/command/debug.rb +7 -5
  29. data/lib/fluent/command/fluentd.rb +97 -2
  30. data/lib/fluent/compat/call_super_mixin.rb +67 -0
  31. data/lib/fluent/compat/filter.rb +50 -0
  32. data/lib/fluent/compat/formatter.rb +109 -0
  33. data/lib/fluent/compat/input.rb +50 -0
  34. data/lib/fluent/compat/output.rb +617 -0
  35. data/lib/fluent/compat/output_chain.rb +60 -0
  36. data/lib/fluent/compat/parser.rb +163 -0
  37. data/lib/fluent/compat/propagate_default.rb +62 -0
  38. data/lib/fluent/config.rb +23 -20
  39. data/lib/fluent/config/configure_proxy.rb +119 -70
  40. data/lib/fluent/config/dsl.rb +5 -18
  41. data/lib/fluent/config/element.rb +72 -8
  42. data/lib/fluent/config/error.rb +0 -3
  43. data/lib/fluent/config/literal_parser.rb +0 -2
  44. data/lib/fluent/config/parser.rb +4 -4
  45. data/lib/fluent/config/section.rb +39 -28
  46. data/lib/fluent/config/types.rb +2 -13
  47. data/lib/fluent/config/v1_parser.rb +1 -3
  48. data/lib/fluent/configurable.rb +48 -16
  49. data/lib/fluent/daemon.rb +15 -0
  50. data/lib/fluent/engine.rb +26 -52
  51. data/lib/fluent/env.rb +6 -4
  52. data/lib/fluent/event.rb +58 -11
  53. data/lib/fluent/event_router.rb +5 -5
  54. data/lib/fluent/filter.rb +2 -50
  55. data/lib/fluent/formatter.rb +4 -293
  56. data/lib/fluent/input.rb +2 -32
  57. data/lib/fluent/label.rb +2 -2
  58. data/lib/fluent/load.rb +3 -2
  59. data/lib/fluent/log.rb +107 -38
  60. data/lib/fluent/match.rb +0 -36
  61. data/lib/fluent/mixin.rb +117 -7
  62. data/lib/fluent/msgpack_factory.rb +62 -0
  63. data/lib/fluent/output.rb +7 -612
  64. data/lib/fluent/output_chain.rb +23 -0
  65. data/lib/fluent/parser.rb +4 -800
  66. data/lib/fluent/plugin.rb +100 -121
  67. data/lib/fluent/plugin/bare_output.rb +63 -0
  68. data/lib/fluent/plugin/base.rb +121 -0
  69. data/lib/fluent/plugin/buf_file.rb +101 -182
  70. data/lib/fluent/plugin/buf_memory.rb +9 -92
  71. data/lib/fluent/plugin/buffer.rb +473 -0
  72. data/lib/fluent/plugin/buffer/chunk.rb +135 -0
  73. data/lib/fluent/plugin/buffer/file_chunk.rb +339 -0
  74. data/lib/fluent/plugin/buffer/memory_chunk.rb +100 -0
  75. data/lib/fluent/plugin/exec_util.rb +80 -75
  76. data/lib/fluent/plugin/file_util.rb +33 -28
  77. data/lib/fluent/plugin/file_wrapper.rb +120 -0
  78. data/lib/fluent/plugin/filter.rb +51 -0
  79. data/lib/fluent/plugin/filter_grep.rb +13 -40
  80. data/lib/fluent/plugin/filter_record_transformer.rb +22 -18
  81. data/lib/fluent/plugin/formatter.rb +93 -0
  82. data/lib/fluent/plugin/formatter_csv.rb +48 -0
  83. data/lib/fluent/plugin/formatter_hash.rb +32 -0
  84. data/lib/fluent/plugin/formatter_json.rb +47 -0
  85. data/lib/fluent/plugin/formatter_ltsv.rb +42 -0
  86. data/lib/fluent/plugin/formatter_msgpack.rb +32 -0
  87. data/lib/fluent/plugin/formatter_out_file.rb +45 -0
  88. data/lib/fluent/plugin/formatter_single_value.rb +34 -0
  89. data/lib/fluent/plugin/formatter_stdout.rb +39 -0
  90. data/lib/fluent/plugin/in_debug_agent.rb +4 -0
  91. data/lib/fluent/plugin/in_dummy.rb +22 -18
  92. data/lib/fluent/plugin/in_exec.rb +18 -8
  93. data/lib/fluent/plugin/in_forward.rb +36 -79
  94. data/lib/fluent/plugin/in_gc_stat.rb +4 -0
  95. data/lib/fluent/plugin/in_http.rb +21 -18
  96. data/lib/fluent/plugin/in_monitor_agent.rb +15 -48
  97. data/lib/fluent/plugin/in_object_space.rb +6 -1
  98. data/lib/fluent/plugin/in_stream.rb +7 -3
  99. data/lib/fluent/plugin/in_syslog.rb +46 -95
  100. data/lib/fluent/plugin/in_tail.rb +58 -640
  101. data/lib/fluent/plugin/in_tcp.rb +8 -1
  102. data/lib/fluent/plugin/in_udp.rb +8 -18
  103. data/lib/fluent/plugin/input.rb +33 -0
  104. data/lib/fluent/plugin/multi_output.rb +95 -0
  105. data/lib/fluent/plugin/out_buffered_null.rb +59 -0
  106. data/lib/fluent/plugin/out_copy.rb +11 -7
  107. data/lib/fluent/plugin/out_exec.rb +15 -11
  108. data/lib/fluent/plugin/out_exec_filter.rb +18 -10
  109. data/lib/fluent/plugin/out_file.rb +34 -5
  110. data/lib/fluent/plugin/out_forward.rb +25 -19
  111. data/lib/fluent/plugin/out_null.rb +0 -14
  112. data/lib/fluent/plugin/out_roundrobin.rb +11 -7
  113. data/lib/fluent/plugin/out_stdout.rb +5 -7
  114. data/lib/fluent/plugin/out_stream.rb +3 -1
  115. data/lib/fluent/plugin/output.rb +979 -0
  116. data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
  117. data/lib/fluent/plugin/parser.rb +244 -0
  118. data/lib/fluent/plugin/parser_apache.rb +24 -0
  119. data/lib/fluent/plugin/parser_apache2.rb +84 -0
  120. data/lib/fluent/plugin/parser_apache_error.rb +21 -0
  121. data/lib/fluent/plugin/parser_csv.rb +31 -0
  122. data/lib/fluent/plugin/parser_json.rb +79 -0
  123. data/lib/fluent/plugin/parser_ltsv.rb +50 -0
  124. data/lib/fluent/plugin/parser_multiline.rb +102 -0
  125. data/lib/fluent/plugin/parser_nginx.rb +24 -0
  126. data/lib/fluent/plugin/parser_none.rb +36 -0
  127. data/lib/fluent/plugin/parser_syslog.rb +82 -0
  128. data/lib/fluent/plugin/parser_tsv.rb +37 -0
  129. data/lib/fluent/plugin/socket_util.rb +119 -117
  130. data/lib/fluent/plugin/storage.rb +84 -0
  131. data/lib/fluent/plugin/storage_local.rb +116 -0
  132. data/lib/fluent/plugin/string_util.rb +16 -13
  133. data/lib/fluent/plugin_helper.rb +39 -0
  134. data/lib/fluent/plugin_helper/child_process.rb +298 -0
  135. data/lib/fluent/plugin_helper/compat_parameters.rb +99 -0
  136. data/lib/fluent/plugin_helper/event_emitter.rb +80 -0
  137. data/lib/fluent/plugin_helper/event_loop.rb +118 -0
  138. data/lib/fluent/plugin_helper/retry_state.rb +177 -0
  139. data/lib/fluent/plugin_helper/storage.rb +308 -0
  140. data/lib/fluent/plugin_helper/thread.rb +147 -0
  141. data/lib/fluent/plugin_helper/timer.rb +85 -0
  142. data/lib/fluent/plugin_id.rb +63 -0
  143. data/lib/fluent/process.rb +21 -30
  144. data/lib/fluent/registry.rb +21 -9
  145. data/lib/fluent/root_agent.rb +115 -40
  146. data/lib/fluent/supervisor.rb +330 -320
  147. data/lib/fluent/system_config.rb +42 -18
  148. data/lib/fluent/test.rb +6 -1
  149. data/lib/fluent/test/base.rb +23 -3
  150. data/lib/fluent/test/driver/base.rb +247 -0
  151. data/lib/fluent/test/driver/event_feeder.rb +98 -0
  152. data/lib/fluent/test/driver/filter.rb +35 -0
  153. data/lib/fluent/test/driver/input.rb +31 -0
  154. data/lib/fluent/test/driver/output.rb +78 -0
  155. data/lib/fluent/test/driver/test_event_router.rb +45 -0
  156. data/lib/fluent/test/filter_test.rb +0 -1
  157. data/lib/fluent/test/formatter_test.rb +2 -1
  158. data/lib/fluent/test/input_test.rb +23 -17
  159. data/lib/fluent/test/output_test.rb +28 -39
  160. data/lib/fluent/test/parser_test.rb +1 -1
  161. data/lib/fluent/time.rb +104 -1
  162. data/lib/fluent/{status.rb → unique_id.rb} +15 -24
  163. data/lib/fluent/version.rb +1 -1
  164. data/lib/fluent/winsvc.rb +72 -0
  165. data/test/compat/test_calls_super.rb +164 -0
  166. data/test/config/test_config_parser.rb +83 -0
  167. data/test/config/test_configurable.rb +547 -274
  168. data/test/config/test_configure_proxy.rb +146 -29
  169. data/test/config/test_dsl.rb +3 -181
  170. data/test/config/test_element.rb +274 -0
  171. data/test/config/test_literal_parser.rb +1 -1
  172. data/test/config/test_section.rb +79 -7
  173. data/test/config/test_system_config.rb +21 -0
  174. data/test/config/test_types.rb +3 -26
  175. data/test/helper.rb +78 -8
  176. data/test/plugin/test_bare_output.rb +118 -0
  177. data/test/plugin/test_base.rb +75 -0
  178. data/test/plugin/test_buf_file.rb +420 -521
  179. data/test/plugin/test_buf_memory.rb +32 -194
  180. data/test/plugin/test_buffer.rb +981 -0
  181. data/test/plugin/test_buffer_chunk.rb +110 -0
  182. data/test/plugin/test_buffer_file_chunk.rb +770 -0
  183. data/test/plugin/test_buffer_memory_chunk.rb +265 -0
  184. data/test/plugin/test_filter.rb +255 -0
  185. data/test/plugin/test_filter_grep.rb +2 -73
  186. data/test/plugin/test_filter_record_transformer.rb +24 -68
  187. data/test/plugin/test_filter_stdout.rb +6 -6
  188. data/test/plugin/test_in_debug_agent.rb +2 -0
  189. data/test/plugin/test_in_dummy.rb +11 -17
  190. data/test/plugin/test_in_exec.rb +6 -25
  191. data/test/plugin/test_in_forward.rb +112 -151
  192. data/test/plugin/test_in_gc_stat.rb +2 -0
  193. data/test/plugin/test_in_http.rb +106 -157
  194. data/test/plugin/test_in_object_space.rb +21 -5
  195. data/test/plugin/test_in_stream.rb +14 -13
  196. data/test/plugin/test_in_syslog.rb +30 -275
  197. data/test/plugin/test_in_tail.rb +95 -282
  198. data/test/plugin/test_in_tcp.rb +14 -0
  199. data/test/plugin/test_in_udp.rb +21 -67
  200. data/test/plugin/test_input.rb +122 -0
  201. data/test/plugin/test_multi_output.rb +180 -0
  202. data/test/plugin/test_out_buffered_null.rb +79 -0
  203. data/test/plugin/test_out_copy.rb +15 -2
  204. data/test/plugin/test_out_exec.rb +75 -25
  205. data/test/plugin/test_out_exec_filter.rb +74 -8
  206. data/test/plugin/test_out_file.rb +61 -7
  207. data/test/plugin/test_out_forward.rb +92 -15
  208. data/test/plugin/test_out_roundrobin.rb +1 -0
  209. data/test/plugin/test_out_stdout.rb +22 -13
  210. data/test/plugin/test_out_stream.rb +18 -0
  211. data/test/plugin/test_output.rb +515 -0
  212. data/test/plugin/test_output_as_buffered.rb +1540 -0
  213. data/test/plugin/test_output_as_buffered_overflow.rb +247 -0
  214. data/test/plugin/test_output_as_buffered_retries.rb +808 -0
  215. data/test/plugin/test_output_as_buffered_secondary.rb +776 -0
  216. data/test/plugin/test_output_as_standard.rb +362 -0
  217. data/test/plugin/test_owned_by.rb +35 -0
  218. data/test/plugin/test_storage.rb +167 -0
  219. data/test/plugin/test_storage_local.rb +8 -0
  220. data/test/plugin_helper/test_child_process.rb +599 -0
  221. data/test/plugin_helper/test_compat_parameters.rb +175 -0
  222. data/test/plugin_helper/test_event_emitter.rb +51 -0
  223. data/test/plugin_helper/test_event_loop.rb +52 -0
  224. data/test/plugin_helper/test_retry_state.rb +399 -0
  225. data/test/plugin_helper/test_storage.rb +411 -0
  226. data/test/plugin_helper/test_thread.rb +164 -0
  227. data/test/plugin_helper/test_timer.rb +100 -0
  228. data/test/scripts/exec_script.rb +0 -6
  229. data/test/scripts/fluent/plugin/out_test.rb +3 -0
  230. data/test/test_config.rb +13 -4
  231. data/test/test_event.rb +24 -13
  232. data/test/test_event_router.rb +8 -7
  233. data/test/test_event_time.rb +187 -0
  234. data/test/test_formatter.rb +13 -51
  235. data/test/test_input.rb +1 -1
  236. data/test/test_log.rb +239 -16
  237. data/test/test_mixin.rb +1 -1
  238. data/test/test_output.rb +53 -66
  239. data/test/test_parser.rb +105 -323
  240. data/test/test_plugin_helper.rb +81 -0
  241. data/test/test_root_agent.rb +4 -52
  242. data/test/test_supervisor.rb +272 -0
  243. data/test/test_unique_id.rb +47 -0
  244. metadata +181 -55
  245. data/CHANGELOG.md +0 -710
  246. data/lib/fluent/buffer.rb +0 -365
  247. data/lib/fluent/plugin/filter_parser.rb +0 -107
  248. data/lib/fluent/plugin/in_status.rb +0 -76
  249. data/lib/fluent/test/helpers.rb +0 -86
  250. data/test/plugin/data/log/foo/bar2 +0 -0
  251. data/test/plugin/test_filter_parser.rb +0 -744
  252. data/test/plugin/test_in_status.rb +0 -38
  253. data/test/test_buffer.rb +0 -624
data/test/test_mixin.rb CHANGED
@@ -208,7 +208,7 @@ module MixinTest
208
208
 
209
209
  def test_timezone_invalid
210
210
  assert_raise(Fluent::ConfigError) do
211
- d = create_driver(Fluent::SetTimeKeyMixin, %[
211
+ create_driver(Fluent::SetTimeKeyMixin, %[
212
212
  include_time_key true
213
213
  timezone Invalid/Invalid
214
214
  ])
data/test/test_output.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  require_relative 'helper'
2
2
  require 'fluent/test'
3
3
  require 'fluent/output'
4
+ require 'fluent/output_chain'
4
5
  require 'timecop'
5
- require 'flexmock'
6
+ require 'flexmock/test_unit'
6
7
 
7
8
  module FluentOutputTest
8
9
  include Fluent
@@ -47,7 +48,6 @@ module FluentOutputTest
47
48
  assert_equal nil, d.instance.max_retry_wait
48
49
  assert_equal 1.0, d.instance.retry_wait
49
50
  assert_equal 1, d.instance.num_threads
50
- assert_equal 20.0, d.instance.slow_flush_log_threshold
51
51
  assert_equal 1, d.instance.queued_chunk_flush_interval
52
52
 
53
53
  # max_retry_wait
@@ -58,12 +58,15 @@ module FluentOutputTest
58
58
  d = create_driver(CONFIG + %[disable_retry_limit true])
59
59
  assert_equal true, d.instance.disable_retry_limit
60
60
 
61
- # retry_wait is converted to Float for calc_retry_wait
62
- d = create_driver(CONFIG + %[retry_wait 1s])
63
- assert_equal Float, d.instance.retry_wait.class
61
+ #### retry_state cares it
62
+ # # retry_wait is converted to Float for calc_retry_wait
63
+ # d = create_driver(CONFIG + %[retry_wait 1s])
64
+ # assert_equal Float, d.instance.retry_wait.class
64
65
  end
65
66
 
66
67
  def test_calc_retry_wait
68
+ omit "too internal test"
69
+
67
70
  # default
68
71
  d = create_driver
69
72
  d.instance.retry_limit.times {
@@ -82,6 +85,8 @@ module FluentOutputTest
82
85
  end
83
86
 
84
87
  def test_calc_retry_wait_with_integer_retry_wait
88
+ omit "too internal test"
89
+
85
90
  d = create_driver(CONFIG + %[retry_wait 2s])
86
91
  d.instance.retry_limit.times {
87
92
  d.instance.instance_eval { @num_errors += 1 }
@@ -90,6 +95,8 @@ module FluentOutputTest
90
95
  end
91
96
 
92
97
  def test_large_num_retries
98
+ omit "too internal test"
99
+
93
100
  # Test that everything works properly after a very large number of
94
101
  # retries and we hit the expected max_retry_wait.
95
102
  exp_max_retry_wait = 300
@@ -135,6 +142,8 @@ module FluentOutputTest
135
142
  end
136
143
 
137
144
  def test_submit_flush_target
145
+ omit "too internal test"
146
+
138
147
  # default
139
148
  d = create_mock_driver
140
149
  d.instance.start_mock
@@ -188,6 +197,8 @@ module FluentOutputTest
188
197
  end
189
198
 
190
199
  test "force_flush works on retrying" do
200
+ omit "too internal test"
201
+
191
202
  d = create_driver(CONFIG)
192
203
  d.instance.start
193
204
  buffer = d.instance.instance_variable_get(:@buffer)
@@ -202,67 +213,25 @@ module FluentOutputTest
202
213
  10.times { sleep 0.05 }
203
214
  end
204
215
  end
216
+ end
205
217
 
206
- sub_test_case "test slow_flush_log_threshold" do
207
- def create_slow_driver(conf, sleep_time)
208
- d = Fluent::Test::BufferedOutputTestDriver.new(Fluent::BufferedOutput) do
209
- attr_accessor :sleep_time
210
-
211
- def initialize
212
- super
213
- @_written_check_mutex = Mutex.new
214
- @_written_check = false
215
- end
216
-
217
- def written_check
218
- @_written_check_mutex.synchronize { @_written_check }
219
- end
220
-
221
- def write(chunk)
222
- sleep @sleep_time
223
- end
224
-
225
- def try_flush
226
- super
227
- @_written_check_mutex.synchronize { @_written_check = true }
228
- end
229
- end.configure(conf)
230
- d.instance.sleep_time = sleep_time
231
- d
232
- end
233
-
234
- def setup
235
- # output#try_flush uses $log, so it should be replaced
236
- @orig_log = $log
237
- $log = Fluent::Test::TestLogger.new
238
- end
218
+ class ObjectBufferedOutputTest < ::Test::Unit::TestCase
219
+ include FluentOutputTest
239
220
 
240
- def teardown
241
- $log = @orig_log
242
- end
221
+ def setup
222
+ Fluent::Test.setup
223
+ end
243
224
 
244
- test "flush took longer time than slow_flush_log_threshold" do
245
- d = create_slow_driver(%[
246
- slow_flush_log_threshold 0.5
247
- ], 1.5)
248
- run_driver(d)
249
- assert_equal 1, $log.logs.count { |line| line =~ /buffer flush took longer time than slow_flush_log_threshold:/ }
250
- end
225
+ CONFIG = %[]
251
226
 
252
- test "flush took lower time than slow_flush_log_threshold. No logs" do
253
- d = create_slow_driver(%[
254
- slow_flush_log_threshold 5.0
255
- ], 0)
256
- run_driver(d)
257
- assert_equal 0, $log.logs.count { |line| line =~ /buffer flush took longer time than slow_flush_log_threshold:/ }
258
- end
227
+ def create_driver(conf=CONFIG)
228
+ Fluent::Test::OutputTestDriver.new(Fluent::ObjectBufferedOutput).configure(conf, true)
229
+ end
259
230
 
260
- def run_driver(d)
261
- d.instance.start
262
- d.instance.emit('test', OneEventStream.new(@time.to_i, {"message" => "foo"}), NullOutputChain.instance)
263
- d.instance.force_flush
264
- until d.instance.written_check; end
265
- end
231
+ def test_configure
232
+ # default
233
+ d = create_driver
234
+ assert_equal true, d.instance.time_as_integer
266
235
  end
267
236
  end
268
237
 
@@ -278,10 +247,19 @@ module FluentOutputTest
278
247
 
279
248
  TMP_DIR = File.expand_path(File.dirname(__FILE__) + "/tmp/time_sliced_output")
280
249
 
281
- CONFIG = %[buffer_path #{TMP_DIR}/foo]
250
+ CONFIG = %[
251
+ buffer_path #{TMP_DIR}/foo
252
+ time_slice_format %Y%m%d
253
+ ]
254
+
255
+ class TimeSlicedOutputTestPlugin < Fluent::TimeSlicedOutput
256
+ def format(tag, time, record)
257
+ ''
258
+ end
259
+ end
282
260
 
283
261
  def create_driver(conf=CONFIG)
284
- Fluent::Test::TimeSlicedOutputTestDriver.new(Fluent::TimeSlicedOutput).configure(conf, true)
262
+ Fluent::Test::TimeSlicedOutputTestDriver.new(TimeSlicedOutputTestPlugin).configure(conf, true)
285
263
  end
286
264
 
287
265
  sub_test_case "force_flush test" do
@@ -296,6 +274,8 @@ module FluentOutputTest
296
274
  end
297
275
 
298
276
  test "force_flush immediately flushes" do
277
+ omit "too internal test"
278
+
299
279
  d = create_driver(CONFIG + %[
300
280
  time_format %Y%m%d%H%M%S
301
281
  ])
@@ -320,17 +300,24 @@ module FluentOutputTest
320
300
  end
321
301
 
322
302
  test "emit with valid event" do
303
+ omit "there's no #emit method anymore in output plugins"
304
+
323
305
  d = create_driver
324
306
  d.instance.start
325
- d.instance.emit('test', OneEventStream.new(@time.to_i, {"message" => "foo"}), NullOutputChain.instance)
307
+ if d.instance.method(:emit).arity == 3
308
+ d.instance.emit('test', OneEventStream.new(@time.to_i, {"message" => "foo"}), NullOutputChain.instance)
309
+ else
310
+ d.instance.emit('test', OneEventStream.new(@time.to_i, {"message" => "foo"}))
311
+ end
326
312
  assert_equal 0, d.instance.log.logs.size
327
313
  end
328
314
 
329
315
  test "emit with invalid event" do
330
316
  d = create_driver
331
317
  d.instance.start
332
- d.instance.emit('test', OneEventStream.new('string', 10), NullOutputChain.instance)
333
- assert_equal 1, d.instance.log.logs.count { |line| line =~ /dump an error event/ }
318
+ assert_raise ArgumentError, "time must be a Fluent::EventTime (or Integer)" do
319
+ d.instance.emit_events('test', OneEventStream.new('string', 10))
320
+ end
334
321
  end
335
322
  end
336
323
  end
data/test/test_parser.rb CHANGED
@@ -1,11 +1,22 @@
1
1
  require_relative 'helper'
2
2
  require 'fluent/test'
3
3
  require 'fluent/parser'
4
- require 'fluent/plugin/string_util'
5
4
 
6
5
  module ParserTest
7
6
  include Fluent
8
7
 
8
+ def setup
9
+ Fluent::Test.setup
10
+ end
11
+
12
+ def str2time(str_time, format = nil)
13
+ if format
14
+ Fluent::EventTime.from_time(Time.strptime(str_time, format))
15
+ else
16
+ Fluent::EventTime.parse(str_time)
17
+ end
18
+ end
19
+
9
20
  class BaseParserTest < ::Test::Unit::TestCase
10
21
  include ParserTest
11
22
 
@@ -63,24 +74,28 @@ module ParserTest
63
74
  def test_call_with_parse
64
75
  parser = TextParser::TimeParser.new(nil)
65
76
 
66
- time = event_time('2013-09-18 12:00:00 +0900')
67
- assert_equal_event_time(time, parser.parse('2013-09-18 12:00:00 +0900'))
77
+ assert(parser.parse('2013-09-18 12:00:00 +0900').is_a?(Fluent::EventTime))
78
+
79
+ time = str2time('2013-09-18 12:00:00 +0900')
80
+ assert_equal(time, parser.parse('2013-09-18 12:00:00 +0900'))
68
81
  end
69
82
 
70
83
  def test_parse_with_strptime
71
84
  parser = TextParser::TimeParser.new('%d/%b/%Y:%H:%M:%S %z')
72
85
 
73
- time = event_time('28/Feb/2013:12:00:00 +0900', format: '%d/%b/%Y:%H:%M:%S %z')
74
- assert_equal_event_time(time, parser.parse('28/Feb/2013:12:00:00 +0900'))
86
+ assert(parser.parse('28/Feb/2013:12:00:00 +0900').is_a?(Fluent::EventTime))
87
+
88
+ time = str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z')
89
+ assert_equal(time, parser.parse('28/Feb/2013:12:00:00 +0900'))
75
90
  end
76
91
 
77
- data('with sec' => '2017-01-01T12:00:00+09:00',
78
- 'with msec' => '2017-01-01T12:00:00.123+09:00')
79
- def test_parse_with_iso8601(data)
80
- parser = TextParser::TimeParser.new('%iso8601')
92
+ def test_parse_nsec_with_strptime
93
+ parser = TextParser::TimeParser.new('%d/%b/%Y:%H:%M:%S:%N %z')
81
94
 
82
- time = event_time(data)
83
- assert_equal_event_time(time, parser.parse(data))
95
+ assert(parser.parse('28/Feb/2013:12:00:00:123456789 +0900').is_a?(Fluent::EventTime))
96
+
97
+ time = str2time('28/Feb/2013:12:00:00:123456789 +0900', '%d/%b/%Y:%H:%M:%S:%N %z')
98
+ assert_equal_event_time(time, parser.parse('28/Feb/2013:12:00:00:123456789 +0900'))
84
99
  end
85
100
 
86
101
  def test_parse_with_invalid_argument
@@ -99,14 +114,14 @@ module ParserTest
99
114
 
100
115
  def internal_test_case(parser)
101
116
  text = '192.168.0.1 - - [28/Feb/2013:12:00:00 +0900] [14/Feb/2013:12:00:00 +0900] "true /,/user HTTP/1.1" 200 777'
102
- [parser.parse(text), parser.parse(text) { |time, record| return time, record}].each { |time, record|
103
- assert_equal_event_time(event_time('28/Feb/2013:12:00:00 +0900', format: '%d/%b/%Y:%H:%M:%S %z'), time)
117
+ parser.parse(text) { |time, record|
118
+ assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
104
119
  assert_equal({
105
120
  'user' => '-',
106
121
  'flag' => true,
107
122
  'code' => 200.0,
108
123
  'size' => 777,
109
- 'date' => event_time('14/Feb/2013:12:00:00 +0900', format: '%d/%b/%Y:%H:%M:%S %z'),
124
+ 'date' => str2time('14/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'),
110
125
  'host' => '192.168.0.1',
111
126
  'path' => ['/', '/user']
112
127
  }, record)
@@ -140,18 +155,18 @@ module ParserTest
140
155
  )
141
156
  text = '2013-02-28 12:00:00 +0900'
142
157
  parser.parse(text) do |time, record|
143
- assert_equal event_time(text), time
158
+ assert_equal Fluent::EventTime.parse(text), time
144
159
  end
145
160
  end
146
161
 
147
162
  def test_parse_without_time
148
- time_at_start = event_time()
163
+ time_at_start = Time.now.to_i
149
164
  text = "tagomori_satoshi tagomoris 34\n"
150
165
 
151
166
  parser = TextParser::RegexpParser.new(Regexp.new(%q!^(?<name>[^ ]*) (?<user>[^ ]*) (?<age>\d*)$!))
152
- parser.configure('types'=>'name:string,user:string,age:bool')
167
+ parser.configure('types'=>'name:string,user:string,age:integer')
153
168
 
154
- [parser.parse(text), parser.parse(text) { |time, record| return time, record}].each { |time, record|
169
+ parser.parse(text) { |time, record|
155
170
  assert time && time >= time_at_start, "parser puts current time without time input"
156
171
  assert_equal "tagomori_satoshi", record["name"]
157
172
  assert_equal "tagomoris", record["user"]
@@ -161,7 +176,8 @@ module ParserTest
161
176
  parser2 = Fluent::Test::ParserTestDriver.new(TextParser::RegexpParser, Regexp.new(%q!^(?<name>[^ ]*) (?<user>[^ ]*) (?<age>\d*)$!))
162
177
  parser2.configure('types'=>'name:string,user:string,age:integer')
163
178
  parser2.instance.estimate_current_event = false
164
- [parser2.parse(text), parser2.parse(text) { |time, record| return time, record}].each { |time, record|
179
+
180
+ parser2.parse(text) { |time, record|
165
181
  assert_equal "tagomori_satoshi", record["name"]
166
182
  assert_equal "tagomoris", record["user"]
167
183
  assert_equal 34, record["age"]
@@ -200,14 +216,14 @@ module ParserTest
200
216
  include ParserTest
201
217
 
202
218
  def setup
203
- @parser = TextParser::TEMPLATE_REGISTRY.lookup('apache').call
219
+ @parser = Fluent::Plugin.new_parser('apache')
204
220
  end
205
221
 
206
222
  data('parse' => :parse, 'call' => :call)
207
223
  def test_call(method_name)
208
224
  m = @parser.method(method_name)
209
225
  m.call('192.168.0.1 - - [28/Feb/2013:12:00:00 +0900] "GET / HTTP/1.1" 200 777') { |time, record|
210
- assert_equal_event_time(event_time('28/Feb/2013:12:00:00 +0900', format: '%d/%b/%Y:%H:%M:%S %z'), time)
226
+ assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
211
227
  assert_equal({
212
228
  'user' => '-',
213
229
  'method' => 'GET',
@@ -236,7 +252,8 @@ module ParserTest
236
252
  include ParserTest
237
253
 
238
254
  def setup
239
- @parser = TextParser::TEMPLATE_REGISTRY.lookup('apache_error').call
255
+ @parser = Fluent::Plugin.new_parser('apache_error')
256
+ @parser.configure({})
240
257
  @expected = {
241
258
  'level' => 'error',
242
259
  'client' => '127.0.0.1',
@@ -246,21 +263,21 @@ module ParserTest
246
263
 
247
264
  def test_parse
248
265
  @parser.parse('[Wed Oct 11 14:32:52 2000] [error] [client 127.0.0.1] client denied by server configuration') { |time, record|
249
- assert_equal_event_time(event_time('Wed Oct 11 14:32:52 2000'), time)
266
+ assert_equal(str2time('Wed Oct 11 14:32:52 2000'), time)
250
267
  assert_equal(@expected, record)
251
268
  }
252
269
  end
253
270
 
254
271
  def test_parse_with_pid
255
272
  @parser.parse('[Wed Oct 11 14:32:52 2000] [error] [pid 1000] [client 127.0.0.1] client denied by server configuration') { |time, record|
256
- assert_equal_event_time(event_time('Wed Oct 11 14:32:52 2000'), time)
273
+ assert_equal(str2time('Wed Oct 11 14:32:52 2000'), time)
257
274
  assert_equal(@expected.merge('pid' => '1000'), record)
258
275
  }
259
276
  end
260
277
 
261
278
  def test_parse_without_client
262
279
  @parser.parse('[Wed Oct 11 14:32:52 2000] [notice] Apache/2.2.15 (Unix) DAV/2 configured -- resuming normal operations') { |time, record|
263
- assert_equal_event_time(event_time('Wed Oct 11 14:32:52 2000'), time)
280
+ assert_equal(str2time('Wed Oct 11 14:32:52 2000'), time)
264
281
  assert_equal({
265
282
  'level' => 'notice',
266
283
  'message' => 'Apache/2.2.15 (Unix) DAV/2 configured -- resuming normal operations'
@@ -288,7 +305,7 @@ module ParserTest
288
305
 
289
306
  def test_parse
290
307
  @parser.parse('192.168.0.1 - - [28/Feb/2013:12:00:00 +0900] "GET / HTTP/1.1" 200 777 "-" "Opera/12.0"') { |time, record|
291
- assert_equal_event_time(event_time('28/Feb/2013:12:00:00 +0900', format: '%d/%b/%Y:%H:%M:%S %z'), time)
308
+ assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
292
309
  assert_equal(@expected, record)
293
310
  }
294
311
  assert_equal(TextParser::ApacheParser::REGEXP, @parser.patterns['format'])
@@ -297,18 +314,10 @@ module ParserTest
297
314
 
298
315
  def test_parse_without_http_version
299
316
  @parser.parse('192.168.0.1 - - [28/Feb/2013:12:00:00 +0900] "GET /" 200 777 "-" "Opera/12.0"') { |time, record|
300
- assert_equal_event_time(event_time('28/Feb/2013:12:00:00 +0900', format: '%d/%b/%Y:%H:%M:%S %z'), time)
317
+ assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
301
318
  assert_equal(@expected, record)
302
319
  }
303
320
  end
304
-
305
- def test_parse_with_escape_sequence
306
- @parser.parse('192.168.0.1 - - [28/Feb/2013:12:00:00 +0900] "GET /\" HTTP/1.1" 200 777 "referer \\\ \"" "user agent \\\ \""') { |_, record|
307
- assert_equal('/\"', record['path'])
308
- assert_equal('referer \\\ \"', record['referer'])
309
- assert_equal('user agent \\\ \"', record['agent'])
310
- }
311
- end
312
321
  end
313
322
 
314
323
  class SyslogParserTest < ::Test::Unit::TestCase
@@ -327,7 +336,7 @@ module ParserTest
327
336
  def test_parse
328
337
  @parser.configure({})
329
338
  @parser.parse('Feb 28 12:00:00 192.168.0.1 fluentd[11111]: [error] Syslog test') { |time, record|
330
- assert_equal_event_time(event_time('Feb 28 12:00:00', format: '%b %d %H:%M:%S'), time)
339
+ assert_equal(str2time('Feb 28 12:00:00', '%b %d %H:%M:%S'), time)
331
340
  assert_equal(@expected, record)
332
341
  }
333
342
  assert_equal(TextParser::SyslogParser::REGEXP, @parser.instance.patterns['format'])
@@ -337,7 +346,7 @@ module ParserTest
337
346
  def test_parse_with_time_format
338
347
  @parser.configure('time_format' => '%b %d %M:%S:%H')
339
348
  @parser.parse('Feb 28 00:00:12 192.168.0.1 fluentd[11111]: [error] Syslog test') { |time, record|
340
- assert_equal_event_time(event_time('Feb 28 12:00:00', format: '%b %d %H:%M:%S'), time)
349
+ assert_equal(str2time('Feb 28 12:00:00', '%b %d %H:%M:%S'), time)
341
350
  assert_equal(@expected, record)
342
351
  }
343
352
  assert_equal('%b %d %M:%S:%H', @parser.instance.patterns['time_format'])
@@ -346,7 +355,7 @@ module ParserTest
346
355
  def test_parse_with_priority
347
356
  @parser.configure('with_priority' => true)
348
357
  @parser.parse('<6>Feb 28 12:00:00 192.168.0.1 fluentd[11111]: [error] Syslog test') { |time, record|
349
- assert_equal_event_time(event_time('Feb 28 12:00:00', format: '%b %d %H:%M:%S'), time)
358
+ assert_equal(str2time('Feb 28 12:00:00', '%b %d %H:%M:%S'), time)
350
359
  assert_equal(@expected.merge('pri' => 6), record)
351
360
  }
352
361
  assert_equal(TextParser::SyslogParser::REGEXP_WITH_PRI, @parser.instance.patterns['format'])
@@ -356,7 +365,7 @@ module ParserTest
356
365
  def test_parse_without_colon
357
366
  @parser.configure({})
358
367
  @parser.parse('Feb 28 12:00:00 192.168.0.1 fluentd[11111] [error] Syslog test') { |time, record|
359
- assert_equal_event_time(event_time('Feb 28 12:00:00', format: '%b %d %H:%M:%S'), time)
368
+ assert_equal(str2time('Feb 28 12:00:00', '%b %d %H:%M:%S'), time)
360
369
  assert_equal(@expected, record)
361
370
  }
362
371
  assert_equal(TextParser::SyslogParser::REGEXP, @parser.instance.patterns['format'])
@@ -373,256 +382,6 @@ module ParserTest
373
382
  assert_equal "Feb 28 00:00:12", record['time']
374
383
  end
375
384
  end
376
-
377
- def test_parse_various_characters_for_tag
378
- ident = '~!@#$%^&*()_+=-`]{};"\'/?\\,.<>'
379
- @parser.configure({})
380
- @parser.parse("Feb 28 12:00:00 192.168.0.1 #{ident}[11111]: [error] Syslog test") { |time, record|
381
- assert_equal_event_time(event_time('Feb 28 12:00:00', format: '%b %d %H:%M:%S'), time)
382
- assert_equal(@expected.merge('ident' => ident), record)
383
- }
384
- end
385
-
386
- def test_parse_various_characters_for_tag_with_priority
387
- ident = '~!@#$%^&*()_+=-`]{};"\'/?\\,.<>'
388
- @parser.configure({'with_priority' => true})
389
- @parser.parse("<6>Feb 28 12:00:00 192.168.0.1 #{ident}[11111]: [error] Syslog test") { |time, record|
390
- assert_equal_event_time(event_time('Feb 28 12:00:00', format: '%b %d %H:%M:%S'), time)
391
- assert_equal(@expected.merge('pri' => 6, 'ident' => ident), record)
392
- }
393
- end
394
-
395
- class TestRFC5424Regexp < self
396
- def test_parse_with_rfc5424_message
397
- @parser.configure(
398
- 'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
399
- 'message_format' => 'rfc5424',
400
- 'with_priority' => true,
401
- )
402
- text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
403
- @parser.parse(text) do |time, record|
404
- assert_equal(event_time("2017-02-06T13:14:15.003Z", format: '%Y-%m-%dT%H:%M:%S.%L%z'), time)
405
- assert_equal "-", record["pid"]
406
- assert_equal "-", record["msgid"]
407
- assert_equal "-", record["extradata"]
408
- assert_equal "Hi, from Fluentd!", record["message"]
409
- end
410
- assert_equal(TextParser::SyslogParser::REGEXP_RFC5424_WITH_PRI,
411
- @parser.instance.patterns['format'])
412
-
413
- end
414
-
415
- def test_parse_with_rfc5424_message_and_without_priority
416
- @parser.configure(
417
- 'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
418
- 'message_format' => 'rfc5424',
419
- )
420
- text = '2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
421
- @parser.instance.parse(text) do |time, record|
422
- assert_equal(event_time("2017-02-06T13:14:15.003Z", format: '%Y-%m-%dT%H:%M:%S.%L%z'), time)
423
- assert_equal "-", record["pid"]
424
- assert_equal "-", record["msgid"]
425
- assert_equal "-", record["extradata"]
426
- assert_equal "Hi, from Fluentd!", record["message"]
427
- end
428
- assert_equal(TextParser::SyslogParser::REGEXP_RFC5424,
429
- @parser.instance.patterns['format'])
430
- end
431
-
432
- def test_parse_with_rfc5424_message_without_time_format
433
- @parser.configure(
434
- 'message_format' => 'rfc5424',
435
- 'with_priority' => true,
436
- )
437
- text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
438
- @parser.instance.parse(text) do |time, record|
439
- assert_equal(event_time("2017-02-06T13:14:15.003Z", format: '%Y-%m-%dT%H:%M:%S.%L%z'), time)
440
- assert_equal "-", record["pid"]
441
- assert_equal "-", record["msgid"]
442
- assert_equal "-", record["extradata"]
443
- assert_equal "Hi, from Fluentd!", record["message"]
444
- end
445
- end
446
-
447
- def test_parse_with_rfc5424_structured_message
448
- @parser.configure(
449
- 'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
450
- 'message_format' => 'rfc5424',
451
- 'with_priority' => true,
452
- )
453
- 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!'
454
- @parser.parse(text) do |time, record|
455
- assert_equal(event_time("2017-02-06T13:14:15.003Z", format: '%Y-%m-%dT%H:%M:%S.%L%z'), time)
456
- assert_equal "11111", record["pid"]
457
- assert_equal "ID24224", record["msgid"]
458
- assert_equal "[exampleSDID@20224 iut=\"3\" eventSource=\"Application\" eventID=\"11211\"]",
459
- record["extradata"]
460
- assert_equal "Hi, from Fluentd!", record["message"]
461
- end
462
- end
463
- end
464
-
465
- class TestAutoRegexp < self
466
- def test_auto_with_legacy_syslog_message
467
- @parser.configure(
468
- 'time_format' => '%b %d %M:%S:%H',
469
- 'mseeage_format' => 'auto',
470
- )
471
- text = 'Feb 28 00:00:12 192.168.0.1 fluentd[11111]: [error] Syslog test'
472
- @parser.parse(text) do |time, record|
473
- assert_equal(event_time("Feb 28 00:00:12", format: '%b %d %M:%S:%H'), time)
474
- assert_equal(@expected, record)
475
- end
476
- end
477
-
478
- def test_auto_with_legacy_syslog_priority_message
479
- @parser.configure(
480
- 'time_format' => '%b %d %M:%S:%H',
481
- 'with_priority' => true,
482
- 'mseeage_format' => 'auto',
483
- )
484
- text = '<6>Feb 28 12:00:00 192.168.0.1 fluentd[11111]: [error] Syslog test'
485
- @parser.parse(text) do |time, record|
486
- assert_equal(event_time("Feb 28 12:00:00", format: '%b %d %M:%S:%H'), time)
487
- assert_equal(@expected.merge('pri' => 6), record)
488
- end
489
- assert_equal(TextParser::SyslogParser::REGEXP_WITH_PRI,
490
- @parser.instance.patterns['format'])
491
- end
492
-
493
- def test_parse_with_rfc5424_message
494
- @parser.configure(
495
- 'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
496
- 'message_format' => 'auto',
497
- 'with_priority' => true,
498
- )
499
- text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
500
- @parser.parse(text) do |time, record|
501
- assert_equal(event_time("2017-02-06T13:14:15.003Z", format: '%Y-%m-%dT%H:%M:%S.%L%z'), time)
502
- assert_equal "-", record["pid"]
503
- assert_equal "-", record["msgid"]
504
- assert_equal "-", record["extradata"]
505
- assert_equal "Hi, from Fluentd!", record["message"]
506
- end
507
- assert_equal(TextParser::SyslogParser::REGEXP_RFC5424_WITH_PRI,
508
- @parser.instance.patterns['format'])
509
- end
510
-
511
- def test_parse_with_rfc5424_structured_message
512
- @parser.configure(
513
- 'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
514
- 'message_format' => 'auto',
515
- 'with_priority' => true,
516
- )
517
- 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!'
518
- @parser.parse(text) do |time, record|
519
- assert_equal(event_time("2017-02-06T13:14:15.003Z", format: '%Y-%m-%dT%H:%M:%S.%L%z'), time)
520
- assert_equal "11111", record["pid"]
521
- assert_equal "ID24224", record["msgid"]
522
- assert_equal "[exampleSDID@20224 iut=\"3\" eventSource=\"Application\" eventID=\"11211\"]",
523
- record["extradata"]
524
- assert_equal "Hi, from Fluentd!", record["message"]
525
- end
526
- assert_equal(TextParser::SyslogParser::REGEXP_RFC5424_WITH_PRI,
527
- @parser.instance.patterns['format'])
528
- end
529
-
530
- def test_parse_with_both_message_type
531
- @parser.configure(
532
- 'time_format' => '%b %d %M:%S:%H',
533
- 'rfc5424_time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
534
- 'message_format' => 'auto',
535
- 'with_priority' => true,
536
- )
537
- text = '<1>Feb 28 12:00:00 192.168.0.1 fluentd[11111]: [error] Syslog test'
538
- @parser.parse(text) do |time, record|
539
- assert_equal(event_time("Feb 28 12:00:00", format: '%b %d %M:%S:%H'), time)
540
- assert_equal(@expected.merge('pri' => 1), record)
541
- end
542
- assert_equal(TextParser::SyslogParser::REGEXP_WITH_PRI,
543
- @parser.instance.patterns['format'])
544
-
545
- 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!'
546
- @parser.parse(text) do |time, record|
547
- assert_equal(event_time("2017-02-06T13:14:15.003Z", format: '%Y-%m-%dT%H:%M:%S.%L%z'), time)
548
- assert_equal "11111", record["pid"]
549
- assert_equal "ID24224", record["msgid"]
550
- assert_equal "[exampleSDID@20224 iut=\"3\" eventSource=\"Application\" eventID=\"11211\"]",
551
- record["extradata"]
552
- assert_equal "Hi, from Fluentd!", record["message"]
553
- end
554
- assert_equal(TextParser::SyslogParser::REGEXP_RFC5424_WITH_PRI,
555
- @parser.instance.patterns['format'])
556
-
557
- text = '<1>Feb 28 12:00:02 192.168.0.1 fluentd[11111]: [error] Syslog test'
558
- @parser.parse(text) do |time, record|
559
- assert_equal(event_time("Feb 28 12:00:02", format: '%b %d %M:%S:%H'), time)
560
- assert_equal(@expected.merge('pri' => 1), record)
561
- end
562
- assert_equal(TextParser::SyslogParser::REGEXP_WITH_PRI,
563
- @parser.instance.patterns['format'])
564
-
565
- text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
566
- @parser.parse(text) do |time, record|
567
- assert_equal(event_time("2017-02-06T13:14:15.003Z", format: '%Y-%m-%dT%H:%M:%S.%L%z'), time)
568
- assert_equal "-", record["pid"]
569
- assert_equal "-", record["msgid"]
570
- assert_equal "-", record["extradata"]
571
- assert_equal "Hi, from Fluentd!", record["message"]
572
- end
573
- assert_equal(TextParser::SyslogParser::REGEXP_RFC5424_WITH_PRI,
574
- @parser.instance.patterns['format'])
575
-
576
- end
577
-
578
- def test_parse_with_both_message_type_and_priority
579
- @parser.configure(
580
- 'time_format' => '%b %d %M:%S:%H',
581
- 'rfc5424_time_format' => '%Y-%m-%dT%H:%M:%S.%L%z',
582
- 'with_priority' => true,
583
- 'message_format' => 'auto',
584
- )
585
- text = '<6>Feb 28 12:00:00 192.168.0.1 fluentd[11111]: [error] Syslog test'
586
- @parser.parse(text) do |time, record|
587
- assert_equal(event_time("Feb 28 12:00:00", format: '%b %d %M:%S:%H'), time)
588
- assert_equal(@expected.merge('pri' => 6), record)
589
- end
590
- assert_equal(TextParser::SyslogParser::REGEXP_WITH_PRI,
591
- @parser.instance.patterns['format'])
592
-
593
- 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!'
594
- @parser.parse(text) do |time, record|
595
- assert_equal(event_time("2017-02-06T13:14:15.003Z", format: '%Y-%m-%dT%H:%M:%S.%L%z'), time)
596
- assert_equal "11111", record["pid"]
597
- assert_equal "ID24224", record["msgid"]
598
- assert_equal "[exampleSDID@20224 iut=\"3\" eventSource=\"Application\" eventID=\"11211\"]",
599
- record["extradata"]
600
- assert_equal "Hi, from Fluentd!", record["message"]
601
- end
602
- assert_equal(TextParser::SyslogParser::REGEXP_RFC5424_WITH_PRI,
603
- @parser.instance.patterns['format'])
604
-
605
- text = '<16>Feb 28 12:00:02 192.168.0.1 fluentd[11111]: [error] Syslog test'
606
- @parser.parse(text) do |time, record|
607
- assert_equal(event_time("Feb 28 12:00:02", format: '%b %d %M:%S:%H'), time)
608
- assert_equal(@expected.merge('pri' => 16), record)
609
- end
610
- assert_equal(TextParser::SyslogParser::REGEXP_WITH_PRI,
611
- @parser.instance.patterns['format'])
612
-
613
- text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!'
614
- @parser.parse(text) do |time, record|
615
- assert_equal(event_time("2017-02-06T13:14:15.003Z", format: '%Y-%m-%dT%H:%M:%S.%L%z'), time)
616
- assert_equal "-", record["pid"]
617
- assert_equal "-", record["msgid"]
618
- assert_equal "-", record["extradata"]
619
- assert_equal "Hi, from Fluentd!", record["message"]
620
- end
621
- assert_equal(TextParser::SyslogParser::REGEXP_RFC5424_WITH_PRI,
622
- @parser.instance.patterns['format'])
623
-
624
- end
625
- end
626
385
  end
627
386
 
628
387
  class JsonParserTest < ::Test::Unit::TestCase
@@ -636,7 +395,7 @@ module ParserTest
636
395
  def test_parse(data)
637
396
  @parser.configure('json_parser' => data)
638
397
  @parser.parse('{"time":1362020400,"host":"192.168.0.1","size":777,"method":"PUT"}') { |time, record|
639
- assert_equal_event_time(event_time('2013-02-28 12:00:00 +0900'), time)
398
+ assert_equal(str2time('2013-02-28 12:00:00 +0900').to_i, time)
640
399
  assert_equal({
641
400
  'host' => '192.168.0.1',
642
401
  'size' => 777,
@@ -680,14 +439,6 @@ module ParserTest
680
439
  }
681
440
  end
682
441
 
683
- data('oj' => 'oj', 'yajl' => 'yajl')
684
- def test_parse_with_colon_string(data)
685
- @parser.configure('json_parser' => data)
686
- @parser.parse('{"time":1362020400,"log":":message"}') { |time, record|
687
- assert_equal(record['log'], ':message')
688
- }
689
- end
690
-
691
442
  data('oj' => 'oj', 'yajl' => 'yajl')
692
443
  def test_parse_with_invalid_time(data)
693
444
  @parser.configure('json_parser' => data)
@@ -696,16 +447,43 @@ module ParserTest
696
447
  end
697
448
  end
698
449
 
450
+ data('oj' => 'oj', 'yajl' => 'yajl')
451
+ def test_parse_float_time(data)
452
+ parser = TextParser::JSONParser.new
453
+ parser.configure('json_parser' => data)
454
+ text = "100.1"
455
+ parser.parse("{\"time\":\"#{text}\"}") do |time, record|
456
+ assert_equal Time.at(text.to_f).to_i, time.sec
457
+ assert_equal Time.at(text.to_f).nsec, time.nsec
458
+ end
459
+ end
460
+
699
461
  data('oj' => 'oj', 'yajl' => 'yajl')
700
462
  def test_parse_with_keep_time_key(data)
701
463
  parser = TextParser::JSONParser.new
464
+ format = "%d/%b/%Y:%H:%M:%S %z"
702
465
  parser.configure(
703
- 'time_format' => "%d/%b/%Y:%H:%M:%S %z",
466
+ 'time_format' => format,
704
467
  'keep_time_key' => 'true',
705
468
  'json_parser' => data
706
469
  )
707
470
  text = "28/Feb/2013:12:00:00 +0900"
708
471
  parser.parse("{\"time\":\"#{text}\"}") do |time, record|
472
+ assert_equal Time.strptime(text, format).to_i, time.sec
473
+ assert_equal text, record['time']
474
+ end
475
+ end
476
+
477
+ data('oj' => 'oj', 'yajl' => 'yajl')
478
+ def test_parse_with_keep_time_key_without_time_format(data)
479
+ parser = TextParser::JSONParser.new
480
+ parser.configure(
481
+ 'keep_time_key' => 'true',
482
+ 'json_parser' => data
483
+ )
484
+ text = "100"
485
+ parser.parse("{\"time\":\"#{text}\"}") do |time, record|
486
+ assert_equal text.to_i, time.sec
709
487
  assert_equal text, record['time']
710
488
  end
711
489
  end
@@ -715,7 +493,7 @@ module ParserTest
715
493
  include ParserTest
716
494
 
717
495
  def setup
718
- @parser = TextParser::TEMPLATE_REGISTRY.lookup('nginx').call
496
+ @parser = Fluent::Plugin.new_parser('nginx')
719
497
  @expected = {
720
498
  'remote' => '127.0.0.1',
721
499
  'host' => '192.168.0.1',
@@ -731,21 +509,21 @@ module ParserTest
731
509
 
732
510
  def test_parse
733
511
  @parser.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|
734
- assert_equal_event_time(event_time('28/Feb/2013:12:00:00 +0900', format: '%d/%b/%Y:%H:%M:%S %z'), time)
512
+ assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
735
513
  assert_equal(@expected, record)
736
514
  }
737
515
  end
738
516
 
739
517
  def test_parse_with_empty_included_path
740
518
  @parser.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|
741
- assert_equal_event_time(event_time('28/Feb/2013:12:00:00 +0900', format: '%d/%b/%Y:%H:%M:%S %z'), time)
519
+ assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
742
520
  assert_equal(@expected.merge('path' => '/a[ ]b'), record)
743
521
  }
744
522
  end
745
523
 
746
524
  def test_parse_without_http_version
747
525
  @parser.parse('127.0.0.1 192.168.0.1 - [28/Feb/2013:12:00:00 +0900] "GET /" 200 777 "-" "Opera/12.0"') { |time, record|
748
- assert_equal_event_time(event_time('28/Feb/2013:12:00:00 +0900', format: '%d/%b/%Y:%H:%M:%S %z'), time)
526
+ assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
749
527
  assert_equal(@expected, record)
750
528
  }
751
529
  end
@@ -774,7 +552,7 @@ module ParserTest
774
552
  parser = TextParser::TSVParser.new
775
553
  parser.configure('keys' => param, 'time_key' => 'time')
776
554
  parser.parse("2013/02/28 12:00:00\t192.168.0.1\t111") { |time, record|
777
- assert_equal_event_time(event_time('2013/02/28 12:00:00', format: '%Y/%m/%d %H:%M:%S'), time)
555
+ assert_equal(str2time('2013/02/28 12:00:00', '%Y/%m/%d %H:%M:%S'), time)
778
556
  assert_equal({
779
557
  'a' => '192.168.0.1',
780
558
  'b' => '111',
@@ -839,10 +617,11 @@ module ParserTest
839
617
  end
840
618
 
841
619
  data('array param' => '["a","b","c","d","e","f"]', 'string param' => 'a,b,c,d,e,f')
842
- def test_parse_with_null_value_pattern(param)
620
+ def test_parse_with_null_value_pattern
843
621
  parser = TextParser::TSVParser.new
844
622
  parser.configure(
845
623
  'keys'=>param,
624
+ 'time_key'=>'time',
846
625
  'null_value_pattern'=>'^(-|null|NULL)$'
847
626
  )
848
627
  parser.parse("-\tnull\tNULL\t\t--\tnuLL") do |time, record|
@@ -856,10 +635,11 @@ module ParserTest
856
635
  end
857
636
 
858
637
  data('array param' => '["a","b"]', 'string param' => 'a,b')
859
- def test_parse_with_null_empty_string(param)
638
+ def test_parse_with_null_empty_string
860
639
  parser = TextParser::TSVParser.new
861
640
  parser.configure(
862
641
  'keys'=>param,
642
+ 'time_key'=>'time',
863
643
  'null_empty_string'=>true
864
644
  )
865
645
  parser.parse("\t ") do |time, record|
@@ -877,7 +657,7 @@ module ParserTest
877
657
  parser = TextParser::CSVParser.new
878
658
  parser.configure('keys' => param, 'time_key' => 'time')
879
659
  parser.parse("2013/02/28 12:00:00,192.168.0.1,111") { |time, record|
880
- assert_equal_event_time(event_time('2013/02/28 12:00:00', format: '%Y/%m/%d %H:%M:%S'), time)
660
+ assert_equal(str2time('2013/02/28 12:00:00', '%Y/%m/%d %H:%M:%S'), time)
881
661
  assert_equal({
882
662
  'c' => '192.168.0.1',
883
663
  'd' => '111',
@@ -926,27 +706,29 @@ module ParserTest
926
706
  end
927
707
 
928
708
  data('array param' => '["a","b","c","d","e","f"]', 'string param' => 'a,b,c,d,e,f')
929
- def test_parse_with_null_value_pattern(param)
709
+ def test_parse_with_null_value_pattern
930
710
  parser = TextParser::CSVParser.new
931
711
  parser.configure(
932
712
  'keys'=>param,
713
+ 'time_key'=>'time',
933
714
  'null_value_pattern'=>'^(-|null|NULL)$'
934
715
  )
935
716
  parser.parse("-,null,NULL,,--,nuLL") do |time, record|
936
717
  assert_nil record['a']
937
718
  assert_nil record['b']
938
719
  assert_nil record['c']
939
- assert_nil record['d']
720
+ assert_equal record['d'], ''
940
721
  assert_equal record['e'], '--'
941
722
  assert_equal record['f'], 'nuLL'
942
723
  end
943
724
  end
944
725
 
945
726
  data('array param' => '["a","b"]', 'string param' => 'a,b')
946
- def test_parse_with_null_empty_string(param)
727
+ def test_parse_with_null_empty_string
947
728
  parser = TextParser::CSVParser.new
948
729
  parser.configure(
949
730
  'keys'=>param,
731
+ 'time_key'=>'time',
950
732
  'null_empty_string'=>true
951
733
  )
952
734
  parser.parse(", ") do |time, record|
@@ -978,7 +760,7 @@ module ParserTest
978
760
  parser = TextParser::LabeledTSVParser.new
979
761
  parser.configure({})
980
762
  parser.parse("time:2013/02/28 12:00:00\thost:192.168.0.1\treq_id:111") { |time, record|
981
- assert_equal_event_time(event_time('2013/02/28 12:00:00', format: '%Y/%m/%d %H:%M:%S'), time)
763
+ assert_equal(str2time('2013/02/28 12:00:00', '%Y/%m/%d %H:%M:%S'), time)
982
764
  assert_equal({
983
765
  'host' => '192.168.0.1',
984
766
  'req_id' => '111',
@@ -993,7 +775,7 @@ module ParserTest
993
775
  'label_delimiter' => '=',
994
776
  )
995
777
  parser.parse('time=2013/02/28 12:00:00,host=192.168.0.1,req_id=111') { |time, record|
996
- assert_equal_event_time(event_time('2013/02/28 12:00:00', format: '%Y/%m/%d %H:%M:%S'), time)
778
+ assert_equal(str2time('2013/02/28 12:00:00', '%Y/%m/%d %H:%M:%S'), time)
997
779
  assert_equal({
998
780
  'host' => '192.168.0.1',
999
781
  'req_id' => '111',
@@ -1008,7 +790,7 @@ module ParserTest
1008
790
  'time_format' => '%d/%b/%Y:%H:%M:%S %z',
1009
791
  )
1010
792
  parser.parse("mytime:28/Feb/2013:12:00:00 +0900\thost:192.168.0.1\treq_id:111") { |time, record|
1011
- assert_equal_event_time(event_time('28/Feb/2013:12:00:00 +0900', format: '%d/%b/%Y:%H:%M:%S %z'), time)
793
+ assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
1012
794
  assert_equal({
1013
795
  'host' => '192.168.0.1',
1014
796
  'req_id' => '111',
@@ -1093,7 +875,7 @@ module ParserTest
1093
875
  end
1094
876
 
1095
877
  def test_parse
1096
- parser = TextParser::TEMPLATE_REGISTRY.lookup('none').call
878
+ parser = Fluent::Plugin.new_parser('none')
1097
879
  parser.configure({})
1098
880
  parser.parse('log message!') { |time, record|
1099
881
  assert_equal({'message' => 'log message!'}, record)
@@ -1111,14 +893,14 @@ module ParserTest
1111
893
  def test_parse_without_default_time
1112
894
  time_at_start = Time.now.to_i
1113
895
 
1114
- parser = TextParser::TEMPLATE_REGISTRY.lookup('none').call
896
+ parser = Fluent::Plugin.new_parser('none')
1115
897
  parser.configure({})
1116
898
  parser.parse('log message!') { |time, record|
1117
899
  assert time && time >= time_at_start, "parser puts current time without time input"
1118
900
  assert_equal({'message' => 'log message!'}, record)
1119
901
  }
1120
902
 
1121
- parser = TextParser::TEMPLATE_REGISTRY.lookup('none').call
903
+ parser = Fluent::Plugin.new_parser('none')
1122
904
  parser.estimate_current_event = false
1123
905
  parser.configure({})
1124
906
  parser.parse('log message!') { |time, record|
@@ -1132,7 +914,7 @@ module ParserTest
1132
914
  include ParserTest
1133
915
 
1134
916
  def create_parser(conf)
1135
- parser = TextParser::TEMPLATE_REGISTRY.lookup('multiline').call
917
+ parser = Fluent::Plugin.new_parser('multiline')
1136
918
  parser.configure(conf)
1137
919
  parser
1138
920
  end
@@ -1153,7 +935,7 @@ javax.management.RuntimeErrorException: null
1153
935
  \tat Main.main(Main.java:16) ~[bin/:na]
1154
936
  EOS
1155
937
 
1156
- assert_equal_event_time(event_time('2013-3-03 14:27:33'), time)
938
+ assert_equal(str2time('2013-3-03 14:27:33').to_i, time)
1157
939
  assert_equal({
1158
940
  "thread" => "main",
1159
941
  "level" => "ERROR",
@@ -1171,7 +953,7 @@ message=test1
1171
953
  EOS
1172
954
 
1173
955
  assert(parser.firstline?('----'))
1174
- assert_equal_event_time(event_time('2013-3-03 14:27:33'), time)
956
+ assert_equal(str2time('2013-3-03 14:27:33').to_i, time)
1175
957
  assert_equal({"message" => "test1"}, record)
1176
958
  }
1177
959
  end
@@ -1193,7 +975,7 @@ Completed 200 OK in 4ms (Views: 3.2ms | ActiveRecord: 0.0ms)
1193
975
  EOS
1194
976
 
1195
977
  assert(parser.firstline?('Started GET "/users/123/" for 127.0.0.1...'))
1196
- assert_equal_event_time(event_time('2013-06-14 12:00:11 +0900'), time)
978
+ assert_equal(str2time('2013-06-14 12:00:11 +0900').to_i, time)
1197
979
  assert_equal({
1198
980
  "method" => "GET",
1199
981
  "path" => "/users/123/",
@@ -1245,7 +1027,7 @@ EOS
1245
1027
 
1246
1028
  def test_lookup_unknown_format
1247
1029
  assert_raise ConfigError do
1248
- TextParser::TEMPLATE_REGISTRY.lookup('unknown')
1030
+ Fluent::Plugin.new_parser('unknown')
1249
1031
  end
1250
1032
  end
1251
1033
 
@@ -1253,7 +1035,7 @@ EOS
1253
1035
  def test_lookup_known_parser(data)
1254
1036
  $LOAD_PATH.unshift(File.join(File.expand_path(File.dirname(__FILE__)), 'scripts'))
1255
1037
  assert_nothing_raised ConfigError do
1256
- TextParser::TEMPLATE_REGISTRY.lookup(data)
1038
+ Fluent::Plugin.new_parser(data)
1257
1039
  end
1258
1040
  $LOAD_PATH.shift
1259
1041
  end
@@ -1261,7 +1043,7 @@ EOS
1261
1043
  def test_parse_with_return
1262
1044
  parser = TextParser.new
1263
1045
  parser.configure('format' => 'none')
1264
- time, record = parser.parse('log message!')
1046
+ _time, record = parser.parse('log message!')
1265
1047
  assert_equal({'message' => 'log message!'}, record)
1266
1048
  end
1267
1049