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,13 +1,30 @@
1
1
  require_relative '../helper'
2
- require 'fluent/test'
2
+ require 'fluent/test/driver/input'
3
3
  require 'fluent/plugin/in_http'
4
4
  require 'net/http'
5
+ require 'timecop'
5
6
 
6
7
  class HttpInputTest < Test::Unit::TestCase
8
+ class << self
9
+ def startup
10
+ socket_manager_path = ServerEngine::SocketManager::Server.generate_path
11
+ @server = ServerEngine::SocketManager::Server.open(socket_manager_path)
12
+ ENV['SERVERENGINE_SOCKETMANAGER_PATH'] = socket_manager_path.to_s
13
+ end
14
+
15
+ def shutdown
16
+ @server.close
17
+ end
18
+ end
19
+
7
20
  def setup
8
21
  Fluent::Test.setup
9
22
  end
10
23
 
24
+ def teardown
25
+ Timecop.return
26
+ end
27
+
11
28
  PORT = unused_port
12
29
  CONFIG = %[
13
30
  port #{PORT}
@@ -18,7 +35,7 @@ class HttpInputTest < Test::Unit::TestCase
18
35
  ]
19
36
 
20
37
  def create_driver(conf=CONFIG)
21
- Fluent::Test::InputTestDriver.new(Fluent::HttpInput).configure(conf, true)
38
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::HttpInput).configure(conf)
22
39
  end
23
40
 
24
41
  def test_configure
@@ -32,137 +49,252 @@ class HttpInputTest < Test::Unit::TestCase
32
49
 
33
50
  def test_time
34
51
  d = create_driver
52
+ time = event_time("2011-01-02 13:14:15.123 UTC")
53
+ Timecop.freeze(Time.at(time))
35
54
 
36
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
37
- Fluent::Engine.now = time
55
+ events = [
56
+ ["tag1", time, {"a" => 1}],
57
+ ["tag2", time, {"a" => 2}],
58
+ ]
59
+ res_codes = []
38
60
 
39
- d.expect_emit "tag1", time, {"a"=>1}
40
- d.expect_emit "tag2", time, {"a"=>2}
41
-
42
- d.run do
43
- d.expected_emits.each {|tag,time,record|
61
+ d.run(expect_records: 2) do
62
+ events.each do |tag, _time, record|
44
63
  res = post("/#{tag}", {"json"=>record.to_json})
45
- assert_equal "200", res.code
46
- }
64
+ res_codes << res.code
65
+ end
66
+ end
67
+
68
+ assert_equal ["200", "200"], res_codes
69
+ assert_equal events, d.events
70
+ assert_equal_event_time time, d.events[0][1]
71
+ assert_equal_event_time time, d.events[1][1]
72
+ end
73
+
74
+ def test_time_as_float
75
+ d = create_driver
76
+ time = event_time("2011-01-02 13:14:15.123 UTC")
77
+ float_time = time.to_f
78
+
79
+ events = [
80
+ ["tag1", time, {"a"=>1}],
81
+ ]
82
+ res_codes = []
83
+
84
+ d.run(expect_records: 1) do
85
+ events.each do |tag, t, record|
86
+ res = post("/#{tag}", {"json"=>record.to_json, "time"=>float_time.to_s})
87
+ res_codes << res.code
88
+ end
47
89
  end
90
+ assert_equal ["200"], res_codes
91
+ assert_equal events, d.events
92
+ assert_equal_event_time time, d.events[0][1]
48
93
  end
49
94
 
50
95
  def test_json
51
96
  d = create_driver
52
-
53
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
54
-
55
- d.expect_emit "tag1", time, {"a"=>1}
56
- d.expect_emit "tag2", time, {"a"=>2}
57
-
58
- d.run do
59
- d.expected_emits.each {|tag,time,record|
60
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>time.to_s})
61
- assert_equal "200", res.code
62
- }
97
+ time = event_time("2011-01-02 13:14:15 UTC")
98
+ time_i = time.to_i
99
+
100
+ events = [
101
+ ["tag1", time_i, {"a"=>1}],
102
+ ["tag2", time_i, {"a"=>2}],
103
+ ]
104
+ res_codes = []
105
+
106
+ d.run(expect_records: 2) do
107
+ events.each do |tag, t, record|
108
+ res = post("/#{tag}", {"json"=>record.to_json, "time"=>t.to_s})
109
+ res_codes << res.code
110
+ end
63
111
  end
64
-
65
- d.emit_streams.each { |tag, es|
66
- assert !include_http_header?(es.first[1])
67
- }
112
+ assert_equal ["200", "200"], res_codes
113
+ assert_equal events, d.events
114
+ assert_equal_event_time time, d.events[0][1]
115
+ assert_equal_event_time time, d.events[1][1]
68
116
  end
69
117
 
70
118
  def test_multi_json
71
119
  d = create_driver
120
+ time = event_time("2011-01-02 13:14:15 UTC")
121
+ time_i = time.to_i
122
+
123
+ records = [{"a"=>1},{"a"=>2}]
124
+ events = [
125
+ ["tag1", time_i, records[0]],
126
+ ["tag1", time_i, records[1]],
127
+ ]
128
+ tag = "tag1"
129
+ res_codes = []
130
+ d.run(expect_records: 2, timeout: 5) do
131
+ res = post("/#{tag}", {"json"=>records.to_json, "time"=>time_i.to_s})
132
+ res_codes << res.code
133
+ end
134
+ assert_equal ["200"], res_codes
135
+ assert_equal events, d.events
136
+ assert_equal_event_time time, d.events[0][1]
137
+ assert_equal_event_time time, d.events[1][1]
138
+ end
72
139
 
