fluentd 0.12.40 → 1.6.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 (428) hide show
  1. checksums.yaml +5 -5
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +39 -0
  3. data/.github/ISSUE_TEMPLATE/feature_request.md +23 -0
  4. data/.github/ISSUE_TEMPLATE.md +17 -0
  5. data/.github/PULL_REQUEST_TEMPLATE.md +13 -0
  6. data/.gitignore +5 -0
  7. data/.gitlab/cicd-template.yaml +10 -0
  8. data/.gitlab-ci.yml +147 -0
  9. data/.travis.yml +56 -20
  10. data/ADOPTERS.md +5 -0
  11. data/CHANGELOG.md +1369 -0
  12. data/CONTRIBUTING.md +16 -5
  13. data/GOVERNANCE.md +55 -0
  14. data/Gemfile +5 -0
  15. data/GithubWorkflow.md +78 -0
  16. data/LICENSE +202 -0
  17. data/MAINTAINERS.md +7 -0
  18. data/README.md +23 -11
  19. data/Rakefile +48 -2
  20. data/Vagrantfile +17 -0
  21. data/appveyor.yml +37 -0
  22. data/bin/fluent-binlog-reader +7 -0
  23. data/bin/fluent-ca-generate +6 -0
  24. data/bin/fluent-plugin-config-format +5 -0
  25. data/bin/fluent-plugin-generate +5 -0
  26. data/bin/fluentd +3 -0
  27. data/code-of-conduct.md +3 -0
  28. data/example/copy_roundrobin.conf +39 -0
  29. data/example/counter.conf +18 -0
  30. data/example/in_dummy_blocks.conf +17 -0
  31. data/example/in_dummy_with_compression.conf +23 -0
  32. data/example/in_forward.conf +7 -0
  33. data/example/in_forward_client.conf +37 -0
  34. data/example/in_forward_shared_key.conf +15 -0
  35. data/example/in_forward_tls.conf +14 -0
  36. data/example/in_forward_users.conf +24 -0
  37. data/example/in_forward_workers.conf +21 -0
  38. data/example/in_http.conf +3 -1
  39. data/example/in_out_forward.conf +17 -0
  40. data/example/logevents.conf +25 -0
  41. data/example/multi_filters.conf +61 -0
  42. data/example/out_exec_filter.conf +42 -0
  43. data/example/out_forward.conf +13 -13
  44. data/example/out_forward_buf_file.conf +23 -0
  45. data/example/out_forward_client.conf +109 -0
  46. data/example/out_forward_heartbeat_none.conf +16 -0
  47. data/example/out_forward_shared_key.conf +36 -0
  48. data/example/out_forward_tls.conf +18 -0
  49. data/example/out_forward_users.conf +65 -0
  50. data/example/out_null.conf +36 -0
  51. data/example/secondary_file.conf +42 -0
  52. data/example/suppress_config_dump.conf +7 -0
  53. data/example/worker_section.conf +36 -0
  54. data/fluent.conf +29 -0
  55. data/fluentd.gemspec +21 -11
  56. data/lib/fluent/agent.rb +67 -90
  57. data/lib/fluent/clock.rb +62 -0
  58. data/lib/fluent/command/binlog_reader.rb +244 -0
  59. data/lib/fluent/command/ca_generate.rb +181 -0
  60. data/lib/fluent/command/cat.rb +42 -18
  61. data/lib/fluent/command/debug.rb +12 -10
  62. data/lib/fluent/command/fluentd.rb +153 -5
  63. data/lib/fluent/command/plugin_config_formatter.rb +292 -0
  64. data/lib/fluent/command/plugin_generator.rb +324 -0
  65. data/lib/fluent/compat/call_super_mixin.rb +67 -0
  66. data/lib/fluent/compat/detach_process_mixin.rb +33 -0
  67. data/lib/fluent/compat/exec_util.rb +129 -0
  68. data/lib/fluent/compat/file_util.rb +54 -0
  69. data/lib/fluent/compat/filter.rb +68 -0
  70. data/lib/fluent/compat/formatter.rb +111 -0
  71. data/lib/fluent/compat/formatter_utils.rb +85 -0
  72. data/lib/fluent/compat/handle_tag_and_time_mixin.rb +62 -0
  73. data/lib/fluent/compat/handle_tag_name_mixin.rb +53 -0
  74. data/lib/fluent/compat/input.rb +49 -0
  75. data/lib/fluent/compat/output.rb +718 -0
  76. data/lib/fluent/compat/output_chain.rb +60 -0
  77. data/lib/fluent/compat/parser.rb +310 -0
  78. data/lib/fluent/compat/parser_utils.rb +40 -0
  79. data/lib/fluent/compat/propagate_default.rb +62 -0
  80. data/lib/fluent/compat/record_filter_mixin.rb +34 -0
  81. data/lib/fluent/compat/set_tag_key_mixin.rb +50 -0
  82. data/lib/fluent/compat/set_time_key_mixin.rb +69 -0
  83. data/lib/fluent/compat/socket_util.rb +165 -0
  84. data/lib/fluent/compat/string_util.rb +34 -0
  85. data/lib/fluent/compat/structured_format_mixin.rb +26 -0
  86. data/lib/fluent/compat/type_converter.rb +90 -0
  87. data/lib/fluent/config/configure_proxy.rb +210 -62
  88. data/lib/fluent/config/dsl.rb +12 -5
  89. data/lib/fluent/config/element.rb +107 -9
  90. data/lib/fluent/config/literal_parser.rb +9 -3
  91. data/lib/fluent/config/parser.rb +4 -4
  92. data/lib/fluent/config/section.rb +51 -14
  93. data/lib/fluent/config/types.rb +28 -13
  94. data/lib/fluent/config/v1_parser.rb +3 -5
  95. data/lib/fluent/config.rb +23 -20
  96. data/lib/fluent/configurable.rb +79 -21
  97. data/lib/fluent/counter/base_socket.rb +46 -0
  98. data/lib/fluent/counter/client.rb +297 -0
  99. data/lib/fluent/counter/error.rb +86 -0
  100. data/lib/fluent/counter/mutex_hash.rb +163 -0
  101. data/lib/fluent/counter/server.rb +273 -0
  102. data/lib/fluent/counter/store.rb +205 -0
  103. data/lib/fluent/counter/validator.rb +145 -0
  104. data/lib/fluent/counter.rb +23 -0
  105. data/lib/fluent/daemon.rb +15 -0
  106. data/lib/fluent/engine.rb +102 -65
  107. data/lib/fluent/env.rb +7 -3
  108. data/lib/fluent/error.rb +30 -0
  109. data/lib/fluent/event.rb +197 -21
  110. data/lib/fluent/event_router.rb +93 -10
  111. data/lib/fluent/filter.rb +2 -50
  112. data/lib/fluent/formatter.rb +4 -293
  113. data/lib/fluent/input.rb +2 -32
  114. data/lib/fluent/label.rb +10 -2
  115. data/lib/fluent/load.rb +3 -3
  116. data/lib/fluent/log.rb +348 -81
  117. data/lib/fluent/match.rb +37 -36
  118. data/lib/fluent/mixin.rb +12 -176
  119. data/lib/fluent/msgpack_factory.rb +62 -0
  120. data/lib/fluent/output.rb +10 -612
  121. data/lib/fluent/output_chain.rb +23 -0
  122. data/lib/fluent/parser.rb +4 -800
  123. data/lib/fluent/plugin/bare_output.rb +63 -0
  124. data/lib/fluent/plugin/base.rb +192 -0
  125. data/lib/fluent/plugin/buf_file.rb +128 -174
  126. data/lib/fluent/plugin/buf_memory.rb +9 -92
  127. data/lib/fluent/plugin/buffer/chunk.rb +221 -0
  128. data/lib/fluent/plugin/buffer/file_chunk.rb +383 -0
  129. data/lib/fluent/plugin/buffer/memory_chunk.rb +90 -0
  130. data/lib/fluent/plugin/buffer.rb +779 -0
  131. data/lib/fluent/plugin/compressable.rb +92 -0
  132. data/lib/fluent/plugin/exec_util.rb +3 -108
  133. data/lib/fluent/plugin/file_util.rb +4 -34
  134. data/lib/fluent/plugin/file_wrapper.rb +120 -0
  135. data/lib/fluent/plugin/filter.rb +93 -0
  136. data/lib/fluent/plugin/filter_grep.rb +117 -34
  137. data/lib/fluent/plugin/filter_parser.rb +85 -62
  138. data/lib/fluent/plugin/filter_record_transformer.rb +27 -39
  139. data/lib/fluent/plugin/filter_stdout.rb +15 -12
  140. data/lib/fluent/plugin/formatter.rb +50 -0
  141. data/lib/fluent/plugin/formatter_csv.rb +52 -0
  142. data/lib/fluent/plugin/formatter_hash.rb +33 -0
  143. data/lib/fluent/plugin/formatter_json.rb +55 -0
  144. data/lib/fluent/plugin/formatter_ltsv.rb +42 -0
  145. data/lib/fluent/plugin/formatter_msgpack.rb +33 -0
  146. data/lib/fluent/plugin/formatter_out_file.rb +51 -0
  147. data/lib/fluent/plugin/formatter_single_value.rb +34 -0
  148. data/lib/fluent/plugin/formatter_stdout.rb +76 -0
  149. data/lib/fluent/plugin/formatter_tsv.rb +38 -0
  150. data/lib/fluent/plugin/in_debug_agent.rb +17 -6
  151. data/lib/fluent/plugin/in_dummy.rb +47 -20
  152. data/lib/fluent/plugin/in_exec.rb +55 -123
  153. data/lib/fluent/plugin/in_forward.rb +299 -216
  154. data/lib/fluent/plugin/in_gc_stat.rb +14 -36
  155. data/lib/fluent/plugin/in_http.rb +204 -91
  156. data/lib/fluent/plugin/in_monitor_agent.rb +186 -258
  157. data/lib/fluent/plugin/in_object_space.rb +13 -41
  158. data/lib/fluent/plugin/in_syslog.rb +112 -134
  159. data/lib/fluent/plugin/in_tail.rb +408 -745
  160. data/lib/fluent/plugin/in_tcp.rb +66 -9
  161. data/lib/fluent/plugin/in_udp.rb +60 -11
  162. data/lib/fluent/plugin/{in_stream.rb → in_unix.rb} +8 -4
  163. data/lib/fluent/plugin/input.rb +37 -0
  164. data/lib/fluent/plugin/multi_output.rb +158 -0
  165. data/lib/fluent/plugin/out_copy.rb +23 -35
  166. data/lib/fluent/plugin/out_exec.rb +67 -70
  167. data/lib/fluent/plugin/out_exec_filter.rb +204 -271
  168. data/lib/fluent/plugin/out_file.rb +267 -73
  169. data/lib/fluent/plugin/out_forward.rb +854 -325
  170. data/lib/fluent/plugin/out_null.rb +42 -9
  171. data/lib/fluent/plugin/out_relabel.rb +9 -5
  172. data/lib/fluent/plugin/out_roundrobin.rb +18 -37
  173. data/lib/fluent/plugin/out_secondary_file.rb +133 -0
  174. data/lib/fluent/plugin/out_stdout.rb +43 -10
  175. data/lib/fluent/plugin/out_stream.rb +7 -2
  176. data/lib/fluent/plugin/output.rb +1498 -0
  177. data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
  178. data/lib/fluent/plugin/parser.rb +191 -0
  179. data/lib/fluent/plugin/parser_apache.rb +28 -0
  180. data/lib/fluent/plugin/parser_apache2.rb +88 -0
  181. data/lib/fluent/plugin/parser_apache_error.rb +26 -0
  182. data/lib/fluent/plugin/parser_csv.rb +39 -0
  183. data/lib/fluent/plugin/parser_json.rb +94 -0
  184. data/lib/fluent/plugin/parser_ltsv.rb +49 -0
  185. data/lib/fluent/plugin/parser_msgpack.rb +50 -0
  186. data/lib/fluent/plugin/parser_multiline.rb +106 -0
  187. data/lib/fluent/plugin/parser_nginx.rb +28 -0
  188. data/lib/fluent/plugin/parser_none.rb +36 -0
  189. data/lib/fluent/plugin/parser_regexp.rb +68 -0
  190. data/lib/fluent/plugin/parser_syslog.rb +142 -0
  191. data/lib/fluent/plugin/parser_tsv.rb +42 -0
  192. data/lib/fluent/plugin/socket_util.rb +3 -143
  193. data/lib/fluent/plugin/storage.rb +84 -0
  194. data/lib/fluent/plugin/storage_local.rb +164 -0
  195. data/lib/fluent/plugin/string_util.rb +3 -15
  196. data/lib/fluent/plugin.rb +122 -121
  197. data/lib/fluent/plugin_helper/cert_option.rb +178 -0
  198. data/lib/fluent/plugin_helper/child_process.rb +364 -0
  199. data/lib/fluent/plugin_helper/compat_parameters.rb +333 -0
  200. data/lib/fluent/plugin_helper/counter.rb +51 -0
  201. data/lib/fluent/plugin_helper/event_emitter.rb +93 -0
  202. data/lib/fluent/plugin_helper/event_loop.rb +170 -0
  203. data/lib/fluent/plugin_helper/extract.rb +104 -0
  204. data/lib/fluent/plugin_helper/formatter.rb +147 -0
  205. data/lib/fluent/plugin_helper/http_server/app.rb +79 -0
  206. data/lib/fluent/plugin_helper/http_server/compat/server.rb +81 -0
  207. data/lib/fluent/plugin_helper/http_server/compat/webrick_handler.rb +58 -0
  208. data/lib/fluent/plugin_helper/http_server/methods.rb +35 -0
  209. data/lib/fluent/plugin_helper/http_server/request.rb +42 -0
  210. data/lib/fluent/plugin_helper/http_server/router.rb +54 -0
  211. data/lib/fluent/plugin_helper/http_server/server.rb +87 -0
  212. data/lib/fluent/plugin_helper/http_server.rb +76 -0
  213. data/lib/fluent/plugin_helper/inject.rb +151 -0
  214. data/lib/fluent/plugin_helper/parser.rb +147 -0
  215. data/lib/fluent/plugin_helper/record_accessor.rb +210 -0
  216. data/lib/fluent/plugin_helper/retry_state.rb +205 -0
  217. data/lib/fluent/plugin_helper/server.rb +807 -0
  218. data/lib/fluent/plugin_helper/socket.rb +250 -0
  219. data/lib/fluent/plugin_helper/socket_option.rb +80 -0
  220. data/lib/fluent/plugin_helper/storage.rb +349 -0
  221. data/lib/fluent/plugin_helper/thread.rb +179 -0
  222. data/lib/fluent/plugin_helper/timer.rb +92 -0
  223. data/lib/fluent/plugin_helper.rb +73 -0
  224. data/lib/fluent/plugin_id.rb +80 -0
  225. data/lib/fluent/process.rb +3 -489
  226. data/lib/fluent/registry.rb +52 -10
  227. data/lib/fluent/root_agent.rb +204 -42
  228. data/lib/fluent/supervisor.rb +597 -359
  229. data/lib/fluent/system_config.rb +131 -42
  230. data/lib/fluent/test/base.rb +6 -54
  231. data/lib/fluent/test/driver/base.rb +224 -0
  232. data/lib/fluent/test/driver/base_owned.rb +70 -0
  233. data/lib/fluent/test/driver/base_owner.rb +135 -0
  234. data/lib/fluent/test/driver/event_feeder.rb +98 -0
  235. data/lib/fluent/test/driver/filter.rb +57 -0
  236. data/lib/fluent/test/driver/formatter.rb +30 -0
  237. data/lib/fluent/test/driver/input.rb +31 -0
  238. data/lib/fluent/test/driver/multi_output.rb +53 -0
  239. data/lib/fluent/test/driver/output.rb +102 -0
  240. data/lib/fluent/test/driver/parser.rb +30 -0
  241. data/lib/fluent/test/driver/test_event_router.rb +45 -0
  242. data/lib/fluent/test/filter_test.rb +0 -1
  243. data/lib/fluent/test/formatter_test.rb +4 -1
  244. data/lib/fluent/test/helpers.rb +58 -10
  245. data/lib/fluent/test/input_test.rb +27 -19
  246. data/lib/fluent/test/log.rb +79 -0
  247. data/lib/fluent/test/output_test.rb +28 -39
  248. data/lib/fluent/test/parser_test.rb +3 -1
  249. data/lib/fluent/test/startup_shutdown.rb +46 -0
  250. data/lib/fluent/test.rb +33 -1
  251. data/lib/fluent/time.rb +450 -1
  252. data/lib/fluent/timezone.rb +27 -3
  253. data/lib/fluent/{status.rb → unique_id.rb} +15 -24
  254. data/lib/fluent/version.rb +1 -1
  255. data/lib/fluent/winsvc.rb +85 -0
  256. data/templates/new_gem/Gemfile +3 -0
  257. data/templates/new_gem/README.md.erb +43 -0
  258. data/templates/new_gem/Rakefile +13 -0
  259. data/templates/new_gem/fluent-plugin.gemspec.erb +27 -0
  260. data/templates/new_gem/lib/fluent/plugin/filter.rb.erb +14 -0
  261. data/templates/new_gem/lib/fluent/plugin/formatter.rb.erb +14 -0
  262. data/templates/new_gem/lib/fluent/plugin/input.rb.erb +11 -0
  263. data/templates/new_gem/lib/fluent/plugin/output.rb.erb +11 -0
  264. data/templates/new_gem/lib/fluent/plugin/parser.rb.erb +15 -0
  265. data/templates/new_gem/test/helper.rb.erb +8 -0
  266. data/templates/new_gem/test/plugin/test_filter.rb.erb +18 -0
  267. data/templates/new_gem/test/plugin/test_formatter.rb.erb +18 -0
  268. data/templates/new_gem/test/plugin/test_input.rb.erb +18 -0
  269. data/templates/new_gem/test/plugin/test_output.rb.erb +18 -0
  270. data/templates/new_gem/test/plugin/test_parser.rb.erb +18 -0
  271. data/templates/plugin_config_formatter/param.md-compact.erb +25 -0
  272. data/templates/plugin_config_formatter/param.md.erb +34 -0
  273. data/templates/plugin_config_formatter/section.md.erb +12 -0
  274. data/test/command/test_binlog_reader.rb +346 -0
  275. data/test/command/test_ca_generate.rb +70 -0
  276. data/test/command/test_fluentd.rb +901 -0
  277. data/test/command/test_plugin_config_formatter.rb +276 -0
  278. data/test/command/test_plugin_generator.rb +92 -0
  279. data/test/compat/test_calls_super.rb +166 -0
  280. data/test/compat/test_parser.rb +92 -0
  281. data/test/config/test_config_parser.rb +126 -2
  282. data/test/config/test_configurable.rb +946 -187
  283. data/test/config/test_configure_proxy.rb +424 -74
  284. data/test/config/test_dsl.rb +11 -11
  285. data/test/config/test_element.rb +500 -0
  286. data/test/config/test_literal_parser.rb +8 -0
  287. data/test/config/test_plugin_configuration.rb +56 -0
  288. data/test/config/test_section.rb +79 -7
  289. data/test/config/test_system_config.rb +122 -35
  290. data/test/config/test_types.rb +38 -0
  291. data/test/counter/test_client.rb +559 -0
  292. data/test/counter/test_error.rb +44 -0
  293. data/test/counter/test_mutex_hash.rb +179 -0
  294. data/test/counter/test_server.rb +589 -0
  295. data/test/counter/test_store.rb +258 -0
  296. data/test/counter/test_validator.rb +137 -0
  297. data/test/helper.rb +89 -6
  298. data/test/helpers/fuzzy_assert.rb +89 -0
  299. data/test/plugin/test_bare_output.rb +118 -0
  300. data/test/plugin/test_base.rb +115 -0
  301. data/test/plugin/test_buf_file.rb +823 -460
  302. data/test/plugin/test_buf_memory.rb +32 -194
  303. data/test/plugin/test_buffer.rb +1233 -0
  304. data/test/plugin/test_buffer_chunk.rb +198 -0
  305. data/test/plugin/test_buffer_file_chunk.rb +844 -0
  306. data/test/plugin/test_buffer_memory_chunk.rb +338 -0
  307. data/test/plugin/test_compressable.rb +84 -0
  308. data/test/plugin/test_filter.rb +357 -0
  309. data/test/plugin/test_filter_grep.rb +540 -29
  310. data/test/plugin/test_filter_parser.rb +439 -452
  311. data/test/plugin/test_filter_record_transformer.rb +123 -166
  312. data/test/plugin/test_filter_stdout.rb +160 -72
  313. data/test/plugin/test_formatter_csv.rb +111 -0
  314. data/test/plugin/test_formatter_hash.rb +35 -0
  315. data/test/plugin/test_formatter_json.rb +51 -0
  316. data/test/plugin/test_formatter_ltsv.rb +62 -0
  317. data/test/plugin/test_formatter_msgpack.rb +28 -0
  318. data/test/plugin/test_formatter_out_file.rb +95 -0
  319. data/test/plugin/test_formatter_single_value.rb +38 -0
  320. data/test/plugin/test_formatter_tsv.rb +68 -0
  321. data/test/plugin/test_in_debug_agent.rb +24 -1
  322. data/test/plugin/test_in_dummy.rb +111 -18
  323. data/test/plugin/test_in_exec.rb +200 -113
  324. data/test/plugin/test_in_forward.rb +990 -387
  325. data/test/plugin/test_in_gc_stat.rb +10 -8
  326. data/test/plugin/test_in_http.rb +600 -224
  327. data/test/plugin/test_in_monitor_agent.rb +690 -0
  328. data/test/plugin/test_in_object_space.rb +24 -8
  329. data/test/plugin/test_in_syslog.rb +154 -215
  330. data/test/plugin/test_in_tail.rb +1006 -707
  331. data/test/plugin/test_in_tcp.rb +125 -48
  332. data/test/plugin/test_in_udp.rb +204 -63
  333. data/test/plugin/{test_in_stream.rb → test_in_unix.rb} +14 -13
  334. data/test/plugin/test_input.rb +126 -0
  335. data/test/plugin/test_metadata.rb +89 -0
  336. data/test/plugin/test_multi_output.rb +180 -0
  337. data/test/plugin/test_out_copy.rb +117 -112
  338. data/test/plugin/test_out_exec.rb +258 -53
  339. data/test/plugin/test_out_exec_filter.rb +538 -115
  340. data/test/plugin/test_out_file.rb +865 -178
  341. data/test/plugin/test_out_forward.rb +998 -210
  342. data/test/plugin/test_out_null.rb +105 -0
  343. data/test/plugin/test_out_relabel.rb +28 -0
  344. data/test/plugin/test_out_roundrobin.rb +36 -29
  345. data/test/plugin/test_out_secondary_file.rb +458 -0
  346. data/test/plugin/test_out_stdout.rb +135 -37
  347. data/test/plugin/test_out_stream.rb +18 -0
  348. data/test/plugin/test_output.rb +984 -0
  349. data/test/plugin/test_output_as_buffered.rb +2021 -0
  350. data/test/plugin/test_output_as_buffered_backup.rb +312 -0
  351. data/test/plugin/test_output_as_buffered_compress.rb +165 -0
  352. data/test/plugin/test_output_as_buffered_overflow.rb +250 -0
  353. data/test/plugin/test_output_as_buffered_retries.rb +911 -0
  354. data/test/plugin/test_output_as_buffered_secondary.rb +874 -0
  355. data/test/plugin/test_output_as_standard.rb +374 -0
  356. data/test/plugin/test_owned_by.rb +35 -0
  357. data/test/plugin/test_parser.rb +359 -0
  358. data/test/plugin/test_parser_apache.rb +42 -0
  359. data/test/plugin/test_parser_apache2.rb +47 -0
  360. data/test/plugin/test_parser_apache_error.rb +45 -0
  361. data/test/plugin/test_parser_csv.rb +103 -0
  362. data/test/plugin/test_parser_json.rb +138 -0
  363. data/test/plugin/test_parser_labeled_tsv.rb +145 -0
  364. data/test/plugin/test_parser_multiline.rb +100 -0
  365. data/test/plugin/test_parser_nginx.rb +88 -0
  366. data/test/plugin/test_parser_none.rb +52 -0
  367. data/test/plugin/test_parser_regexp.rb +289 -0
  368. data/test/plugin/test_parser_syslog.rb +441 -0
  369. data/test/plugin/test_parser_tsv.rb +122 -0
  370. data/test/plugin/test_storage.rb +167 -0
  371. data/test/plugin/test_storage_local.rb +335 -0
  372. data/test/plugin_helper/data/cert/cert-key.pem +27 -0
  373. data/test/plugin_helper/data/cert/cert-with-no-newline.pem +19 -0
  374. data/test/plugin_helper/data/cert/cert.pem +19 -0
  375. data/test/plugin_helper/http_server/test_app.rb +65 -0
  376. data/test/plugin_helper/http_server/test_route.rb +32 -0
  377. data/test/plugin_helper/test_cert_option.rb +16 -0
  378. data/test/plugin_helper/test_child_process.rb +794 -0
  379. data/test/plugin_helper/test_compat_parameters.rb +353 -0
  380. data/test/plugin_helper/test_event_emitter.rb +51 -0
  381. data/test/plugin_helper/test_event_loop.rb +52 -0
  382. data/test/plugin_helper/test_extract.rb +194 -0
  383. data/test/plugin_helper/test_formatter.rb +255 -0
  384. data/test/plugin_helper/test_http_server_helper.rb +205 -0
  385. data/test/plugin_helper/test_inject.rb +519 -0
  386. data/test/plugin_helper/test_parser.rb +264 -0
  387. data/test/plugin_helper/test_record_accessor.rb +197 -0
  388. data/test/plugin_helper/test_retry_state.rb +442 -0
  389. data/test/plugin_helper/test_server.rb +1714 -0
  390. data/test/plugin_helper/test_storage.rb +542 -0
  391. data/test/plugin_helper/test_thread.rb +164 -0
  392. data/test/plugin_helper/test_timer.rb +132 -0
  393. data/test/scripts/exec_script.rb +0 -6
  394. data/test/scripts/fluent/plugin/formatter1/formatter_test1.rb +7 -0
  395. data/test/scripts/fluent/plugin/formatter2/formatter_test2.rb +7 -0
  396. data/test/scripts/fluent/plugin/out_test.rb +23 -15
  397. data/test/scripts/fluent/plugin/out_test2.rb +80 -0
  398. data/test/test_clock.rb +164 -0
  399. data/test/test_config.rb +16 -7
  400. data/test/test_configdsl.rb +2 -2
  401. data/test/test_event.rb +360 -13
  402. data/test/test_event_router.rb +108 -11
  403. data/test/test_event_time.rb +199 -0
  404. data/test/test_filter.rb +48 -6
  405. data/test/test_formatter.rb +11 -391
  406. data/test/test_input.rb +1 -1
  407. data/test/test_log.rb +591 -31
  408. data/test/test_mixin.rb +1 -1
  409. data/test/test_output.rb +121 -185
  410. data/test/test_plugin.rb +251 -0
  411. data/test/test_plugin_classes.rb +177 -10
  412. data/test/test_plugin_helper.rb +81 -0
  413. data/test/test_plugin_id.rb +101 -0
  414. data/test/test_process.rb +8 -42
  415. data/test/test_root_agent.rb +766 -21
  416. data/test/test_supervisor.rb +481 -0
  417. data/test/test_test_drivers.rb +135 -0
  418. data/test/test_time_formatter.rb +282 -0
  419. data/test/test_time_parser.rb +231 -0
  420. data/test/test_unique_id.rb +47 -0
  421. metadata +454 -60
  422. data/COPYING +0 -14
  423. data/ChangeLog +0 -666
  424. data/lib/fluent/buffer.rb +0 -365
  425. data/lib/fluent/plugin/in_status.rb +0 -76
  426. data/test/plugin/test_in_status.rb +0 -38
  427. data/test/test_buffer.rb +0 -624
  428. data/test/test_parser.rb +0 -1305