73
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
74
-
75
- events = [{"a"=>1},{"a"=>2}]
140
+ def test_multi_json_with_time_field
141
+ d = create_driver
142
+ time = event_time("2011-01-02 13:14:15 UTC")
143
+ time_i = time.to_i
144
+ time_f = time.to_f
145
+
146
+ records = [{"a" => 1, 'time' => time_i},{"a" => 2, 'time' => time_f}]
147
+ events = [
148
+ ["tag1", time, {'a' => 1}],
149
+ ["tag1", time, {'a' => 2}],
150
+ ]
76
151
  tag = "tag1"
152
+ res_codes = []
153
+ d.run(expect_records: 2, timeout: 5) do
154
+ res = post("/#{tag}", {"json" => records.to_json})
155
+ res_codes << res.code
156
+ end
157
+ assert_equal ["200"], res_codes
158
+ assert_equal events, d.events
159
+ assert_instance_of Fluent::EventTime, d.events[0][1]
160
+ assert_instance_of Fluent::EventTime, d.events[1][1]
161
+ assert_equal_event_time time, d.events[0][1]
162
+ assert_equal_event_time time, d.events[1][1]
163
+ end
77
164
 
78
- events.each { |ev|
79
- d.expect_emit tag, time, ev
80
- }
165
+ def test_multi_json_with_nonexistent_time_key
166
+ d = create_driver(CONFIG + %[
167
+ <parse>
168
+ time_key missing
169
+ </parse>
170
+ ])
171
+ time = event_time("2011-01-02 13:14:15 UTC")
172
+ time_i = time.to_i
173
+ time_f = time.to_f
81
174
 
82
- d.run do
83
- res = post("/#{tag}", {"json"=>events.to_json, "time"=>time.to_s})
84
- assert_equal "200", res.code
175
+ records = [{"a" => 1, 'time' => time_i},{"a" => 2, 'time' => time_f}]
176
+ tag = "tag1"
177
+ res_codes = []
178
+ d.run(expect_records: 2, timeout: 5) do
179
+ res = post("/#{tag}", {"json" => records.to_json})
180
+ res_codes << res.code
85
181
  end
86
-
182
+ assert_equal ["200"], res_codes
183
+ assert_equal 2, d.events.size
184
+ assert_not_equal time_i, d.events[0][1].sec # current time is used because "missing" field doesn't exist
185
+ assert_not_equal time_i, d.events[1][1].sec
87
186
  end
88
187
 
89
188
  def test_json_with_add_remote_addr
90
189
  d = create_driver(CONFIG + "add_remote_addr true")
91
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
92
-
93
- d.expect_emit "tag1", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>1}
94
- d.expect_emit "tag2", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>2}
95
-
96
- d.run do
97
- d.expected_emits.each {|tag,time,record|
98
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>time.to_s})
99
- assert_equal "200", res.code
100
- }
190
+ time = event_time("2011-01-02 13:14:15 UTC")
191
+ time_i = time.to_i
192
+
193
+ events = [
194
+ ["tag1", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>1}],
195
+ ["tag2", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>2}],
196
+ ]
197
+ res_codes = []
198
+ d.run(expect_records: 2) do
199
+ events.each do |tag, _t, record|
200
+ res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s})
201
+ res_codes << res.code
202
+ end
101
203
  end
102
-
204
+ assert_equal ["200", "200"], res_codes
205
+ assert_equal events, d.events
206
+ assert_equal_event_time time, d.events[0][1]
207
+ assert_equal_event_time time, d.events[1][1]
103
208
  end
104
209
 
105
210
  def test_multi_json_with_add_remote_addr
106
211
  d = create_driver(CONFIG + "add_remote_addr true")
212
+ time = event_time("2011-01-02 13:14:15 UTC")
213
+ time_i = time.to_i
107
214
 
108
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
109
- events = [{"a"=>1},{"a"=>2}]
215
+ records = [{"a"=>1},{"a"=>2}]
110
216
  tag = "tag1"
217
+ res_codes = []
111
218
 
112
- d.expect_emit "tag1", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>1}
113
- d.expect_emit "tag1", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>2}
114
-
115
- d.run do
116
- res = post("/#{tag}", {"json"=>events.to_json, "time"=>time.to_s})
117
- assert_equal "200", res.code
219
+ d.run(expect_records: 2, timeout: 5) do
220
+ res = post("/#{tag}", {"json"=>records.to_json, "time"=>time_i.to_s})
221
+ res_codes << res.code
118
222
  end
223
+ assert_equal ["200"], res_codes
119
224
 
225
+ assert_equal "tag1", d.events[0][0]
226
+ assert_equal_event_time time, d.events[0][1]
227
+ assert_equal 1, d.events[0][2]["a"]
228
+ assert{ d.events[0][2].has_key?("REMOTE_ADDR") && d.events[0][2]["REMOTE_ADDR"] =~ /^\d{1,4}(\.\d{1,4}){3}$/ }
229
+
230
+ assert_equal "tag1", d.events[1][0]
231
+ assert_equal_event_time time, d.events[1][1]
232
+ assert_equal 2, d.events[1][2]["a"]
120
233
  end
121
234
 