@@ -1,97 +1,107 @@
1
1
  require_relative '../helper'
2
2
  require 'timecop'
3
+ require 'fluent/test/driver/filter'
3
4
  require 'fluent/plugin/filter_parser'
4
5
  require 'flexmock/test_unit'
5
6
 
6
7
  class ParserFilterTest < Test::Unit::TestCase
7
8
  include FlexMock::TestCase
8
9
 
9
- setup do
10
+ def setup
10
11
  Fluent::Test.setup
11
- @time = Time.parse("2012-01-02 13:14:15")
12
- Timecop.freeze(@time)
12
+ @tag = 'test'
13
+ @default_time = Time.parse('2010-05-04 03:02:01 UTC')
14
+ Timecop.freeze(@default_time)
13
15
  end
14
16
 
15
- teardown do
17
+ def teardown
18
+ super
16
19
  Timecop.return
17
20
  end
18
21
 
22
+ def assert_equal_parsed_time(expected, actual)
23
+ if expected.is_a?(Integer)
24
+ assert_equal(expected, actual.to_i)
25
+ else
26
+ assert_equal_event_time(expected, actual)
27
+ end
28
+ end
29
+
30
+ ParserError = Fluent::Plugin::Parser::ParserError
19
31
  CONFIG = %[
20
- key_name message
21
- format /^(?<x>.)(?<y>.) (?<time>.+)$/
22
- time_format %Y%m%d%H%M%S
23
- reserve_data true
32
+ key_name message
33
+ reserve_data true
34
+ <parse>
35
+ @type regexp
36
+ expression /^(?<x>.)(?<y>.) (?<time>.+)$/
37
+ time_format %Y%m%d%H%M%S
38
+ </parse>
24
39
  ]
25
40
 
26
- def create_driver(conf=CONFIG,tag='test')
27
- Fluent::Test::FilterTestDriver.new(Fluent::ParserFilter, tag).configure(conf)
41
+ def create_driver(conf=CONFIG)
42
+ Fluent::Test::Driver::Filter.new(Fluent::Plugin::ParserFilter).configure(conf)
28
43
  end
29
44
 
30
45
  def test_configure
31
46
  assert_raise(Fluent::ConfigError) {
32
- d = create_driver('')
47
+ create_driver('')
33
48
  }
34
49
  assert_raise(Fluent::ConfigError) {
35
- d = create_driver %[
36
- format unknown_format_that_will_never_be_implemented
37
- key_name foo
38
- ]
39
- }
40
- assert_nothing_raised {
41
- d = create_driver %[
42
- format /(?<x>.)/
50
+ create_driver %[
43
51
  key_name foo
52
+ <parse>
53
+ @type unknown_format_that_will_never_be_implemented
54
+ </parse>
44
55
  ]
45
56
  }
46
57
  assert_nothing_raised {
47
- d = create_driver %[
48
- format /(?<x>.)/
58
+ create_driver %[
49
59
  key_name foo
60
+ <parse>
61
+ @type regexp
62
+ expression /(?<x>.)/
63
+ </parse>
50
64
  ]
51
65
  }
52
66
  assert_nothing_raised {
53
- d = create_driver %[
54
- format /(?<x>.)/
67
+ create_driver %[
55
68
  key_name foo
69
+ <parse>
70
+ @type json
71
+ </parse>
56
72
  ]
57
73
  }
58
74
  assert_nothing_raised {
59
- d = create_driver %[
60
- format /(?<x>.)/
75
+ create_driver %[
61
76
  key_name foo
62
- ]
63
- }
64
- assert_nothing_raised {
65
- d = create_driver %[
66
77
  format json
67
- key_name foo
68
78
  ]
69
79
  }
70
80
  assert_nothing_raised {
71
- d = create_driver %[
72
- format ltsv
81
+ create_driver %[
73
82
  key_name foo
83
+ <parse>
84
+ @type ltsv
85
+ </parse>
74
86
  ]
75
87
  }
76
88
  assert_nothing_raised {
77
- d = create_driver %[
78
- format /^col1=(?<col1>.+) col2=(?<col2>.+)$/
79
- key_name message
80
- suppress_parse_error_log true
81
- ]
82
- }
83
- assert_nothing_raised {
84
- d = create_driver %[
85
- format /^col1=(?<col1>.+) col2=(?<col2>.+)$/
89
+ create_driver %[
86
90
  key_name message
87
- suppress_parse_error_log false
91
+ <parse>
92
+ @type regexp
93
+ expression /^col1=(?<col1>.+) col2=(?<col2>.+)$/
94
+ </parse>
88
95
  ]
89
96
  }
90
97
  d = create_driver %[
91
98
  key_name foo
92
- format /(?<x>.)/
99
+ <parse>
100
+ @type regexp
101
+ expression /(?<x>.)/
102
+ </parse>
93
103
  ]
94
- assert_equal false, d.instance.reserve_data
104
+ assert_false d.instance.reserve_data
95
105
  end
96
106
 
97
107
  # CONFIG = %[
@@ -103,404 +113,463 @@ class ParserFilterTest < Test::Unit::TestCase
103
113
  # reserve_data true
104
114
  # ]
105
115
  def test_filter
106
- d1 = create_driver(CONFIG, 'test.no.change')
107
- time = @time.to_i
108
- d1.run do
109
- d1.filter({'message' => '12 20120402182059'}, time)
110
- d1.filter({'message' => '34 20120402182100'}, time)
111
- d1.filter({'message' => '56 20120402182100'}, time)
112
- d1.filter({'message' => '78 20120402182101'}, time)
113
- d1.filter({'message' => '90 20120402182100'}, time)
116
+ d1 = create_driver(CONFIG)
117
+ time = event_time("2012-01-02 13:14:15")
118
+ d1.run(default_tag: @tag) do
119
+ d1.feed(time, {'message' => '12 20120402182059'})
120
+ d1.feed(time, {'message' => '34 20120402182100'})
121
+ d1.feed(time, {'message' => '56 20120402182100'})
122
+ d1.feed(time, {'message' => '78 20120402182101'})
123
+ d1.feed(time, {'message' => '90 20120402182100'})
114
124
  end
115
- filtered = d1.filtered_as_array
125
+ filtered = d1.filtered
116
126
  assert_equal 5, filtered.length
117
127
 
118
128
  first = filtered[0]
119
- assert_equal 'test.no.change', first[0]
120
- assert_equal Time.parse("2012-04-02 18:20:59").to_i, first[1]
121
- assert_equal '1', first[2]['x']
122
- assert_equal '2', first[2]['y']
123
- assert_equal '12 20120402182059', first[2]['message']
129
+ assert_equal_event_time event_time("2012-04-02 18:20:59"), first[0]
130
+ assert_equal '1', first[1]['x']
131
+ assert_equal '2', first[1]['y']
132
+ assert_equal '12 20120402182059', first[1]['message']
124
133
 
125
134
  second = filtered[1]
126
- assert_equal 'test.no.change', second[0]
127
- assert_equal Time.parse("2012-04-02 18:21:00").to_i, second[1]
128
- assert_equal '3', second[2]['x']
129
- assert_equal '4', second[2]['y']
135
+ assert_equal_event_time event_time("2012-04-02 18:21:00"), second[0]
136
+ assert_equal '3', second[1]['x']
137
+ assert_equal '4', second[1]['y']
130
138
 
131
139
  third = filtered[2]
132
- assert_equal 'test.no.change', third[0]
133
- assert_equal Time.parse("2012-04-02 18:21:00").to_i, third[1]
134
- assert_equal '5', third[2]['x']
135
- assert_equal '6', third[2]['y']
140
+ assert_equal_event_time event_time("2012-04-02 18:21:00"), third[0]
141
+ assert_equal '5', third[1]['x']
142
+ assert_equal '6', third[1]['y']
136
143
 
137
144
  fourth = filtered[3]
138
- assert_equal 'test.no.change', fourth[0]
139
- assert_equal Time.parse("2012-04-02 18:21:01").to_i, fourth[1]
140
- assert_equal '7', fourth[2]['x']
141
- assert_equal '8', fourth[2]['y']
145
+ assert_equal_event_time event_time("2012-04-02 18:21:01"), fourth[0]
146
+ assert_equal '7', fourth[1]['x']
147
+ assert_equal '8', fourth[1]['y']
142
148
 
143
149
  fifth = filtered[4]
144
- assert_equal 'test.no.change', fifth[0]
145
- assert_equal Time.parse("2012-04-02 18:21:00").to_i, fifth[1]
146
- assert_equal '9', fifth[2]['x']
147
- assert_equal '0', fifth[2]['y']
150
+ assert_equal_event_time event_time("2012-04-02 18:21:00"), fifth[0]
151
+ assert_equal '9', fifth[1]['x']
152
+ assert_equal '0', fifth[1]['y']
148
153
 
149
154
  d2 = create_driver(%[
150
- tag parsed
151
- key_name data
152
- format /^(?<x>.)(?<y>.) (?<t>.+)$/
153
- ], 'test.no.change')
154
- time = @time.to_i
155
- d2.run do
156
- d2.filter({'data' => '12 20120402182059'}, time)
157
- d2.filter({'data' => '34 20120402182100'}, time)
155
+ key_name data
156
+ format /^(?<x>.)(?<y>.) (?<t>.+)$/
157
+ ])
158
+ time = Fluent::EventTime.from_time(@default_time) # EventTime emit test
159
+ d2.run(default_tag: @tag) do
160
+ d2.feed(time, {'data' => '12 20120402182059'})
161
+ d2.feed(time, {'data' => '34 20120402182100'})
158
162
  end
159
- filtered = d2.filtered_as_array
163
+ filtered = d2.filtered
160
164
  assert_equal 2, filtered.length
161
165
 
162
166
  first = filtered[0]
163
- assert_equal 'test.no.change', first[0]
164
- assert_equal time, first[1]
165
- assert_nil first[2]['data']
166
- assert_equal '1', first[2]['x']
167
- assert_equal '2', first[2]['y']
168
- assert_equal '20120402182059', first[2]['t']
167
+ assert_equal_event_time time, first[0]
168
+ assert_nil first[1]['data']
169
+ assert_equal '1', first[1]['x']
170
+ assert_equal '2', first[1]['y']
171
+ assert_equal '20120402182059', first[1]['t']
169
172
 
170
173
  second = filtered[1]
171
- assert_equal 'test.no.change', second[0]
172
- assert_equal time, second[1]
173
- assert_nil second[2]['data']
174
- assert_equal '3', second[2]['x']
175
- assert_equal '4', second[2]['y']
176
- assert_equal '20120402182100', second[2]['t']
174
+ assert_equal_event_time time, second[0]
175
+ assert_nil second[1]['data']
176
+ assert_equal '3', second[1]['x']
177
+ assert_equal '4', second[1]['y']
178
+ assert_equal '20120402182100', second[1]['t']
177
179
 
178
180
  d3 = create_driver(%[
179
- tag parsed
180
- key_name data
181
- format /^(?<x>[0-9])(?<y>[0-9]) (?<t>.+)$/
182
- ], 'test.no.change')
183
- time = @time.to_i
184
- d3.run do
185
- d3.filter({'data' => '12 20120402182059'}, time)
186
- d3.filter({'data' => '34 20120402182100'}, time)
187
- d3.filter({'data' => 'xy 20120402182101'}, time)
181
+ key_name data
182
+ <parse>
183
+ @type regexp
184
+ expression /^(?<x>[0-9])(?<y>[0-9]) (?<t>.+)$/
185
+ </parse>
186
+ ])
187
+ time = Time.parse("2012-04-02 18:20:59").to_i
188
+ d3.run(default_tag: @tag) do
189
+ d3.feed(time, {'data' => '12 20120402182059'})
190
+ d3.feed(time, {'data' => '34 20120402182100'})
191
+ d3.feed(time, {'data' => 'xy 20120402182101'})
188
192
  end
189
- filtered = d3.filtered_as_array
193
+ filtered = d3.filtered
190
194
  assert_equal 2, filtered.length
191
195
 
192
- d3x = create_driver(%[
193
- tag parsed
194
- key_name data
195
- format /^(?<x>\\d)(?<y>\\d) (?<t>.+)$/
196
- reserve_data yes
197
- ], 'test.no.change')
198
- time = @time.to_i
199
- d3x.run do
200
- d3x.filter({'data' => '12 20120402182059'}, time)
201
- d3x.filter({'data' => '34 20120402182100'}, time)
202
- d3x.filter({'data' => 'xy 20120402182101'}, time)
203
- end
204
- filtered = d3x.filtered_as_array
205
- assert_equal 3, filtered.length
206
-
207
196
  d4 = create_driver(%[
208
- tag parsed
209
- key_name data
210
- format json
211
- ], 'test.no.change')
212
- time = @time.to_i
213
- d4.run do
214
- d4.filter({'data' => '{"xxx":"first","yyy":"second"}', 'xxx' => 'x', 'yyy' => 'y'}, time)
215
- d4.filter({'data' => 'foobar', 'xxx' => 'x', 'yyy' => 'y'}, time)
197
+ key_name data
198
+ <parse>
199
+ @type json
200
+ </parse>
201
+ ])
202
+ time = Time.parse("2012-04-02 18:20:59").to_i
203
+ d4.run(default_tag: @tag) do
204
+ d4.feed(time, {'data' => '{"xxx":"first","yyy":"second"}', 'xxx' => 'x', 'yyy' => 'y'})
205
+ d4.feed(time, {'data' => 'foobar', 'xxx' => 'x', 'yyy' => 'y'})
216
206
  end