122
235
  def test_json_with_add_remote_addr_given_x_forwarded_for
123
236
  d = create_driver(CONFIG + "add_remote_addr true")
124
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
125
-
126
- d.expect_emit "tag1", time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>1}
127
- d.expect_emit "tag2", time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>1}
128
-
129
- d.run do
130
- d.expected_emits.each {|tag,_time,record|
131
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s}, {"X-Forwarded-For"=>"129.78.138.66, 127.0.0.1"})
132
- assert_equal "200", res.code
133
- }
237
+ time = event_time("2011-01-02 13:14:15 UTC")
238
+ time_i = time.to_i
239
+
240
+ events = [
241
+ ["tag1", time, {"a"=>1}],
242
+ ["tag2", time, {"a"=>2}],
243
+ ]
244
+ res_codes = []
245
+
246
+ d.run(expect_records: 2) do
247
+ events.each do |tag, _t, record|
248
+ res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s}, {"X-Forwarded-For"=>"129.78.138.66, 127.0.0.1"})
249
+ res_codes << res.code
250
+ end
134
251
  end
252
+ assert_equal ["200", "200"], res_codes
135
253
 
254
+ assert_equal "tag1", d.events[0][0]
255
+ assert_equal_event_time time, d.events[0][1]
256
+ assert_equal({"REMOTE_ADDR"=>"129.78.138.66", "a"=>1}, d.events[0][2])
257
+
258
+ assert_equal "tag2", d.events[1][0]
259
+ assert_equal_event_time time, d.events[1][1]
260
+ assert_equal({"REMOTE_ADDR"=>"129.78.138.66", "a"=>2}, d.events[1][2])
136
261
  end
137
262
 
138
263
  def test_multi_json_with_add_remote_addr_given_x_forwarded_for
139
264
  d = create_driver(CONFIG + "add_remote_addr true")
140
265
 
141
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
142
- events = [{"a"=>1},{"a"=>2}]
143
266
  tag = "tag1"
144
-
145
- d.expect_emit "tag1", time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>1}
146
- d.expect_emit "tag1", time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>2}
147
-
148
- d.run do
149
- res = post("/#{tag}", {"json"=>events.to_json, "time"=>time.to_s}, {"X-Forwarded-For"=>"129.78.138.66, 127.0.0.1"})
150
- assert_equal "200", res.code
267
+ time = event_time("2011-01-02 13:14:15 UTC")
268
+ time_i = time.to_i
269
+ records = [{"a"=>1},{"a"=>2}]
270
+ events = [
271
+ [tag, time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>1}],
272
+ [tag, time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>2}],
273
+ ]
274
+ res_codes = []
275
+
276
+ d.run(expect_records: 2, timeout: 5) do
277
+ res = post("/#{tag}", {"json"=>records.to_json, "time"=>time_i.to_s}, {"X-Forwarded-For"=>"129.78.138.66, 127.0.0.1"})
278
+ res_codes << res.code
151
279
  end
152
-
280
+ assert_equal ["200"], res_codes
281
+ assert_equal events, d.events
282
+ assert_equal_event_time time, d.events[0][1]
283
+ assert_equal_event_time time, d.events[1][1]
153
284
  end
154
285
 
155
286
  def test_add_remote_addr_given_multi_x_forwarded_for
156
287
  d = create_driver(CONFIG + "add_remote_addr true")
157
288
 
158
289
  tag = "tag1"
159
- time = event_time("2011-01-02 13:14:15 UTC").to_i
290
+ time = event_time("2011-01-02 13:14:15 UTC")
291
+ time_i = time.to_i
160
292
  record = {"a" => 1}
293
+ event = ["tag1", time, {"REMOTE_ADDR" => "129.78.138.66", "a" => 1}]
294
+ res_code = nil
161
295
 
162
- d.expect_emit tag, time, {"REMOTE_ADDR"=>"129.78.138.66", "a" => 1}
163
-
164
- d.run do
165
- res = post("/#{tag}", {"json" => record.to_json, "time" => time.to_s}) { |http, req|
296
+ d.run(expect_records: 1, timeout: 5) do
297
+ res = post("/#{tag}", {"json" => record.to_json, "time" => time_i.to_s}) { |http, req|
166
298
  # net/http can't send multiple headers so overwrite it.
167
299
  def req.each_capitalized
168
300
  block_given? or return enum_for(__method__) { @header.size }
@@ -175,112 +307,189 @@ class HttpInputTest < Test::Unit::TestCase
175
307
  req.add_field("X-Forwarded-For", "129.78.138.66, 127.0.0.1")
176
308
  req.add_field("X-Forwarded-For", "8.8.8.8")
177
309
  }
178
- assert_equal "200", res.code
310
+ res_code = res.code
179
311
  end
312
+ assert_equal "200", res_code
313
+ assert_equal event, d.events.first
314
+ assert_equal_event_time time, d.events.first[1]
180
315
  end
181
316
 
182
317
  def test_multi_json_with_add_http_headers
183
318
  d = create_driver(CONFIG + "add_http_headers true")
184
-
185
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
186
- events = [{"a"=>1},{"a"=>2}]
319
+ time = event_time("2011-01-02 13:14:15 UTC")
320
+ time_i = time.to_i
321
+ records = [{"a"=>1},{"a"=>2}]
187
322
  tag = "tag1"
323
+ res_codes = []
188
324
 
189
- d.run do
190
- res = post("/#{tag}", {"json"=>events.to_json, "time"=>time.to_s})
191
- assert_equal "200", res.code
325
+ d.run(expect_records: 2, timeout: 5) do
326
+ res = post("/#{tag}", {"json"=>records.to_json, "time"=>time_i.to_s})
327
+ res_codes << res.code
192
328
  end
329
+ assert_equal ["200"], res_codes
330
+
331
+ assert_equal "tag1", d.events[0][0]
332
+ assert_equal_event_time time, d.events[0][1]
333
+ assert_equal 1, d.events[0][2]["a"]
193
334
 
194
- d.emit_streams.each { |tag, es|
195
- assert include_http_header?(es.first[1])
196
- }
335
+ assert_equal "tag1", d.events[1][0]
336
+ assert_equal_event_time time, d.events[1][1]
337
+ assert_equal 2, d.events[1][2]["a"]
338
+
339
+ assert include_http_header?(d.events[0][2])
340
+ assert include_http_header?(d.events[1][2])
197
341
  end
198
342
 
199
343
  def test_json_with_add_http_headers
200
344
  d = create_driver(CONFIG + "add_http_headers true")
345
+ time = event_time("2011-01-02 13:14:15 UTC")
346
+ time_i = time.to_i
347
+ events = [
348
+ ["tag1", time, {"a"=>1}],
349
+ ["tag2", time, {"a"=>2}],
350
+ ]
351
+ res_codes = []
352
+
353
+ d.run(expect_records: 2) do
354
+ events.each do |tag, t, record|
355
+ res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s})
356
+ res_codes << res.code
357
+ end
358
+ end
359
+ assert_equal ["200", "200"], res_codes
201
360
 
202
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
361
+ assert_equal "tag1", d.events[0][0]
362
+ assert_equal_event_time time, d.events[0][1]
363
+ assert_equal 1, d.events[0][2]["a"]
203
364
 
204
- records = [["tag1", time, {"a"=>1}], ["tag2", time, {"a"=>2}]]
365
+ assert_equal "tag2", d.events[1][0]
366
+ assert_equal_event_time time, d.events[1][1]
367
+ assert_equal 2, d.events[1][2]["a"]
205
368
 
206
- d.run do
207
- records.each {|tag,time,record|
208
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>time.to_s})
209
- assert_equal "200", res.code
369
+ assert include_http_header?(d.events[0][2])
370
+ assert include_http_header?(d.events[1][2])
371
+ end
210
372
 
211
- }
373
+ def test_multi_json_with_custom_parser
374
+ d = create_driver(CONFIG + %[
375
+ <parse>
376
+ @type json
377
+ keep_time_key true
378
+ time_key foo
379
+ time_format %iso8601
380
+ </parse>
381
+ ])
382
+
383
+ time = event_time("2011-01-02 13:14:15 UTC")
384
+ time_s = Time.at(time).iso8601
385
+
386
+ records = [{"foo"=>time_s,"bar"=>"test1"},{"foo"=>time_s,"bar"=>"test2"}]
387
+ tag = "tag1"
388
+ res_codes = []
389
+
390
+ d.run(expect_records: 2, timeout: 5) do
391
+ res = post("/#{tag}", records.to_json, {"Content-Type"=>"application/octet-stream"})
392
+ res_codes << res.code
212
393
  end
394
+ assert_equal ["200"], res_codes
213
395
 
214
- d.emit_streams.each { |tag, es|
215
- assert include_http_header?(es.first[1])
216
- }
396
+ assert_equal "tag1", d.events[0][0]
397
+ assert_equal_event_time time, d.events[0][1]
398
+ assert_equal d.events[0][2], records[0]
399
+
400
+ assert_equal "tag1", d.events[1][0]
401
+ assert_equal_event_time time, d.events[1][1]
402
+ assert_equal d.events[1][2], records[1]
217
403
  end
218
404
 
219
405
  def test_application_json
220
406
  d = create_driver
221
-
222
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
223
-
224
- d.expect_emit "tag1", time, {"a"=>1}
225
- d.expect_emit "tag2", time, {"a"=>2}
226
-
227
- d.run do
228
- d.expected_emits.each {|tag,time,record|
229
- res = post("/#{tag}?time=#{time.to_s}", record.to_json, {"content-type"=>"application/json; charset=utf-8"})
230
- assert_equal "200", res.code
231
- }
407
+ time = event_time("2011-01-02 13:14:15 UTC")
408
+ time_i = time.to_i
409
+ events = [
410
+ ["tag1", time, {"a"=>1}],
411
+ ["tag2", time, {"a"=>2}],
412
+ ]
413
+ res_codes = []
414
+
415
+ d.run(expect_records: 2) do
416
+ events.each do |tag, t, record|
417
+ res = post("/#{tag}?time=#{time_i.to_s}", record.to_json, {"Content-Type"=>"application/json; charset=utf-8"})
418
+ res_codes << res.code
419
+ end
232
420
  end
421
+ assert_equal ["200", "200"], res_codes
422
+ assert_equal events, d.events
423
+ assert_equal_event_time time, d.events[0][1]
424
+ assert_equal_event_time time, d.events[1][1]
233
425
  end
234
426
 
235
427
  def test_application_msgpack
236
428
  d = create_driver