217
- filtered = d4.filtered_as_array
207
+ filtered = d4.filtered
218
208
  assert_equal 1, filtered.length
219
209
 
220
- d4x = create_driver(%[
221
- tag parsed
222
- key_name data
223
- format json
224
- reserve_data yes
225
- ], 'test.no.change')
226
- time = @time.to_i
227
- d4x.run do
228
- d4x.filter({'data' => '{"xxx":"first","yyy":"second"}', 'xxx' => 'x', 'yyy' => 'y'}, time)
229
- d4x.filter({'data' => 'foobar', 'xxx' => 'x', 'yyy' => 'y'}, time)
210
+ end
211
+
212
+ data(:keep_key_name => false,
213
+ :remove_key_name => true)
214
+ def test_filter_with_reserved_data(remove_key_name)
215
+ d1 = create_driver(%[
216
+ key_name data
217
+ reserve_data yes
218
+ remove_key_name_field #{remove_key_name}
219
+ <parse>
220
+ @type regexp
221
+ expression /^(?<x>\\d)(?<y>\\d) (?<t>.+)$/
222
+ </parse>
223
+ ])
224
+ time = event_time("2012-04-02 18:20:59")
225
+ d1.run(default_tag: @tag) do
226
+ d1.feed(time, {'data' => '12 20120402182059'})
227
+ d1.feed(time, {'data' => '34 20120402182100'})
228
+ d1.feed(time, {'data' => 'xy 20120402182101'})
230
229
  end