237
-
238
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
239
-
240
- d.expect_emit "tag1", time, {"a"=>1}
241
- d.expect_emit "tag2", time, {"a"=>2}
242
-
243
- d.run do
244
- d.expected_emits.each {|tag,time,record|
245
- res = post("/#{tag}?time=#{time.to_s}", record.to_msgpack, {"content-type"=>"application/msgpack; charset=utf-8"})
246
- assert_equal "200", res.code
247
- }
429
+ time = event_time("2011-01-02 13:14:15 UTC")
430
+ time_i = time.to_i
431
+ events = [
432
+ ["tag1", time, {"a"=>1}],
433
+ ["tag2", time, {"a"=>2}],
434
+ ]
435
+ res_codes = []
436
+
437
+ d.run(expect_records: 2) do
438
+ events.each do |tag, t, record|
439
+ res = post("/#{tag}?time=#{time_i.to_s}", record.to_msgpack, {"Content-Type"=>"application/msgpack"})
440
+ res_codes << res.code
441
+ end
248
442
  end
443
+ assert_equal ["200", "200"], res_codes
444
+ assert_equal events, d.events
445
+ assert_equal_event_time time, d.events[0][1]
446
+ assert_equal_event_time time, d.events[1][1]
249
447
  end
250
448
 
251
449
  def test_msgpack
252
450
  d = create_driver
253
-
254
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
255
-
256
- d.expect_emit "tag1", time, {"a"=>1}
257
- d.expect_emit "tag2", time, {"a"=>2}
258
-
259
- d.run do
260
- d.expected_emits.each {|tag,time,record|
261
- res = post("/#{tag}", {"msgpack"=>record.to_msgpack, "time"=>time.to_s})
262
- assert_equal "200", res.code
263
- }
451
+ time = event_time("2011-01-02 13:14:15 UTC")
452
+ time_i = time.to_i
453
+
454
+ events = [
455
+ ["tag1", time, {"a"=>1}],
456
+ ["tag2", time, {"a"=>2}],
457
+ ]
458
+ res_codes = []
459
+
460
+ d.run(expect_records: 2) do
461
+ events.each do |tag, t, record|
462
+ res = post("/#{tag}", {"msgpack"=>record.to_msgpack, "time"=>time_i.to_s})
463
+ res_codes << res.code
464
+ end
264
465
  end
466
+ assert_equal ["200", "200"], res_codes
467
+ assert_equal events, d.events
468
+ assert_equal_event_time time, d.events[0][1]
469
+ assert_equal_event_time time, d.events[1][1]
265
470
  end
266
471
 
267
472
  def test_multi_msgpack
268
473
  d = create_driver
269
474
 
270
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
475
+ time = event_time("2011-01-02 13:14:15 UTC")
476
+ time_i = time.to_i
271
477
 
272
- events = [{"a"=>1},{"a"=>2}]
478
+ records = [{"a"=>1},{"a"=>2}]
479
+ events = [
480
+ ["tag1", time, records[0]],
481
+ ["tag1", time, records[1]],
482
+ ]
273
483
  tag = "tag1"
274
-
275
- events.each { |ev|
276
- d.expect_emit tag, time, ev
277
- }
278
-
279
- d.run do
280
- res = post("/#{tag}", {"msgpack"=>events.to_msgpack, "time"=>time.to_s})
281
- assert_equal "200", res.code
484
+ res_codes = []
485
+ d.run(expect_records: 2) do
486
+ res = post("/#{tag}", {"msgpack"=>records.to_msgpack, "time"=>time_i.to_s})
487
+ res_codes << res.code
282
488
  end
283
-
489
+ assert_equal ["200"], res_codes
490
+ assert_equal events, d.events
491
+ assert_equal_event_time time, d.events[0][1]
492
+ assert_equal_event_time time, d.events[1][1]
284
493
  end
285
494
 
286
495
  def test_with_regexp
@@ -289,20 +498,27 @@ class HttpInputTest < Test::Unit::TestCase
289
498
  types field_1:integer
290
499
  ])
291
500
 
292
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
293
-
294
- d.expect_emit "tag1", time, {"field_1" => 1, "field_2" => 'str'}
295
- d.expect_emit "tag2", time, {"field_1" => 2, "field_2" => 'str'}
501
+ time = event_time("2011-01-02 13:14:15 UTC")
502
+ time_i = time.to_i
503
+ events = [
504
+ ["tag1", time, {"field_1" => 1, "field_2" => 'str'}],
505
+ ["tag2", time, {"field_1" => 2, "field_2" => 'str'}],
506
+ ]
507
+ res_codes = []
296
508
 
297
- d.run do
298
- d.expected_emits.each { |tag, time, record|
509
+ d.run(expect_records: 2) do
510
+ events.each do |tag, t, record|
299
511
  body = record.map { |k, v|
300
512
  v.to_s
301
513
  }.join(':')
302
- res = post("/#{tag}?time=#{time.to_s}", body)
303
- assert_equal "200", res.code
304
- }
514
+ res = post("/#{tag}?time=#{time_i.to_s}", body, {'Content-Type' => 'application/octet-stream'})
515
+ res_codes << res.code
516
+ end
305
517
  end
518
+ assert_equal ["200", "200"], res_codes
519
+ assert_equal events, d.events
520
+ assert_equal_event_time time, d.events[0][1]
521
+ assert_equal_event_time time, d.events[1][1]
306
522
  end
307
523
 
308
524
  def test_with_csv
@@ -312,77 +528,248 @@ class HttpInputTest < Test::Unit::TestCase
312
528
  format csv
313
529
  keys foo,bar
314
530
  ])
315
-
316
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
317
-
318
- d.expect_emit "tag1", time, {"foo" => "1", "bar" => 'st"r'}
319
- d.expect_emit "tag2", time, {"foo" => "2", "bar" => 'str'}
320
-
321
- d.run do
322
- d.expected_emits.each { |tag, time, record|
531
+ time = event_time("2011-01-02 13:14:15 UTC")
532
+ time_i = time.to_i
533
+ events = [
534
+ ["tag1", time, {"foo" => "1", "bar" => 'st"r'}],
535
+ ["tag2", time, {"foo" => "2", "bar" => 'str'}],
536
+ ]
537
+ res_codes = []
538
+
539
+ d.run(expect_records: 2) do
540
+ events.each do |tag, t, record|
323
541
  body = record.map { |k, v| v }.to_csv
324
- res = post("/#{tag}?time=#{time.to_s}", body)
325
- assert_equal "200", res.code
326
- }
542
+ res = post("/#{tag}?time=#{time_i.to_s}", body, {'Content-Type' => 'text/comma-separated-values'})
543
+ res_codes << res.code
544
+ end
327
545
  end
546
+ assert_equal ["200", "200"], res_codes
547
+ assert_equal events, d.events
548
+ assert_equal_event_time time, d.events[0][1]
549
+ assert_equal_event_time time, d.events[1][1]
328
550
  end
329
551
 
330
552
  def test_resonse_with_empty_img
331
553
  d = create_driver(CONFIG + "respond_with_empty_img true")
332
554
  assert_equal true, d.instance.respond_with_empty_img
333
555
 
334
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
335
-
336
- d.expect_emit "tag1", time, {"a"=>1}
337
- d.expect_emit "tag2", time, {"a"=>2}
556
+ time = event_time("2011-01-02 13:14:15 UTC")
557
+ time_i = time.to_i
558
+ events = [
559
+ ["tag1", time, {"a"=>1}],
560
+ ["tag2", time, {"a"=>2}],
561
+ ]
562
+ res_codes = []
563
+ res_bodies = []
338
564
 
339
565
  d.run do
340
- d.expected_emits.each {|tag,time,record|
341
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>time.to_s})
342
- assert_equal "200", res.code
566
+ events.each do |tag, _t, record|
567
+ res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s})
568
+ res_codes << res.code
343
569
  # Ruby returns ASCII-8 encoded string for GIF.
344
- assert_equal Fluent::HttpInput::EMPTY_GIF_IMAGE, res.body.force_encoding("UTF-8")
345
- }
570
+ res_bodies << res.body.force_encoding("UTF-8")
571
+ end
346
572
  end
573
+ assert_equal ["200", "200"], res_codes
574
+ assert_equal [Fluent::Plugin::HttpInput::EMPTY_GIF_IMAGE, Fluent::Plugin::HttpInput::EMPTY_GIF_IMAGE], res_bodies
575
+ assert_equal events, d.events
576
+ assert_equal_event_time time, d.events[0][1]
577
+ assert_equal_event_time time, d.events[1][1]
347
578
  end
348
579
 
349
580
  def test_cors_allowed
350
581
  d = create_driver(CONFIG + "cors_allow_origins [\"http://foo.com\"]")
351
582
  assert_equal ["http://foo.com"], d.instance.cors_allow_origins
352
583
 
353
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
584
+ time = event_time("2011-01-02 13:14:15 UTC")
585
+ time_i = time.to_i
586
+ events = [
587
+ ["tag1", time, {"a"=>1}],
588
+ ["tag2", time, {"a"=>2}],
589
+ ]
590
+ res_codes = []
591
+ res_headers = []
592
+
593
+ d.run do
594
+ events.each do |tag, _t, record|
595
+ res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s}, {"Origin"=>"http://foo.com"})
596
+ res_codes << res.code
597
+ res_headers << res["Access-Control-Allow-Origin"]
598
+ end
599
+ end
600
+ assert_equal ["200", "200"], res_codes
601
+ assert_equal ["http://foo.com", "http://foo.com"], res_headers
602
+ assert_equal events, d.events
603
+ assert_equal_event_time time, d.events[0][1]
604
+ assert_equal_event_time time, d.events[1][1]
605
+ end
606
+
607
+ def test_cors_allowed_wildcard
608
+ d = create_driver(CONFIG + 'cors_allow_origins ["*"]')
354
609
 
355
- d.expect_emit "tag1", time, {"a"=>1}
356
- d.expect_emit "tag2", time, {"a"=>1}
610
+ time = event_time("2011-01-02 13:14:15 UTC")
611
+ events = [
612
+ ["tag1", time, {"a"=>1}],
613
+ ]
357
614
 
358
615
  d.run do
359
- d.expected_emits.each {|tag,_time,record|
360
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s}, {"Origin"=>"http://foo.com"})
616
+ events.each do |tag, time, record|
617
+ headers = {"Origin" => "http://foo.com"}
618
+
619
+ res = post("/#{tag}", {"json" => record.to_json, "time" => time.to_i}, headers)
620
+
361
621
  assert_equal "200", res.code
362
- assert_equal "http://foo.com", res["Access-Control-Allow-Origin"]
622
+ assert_equal "*", res["Access-Control-Allow-Origin"]
623
+ end
624
+ end
625
+ end
626
+
627
+ def test_cors_preflight
628
+ d = create_driver(CONFIG + 'cors_allow_origins ["*"]')
629
+
630
+ d.run do
631
+ header = {
632
+ "Origin" => "http://foo.com",
633
+ "Access-Control-Request-Method" => "POST",
634
+ "Access-Control-Request-Headers" => "Content-Type",
363
635
  }