231
- filtered = d4x.filtered_as_array
230
+ filtered = d1.filtered
231
+ assert_equal 3, filtered.length
232
+
233
+ d2 = create_driver(%[
234
+ key_name data
235
+ reserve_data yes
236
+ remove_key_name_field #{remove_key_name}
237
+ <parse>
238
+ @type json
239
+ </parse>
240
+ ])
241
+ time = Fluent::EventTime.from_time(@default_time)
242
+ d2.run(default_tag: @tag) do
243
+ d2.feed(time, {'data' => '{"xxx":"first","yyy":"second"}', 'xxx' => 'x', 'yyy' => 'y'})
244
+ d2.feed(time, {'data' => 'foobar', 'xxx' => 'x', 'yyy' => 'y'})
245
+ end
246
+ filtered = d2.filtered
232
247
  assert_equal 2, filtered.length
233
248
 
234
249
  first = filtered[0]
235
- assert_equal 'test.no.change', first[0]
236
- assert_equal time, first[1]
237
- assert_equal '{"xxx":"first","yyy":"second"}', first[2]['data']
238
- assert_equal 'first', first[2]['xxx']
239
- assert_equal 'second', first[2]['yyy']
250
+ assert_equal_event_time time, first[0]
251
+ if remove_key_name
252
+ assert_not_include first[1], 'data'
253
+ else
254
+ assert_equal '{"xxx":"first","yyy":"second"}', first[1]['data']
255
+ end
256
+ assert_equal 'first', first[1]['xxx']
257
+ assert_equal 'second', first[1]['yyy']
240
258
 
241
259
  second = filtered[1]
242
- assert_equal 'test.no.change', second[0]
243
- assert_equal time, second[1]
244
- assert_equal 'foobar', second[2]['data']
245
- assert_equal 'x', second[2]['xxx']
246
- assert_equal 'y', second[2]['yyy']
260
+ assert_equal_event_time time, second[0]
261
+ assert_equal 'foobar', second[1]['data']
262
+ assert_equal 'x', second[1]['xxx']
263
+ assert_equal 'y', second[1]['yyy']
247
264
  end
248
265
 
266
+
249
267
  CONFIG_LTSV = %[
250
- format ltsv
251
268
  key_name data
269
+ <parse>
270
+ @type ltsv
271
+ </parse>
252
272
  ]
253
- def test_filter_ltsv
254
- d = create_driver(CONFIG_LTSV, 'test.no.change')
255
- time = @time.to_i
256
- d.run do
257
- d.filter({'data' => "xxx:first\tyyy:second", 'xxx' => 'x', 'yyy' => 'y'}, time)
258
- d.filter({'data' => "xxx:first\tyyy:second2", 'xxx' => 'x', 'yyy' => 'y'}, time)
273
+ CONFIG_LTSV_WITH_TYPES = %[
274
+ key_name data
275
+ <parse>
276
+ @type ltsv
277
+ types i:integer,s:string,f:float,b:bool
278
+ </parse>
279
+ ]
280
+ data(:event_time => lambda { |time| Fluent::EventTime.from_time(time) },
281
+ :int_time => lambda { |time| time.to_i })
282
+ def test_filter_ltsv(time_parse)
283
+ d = create_driver(CONFIG_LTSV)
284
+ time = time_parse.call(@default_time)
285
+ d.run(default_tag: @tag) do
286
+ d.feed(time, {'data' => "xxx:first\tyyy:second", 'xxx' => 'x', 'yyy' => 'y'})
287
+ d.feed(time, {'data' => "xxx:first\tyyy:second2", 'xxx' => 'x', 'yyy' => 'y'})
259
288
  end
260
- filtered = d.filtered_as_array
289
+ filtered = d.filtered
261
290
  assert_equal 2, filtered.length
262
291
 
263
292
  first = filtered[0]
264
- assert_equal 'test.no.change', first[0]
265
- assert_equal time, first[1]
266
- assert_nil first[2]['data']
267
- assert_equal 'first', first[2]['xxx']
268
- assert_equal 'second', first[2]['yyy']
293
+ assert_equal_parsed_time time, first[0]
294
+ assert_nil first[1]['data']
295
+ assert_equal 'first', first[1]['xxx']
296
+ assert_equal 'second', first[1]['yyy']
269
297
 
270
298
  second = filtered[1]
271
- assert_equal 'test.no.change', second[0]
272
- assert_equal time, second[1]
273
- assert_nil first[2]['data']
274
- assert_equal 'first', second[2]['xxx']
275
- assert_equal 'second2', second[2]['yyy']
276
-
277
- d = create_driver(CONFIG_LTSV + %[
278
- reserve_data yes
279
- ], 'test.no.change')
280
- time = @time.to_i
281
- d.run do
282
- d.filter({'data' => "xxx:first\tyyy:second", 'xxx' => 'x', 'yyy' => 'y'}, time)
283
- d.filter({'data' => "xxx:first\tyyy:second2", 'xxx' => 'x', 'yyy' => 'y'}, time)
299
+ assert_equal_parsed_time time, second[0]
300
+ assert_nil first[1]['data']
301
+ assert_equal 'first', second[1]['xxx']
302
+ assert_equal 'second2', second[1]['yyy']
303
+
304
+ d = create_driver(CONFIG_LTSV + %[reserve_data yes])
305
+ time = @default_time.to_i
306
+ d.run(default_tag: @tag) do
307
+ d.feed(time, {'data' => "xxx:first\tyyy:second", 'xxx' => 'x', 'yyy' => 'y'})
308
+ d.feed(time, {'data' => "xxx:first\tyyy:second2", 'xxx' => 'x', 'yyy' => 'y'})
284
309
  end
285
- filtered = d.filtered_as_array
310
+ filtered = d.filtered
286
311
  assert_equal 2, filtered.length
287
312
 
288
313
  first = filtered[0]
289
- assert_equal 'test.no.change', first[0]
290
- assert_equal time, first[1]
291
- assert_equal "xxx:first\tyyy:second", first[2]['data']
292
- assert_equal 'first', first[2]['xxx']
293
- assert_equal 'second', first[2]['yyy']
314
+ assert_equal_parsed_time time, first[0]
315
+ assert_equal "xxx:first\tyyy:second", first[1]['data']
316
+ assert_equal 'first', first[1]['xxx']
317
+ assert_equal 'second', first[1]['yyy']
294
318
 
295
319
  second = filtered[1]
296
- assert_equal 'test.no.change', second[0]
297
- assert_equal time, second[1]
298
- assert_equal "xxx:first\tyyy:second", first[2]['data']
299
- assert_equal 'first', second[2]['xxx']
300
- assert_equal 'second2', second[2]['yyy']
320
+ assert_equal_parsed_time time, second[0]
321
+ assert_equal "xxx:first\tyyy:second", first[1]['data']
322
+ assert_equal 'first', second[1]['xxx']
323
+ assert_equal 'second2', second[1]['yyy']
301
324
 
302
325
  # convert types