636
+ res = options("/cors.test", {}, header)
637
+
638
+ assert_equal "200", res.code
639
+ assert_equal "*", res["Access-Control-Allow-Origin"]
640
+ assert_equal "POST", res["Access-Control-Allow-Methods"]
641
+ end
642
+ end
643
+
644
+ def test_cors_allowed_wildcard_for_subdomain
645
+ d = create_driver(CONFIG + 'cors_allow_origins ["http://*.foo.com"]')
646
+
647
+ time = event_time("2011-01-02 13:14:15 UTC")
648
+ events = [
649
+ ["tag1", time, {"a"=>1}],
650
+ ]
651
+
652
+ d.run do
653
+ events.each do |tag, time, record|
654
+ headers = {"Origin" => "http://subdomain.foo.com"}
655
+
656
+ res = post("/#{tag}", {"json" => record.to_json, "time" => time.to_i}, headers)
657
+
658
+ assert_equal "200", res.code
659
+ assert_equal "http://subdomain.foo.com", res["Access-Control-Allow-Origin"]
660
+ end
364
661
  end
365
662
  end
663
+
664
+ def test_cors_allowed_exclude_empty_string
665
+ d = create_driver(CONFIG + 'cors_allow_origins ["", "http://*.foo.com"]')
666
+
667
+ time = event_time("2011-01-02 13:14:15 UTC")
668
+ events = [
669
+ ["tag1", time, {"a"=>1}],
670
+ ]
671
+
672
+ d.run do
673
+ events.each do |tag, time, record|
674
+ headers = {"Origin" => "http://subdomain.foo.com"}
675
+
676
+ res = post("/#{tag}", {"json" => record.to_json, "time" => time.to_i}, headers)
677
+
678
+ assert_equal "200", res.code
679
+ assert_equal "http://subdomain.foo.com", res["Access-Control-Allow-Origin"]
680
+ end
681
+ end
682
+ end
683
+
684
+ def test_cors_allowed_wildcard_preflight_for_subdomain
685
+ d = create_driver(CONFIG + 'cors_allow_origins ["http://*.foo.com"]')
686
+
687
+ d.run do
688
+ header = {
689
+ "Origin" => "http://subdomain.foo.com",
690
+ "Access-Control-Request-Method" => "POST",
691
+ "Access-Control-Request-Headers" => "Content-Type",
692
+ }
693
+ res = options("/cors.test", {}, header)
694
+
695
+ assert_equal "200", res.code
696
+ assert_equal "http://subdomain.foo.com", res["Access-Control-Allow-Origin"]
697
+ assert_equal "POST", res["Access-Control-Allow-Methods"]
698
+ end
699
+ end
700
+
701
+ def test_content_encoding_gzip
702
+ d = create_driver
703
+
704
+ time = event_time("2011-01-02 13:14:15 UTC")
705
+ events = [
706
+ ["tag1", time, {"a"=>1}],
707
+ ["tag2", time, {"a"=>2}],
708
+ ]
709
+ res_codes = []
710
+
711
+ d.run do
712
+ events.each do |tag, time, record|
713
+ header = {'Content-Type'=>'application/json', 'Content-Encoding'=>'gzip'}
714
+ res = post("/#{tag}?time=#{time}", compress_gzip(record.to_json), header)
715
+ res_codes << res.code
716
+ end
717
+ end
718
+ assert_equal ["200", "200"], res_codes
719
+ assert_equal events, d.events
720
+ assert_equal_event_time time, d.events[0][1]
721
+ assert_equal_event_time time, d.events[1][1]
722
+ end
723
+
724
+ def test_content_encoding_deflate
725
+ d = create_driver
726
+
727
+ time = event_time("2011-01-02 13:14:15 UTC")
728
+ events = [
729
+ ["tag1", time, {"a"=>1}],
730
+ ["tag2", time, {"a"=>2}],
731
+ ]
732
+ res_codes = []
733
+
734
+ d.run do
735
+ events.each do |tag, time, record|
736
+ header = {'Content-Type'=>'application/msgpack', 'Content-Encoding'=>'deflate'}
737
+ res = post("/#{tag}?time=#{time}", Zlib.deflate(record.to_msgpack), header)
738
+ res_codes << res.code
739
+ end
740
+ end
741
+ assert_equal ["200", "200"], res_codes
742
+ assert_equal events, d.events
743
+ assert_equal_event_time time, d.events[0][1]
744
+ assert_equal_event_time time, d.events[1][1]
745
+ end
366
746
 
367
747
  def test_cors_disallowed
368
748
  d = create_driver(CONFIG + "cors_allow_origins [\"http://foo.com\"]")
369
749
  assert_equal ["http://foo.com"], d.instance.cors_allow_origins
370
750
 
371
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
751
+ time = event_time("2011-01-02 13:14:15 UTC")
752
+ time_i = time.to_i
753
+ res_codes = []
372
754
 
373
- d.expected_emits_length = 0
755
+ d.end_if{ res_codes.size == 2 }
374
756
  d.run do