303
- d = create_driver(CONFIG_LTSV + %[
304
- types i:integer,s:string,f:float,b:bool
305
- ], 'test.no.change')
306
- time = @time.to_i
326
+ #d = create_driver(CONFIG_LTSV + %[
327
+ d = create_driver(CONFIG_LTSV_WITH_TYPES)
328
+ time = @default_time.to_i
307
329
  d.run do
308
- d.filter({'data' => "i:1\ts:2\tf:3\tb:true\tx:123"}, time)
330
+ d.feed(@tag, time, {'data' => "i:1\ts:2\tf:3\tb:true\tx:123"})
309
331
  end
310
- filtered = d.filtered_as_array
332
+ filtered = d.filtered
311
333
  assert_equal 1, filtered.length
312
334
 
313
335
  first = filtered[0]
314
- assert_equal 'test.no.change', first[0]
315
- assert_equal time, first[1]
316
- assert_equal 1, first[2]['i']
317
- assert_equal '2', first[2]['s']
318
- assert_equal 3.0, first[2]['f']
319
- assert_equal true, first[2]['b']
320
- assert_equal '123', first[2]['x']
336
+ assert_equal_parsed_time time, first[0]
337
+ assert_equal 1, first[1]['i']
338
+ assert_equal '2', first[1]['s']
339
+ assert_equal 3.0, first[1]['f']
340
+ assert_equal true, first[1]['b']
341
+ assert_equal '123', first[1]['x']
321
342
  end
322
343
 
323
344
  CONFIG_TSV = %[
324
- format tsv
325
345
  key_name data
326
- keys key1,key2,key3
346
+ <parse>
347
+ @type tsv
348
+ keys key1,key2,key3
349
+ </parse>
327
350
  ]
328
- def test_filter_tsv
329
- d = create_driver(CONFIG_TSV, 'test.no.change')
330
- time = @time.to_i
351
+ data(:event_time => lambda { |time| Fluent::EventTime.from_time(time) },
352
+ :int_time => lambda { |time| time.to_i })
353
+ def test_filter_tsv(time_parse)
354
+ d = create_driver(CONFIG_TSV)
355
+ time = time_parse.call(@default_time)
331
356
  d.run do
332
- d.filter({'data' => "value1\tvalue2\tvalueThree", 'xxx' => 'x', 'yyy' => 'y'}, time)
357
+ d.feed(@tag, time, {'data' => "value1\tvalue2\tvalueThree", 'xxx' => 'x', 'yyy' => 'y'})
333
358
  end
334
- filtered = d.filtered_as_array
359
+ filtered = d.filtered
335
360
  assert_equal 1, filtered.length
336
361
 
337
362
  first = filtered[0]
338
- assert_equal 'test.no.change', first[0]
339
- assert_equal time, first[1]
340
- assert_nil first[2]['data']
341
- assert_equal 'value1', first[2]['key1']
342
- assert_equal 'value2', first[2]['key2']
343
- assert_equal 'valueThree', first[2]['key3']
363
+ assert_equal_parsed_time time, first[0]
364
+ assert_nil first[1]['data']
365
+ assert_equal 'value1', first[1]['key1']
366
+ assert_equal 'value2', first[1]['key2']
367
+ assert_equal 'valueThree', first[1]['key3']
344
368
  end
345
369
 
346
370
  CONFIG_CSV = %[
347
- format csv
348
371
  key_name data
372
+ <parse>
373
+ @type csv
374
+ keys key1,key2,key3
375
+ </parse>
376
+ ]
377
+ CONFIG_CSV_COMPAT = %[
378
+ key_name data
379
+ format csv
349
380
  keys key1,key2,key3
350
381
  ]
351
- def test_filter_csv
352
- d = create_driver(CONFIG_CSV, 'test.no.change')
353
- time = @time.to_i
382
+ data(new_conf: CONFIG_CSV,
383
+ compat_conf: CONFIG_CSV_COMPAT)
384
+ def test_filter_csv(conf)
385
+ d = create_driver(conf)
386
+ time = @default_time.to_i
354
387
  d.run do
355
- d.filter({'data' => 'value1,"value2","value""ThreeYes!"', 'xxx' => 'x', 'yyy' => 'y'}, time)
388
+ d.feed(@tag, time, {'data' => 'value1,"value2","value""ThreeYes!"', 'xxx' => 'x', 'yyy' => 'y'})
356
389
  end
357
- filtered = d.filtered_as_array
390
+ filtered = d.filtered
358
391
  assert_equal 1, filtered.length
359
392
 
360
393
  first = filtered[0]
361
- assert_equal 'test.no.change', first[0]
362
- assert_equal time, first[1]
363
- assert_nil first[2]['data']
364
- assert_equal 'value1', first[2]['key1']
365
- assert_equal 'value2', first[2]['key2']
366
- assert_equal 'value"ThreeYes!', first[2]['key3']
394
+ assert_equal time, first[0]
395
+ assert_nil first[1]['data']
396
+ assert_equal 'value1', first[1]['key1']
397
+ assert_equal 'value2', first[1]['key2']
398
+ assert_equal 'value"ThreeYes!', first[1]['key3']
399
+ end
400
+
401
+ def test_filter_with_nested_record
402
+ d = create_driver(%[
403
+ key_name $.data.log
404
+ <parse>
405
+ @type csv
406
+ keys key1,key2,key3
407
+ </parse>
408
+ ])
409
+ time = @default_time.to_i
410
+ d.run do
411
+ d.feed(@tag, time, {'data' => {'log' => 'value1,"value2","value""ThreeYes!"'}, 'xxx' => 'x', 'yyy' => 'y'})
412
+ end
413
+ filtered = d.filtered
414
+ assert_equal 1, filtered.length
415
+
416
+ first = filtered[0]
417
+ assert_equal time, first[0]
418
+ assert_nil first[1]['data']
419
+ assert_equal 'value1', first[1]['key1']
420
+ assert_equal 'value2', first[1]['key2']
421
+ assert_equal 'value"ThreeYes!', first[1]['key3']
367
422
  end
368
423
 
369
424
  CONFIG_HASH_VALUE_FIELD = %[
370
- format json
371
- key_name data
425
+ key_name data
372
426
  hash_value_field parsed
427
+ <parse>
428
+ @type json
429
+ </parse>
373
430
  ]
374
431
  CONFIG_HASH_VALUE_FIELD_RESERVE_DATA = %[
375
- format json
376
- key_name data
432
+ key_name data
377
433
  reserve_data yes
378
434
  hash_value_field parsed
435
+ <parse>
436
+ @type json
437
+ </parse>
379
438
  ]
380
439
  CONFIG_HASH_VALUE_FIELD_WITH_INJECT_KEY_PREFIX = %[
381
- format json
382
- key_name data
440
+ key_name data
383
441
  hash_value_field parsed
384
442
  inject_key_prefix data.
443
+ <parse>
444
+ @type json
445
+ </parse>
385
446
  ]
386
- def test_filter_inject_hash_value_field
447
+ data(:event_time => lambda { |time| Fluent::EventTime.from_time(time) },
448
+ :int_time => lambda { |time| time.to_i })
449
+ def test_filter_inject_hash_value_field(time_parse)
387
450
  original = {'data' => '{"xxx":"first","yyy":"second"}', 'xxx' => 'x', 'yyy' => 'y'}
388
451
 
389
- d = create_driver(CONFIG_HASH_VALUE_FIELD, 'test.no.change')
390
- time = @time.to_i
452
+ d = create_driver(CONFIG_HASH_VALUE_FIELD)
453
+ time = time_parse.call(@default_time)
391
454
  d.run do
392
- d.filter(original, time)
455
+ d.feed(@tag, time, original)
393
456
  end
394
- filtered = d.filtered_as_array
457
+ filtered = d.filtered
395
458
  assert_equal 1, filtered.length
396
459
 
397
460
  first = filtered[0]
398
- assert_equal 'test.no.change', first[0]
399
- assert_equal time, first[1]
461
+ assert_equal_parsed_time time, first[0]
400
462
 
401
- record = first[2]
463
+ record = first[1]
402
464
  assert_equal 1, record.keys.size
403
465
  assert_equal({"xxx"=>"first","yyy"=>"second"}, record['parsed'])
404
466
 
405
- d = create_driver(CONFIG_HASH_VALUE_FIELD_RESERVE_DATA, 'test.no.change')
406
- time = @time.to_i
467
+ d = create_driver(CONFIG_HASH_VALUE_FIELD_RESERVE_DATA)
468
+ time = @default_time.to_i
407
469
  d.run do
408
- d.filter(original, time)
470
+ d.feed(@tag, time, original)
409
471
  end
410
- filtered = d.filtered_as_array
472
+ filtered = d.filtered
411
473
  assert_equal 1, filtered.length
412
474
 
413
475
  first = filtered[0]
414
- assert_equal 'test.no.change', first[0]
415
- assert_equal time, first[1]
476
+ assert_equal_parsed_time time, first[0]
416
477
 
417
- record = first[2]
478
+ record = first[1]
418
479
  assert_equal 4, record.keys.size
419
480
  assert_equal original['data'], record['data']
420
481
  assert_equal original['xxx'], record['xxx']
421
482
  assert_equal original['yyy'], record['yyy']
422
483
  assert_equal({"xxx"=>"first","yyy"=>"second"}, record['parsed'])
423
484
 
424
- d = create_driver(CONFIG_HASH_VALUE_FIELD_WITH_INJECT_KEY_PREFIX, 'test.no.change')
425
- time = @time.to_i
485
+ d = create_driver(CONFIG_HASH_VALUE_FIELD_WITH_INJECT_KEY_PREFIX)
486
+ time = @default_time.to_i
426
487
  d.run do
427
- d.filter(original, time)
488
+ d.feed(@tag, time, original)
428
489
  end
429
- filtered = d.filtered_as_array
490
+ filtered = d.filtered
430
491
  assert_equal 1, filtered.length
431
492
 
432
493
  first = filtered[0]
433
- assert_equal 'test.no.change', first[0]
434
- assert_equal time, first[1]
494
+ assert_equal_parsed_time time, first[0]
435
495
 
436
- record = first[2]
496
+ record = first[1]
437
497
  assert_equal 1, record.keys.size