375
- res = post("/tag1", {"json"=>{"a"=>1}.to_json, "time"=>time.to_s}, {"Origin"=>"http://bar.com"})
376
- assert_equal "403", res.code
377
- res = post("/tag2", {"json"=>{"a"=>1}.to_json, "time"=>time.to_s}, {"Origin"=>"http://bar.com"})
378
- assert_equal "403", res.code
757
+ res = post("/tag1", {"json"=>{"a"=>1}.to_json, "time"=>time_i.to_s}, {"Origin"=>"http://bar.com"})
758
+ res_codes << res.code
759
+ res = post("/tag2", {"json"=>{"a"=>1}.to_json, "time"=>time_i.to_s}, {"Origin"=>"http://bar.com"})
760
+ res_codes << res.code
379
761
  end
762
+ assert_equal ["403", "403"], res_codes
380
763
  end
381
764
 
382
765
  $test_in_http_connection_object_ids = []
383
766
  $test_in_http_content_types = []
384
767
  $test_in_http_content_types_flag = false
385
768
  module ContentTypeHook
769
+ def initialize(*args)
770
+ @io_handler = nil
771
+ super
772
+ end
386
773
  def on_headers_complete(headers)
387
774
  super
388
775
  if $test_in_http_content_types_flag
@@ -398,64 +785,40 @@ class HttpInputTest < Test::Unit::TestCase
398
785
  end
399
786
  end
400
787
 
401
- class Fluent::HttpInput::Handler
788
+ class Fluent::Plugin::HttpInput::Handler
402
789
  prepend ContentTypeHook
403
790
  end
404
791
 
405
792
  def test_if_content_type_is_initialized_properly
406
793
  # This test is to check if Fluent::HttpInput::Handler's @content_type is initialized properly.
407
794
  # Especially when in Keep-Alive and the second request has no 'Content-Type'.
408
- #
409
- # Actually, in the current implementation of in_http, we can't test it directly.
410
- # So we replace Fluent::HttpInput::Handler temporally with the extended Handler
411
- # in order to collect @content_type(s) per request.
412
- # Finally, we check those collected @content_type(s).
413
-
414
- # Save the original Handler
415
- orig_handler = Fluent::HttpInput::Handler
416
795
 
417
796
  begin
418
- # Create the extended Handler which can store @content_type per request
419
- ext_handler = Class.new(Fluent::HttpInput::Handler) do
420
- @@content_types = []
421
-
422
- def self.content_types
423
- @@content_types
424
- end
425
-
426
- def on_message_complete
427
- @@content_types << @content_type
428
- super
429
- end
430
- end
431
-
432
- # Replace the original Handler temporally with the extended one
433
- Fluent::HttpInput.module_eval do
434
- remove_const(:Handler) if const_defined?(:Handler)
435
- const_set(:Handler, ext_handler)
436
- end
437
-
438
797
  d = create_driver
439
798
 
799
+ $test_in_http_content_types_flag = true
440
800
  d.run do
441
801
  # Send two requests the second one has no Content-Type in Keep-Alive
442
802
  Net::HTTP.start("127.0.0.1", PORT) do |http|
443
- req = Net::HTTP::Post.new("/foodb/bartbl", {"connection" => "keepalive", "content-type" => "application/json"})
444
- res = http.request(req)
445
-
803
+ req = Net::HTTP::Post.new("/foodb/bartbl", {"connection" => "keepalive", "Content-Type" => "application/json"})
804
+ http.request(req)
446
805
  req = Net::HTTP::Get.new("/foodb/bartbl", {"connection" => "keepalive"})
447
- res = http.request(req)
806
+ http.request(req)
448
807
  end
449
808
 
450
- assert_equal(['application/json', ''], ext_handler.content_types)
451
809
  end
452
810
  ensure
453
- # Revert the original Handler
454
- Fluent::HttpInput.module_eval do
455
- remove_const(:Handler) if const_defined?(:Handler)
456
- const_set(:Handler, orig_handler)
457
- end
811
+ $test_in_http_content_types_flag = false
458
812
  end
813
+ assert_equal(['application/json', ''], $test_in_http_content_types)
814
+ # Asserting keepalive
815
+ assert_equal $test_in_http_connection_object_ids[0], $test_in_http_connection_object_ids[1]
816
+ end
817
+
818
+ def options(path, params, header = {})
819
+ http = Net::HTTP.new("127.0.0.1", PORT)
820
+ req = Net::HTTP::Options.new(path, header)
821
+ http.request(req)
459
822
  end
460
823
 
461
824
  def post(path, params, header = {}, &block)
@@ -463,13 +826,26 @@ class HttpInputTest < Test::Unit::TestCase
463
826
  req = Net::HTTP::Post.new(path, header)
464
827
  block.call(http, req) if block
465
828
  if params.is_a?(String)
829
+ unless header.has_key?('Content-Type')
830
+ header['Content-Type'] = 'application/octet-stream'
831
+ end
466
832
  req.body = params
467
833
  else
834
+ unless header.has_key?('Content-Type')
835
+ header['Content-Type'] = 'application/x-www-form-urlencoded'
836
+ end
468
837
  req.set_form_data(params)
469
838
  end
470
839
  http.request(req)
471
840
  end
472
841
 
842
+ def compress_gzip(data)
843
+ io = StringIO.new
844
+ io.binmode
845
+ Zlib::GzipWriter.wrap(io) { |gz| gz.write data }
846
+ return io.string
847
+ end
848
+
473
849
  def include_http_header?(record)
474
850
  record.keys.find { |header| header.start_with?('HTTP_') }
475
851
  end