438
498
  assert_equal({"data.xxx"=>"first","data.yyy"=>"second"}, record['parsed'])
439
499
  end
440
500
 
441
501
  CONFIG_DONT_PARSE_TIME = %[
442
502
  key_name data
503
+ reserve_time true
504
+ <parse>
505
+ @type json
506
+ keep_time_key true
507
+ </parse>
508
+ ]
509
+ CONFIG_DONT_PARSE_TIME_COMPAT = %[
510
+ key_name data
511
+ reserve_time true
443
512
  format json
444
- time_parse no
513
+ keep_time_key true
445
514
  ]
446
- def test_time_should_be_reserved
515
+ data(new_conf: CONFIG_DONT_PARSE_TIME,
516
+ compat_conf: CONFIG_DONT_PARSE_TIME_COMPAT)
517
+ def test_time_should_be_reserved(conf)
447
518
  t = Time.now.to_i
448
- d = create_driver(CONFIG_DONT_PARSE_TIME, 'test.no.change')
449
-
450
- d.run do
451
- d.filter({'data' => '{"time":1383190430, "f1":"v1"}'}, t)
452
- d.filter({'data' => '{"time":"1383190430", "f1":"v1"}'}, t)
453
- d.filter({'data' => '{"time":"2013-10-31 12:34:03 +0900", "f1":"v1"}'}, t)
519
+ d = create_driver(conf)
520
+ d.run(default_tag: @tag) do
521
+ d.feed(t, {'data' => '{"time":1383190430, "f1":"v1"}'})
522
+ d.feed(t, {'data' => '{"time":"1383190430", "f1":"v1"}'})
523
+ d.feed(t, {'data' => '{"time":"2013-10-31 12:34:03 +0900", "f1":"v1"}'})
454
524
  end
455
- filtered = d.filtered_as_array
525
+ filtered = d.filtered
456
526
  assert_equal 3, filtered.length
457
527
 
458
- assert_equal 'test.no.change', filtered[0][0]
459
- assert_equal 'v1', filtered[0][2]['f1']
460
- assert_equal 1383190430, filtered[0][2]['time']
461
- assert_equal t, filtered[0][1]
528
+ assert_equal 'v1', filtered[0][1]['f1']
529
+ assert_equal 1383190430, filtered[0][1]['time']
530
+ assert_equal t, filtered[0][0]
462
531
 
463
- assert_equal 'test.no.change', filtered[1][0]
464
- assert_equal 'v1', filtered[1][2]['f1']
465
- assert_equal "1383190430", filtered[1][2]['time']
466
- assert_equal t, filtered[1][1]
532
+ assert_equal 'v1', filtered[1][1]['f1']
533
+ assert_equal "1383190430", filtered[1][1]['time']
534
+ assert_equal t, filtered[1][0]
467
535
 
468
- assert_equal 'test.no.change', filtered[2][0]
469
- assert_equal 'v1', filtered[2][2]['f1']
470
- assert_equal '2013-10-31 12:34:03 +0900', filtered[2][2]['time']
471
- assert_equal t, filtered[2][1]
536
+ assert_equal 'v1', filtered[2][1]['f1']
537
+ assert_equal '2013-10-31 12:34:03 +0900', filtered[2][1]['time']
538
+ assert_equal t, filtered[2][0]
472
539
  end
473
540
 
474
541
  CONFIG_INVALID_TIME_VALUE = %[
475
- remove_prefix test
476
542
  key_name data
477
- format json
543
+ <parse>
544
+ @type json
545
+ </parse>
478
546
  ] # 'time' is implicit @time_key
479
547
  def test_filter_invalid_time_data
480
548
  # should not raise errors
481
- t = Time.now.to_i
482
- d = create_driver(CONFIG_INVALID_TIME_VALUE, 'test.no.change')
549
+ time = Time.now.to_i
550
+ d = create_driver(CONFIG_INVALID_TIME_VALUE)
483
551
  assert_nothing_raised {
484
- d.run do
485
- d.filter({'data' => '{"time":[], "f1":"v1"}'}, t)
486
- d.filter({'data' => '{"time":"thisisnottime", "f1":"v1"}'}, t)
552
+ d.run(default_tag: @tag) do
553
+ d.feed(time, {'data' => '{"time":[], "f1":"v1"}'})
554
+ d.feed(time, {'data' => '{"time":"thisisnottime", "f1":"v1"}'})
487
555
  end
488
556
  }
489
- filtered = d.filtered_as_array
557
+ filtered = d.filtered
490
558
  assert_equal 1, filtered.length
491
559
 
492
- assert_equal 'test.no.change', filtered[0][0]
493
- assert_equal 0, filtered[0][1]
494
- assert_equal 'v1', filtered[0][2]['f1']
495
- assert_equal 0, filtered[0][2]['time'].to_i
560
+ assert_equal 0, filtered[0][0].to_i
561
+ assert_equal 'v1', filtered[0][1]['f1']
562
+ assert_equal nil, filtered[0][1]['time']
496
563
  end
497
564
 
498
565
  # REGEXP = /^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?$/
499
566
 
500
567
  CONFIG_NOT_REPLACE = %[
501
- remove_prefix test
502
- key_name data
503
- format /^(?<message>.*)$/
568
+ key_name data
569
+ <parse>
570
+ @type regexp
571
+ expression /^(?<message>.*)$/
572
+ </parse>
504
573
  ]
505
574
  CONFIG_INVALID_BYTE = CONFIG_NOT_REPLACE + %[
506
575
  replace_invalid_sequence true
@@ -508,237 +577,155 @@ class ParserFilterTest < Test::Unit::TestCase
508
577
  def test_filter_invalid_byte
509
578
  invalid_utf8 = "\xff".force_encoding('UTF-8')
510
579
 
511
- d = create_driver(CONFIG_NOT_REPLACE, 'test.no.change')
512
- assert_raise(ArgumentError) {
513
- d.run do
514
- d.filter({'data' => invalid_utf8}, Time.now.to_i)
515
- end
516
- }
580
+ d = create_driver(CONFIG_NOT_REPLACE)
581
+ d.run do
582
+ d.feed(@tag, Fluent::EventTime.now.to_i, {'data' => invalid_utf8})
583
+ end
584
+ error_event = d.error_events.first
585
+ assert_equal "test", error_event[0]
586
+ assert_instance_of ArgumentError, error_event[3]
517
587
 
518
- d = create_driver(CONFIG_INVALID_BYTE, 'test.in')
588
+ d = create_driver(CONFIG_INVALID_BYTE)
519
589
  assert_nothing_raised {
520
590
  d.run do
521
- d.emit({'data' => invalid_utf8}, Time.now.to_i)
591
+ d.feed(@tag, Fluent::EventTime.now.to_i, {'data' => invalid_utf8})
522
592
  end
523
593
  }
524
- filtered = d.filtered_as_array
594
+ filtered = d.filtered
525
595
  assert_equal 1, filtered.length
526
- assert_nil filtered[0][2]['data']
527
- assert_equal '?'.force_encoding('UTF-8'), filtered[0][2]['message']
596
+ assert_nil filtered[0][1]['data']
597
+ assert_equal '?'.force_encoding('UTF-8'), filtered[0][1]['message']
528
598
 
529
- d = create_driver(CONFIG_INVALID_BYTE + %[
530
- reserve_data yes
531
- ], 'test.no.change')
599
+ d = create_driver(CONFIG_INVALID_BYTE + %[reserve_data yes])
532
600
  assert_nothing_raised {
533
601
  d.run do
534
- d.filter({'data' => invalid_utf8}, Time.now.to_i)
602
+ d.feed(@tag, Fluent::EventTime.now.to_i, {'data' => invalid_utf8})
535
603
  end
536
604
  }
537
- filtered = d.filtered_as_array
605
+ filtered = d.filtered
538
606
  assert_equal 1, filtered.length
539
- assert_equal invalid_utf8, filtered[0][2]['data']
540
- assert_equal '?'.force_encoding('UTF-8'), filtered[0][2]['message']
607
+ assert_equal invalid_utf8, filtered[0][1]['data']
608
+ assert_equal '?'.force_encoding('UTF-8'), filtered[0][1]['message']
541
609
 
542
610
  invalid_ascii = "\xff".force_encoding('US-ASCII')
543
- d = create_driver(CONFIG_INVALID_BYTE, 'test.no.change')
611
+ d = create_driver(CONFIG_INVALID_BYTE)
544
612
  assert_nothing_raised {
545
613
  d.run do
546
- d.filter({'data' => invalid_ascii}, Time.now.to_i)
614
+ d.feed(@tag, Fluent::EventTime.now.to_i, {'data' => invalid_ascii})
547
615
  end
548
616
  }
549
- filtered = d.filtered_as_array
617
+ filtered = d.filtered
550
618
  assert_equal 1, filtered.length
551
- assert_nil filtered[0][2]['data']
552
- assert_equal '?'.force_encoding('US-ASCII'), filtered[0][2]['message']
619
+ assert_nil filtered[0][1]['data']
620
+ assert_equal '?'.force_encoding('US-ASCII'), filtered[0][1]['message']
553
621
  end
554
622
 
555
623
  CONFIG_NOT_IGNORE = %[
556
- remove_prefix test
557
- key_name data
558
- format json
624
+ key_name data
559
625
  hash_value_field parsed
626
+ <parse>
627
+ @type json
628
+ </parse>
560
629
  ]
561
- CONFIG_IGNORE = CONFIG_NOT_IGNORE + %[
562
- ignore_key_not_exist true
563
- ]
564
- CONFIG_PASS_SAME_RECORD = CONFIG_IGNORE + %[
630
+ CONFIG_PASS_SAME_RECORD = CONFIG_NOT_IGNORE + %[
565
631
  reserve_data true
566
632
  ]
567
633
  def test_filter_key_not_exist
568
- d = create_driver(CONFIG_NOT_IGNORE, 'test.no.ignore')
569
- assert_nothing_raised {
570
- d.run do
571
- d.filter({'foo' => 'bar'}, Time.now.to_i)
572
- end
573
- }
574
- assert_match /data does not exist/, d.instance.log.out.logs.first
575
-
576
- d = create_driver(CONFIG_IGNORE, 'test.ignore')
634
+ d = create_driver(CONFIG_NOT_IGNORE)
635
+ flexmock(d.instance.router).should_receive(:emit_error_event).
636
+ with(String, Integer, Hash, ArgumentError.new("data does not exist")).once
577
637
  assert_nothing_raised {
578
638
  d.run do
579
- d.filter({'foo' => 'bar'}, Time.now.to_i)
639
+ d.feed(@tag, Fluent::EventTime.now.to_i, {'foo' => 'bar'})
580
640
  end
581
641
  }
582
- assert_not_match /data does not exist/, d.instance.log.out.logs.first
583
642
 
584
- d = create_driver(CONFIG_PASS_SAME_RECORD, 'test.pass_same_record')
643
+ d = create_driver(CONFIG_PASS_SAME_RECORD)
585
644
  assert_nothing_raised {
586
645
  d.run do
587
- d.filter({'foo' => 'bar'}, Time.now.to_i)
646
+ d.feed(@tag, Fluent::EventTime.now.to_i, {'foo' => 'bar'})
588
647
  end
589
648
  }
590
- filtered = d.filtered_as_array
649
+ filtered = d.filtered
591
650
  assert_equal 1, filtered.length
592
- assert_nil filtered[0][2]['data']
593
- assert_equal 'bar', filtered[0][2]['foo']
594
-
595
- d = create_driver(CONFIG_NOT_IGNORE + "emit_invalid_record_to_error true", 'test.no.ignore')
596
- assert_nothing_raised {
597
- flexmock(d.instance.router).should_receive(:emit_error_event).
598
- with(String, Integer, Hash, ArgumentError).once
599
- d.run do
600
- d.filter({'foo' => 'bar'}, Time.now.to_i)
601
- end
602
- }
651
+ assert_nil filtered[0][1]['data']
652
+ assert_equal 'bar', filtered[0][1]['foo']
603
653
  end
604
654
 
605
- # suppress_parse_error_log test
606
- CONFIG_DISABELED_SUPPRESS_PARSE_ERROR_LOG = %[
607
- tag hogelog
608
- format /^col1=(?<col1>.+) col2=(?<col2>.+)$/
609
- key_name message
610
- suppress_parse_error_log false
611
- ]
612
- CONFIG_ENABELED_SUPPRESS_PARSE_ERROR_LOG = %[
613
- tag hogelog
614
- format /^col1=(?<col1>.+) col2=(?<col2>.+)$/
615
- key_name message
616
- suppress_parse_error_log true
617
- ]
618
- CONFIG_DEFAULT_SUPPRESS_PARSE_ERROR_LOG = %[
619
- tag hogelog
620
- format /^col1=(?<col1>.+) col2=(?<col2>.+)$/
621
- key_name message
622
- ]
623
-
655
+ # emit_error_event test
624
656
  INVALID_MESSAGE = 'foo bar'
625
657
  VALID_MESSAGE = 'col1=foo col2=bar'
626
658
 
627
- # if call warn() raise exception
628
- class DummyLoggerWarnedException < StandardError; end
629
- class DummyLogger
630
- def reset
631
- end
632
- def warn(message)
633
- raise DummyLoggerWarnedException
659
+ def test_call_emit_error_event_when_parser_error
660
+ d = create_driver(CONFIG_INVALID_TIME_VALUE)
661
+ flexmock(d.instance.router).should_receive(:emit_error_event).
662
+ with(String, Integer, Hash, ParserError).once
663
+ d.run do
664
+ d.feed(@tag, Fluent::EventTime.now.to_i, {'data' => '{"time":[], "f1":"v1"}'})
634
665
  end
635
666
  end
636
667
 
637
- def swap_logger(instance)
638
- raise "use with block" unless block_given?
639
- dummy = DummyLogger.new
640
- saved_logger = instance.log
641
- instance.log = dummy
642
- restore = lambda{ instance.log = saved_logger }
643
-
644
- yield
645
-
646
- restore.call
647
- end
648
-
649
- def test_parser_error_warning
650
- d = create_driver(CONFIG_INVALID_TIME_VALUE, 'test.no.change')
651
- swap_logger(d.instance) do
652
- assert_raise(DummyLoggerWarnedException) {
653
- d.run do
654
- d.filter({'data' => '{"time":[], "f1":"v1"}'}, Time.now.to_i)
655
- end
656
- }
657
- end
658
- end
668
+ CONFIG_UNMATCHED_PATTERN_LOG = %[
669
+ key_name message
670
+ <parse>
671
+ @type regexp
672
+ expression /^col1=(?<col1>.+) col2=(?<col2>.+)$/
673
+ </parse>
674
+ ]
659
675
 
660
- class DefaultSuppressParseErrorLogTest < self
661
- def setup
662
- # default(disabled) 'suppress_parse_error_log' is not specify
663
- @d = create_driver(CONFIG_DEFAULT_SUPPRESS_PARSE_ERROR_LOG, 'test.no.change')
676
+ class UnmatchedPatternLogTest < self
677
+ setup do
678
+ @d = create_driver(CONFIG_UNMATCHED_PATTERN_LOG)
664
679
  end
665
680
 
666
- def test_raise_exception
667
- swap_logger(@d.instance) do
668
- assert_raise(DummyLoggerWarnedException) {
669
- @d.run do
670
- @d.filter({'message' => INVALID_MESSAGE}, Time.now.to_i)
671
- end
672
- }
681
+ def test_call_emit_error_event_when_pattern_is_mismached
682
+ flexmock(@d.instance.router).should_receive(:emit_error_event).
683
+ with(String, Integer, Hash, ParserError.new("pattern not matched with data '#{INVALID_MESSAGE}'")).once
684
+ @d.run do
685
+ @d.feed(@tag, Fluent::EventTime.now.to_i, {'message' => INVALID_MESSAGE})
673
686
  end
674
687
  end
675
688
 
676
- def test_nothing_raised
677
- swap_logger(@d.instance) do
678
- assert_nothing_raised {
679
- @d.run do
680
- @d.filter({'message' => VALID_MESSAGE}, Time.now.to_i)
681
- end
682
- }
689
+ def test_not_call_emit_error_event_when_pattern_is_mached
690
+ flexmock(@d.instance.router).should_receive(:emit_error_event).never
691
+ @d.run do
692
+ @d.feed(@tag, Fluent::EventTime.now.to_i, {'message' => VALID_MESSAGE})
683
693
  end
684
694
  end
685
695
  end
686
696
 
687
- class DisabledSuppressParseErrorLogTest < self
688
- def setup
689
- # disabled 'suppress_parse_error_log'
690
- @d = create_driver(CONFIG_DISABELED_SUPPRESS_PARSE_ERROR_LOG, 'test.no.change')
691
- end
692
-
693
- def test_raise_exception
694
- swap_logger(@d.instance) do
695
- assert_raise(DummyLoggerWarnedException) {
696
- @d.run do
697
- @d.filter({'message' => INVALID_MESSAGE}, Time.now.to_i)
698
- end
699
- }
700
- end
701
- end
702
-
703
- def test_nothing_raised
697
+ class EmitInvalidRecordToErrorTest < self
698
+ def test_pattern_is_mismached_with_emit_invalid_record_to_error
699
+ d = create_driver(CONFIG_UNMATCHED_PATTERN_LOG + "emit_invalid_record_to_error false")
700
+ flexmock(d.instance.router).should_receive(:emit_error_event).never
704
701
  assert_nothing_raised {
705
- @d.run do
706
- @d.filter({'message' => VALID_MESSAGE}, Time.now.to_i)
702
+ d.run do
703
+ d.feed(@tag, Fluent::EventTime.now.to_i, {'message' => INVALID_MESSAGE})
707
704
  end
708
705
  }
709
- end
710
- end
711
-
712
- class EnabledSuppressParseErrorLogTest < self
713
- def setup
714
- # enabled 'suppress_parse_error_log'
715
- @d = create_driver(CONFIG_ENABELED_SUPPRESS_PARSE_ERROR_LOG, 'test.no.change')
706
+ assert_equal 0, d.filtered.length
716
707
  end
717
708
 
718
- def test_nothing_raised
709
+ def test_parser_error_with_emit_invalid_record_to_error
710
+ d = create_driver(CONFIG_INVALID_TIME_VALUE + "emit_invalid_record_to_error false")
711
+ flexmock(d.instance.router).should_receive(:emit_error_event).never
719
712
  assert_nothing_raised {
720
- @d.run do
721
- @d.filter({'message' => INVALID_MESSAGE}, Time.now.to_i)
722
- @d.filter({'message' => VALID_MESSAGE}, Time.now.to_i)
713
+ d.run do
714
+ d.feed(@tag, Fluent::EventTime.now.to_i, {'data' => '{"time":[], "f1":"v1"}'})
723
715
  end
724
716
  }
717
+ assert_equal 0, d.filtered.length
725
718
  end
726
- end
727
719
 
728
- class EmitInvalidRecordErrorTest < self
729
- def setup
730
- # enabled 'suppress_parse_error_log'
731
- @d = create_driver(CONFIG_ENABELED_SUPPRESS_PARSE_ERROR_LOG + "emit_invalid_record_to_error true", 'test.no.change')
732
- end
733
-
734
- def test_nothing_raised
735
- flexmock(@d.instance.router).should_receive(:emit_error_event).
736
- with(String, Integer, Hash, Fluent::ParserError).once
720
+ def test_key_not_exist_with_emit_invalid_record_to_error
721
+ d = create_driver(CONFIG_NOT_IGNORE + "emit_invalid_record_to_error false")
722
+ flexmock(d.instance.router).should_receive(:emit_error_event).never
737
723
  assert_nothing_raised {
738
- @d.run do
739
- @d.filter({'message' => INVALID_MESSAGE}, Time.now.to_i)
724
+ d.run do
725
+ d.feed(@tag, Fluent::EventTime.now.to_i, {'foo' => 'bar'})
740
726
  end
741
727
  }
728
+ assert_equal 0, d.filtered.length
742
729
  end
743
730
  end
744
731
  end