fluentd-hubspot 0.14.14.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (396) hide show
  1. data/.github/ISSUE_TEMPLATE.md +6 -0
  2. data/.gitignore +28 -0
  3. data/.travis.yml +51 -0
  4. data/AUTHORS +2 -0
  5. data/CONTRIBUTING.md +42 -0
  6. data/COPYING +14 -0
  7. data/ChangeLog +593 -0
  8. data/Gemfile +9 -0
  9. data/README.md +76 -0
  10. data/Rakefile +74 -0
  11. data/Vagrantfile +17 -0
  12. data/appveyor.yml +43 -0
  13. data/bin/fluent-binlog-reader +7 -0
  14. data/bin/fluent-debug +5 -0
  15. data/bin/fluent-plugin-config-format +5 -0
  16. data/bin/fluent-plugin-generate +5 -0
  17. data/code-of-conduct.md +3 -0
  18. data/example/copy_roundrobin.conf +39 -0
  19. data/example/filter_stdout.conf +22 -0
  20. data/example/in_dummy_blocks.conf +17 -0
  21. data/example/in_dummy_with_compression.conf +23 -0
  22. data/example/in_forward.conf +14 -0
  23. data/example/in_forward_client.conf +37 -0
  24. data/example/in_forward_shared_key.conf +15 -0
  25. data/example/in_forward_tls.conf +14 -0
  26. data/example/in_forward_users.conf +24 -0
  27. data/example/in_forward_workers.conf +21 -0
  28. data/example/in_http.conf +14 -0
  29. data/example/in_out_forward.conf +17 -0
  30. data/example/in_syslog.conf +15 -0
  31. data/example/in_tail.conf +14 -0
  32. data/example/in_tcp.conf +13 -0
  33. data/example/in_udp.conf +13 -0
  34. data/example/logevents.conf +25 -0
  35. data/example/multi_filters.conf +61 -0
  36. data/example/out_copy.conf +20 -0
  37. data/example/out_exec_filter.conf +42 -0
  38. data/example/out_file.conf +13 -0
  39. data/example/out_forward.conf +35 -0
  40. data/example/out_forward_buf_file.conf +23 -0
  41. data/example/out_forward_client.conf +109 -0
  42. data/example/out_forward_heartbeat_none.conf +16 -0
  43. data/example/out_forward_shared_key.conf +36 -0
  44. data/example/out_forward_tls.conf +18 -0
  45. data/example/out_forward_users.conf +65 -0
  46. data/example/out_null.conf +36 -0
  47. data/example/secondary_file.conf +41 -0
  48. data/example/suppress_config_dump.conf +7 -0
  49. data/example/v0_12_filter.conf +78 -0
  50. data/example/v1_literal_example.conf +36 -0
  51. data/fluent.conf +139 -0
  52. data/fluentd.gemspec +51 -0
  53. data/lib/fluent/agent.rb +163 -0
  54. data/lib/fluent/clock.rb +62 -0
  55. data/lib/fluent/command/binlog_reader.rb +234 -0
  56. data/lib/fluent/command/bundler_injection.rb +45 -0
  57. data/lib/fluent/command/cat.rb +330 -0
  58. data/lib/fluent/command/debug.rb +102 -0
  59. data/lib/fluent/command/fluentd.rb +301 -0
  60. data/lib/fluent/command/plugin_config_formatter.rb +258 -0
  61. data/lib/fluent/command/plugin_generator.rb +301 -0
  62. data/lib/fluent/compat/call_super_mixin.rb +67 -0
  63. data/lib/fluent/compat/detach_process_mixin.rb +25 -0
  64. data/lib/fluent/compat/exec_util.rb +129 -0
  65. data/lib/fluent/compat/file_util.rb +54 -0
  66. data/lib/fluent/compat/filter.rb +68 -0
  67. data/lib/fluent/compat/formatter.rb +111 -0
  68. data/lib/fluent/compat/formatter_utils.rb +85 -0
  69. data/lib/fluent/compat/handle_tag_and_time_mixin.rb +62 -0
  70. data/lib/fluent/compat/handle_tag_name_mixin.rb +53 -0
  71. data/lib/fluent/compat/input.rb +59 -0
  72. data/lib/fluent/compat/output.rb +728 -0
  73. data/lib/fluent/compat/output_chain.rb +60 -0
  74. data/lib/fluent/compat/parser.rb +310 -0
  75. data/lib/fluent/compat/parser_utils.rb +40 -0
  76. data/lib/fluent/compat/propagate_default.rb +62 -0
  77. data/lib/fluent/compat/record_filter_mixin.rb +34 -0
  78. data/lib/fluent/compat/set_tag_key_mixin.rb +50 -0
  79. data/lib/fluent/compat/set_time_key_mixin.rb +69 -0
  80. data/lib/fluent/compat/socket_util.rb +165 -0
  81. data/lib/fluent/compat/string_util.rb +34 -0
  82. data/lib/fluent/compat/structured_format_mixin.rb +26 -0
  83. data/lib/fluent/compat/type_converter.rb +90 -0
  84. data/lib/fluent/config.rb +56 -0
  85. data/lib/fluent/config/basic_parser.rb +123 -0
  86. data/lib/fluent/config/configure_proxy.rb +418 -0
  87. data/lib/fluent/config/dsl.rb +149 -0
  88. data/lib/fluent/config/element.rb +218 -0
  89. data/lib/fluent/config/error.rb +26 -0
  90. data/lib/fluent/config/literal_parser.rb +251 -0
  91. data/lib/fluent/config/parser.rb +107 -0
  92. data/lib/fluent/config/section.rb +223 -0
  93. data/lib/fluent/config/types.rb +136 -0
  94. data/lib/fluent/config/v1_parser.rb +190 -0
  95. data/lib/fluent/configurable.rb +200 -0
  96. data/lib/fluent/daemon.rb +15 -0
  97. data/lib/fluent/engine.rb +266 -0
  98. data/lib/fluent/env.rb +28 -0
  99. data/lib/fluent/error.rb +30 -0
  100. data/lib/fluent/event.rb +334 -0
  101. data/lib/fluent/event_router.rb +269 -0
  102. data/lib/fluent/filter.rb +21 -0
  103. data/lib/fluent/formatter.rb +23 -0
  104. data/lib/fluent/input.rb +21 -0
  105. data/lib/fluent/label.rb +46 -0
  106. data/lib/fluent/load.rb +35 -0
  107. data/lib/fluent/log.rb +546 -0
  108. data/lib/fluent/match.rb +178 -0
  109. data/lib/fluent/mixin.rb +31 -0
  110. data/lib/fluent/msgpack_factory.rb +62 -0
  111. data/lib/fluent/output.rb +29 -0
  112. data/lib/fluent/output_chain.rb +23 -0
  113. data/lib/fluent/parser.rb +23 -0
  114. data/lib/fluent/plugin.rb +183 -0
  115. data/lib/fluent/plugin/bare_output.rb +63 -0
  116. data/lib/fluent/plugin/base.rb +165 -0
  117. data/lib/fluent/plugin/buf_file.rb +184 -0
  118. data/lib/fluent/plugin/buf_memory.rb +34 -0
  119. data/lib/fluent/plugin/buffer.rb +617 -0
  120. data/lib/fluent/plugin/buffer/chunk.rb +221 -0
  121. data/lib/fluent/plugin/buffer/file_chunk.rb +364 -0
  122. data/lib/fluent/plugin/buffer/memory_chunk.rb +90 -0
  123. data/lib/fluent/plugin/compressable.rb +92 -0
  124. data/lib/fluent/plugin/exec_util.rb +22 -0
  125. data/lib/fluent/plugin/file_util.rb +22 -0
  126. data/lib/fluent/plugin/file_wrapper.rb +120 -0
  127. data/lib/fluent/plugin/filter.rb +93 -0
  128. data/lib/fluent/plugin/filter_grep.rb +75 -0
  129. data/lib/fluent/plugin/filter_parser.rb +119 -0
  130. data/lib/fluent/plugin/filter_record_transformer.rb +322 -0
  131. data/lib/fluent/plugin/filter_stdout.rb +53 -0
  132. data/lib/fluent/plugin/formatter.rb +50 -0
  133. data/lib/fluent/plugin/formatter_csv.rb +52 -0
  134. data/lib/fluent/plugin/formatter_hash.rb +33 -0
  135. data/lib/fluent/plugin/formatter_json.rb +55 -0
  136. data/lib/fluent/plugin/formatter_ltsv.rb +42 -0
  137. data/lib/fluent/plugin/formatter_msgpack.rb +33 -0
  138. data/lib/fluent/plugin/formatter_out_file.rb +51 -0
  139. data/lib/fluent/plugin/formatter_single_value.rb +34 -0
  140. data/lib/fluent/plugin/formatter_stdout.rb +75 -0
  141. data/lib/fluent/plugin/formatter_tsv.rb +34 -0
  142. data/lib/fluent/plugin/in_debug_agent.rb +64 -0
  143. data/lib/fluent/plugin/in_dummy.rb +139 -0
  144. data/lib/fluent/plugin/in_exec.rb +108 -0
  145. data/lib/fluent/plugin/in_forward.rb +455 -0
  146. data/lib/fluent/plugin/in_gc_stat.rb +56 -0
  147. data/lib/fluent/plugin/in_http.rb +433 -0
  148. data/lib/fluent/plugin/in_monitor_agent.rb +448 -0
  149. data/lib/fluent/plugin/in_object_space.rb +93 -0
  150. data/lib/fluent/plugin/in_syslog.rb +209 -0
  151. data/lib/fluent/plugin/in_tail.rb +905 -0
  152. data/lib/fluent/plugin/in_tcp.rb +85 -0
  153. data/lib/fluent/plugin/in_udp.rb +81 -0
  154. data/lib/fluent/plugin/in_unix.rb +201 -0
  155. data/lib/fluent/plugin/input.rb +37 -0
  156. data/lib/fluent/plugin/multi_output.rb +157 -0
  157. data/lib/fluent/plugin/out_copy.rb +46 -0
  158. data/lib/fluent/plugin/out_exec.rb +105 -0
  159. data/lib/fluent/plugin/out_exec_filter.rb +317 -0
  160. data/lib/fluent/plugin/out_file.rb +302 -0
  161. data/lib/fluent/plugin/out_forward.rb +912 -0
  162. data/lib/fluent/plugin/out_null.rb +74 -0
  163. data/lib/fluent/plugin/out_relabel.rb +32 -0
  164. data/lib/fluent/plugin/out_roundrobin.rb +84 -0
  165. data/lib/fluent/plugin/out_secondary_file.rb +133 -0
  166. data/lib/fluent/plugin/out_stdout.rb +75 -0
  167. data/lib/fluent/plugin/out_stream.rb +130 -0
  168. data/lib/fluent/plugin/output.rb +1291 -0
  169. data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
  170. data/lib/fluent/plugin/parser.rb +191 -0
  171. data/lib/fluent/plugin/parser_apache.rb +28 -0
  172. data/lib/fluent/plugin/parser_apache2.rb +84 -0
  173. data/lib/fluent/plugin/parser_apache_error.rb +26 -0
  174. data/lib/fluent/plugin/parser_csv.rb +39 -0
  175. data/lib/fluent/plugin/parser_json.rb +81 -0
  176. data/lib/fluent/plugin/parser_ltsv.rb +42 -0
  177. data/lib/fluent/plugin/parser_msgpack.rb +50 -0
  178. data/lib/fluent/plugin/parser_multiline.rb +105 -0
  179. data/lib/fluent/plugin/parser_nginx.rb +28 -0
  180. data/lib/fluent/plugin/parser_none.rb +36 -0
  181. data/lib/fluent/plugin/parser_regexp.rb +63 -0
  182. data/lib/fluent/plugin/parser_syslog.rb +121 -0
  183. data/lib/fluent/plugin/parser_tsv.rb +42 -0
  184. data/lib/fluent/plugin/socket_util.rb +22 -0
  185. data/lib/fluent/plugin/storage.rb +84 -0
  186. data/lib/fluent/plugin/storage_local.rb +159 -0
  187. data/lib/fluent/plugin/string_util.rb +22 -0
  188. data/lib/fluent/plugin_helper.rb +70 -0
  189. data/lib/fluent/plugin_helper/cert_option.rb +159 -0
  190. data/lib/fluent/plugin_helper/child_process.rb +364 -0
  191. data/lib/fluent/plugin_helper/compat_parameters.rb +331 -0
  192. data/lib/fluent/plugin_helper/event_emitter.rb +93 -0
  193. data/lib/fluent/plugin_helper/event_loop.rb +161 -0
  194. data/lib/fluent/plugin_helper/extract.rb +104 -0
  195. data/lib/fluent/plugin_helper/formatter.rb +147 -0
  196. data/lib/fluent/plugin_helper/inject.rb +151 -0
  197. data/lib/fluent/plugin_helper/parser.rb +147 -0
  198. data/lib/fluent/plugin_helper/retry_state.rb +201 -0
  199. data/lib/fluent/plugin_helper/server.rb +738 -0
  200. data/lib/fluent/plugin_helper/socket.rb +241 -0
  201. data/lib/fluent/plugin_helper/socket_option.rb +69 -0
  202. data/lib/fluent/plugin_helper/storage.rb +349 -0
  203. data/lib/fluent/plugin_helper/thread.rb +179 -0
  204. data/lib/fluent/plugin_helper/timer.rb +91 -0
  205. data/lib/fluent/plugin_id.rb +80 -0
  206. data/lib/fluent/process.rb +22 -0
  207. data/lib/fluent/registry.rb +116 -0
  208. data/lib/fluent/root_agent.rb +323 -0
  209. data/lib/fluent/rpc.rb +94 -0
  210. data/lib/fluent/supervisor.rb +741 -0
  211. data/lib/fluent/system_config.rb +159 -0
  212. data/lib/fluent/test.rb +58 -0
  213. data/lib/fluent/test/base.rb +78 -0
  214. data/lib/fluent/test/driver/base.rb +224 -0
  215. data/lib/fluent/test/driver/base_owned.rb +70 -0
  216. data/lib/fluent/test/driver/base_owner.rb +135 -0
  217. data/lib/fluent/test/driver/event_feeder.rb +98 -0
  218. data/lib/fluent/test/driver/filter.rb +57 -0
  219. data/lib/fluent/test/driver/formatter.rb +30 -0
  220. data/lib/fluent/test/driver/input.rb +31 -0
  221. data/lib/fluent/test/driver/multi_output.rb +53 -0
  222. data/lib/fluent/test/driver/output.rb +102 -0
  223. data/lib/fluent/test/driver/parser.rb +30 -0
  224. data/lib/fluent/test/driver/test_event_router.rb +45 -0
  225. data/lib/fluent/test/filter_test.rb +77 -0
  226. data/lib/fluent/test/formatter_test.rb +65 -0
  227. data/lib/fluent/test/helpers.rb +134 -0
  228. data/lib/fluent/test/input_test.rb +174 -0
  229. data/lib/fluent/test/log.rb +79 -0
  230. data/lib/fluent/test/output_test.rb +156 -0
  231. data/lib/fluent/test/parser_test.rb +70 -0
  232. data/lib/fluent/test/startup_shutdown.rb +46 -0
  233. data/lib/fluent/time.rb +412 -0
  234. data/lib/fluent/timezone.rb +133 -0
  235. data/lib/fluent/unique_id.rb +39 -0
  236. data/lib/fluent/version.rb +21 -0
  237. data/lib/fluent/winsvc.rb +71 -0
  238. data/templates/new_gem/Gemfile +3 -0
  239. data/templates/new_gem/README.md.erb +43 -0
  240. data/templates/new_gem/Rakefile +13 -0
  241. data/templates/new_gem/fluent-plugin.gemspec.erb +27 -0
  242. data/templates/new_gem/lib/fluent/plugin/filter.rb.erb +14 -0
  243. data/templates/new_gem/lib/fluent/plugin/formatter.rb.erb +14 -0
  244. data/templates/new_gem/lib/fluent/plugin/input.rb.erb +11 -0
  245. data/templates/new_gem/lib/fluent/plugin/output.rb.erb +11 -0
  246. data/templates/new_gem/lib/fluent/plugin/parser.rb.erb +15 -0
  247. data/templates/new_gem/test/helper.rb.erb +8 -0
  248. data/templates/new_gem/test/plugin/test_filter.rb.erb +18 -0
  249. data/templates/new_gem/test/plugin/test_formatter.rb.erb +18 -0
  250. data/templates/new_gem/test/plugin/test_input.rb.erb +18 -0
  251. data/templates/new_gem/test/plugin/test_output.rb.erb +18 -0
  252. data/templates/new_gem/test/plugin/test_parser.rb.erb +18 -0
  253. data/templates/plugin_config_formatter/param.md-compact.erb +25 -0
  254. data/templates/plugin_config_formatter/param.md.erb +34 -0
  255. data/templates/plugin_config_formatter/section.md.erb +12 -0
  256. data/test/command/test_binlog_reader.rb +346 -0
  257. data/test/command/test_fluentd.rb +618 -0
  258. data/test/command/test_plugin_config_formatter.rb +275 -0
  259. data/test/command/test_plugin_generator.rb +66 -0
  260. data/test/compat/test_calls_super.rb +166 -0
  261. data/test/compat/test_parser.rb +92 -0
  262. data/test/config/assertions.rb +42 -0
  263. data/test/config/test_config_parser.rb +513 -0
  264. data/test/config/test_configurable.rb +1587 -0
  265. data/test/config/test_configure_proxy.rb +566 -0
  266. data/test/config/test_dsl.rb +415 -0
  267. data/test/config/test_element.rb +403 -0
  268. data/test/config/test_literal_parser.rb +297 -0
  269. data/test/config/test_section.rb +184 -0
  270. data/test/config/test_system_config.rb +168 -0
  271. data/test/config/test_types.rb +191 -0
  272. data/test/helper.rb +153 -0
  273. data/test/plugin/data/2010/01/20100102-030405.log +0 -0
  274. data/test/plugin/data/2010/01/20100102-030406.log +0 -0
  275. data/test/plugin/data/2010/01/20100102.log +0 -0
  276. data/test/plugin/data/log/bar +0 -0
  277. data/test/plugin/data/log/foo/bar.log +0 -0
  278. data/test/plugin/data/log/foo/bar2 +0 -0
  279. data/test/plugin/data/log/test.log +0 -0
  280. data/test/plugin/test_bare_output.rb +118 -0
  281. data/test/plugin/test_base.rb +115 -0
  282. data/test/plugin/test_buf_file.rb +843 -0
  283. data/test/plugin/test_buf_memory.rb +42 -0
  284. data/test/plugin/test_buffer.rb +1220 -0
  285. data/test/plugin/test_buffer_chunk.rb +198 -0
  286. data/test/plugin/test_buffer_file_chunk.rb +844 -0
  287. data/test/plugin/test_buffer_memory_chunk.rb +338 -0
  288. data/test/plugin/test_compressable.rb +84 -0
  289. data/test/plugin/test_file_util.rb +96 -0
  290. data/test/plugin/test_filter.rb +357 -0
  291. data/test/plugin/test_filter_grep.rb +119 -0
  292. data/test/plugin/test_filter_parser.rb +700 -0
  293. data/test/plugin/test_filter_record_transformer.rb +556 -0
  294. data/test/plugin/test_filter_stdout.rb +202 -0
  295. data/test/plugin/test_formatter_csv.rb +111 -0
  296. data/test/plugin/test_formatter_hash.rb +35 -0
  297. data/test/plugin/test_formatter_json.rb +51 -0
  298. data/test/plugin/test_formatter_ltsv.rb +59 -0
  299. data/test/plugin/test_formatter_msgpack.rb +28 -0
  300. data/test/plugin/test_formatter_out_file.rb +95 -0
  301. data/test/plugin/test_formatter_single_value.rb +38 -0
  302. data/test/plugin/test_in_debug_agent.rb +28 -0
  303. data/test/plugin/test_in_dummy.rb +192 -0
  304. data/test/plugin/test_in_exec.rb +245 -0
  305. data/test/plugin/test_in_forward.rb +1120 -0
  306. data/test/plugin/test_in_gc_stat.rb +39 -0
  307. data/test/plugin/test_in_http.rb +588 -0
  308. data/test/plugin/test_in_monitor_agent.rb +516 -0
  309. data/test/plugin/test_in_object_space.rb +64 -0
  310. data/test/plugin/test_in_syslog.rb +271 -0
  311. data/test/plugin/test_in_tail.rb +1216 -0
  312. data/test/plugin/test_in_tcp.rb +118 -0
  313. data/test/plugin/test_in_udp.rb +152 -0
  314. data/test/plugin/test_in_unix.rb +126 -0
  315. data/test/plugin/test_input.rb +126 -0
  316. data/test/plugin/test_multi_output.rb +180 -0
  317. data/test/plugin/test_out_copy.rb +160 -0
  318. data/test/plugin/test_out_exec.rb +310 -0
  319. data/test/plugin/test_out_exec_filter.rb +613 -0
  320. data/test/plugin/test_out_file.rb +873 -0
  321. data/test/plugin/test_out_forward.rb +685 -0
  322. data/test/plugin/test_out_null.rb +105 -0
  323. data/test/plugin/test_out_relabel.rb +28 -0
  324. data/test/plugin/test_out_roundrobin.rb +146 -0
  325. data/test/plugin/test_out_secondary_file.rb +442 -0
  326. data/test/plugin/test_out_stdout.rb +170 -0
  327. data/test/plugin/test_out_stream.rb +93 -0
  328. data/test/plugin/test_output.rb +870 -0
  329. data/test/plugin/test_output_as_buffered.rb +1932 -0
  330. data/test/plugin/test_output_as_buffered_compress.rb +165 -0
  331. data/test/plugin/test_output_as_buffered_overflow.rb +250 -0
  332. data/test/plugin/test_output_as_buffered_retries.rb +839 -0
  333. data/test/plugin/test_output_as_buffered_secondary.rb +877 -0
  334. data/test/plugin/test_output_as_standard.rb +374 -0
  335. data/test/plugin/test_owned_by.rb +35 -0
  336. data/test/plugin/test_parser.rb +359 -0
  337. data/test/plugin/test_parser_apache.rb +42 -0
  338. data/test/plugin/test_parser_apache2.rb +46 -0
  339. data/test/plugin/test_parser_apache_error.rb +45 -0
  340. data/test/plugin/test_parser_csv.rb +103 -0
  341. data/test/plugin/test_parser_json.rb +114 -0
  342. data/test/plugin/test_parser_labeled_tsv.rb +128 -0
  343. data/test/plugin/test_parser_multiline.rb +100 -0
  344. data/test/plugin/test_parser_nginx.rb +48 -0
  345. data/test/plugin/test_parser_none.rb +52 -0
  346. data/test/plugin/test_parser_regexp.rb +281 -0
  347. data/test/plugin/test_parser_syslog.rb +242 -0
  348. data/test/plugin/test_parser_tsv.rb +122 -0
  349. data/test/plugin/test_storage.rb +167 -0
  350. data/test/plugin/test_storage_local.rb +335 -0
  351. data/test/plugin/test_string_util.rb +26 -0
  352. data/test/plugin_helper/test_child_process.rb +794 -0
  353. data/test/plugin_helper/test_compat_parameters.rb +331 -0
  354. data/test/plugin_helper/test_event_emitter.rb +51 -0
  355. data/test/plugin_helper/test_event_loop.rb +52 -0
  356. data/test/plugin_helper/test_extract.rb +194 -0
  357. data/test/plugin_helper/test_formatter.rb +255 -0
  358. data/test/plugin_helper/test_inject.rb +519 -0
  359. data/test/plugin_helper/test_parser.rb +264 -0
  360. data/test/plugin_helper/test_retry_state.rb +422 -0
  361. data/test/plugin_helper/test_server.rb +1677 -0
  362. data/test/plugin_helper/test_storage.rb +542 -0
  363. data/test/plugin_helper/test_thread.rb +164 -0
  364. data/test/plugin_helper/test_timer.rb +132 -0
  365. data/test/scripts/exec_script.rb +32 -0
  366. data/test/scripts/fluent/plugin/formatter1/formatter_test1.rb +7 -0
  367. data/test/scripts/fluent/plugin/formatter2/formatter_test2.rb +7 -0
  368. data/test/scripts/fluent/plugin/formatter_known.rb +8 -0
  369. data/test/scripts/fluent/plugin/out_test.rb +81 -0
  370. data/test/scripts/fluent/plugin/out_test2.rb +80 -0
  371. data/test/scripts/fluent/plugin/parser_known.rb +4 -0
  372. data/test/test_clock.rb +164 -0
  373. data/test/test_config.rb +179 -0
  374. data/test/test_configdsl.rb +148 -0
  375. data/test/test_event.rb +515 -0
  376. data/test/test_event_router.rb +331 -0
  377. data/test/test_event_time.rb +186 -0
  378. data/test/test_filter.rb +121 -0
  379. data/test/test_formatter.rb +312 -0
  380. data/test/test_input.rb +31 -0
  381. data/test/test_log.rb +828 -0
  382. data/test/test_match.rb +137 -0
  383. data/test/test_mixin.rb +351 -0
  384. data/test/test_output.rb +273 -0
  385. data/test/test_plugin.rb +251 -0
  386. data/test/test_plugin_classes.rb +253 -0
  387. data/test/test_plugin_helper.rb +81 -0
  388. data/test/test_plugin_id.rb +101 -0
  389. data/test/test_process.rb +14 -0
  390. data/test/test_root_agent.rb +611 -0
  391. data/test/test_supervisor.rb +373 -0
  392. data/test/test_test_drivers.rb +135 -0
  393. data/test/test_time_formatter.rb +282 -0
  394. data/test/test_time_parser.rb +211 -0
  395. data/test/test_unique_id.rb +47 -0
  396. metadata +898 -0
@@ -0,0 +1,1120 @@
1
+ require_relative '../helper'
2
+
3
+ require 'fluent/test/driver/input'
4
+ require 'fluent/test/startup_shutdown'
5
+ require 'base64'
6
+
7
+ require 'fluent/env'
8
+ require 'fluent/event'
9
+ require 'fluent/plugin/in_forward'
10
+ require 'fluent/plugin/compressable'
11
+
12
+ require 'timecop'
13
+
14
+ class ForwardInputTest < Test::Unit::TestCase
15
+ include Fluent::Plugin::Compressable
16
+
17
+ def setup
18
+ Fluent::Test.setup
19
+ @responses = [] # for testing responses after sending data
20
+ @d = nil
21
+ end
22
+
23
+ def teardown
24
+ @d.instance_shutdown if @d
25
+ end
26
+
27
+ PORT = unused_port
28
+
29
+ SHARED_KEY = 'foobar1'
30
+ USER_NAME = 'tagomoris'
31
+ USER_PASSWORD = 'fluentd'
32
+
33
+ CONFIG = %[
34
+ port #{PORT}
35
+ bind 127.0.0.1
36
+ ]
37
+ LOCALHOST_HOSTNAME_GETTER = ->(){sock = UDPSocket.new(::Socket::AF_INET); sock.do_not_reverse_lookup = false; sock.connect("127.0.0.1", 2048); sock.peeraddr[2] }
38
+ LOCALHOST_HOSTNAME = LOCALHOST_HOSTNAME_GETTER.call
39
+ DUMMY_SOCK = Struct.new(:remote_host, :remote_addr, :remote_port).new(LOCALHOST_HOSTNAME, "127.0.0.1", 0)
40
+ CONFIG_AUTH = %[
41
+ port #{PORT}
42
+ bind 127.0.0.1
43
+ <security>
44
+ self_hostname localhost
45
+ shared_key foobar1
46
+ user_auth true
47
+ <user>
48
+ username #{USER_NAME}
49
+ password #{USER_PASSWORD}
50
+ </user>
51
+ <client>
52
+ network 127.0.0.0/8
53
+ shared_key #{SHARED_KEY}
54
+ users ["#{USER_NAME}"]
55
+ </client>
56
+ </security>
57
+ ]
58
+
59
+ def create_driver(conf=CONFIG)
60
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::ForwardInput).configure(conf)
61
+ end
62
+
63
+ sub_test_case '#configure' do
64
+ test 'simple' do
65
+ @d = d = create_driver
66
+ assert_equal PORT, d.instance.port
67
+ assert_equal '127.0.0.1', d.instance.bind
68
+ assert_equal 0, d.instance.linger_timeout
69
+ assert_equal 0.5, d.instance.blocking_timeout
70
+ assert !d.instance.backlog
71
+ end
72
+
73
+ test 'auth' do
74
+ @d = d = create_driver(CONFIG_AUTH)
75
+ assert_equal PORT, d.instance.port
76
+ assert_equal '127.0.0.1', d.instance.bind
77
+ assert_equal 0, d.instance.linger_timeout
78
+ assert !d.instance.backlog
79
+
80
+ assert d.instance.security
81
+ assert_equal 1, d.instance.security.users.size
82
+ assert_equal 1, d.instance.security.clients.size
83
+ end
84
+ end
85
+
86
+ sub_test_case 'message' do
87
+ test 'time' do
88
+ time = event_time("2011-01-02 13:14:15 UTC")
89
+ begin
90
+ Timecop.freeze(Time.at(time))
91
+ @d = d = create_driver
92
+
93
+ records = [
94
+ ["tag1", time, {"a"=>1}],
95
+ ["tag2", time, {"a"=>2}],
96
+ ]
97
+
98
+ d.run(expect_records: records.length, timeout: 5) do
99
+ records.each {|tag, _time, record|
100
+ send_data packer.write([tag, 0, record]).to_s
101
+ }
102
+ end
103
+ assert_equal(records, d.events.sort_by {|a| a[0] })
104
+ ensure
105
+ Timecop.return
106
+ end
107
+ end
108
+
109
+ test 'plain' do
110
+ @d = d = create_driver
111
+
112
+ time = event_time("2011-01-02 13:14:15 UTC")
113
+
114
+ records = [
115
+ ["tag1", time, {"a"=>1}],
116
+ ["tag2", time, {"a"=>2}],
117
+ ]
118
+
119
+ d.run(expect_records: records.length, timeout: 5) do
120
+ records.each {|tag, _time, record|
121
+ send_data packer.write([tag, _time, record]).to_s
122
+ }
123
+ end
124
+ assert_equal(records, d.events)
125
+ end
126
+
127
+ test 'time_as_integer' do
128
+ @d = d = create_driver
129
+
130
+ time_i = event_time("2011-01-02 13:14:15 UTC").to_i
131
+
132
+ records = [
133
+ ["tag1", time_i, {"a"=>1}],
134
+ ["tag2", time_i, {"a"=>2}],
135
+ ]
136
+
137
+ d.run(expect_records: records.length, timeout: 5) do
138
+ records.each {|tag, _time, record|
139
+ send_data packer.write([tag, _time, record]).to_s
140
+ }
141
+ end
142
+
143
+ assert_equal(records, d.events)
144
+ end
145
+
146
+ test 'skip_invalid_event' do
147
+ @d = d = create_driver(CONFIG + "skip_invalid_event true")
148
+
149
+ time = event_time("2011-01-02 13:14:15 UTC")
150
+
151
+ records = [
152
+ ["tag1", time, {"a" => 1}],
153
+ ["tag2", time, {"a" => 2}],
154
+ ]
155
+
156
+ d.run(shutdown: false, expect_records: 2, timeout: 10) do
157
+ entries = []
158
+ # These entries are skipped
159
+ entries << ['tag1', true, {'a' => 3}] << ['tag2', time, 'invalid record']
160
+ entries += records.map { |tag, _time, record| [tag, _time, record] }
161
+
162
+ entries.each {|tag, _time, record|
163
+ # Without ack, logs are sometimes not saved to logs during test.
164
+ send_data packer.write([tag, _time, record]).to_s #, try_to_receive_response: true
165
+ }
166
+ end
167
+
168
+ logs = d.instance.log.logs
169
+ assert_equal 2, logs.count { |line| line =~ /got invalid event and drop it/ }
170
+ assert_equal records[0], d.events[0]
171
+ assert_equal records[1], d.events[1]
172
+
173
+ d.instance_shutdown
174
+ end
175
+
176
+ test 'json_using_integer_time' do
177
+ @d = d = create_driver
178
+
179
+ time_i = event_time("2011-01-02 13:14:15 UTC").to_i
180
+
181
+ records = [
182
+ ["tag1", time_i, {"a"=>1}],
183
+ ["tag2", time_i, {"a"=>2}],
184
+ ]
185
+
186
+ d.run(expect_records: records.length, timeout: 20) do
187
+ records.each {|tag, _time, record|
188
+ send_data [tag, _time, record].to_json
189
+ }
190
+ end
191
+
192
+ assert_equal(records, d.events.sort_by {|a| a[1] })
193
+ end
194
+
195
+ test 'json_with_newline' do
196
+ @d = d = create_driver
197
+
198
+ time_i = event_time("2011-01-02 13:14:15 UTC").to_i
199
+
200
+ records = [
201
+ ["tag1", time_i, {"a"=>1}],
202
+ ["tag2", time_i, {"a"=>2}],
203
+ ]
204
+
205
+ d.run(expect_records: records.length, timeout: 20) do
206
+ records.each {|tag, _time, record|
207
+ send_data [tag, _time, record].to_json + "\n"
208
+ sleep 1
209
+ }
210
+ end
211
+
212
+ assert_equal(records, d.events.sort_by {|a| a[1] })
213
+ end
214
+ end
215
+
216
+ sub_test_case 'forward' do
217
+ data(tcp: {
218
+ config: CONFIG,
219
+ options: {
220
+ auth: false
221
+ }
222
+ },
223
+ auth: {
224
+ config: CONFIG_AUTH,
225
+ options: {
226
+ auth: true
227
+ }
228
+ })
229
+ test 'plain' do |data|
230
+ config = data[:config]
231
+ options = data[:options]
232
+ @d = d = create_driver(config)
233
+
234
+ time = event_time("2011-01-02 13:14:15 UTC")
235
+
236
+ records = [
237
+ ["tag1", time, {"a"=>1}],
238
+ ["tag1", time, {"a"=>2}]
239
+ ]
240
+
241
+ d.run(expect_records: records.length, timeout: 20) do
242
+ entries = []
243
+ records.each {|tag, _time, record|
244
+ entries << [_time, record]
245
+ }
246
+ send_data packer.write(["tag1", entries]).to_s, **options
247
+ end
248
+ assert_equal(records, d.events)
249
+ end
250
+
251
+ data(tcp: {
252
+ config: CONFIG,
253
+ options: {
254
+ auth: false
255
+ }
256
+ },
257
+ auth: {
258
+ config: CONFIG_AUTH,
259
+ options: {
260
+ auth: true
261
+ }
262
+ })
263
+ test 'time_as_integer' do |data|
264
+ config = data[:config]
265
+ options = data[:options]
266
+ @d = d = create_driver(config)
267
+
268
+ time_i = event_time("2011-01-02 13:14:15 UTC")
269
+
270
+ records = [
271
+ ["tag1", time_i, {"a"=>1}],
272
+ ["tag1", time_i, {"a"=>2}]
273
+ ]
274
+
275
+ d.run(expect_records: records.length, timeout: 20) do
276
+ entries = []
277
+ records.each {|tag, _time, record|
278
+ entries << [_time, record]
279
+ }
280
+ send_data packer.write(["tag1", entries]).to_s, **options
281
+ end
282
+
283
+ assert_equal(records, d.events)
284
+ end
285
+
286
+ data(tcp: {
287
+ config: CONFIG,
288
+ options: {
289
+ auth: false
290
+ }
291
+ },
292
+ auth: {
293
+ config: CONFIG_AUTH,
294
+ options: {
295
+ auth: true
296
+ }
297
+ })
298
+ test 'skip_invalid_event' do |data|
299
+ config = data[:config]
300
+ options = data[:options]
301
+ @d = d = create_driver(config + "skip_invalid_event true")
302
+
303
+ time = event_time("2011-01-02 13:14:15 UTC")
304
+
305
+ records = [
306
+ ["tag1", time, {"a" => 1}],
307
+ ["tag1", time, {"a" => 2}],
308
+ ]
309
+
310
+ d.run(shutdown: false, expect_records: records.length, timeout: 20) do
311
+ entries = records.map { |tag, _time, record| [_time, record] }
312
+ # These entries are skipped
313
+ entries << ['invalid time', {'a' => 3}] << [time, 'invalid record']
314
+
315
+ send_data packer.write(["tag1", entries]).to_s, **options
316
+ end
317
+
318
+ logs = d.instance.log.out.logs
319
+ assert{ logs.select{|line| line =~ /skip invalid event/ }.size == 2 }
320
+
321
+ d.instance_shutdown
322
+ end
323
+ end
324
+
325
+ sub_test_case 'packed forward' do
326
+ data(tcp: {
327
+ config: CONFIG,
328
+ options: {
329
+ auth: false
330
+ }
331
+ },
332
+ auth: {
333
+ config: CONFIG_AUTH,
334
+ options: {
335
+ auth: true
336
+ }
337
+ })
338
+ test 'plain' do |data|
339
+ config = data[:config]
340
+ options = data[:options]
341
+ @d = d = create_driver(config)
342
+
343
+ time = event_time("2011-01-02 13:14:15 UTC")
344
+
345
+ records = [
346
+ ["tag1", time, {"a"=>1}],
347
+ ["tag1", time, {"a"=>2}],
348
+ ]
349
+
350
+ d.run(expect_records: records.length, timeout: 20) do
351
+ entries = ''
352
+ records.each {|_tag, _time, record|
353
+ packer(entries).write([_time, record]).flush
354
+ }
355
+ send_data packer.write(["tag1", entries]).to_s, **options
356
+ end
357
+ assert_equal(records, d.events)
358
+ end
359
+
360
+ data(tcp: {
361
+ config: CONFIG,
362
+ options: {
363
+ auth: false
364
+ }
365
+ },
366
+ auth: {
367
+ config: CONFIG_AUTH,
368
+ options: {
369
+ auth: true
370
+ }
371
+ })
372
+ test 'time_as_integer' do |data|
373
+ config = data[:config]
374
+ options = data[:options]
375
+ @d = d = create_driver(config)
376
+
377
+ time_i = event_time("2011-01-02 13:14:15 UTC").to_i
378
+
379
+ records = [
380
+ ["tag1", time_i, {"a"=>1}],
381
+ ["tag1", time_i, {"a"=>2}],
382
+ ]
383
+
384
+ d.run(expect_records: records.length, timeout: 20) do
385
+ entries = ''
386
+ records.each {|tag, _time, record|
387
+ packer(entries).write([_time, record]).flush
388
+ }
389
+ send_data packer.write(["tag1", entries]).to_s, **options
390
+ end
391
+ assert_equal(records, d.events)
392
+ end
393
+
394
+ data(tcp: {
395
+ config: CONFIG,
396
+ options: {
397
+ auth: false
398
+ }
399
+ },
400
+ auth: {
401
+ config: CONFIG_AUTH,
402
+ options: {
403
+ auth: true
404
+ }
405
+ })
406
+ test 'skip_invalid_event' do |data|
407
+ config = data[:config]
408
+ options = data[:options]
409
+ @d = d = create_driver(config + "skip_invalid_event true")
410
+
411
+ time = event_time("2011-01-02 13:14:15 UTC")
412
+
413
+ records = [
414
+ ["tag1", time, {"a" => 1}],
415
+ ["tag1", time, {"a" => 2}],
416
+ ]
417
+
418
+ d.run(shutdown: false, expect_records: records.length, timeout: 20) do
419
+ entries = records.map { |tag, _time, record| [_time, record] }
420
+ # These entries are skipped
421
+ entries << ['invalid time', {'a' => 3}] << [time, 'invalid record']
422
+
423
+ packed_entries = ''
424
+ entries.each { |_time, record|
425
+ packer(packed_entries).write([_time, record]).flush
426
+ }
427
+ send_data packer.write(["tag1", packed_entries]).to_s, **options
428
+ end
429
+
430
+ logs = d.instance.log.logs
431
+ assert_equal 2, logs.count { |line| line =~ /skip invalid event/ }
432
+
433
+ d.instance_shutdown
434
+ end
435
+ end
436
+
437
+ sub_test_case 'compressed packed forward' do
438
+ test 'set_compress_to_option' do
439
+ @d = d = create_driver
440
+
441
+ time_i = event_time("2011-01-02 13:14:15 UTC").to_i
442
+ events = [
443
+ ["tag1", time_i, {"a"=>1}],
444
+ ["tag1", time_i, {"a"=>2}]
445
+ ]
446
+
447
+ # create compressed entries
448
+ entries = ''
449
+ events.each do |_tag, _time, record|
450
+ v = [_time, record].to_msgpack
451
+ entries << compress(v)
452
+ end
453
+ chunk = ["tag1", entries, { 'compressed' => 'gzip' }].to_msgpack
454
+
455
+ d.run do
456
+ Fluent::Engine.msgpack_factory.unpacker.feed_each(chunk) do |obj|
457
+ option = d.instance.send(:on_message, obj, chunk.size, DUMMY_SOCK)
458
+ assert_equal 'gzip', option['compressed']
459
+ end
460
+ end
461
+
462
+ assert_equal events, d.events
463
+ end
464
+
465
+ test 'create_CompressedMessagePackEventStream_with_gzip_compress_option' do
466
+ @d = d = create_driver
467
+
468
+ time_i = event_time("2011-01-02 13:14:15 UTC").to_i
469
+ events = [
470
+ ["tag1", time_i, {"a"=>1}],
471
+ ["tag1", time_i, {"a"=>2}]
472
+ ]
473
+
474
+ # create compressed entries
475
+ entries = ''
476
+ events.each do |_tag, _time, record|
477
+ v = [_time, record].to_msgpack
478
+ entries << compress(v)
479
+ end
480
+ chunk = ["tag1", entries, { 'compressed' => 'gzip' }].to_msgpack
481
+
482
+ # check CompressedMessagePackEventStream is created
483
+ mock(Fluent::CompressedMessagePackEventStream).new(entries, nil, 0)
484
+
485
+ d.run do
486
+ Fluent::Engine.msgpack_factory.unpacker.feed_each(chunk) do |obj|
487
+ option = d.instance.send(:on_message, obj, chunk.size, DUMMY_SOCK)
488
+ assert_equal 'gzip', option['compressed']
489
+ end
490
+ end
491
+ end
492
+ end
493
+
494
+ sub_test_case 'warning' do
495
+ test 'send_large_chunk_warning' do
496
+ @d = d = create_driver(CONFIG + %[
497
+ chunk_size_warn_limit 16M
498
+ chunk_size_limit 32M
499
+ ])
500
+
501
+ time = event_time("2014-04-25 13:14:15 UTC")
502
+
503
+ # generate over 16M chunk
504
+ str = "X" * 1024 * 1024
505
+ chunk = [ "test.tag", (0...16).map{|i| [time + i, {"data" => str}] } ].to_msgpack
506
+ assert chunk.size > (16 * 1024 * 1024)
507
+ assert chunk.size < (32 * 1024 * 1024)
508
+
509
+ d.run(shutdown: false) do
510
+ Fluent::Engine.msgpack_factory.unpacker.feed_each(chunk) do |obj|
511
+ d.instance.send(:on_message, obj, chunk.size, DUMMY_SOCK)
512
+ end
513
+ end
514
+
515
+ # check emitted data
516
+ emits = d.events
517
+ assert_equal 16, emits.size
518
+ assert emits.map(&:first).all?{|t| t == "test.tag" }
519
+ assert_equal (0...16).to_a, emits.map{|_tag, t, _record| t - time }
520
+
521
+ # check log
522
+ logs = d.instance.log.logs
523
+ assert_equal 1, logs.select{|line|
524
+ line =~ / \[warn\]: Input chunk size is larger than 'chunk_size_warn_limit':/ &&
525
+ line =~ / tag="test.tag" host="#{LOCALHOST_HOSTNAME}" limit=16777216 size=16777501/
526
+ }.size, "large chunk warning is not logged"
527
+
528
+ d.instance_shutdown
529
+ end
530
+
531
+ test 'send_large_chunk_only_warning' do
532
+ @d = d = create_driver(CONFIG + %[
533
+ chunk_size_warn_limit 16M
534
+ ])
535
+ time = event_time("2014-04-25 13:14:15 UTC")
536
+
537
+ # generate over 16M chunk
538
+ str = "X" * 1024 * 1024
539
+ chunk = [ "test.tag", (0...16).map{|i| [time + i, {"data" => str}] } ].to_msgpack
540
+
541
+ d.run(shutdown: false) do
542
+ Fluent::Engine.msgpack_factory.unpacker.feed_each(chunk) do |obj|
543
+ d.instance.send(:on_message, obj, chunk.size, DUMMY_SOCK)
544
+ end
545
+ end
546
+
547
+ # check log
548
+ logs = d.instance.log.logs
549
+ assert_equal 1, logs.select{ |line|
550
+ line =~ / \[warn\]: Input chunk size is larger than 'chunk_size_warn_limit':/ &&
551
+ line =~ / tag="test.tag" host="#{LOCALHOST_HOSTNAME}" limit=16777216 size=16777501/
552
+ }.size, "large chunk warning is not logged"
553
+
554
+ d.instance_shutdown
555
+ end
556
+
557
+ test 'send_large_chunk_limit' do
558
+ @d = d = create_driver(CONFIG + %[
559
+ chunk_size_warn_limit 16M
560
+ chunk_size_limit 32M
561
+ ])
562
+
563
+ time = event_time("2014-04-25 13:14:15 UTC")
564
+
565
+ # generate over 32M chunk
566
+ str = "X" * 1024 * 1024
567
+ chunk = [ "test.tag", (0...32).map{|i| [time + i, {"data" => str}] } ].to_msgpack
568
+ assert chunk.size > (32 * 1024 * 1024)
569
+
570
+ # d.run => send_data
571
+ d.run(shutdown: false) do
572
+ Fluent::Engine.msgpack_factory.unpacker.feed_each(chunk) do |obj|
573
+ d.instance.send(:on_message, obj, chunk.size, DUMMY_SOCK)
574
+ end
575
+ end
576
+
577
+ # check emitted data
578
+ emits = d.events
579
+ assert_equal 0, emits.size
580
+
581
+ # check log
582
+ logs = d.instance.log.logs
583
+ assert_equal 1, logs.select{|line|
584
+ line =~ / \[warn\]: Input chunk size is larger than 'chunk_size_limit', dropped:/ &&
585
+ line =~ / tag="test.tag" host="#{LOCALHOST_HOSTNAME}" limit=33554432 size=33554989/
586
+ }.size, "large chunk warning is not logged"
587
+
588
+ d.instance_shutdown
589
+ end
590
+
591
+ data('string chunk' => 'broken string',
592
+ 'integer chunk' => 10)
593
+ test 'send_broken_chunk' do |data|
594
+ @d = d = create_driver
595
+
596
+ # d.run => send_data
597
+ d.run(shutdown: false) do
598
+ d.instance.send(:on_message, data, 1000000000, DUMMY_SOCK)
599
+ end
600
+
601
+ # check emitted data
602
+ assert_equal 0, d.events.size
603
+
604
+ # check log
605
+ logs = d.instance.log.logs
606
+ assert_equal 1, logs.select{|line|
607
+ line =~ / \[warn\]: incoming chunk is broken: host="#{LOCALHOST_HOSTNAME}" msg=#{data.inspect}/
608
+ }.size, "should not accept broken chunk"
609
+
610
+ d.instance_shutdown
611
+ end
612
+ end
613
+
614
+ sub_test_case 'respond to required ack' do
615
+ data(tcp: {
616
+ config: CONFIG,
617
+ options: {
618
+ auth: false
619
+ }
620
+ },
621
+ auth: {
622
+ config: CONFIG_AUTH,
623
+ options: {
624
+ auth: true
625
+ }
626
+ })
627
+ test 'message' do |data|
628
+ config = data[:config]
629
+ options = data[:options]
630
+ @d = d = create_driver(config)
631
+
632
+ time = event_time("2011-01-02 13:14:15 UTC")
633
+
634
+ events = [
635
+ ["tag1", time, {"a"=>1}],
636
+ ["tag2", time, {"a"=>2}]
637
+ ]
638
+
639
+ expected_acks = []
640
+
641
+ d.run(expect_records: events.size) do
642
+ events.each {|tag, _time, record|
643
+ op = { 'chunk' => Base64.encode64(record.object_id.to_s) }
644
+ expected_acks << op['chunk']
645
+ send_data [tag, _time, record, op].to_msgpack, try_to_receive_response: true, **options
646
+ }
647
+ end
648
+
649
+ assert_equal events, d.events
650
+ assert_equal expected_acks, @responses.map { |res| MessagePack.unpack(res)['ack'] }
651
+ end
652
+
653
+ # FIX: response is not pushed into @responses because IO.select has been blocked until InputForward shutdowns
654
+ data(tcp: {
655
+ config: CONFIG,
656
+ options: {
657
+ auth: false
658
+ }
659
+ },
660
+ auth: {
661
+ config: CONFIG_AUTH,
662
+ options: {
663
+ auth: true
664
+ }
665
+ })
666
+ test 'forward' do |data|
667
+ config = data[:config]
668
+ options = data[:options]
669
+ @d = d = create_driver(config)
670
+
671
+ time = event_time("2011-01-02 13:14:15 UTC")
672
+
673
+ events = [
674
+ ["tag1", time, {"a"=>1}],
675
+ ["tag1", time, {"a"=>2}]
676
+ ]
677
+
678
+ expected_acks = []
679
+
680
+ d.run(expect_records: events.size) do
681
+ entries = []
682
+ events.each {|_tag, _time, record|
683
+ entries << [_time, record]
684
+ }
685
+ op = { 'chunk' => Base64.encode64(entries.object_id.to_s) }
686
+ expected_acks << op['chunk']
687
+ send_data ["tag1", entries, op].to_msgpack, try_to_receive_response: true, **options
688
+ end
689
+
690
+ assert_equal events, d.events
691
+ assert_equal expected_acks, @responses.map { |res| MessagePack.unpack(res)['ack'] }
692
+ end
693
+
694
+ data(tcp: {
695
+ config: CONFIG,
696
+ options: {
697
+ auth: false
698
+ }
699
+ },
700
+ auth: {
701
+ config: CONFIG_AUTH,
702
+ options: {
703
+ auth: true
704
+ }
705
+ })
706
+ test 'packed_forward' do |data|
707
+ config = data[:config]
708
+ options = data[:options]
709
+ @d = d = create_driver(config)
710
+
711
+ time = event_time("2011-01-02 13:14:15 UTC")
712
+
713
+ events = [
714
+ ["tag1", time, {"a"=>1}],
715
+ ["tag1", time, {"a"=>2}]
716
+ ]
717
+
718
+ expected_acks = []
719
+
720
+ d.run(expect_records: events.size) do
721
+ entries = ''
722
+ events.each {|_tag, _time,record|
723
+ [time, record].to_msgpack(entries)
724
+ }
725
+ op = { 'chunk' => Base64.encode64(entries.object_id.to_s) }
726
+ expected_acks << op['chunk']
727
+ send_data ["tag1", entries, op].to_msgpack, try_to_receive_response: true, **options
728
+ end
729
+
730
+ assert_equal events, d.events
731
+ assert_equal expected_acks, @responses.map { |res| MessagePack.unpack(res)['ack'] }
732
+ end
733
+
734
+ data(
735
+ tcp: {
736
+ config: CONFIG,
737
+ options: {
738
+ auth: false
739
+ }
740
+ },
741
+ ### Auth is not supported with json
742
+ # auth: {
743
+ # config: CONFIG_AUTH,
744
+ # options: {
745
+ # auth: true
746
+ # }
747
+ # },
748
+ )
749
+ test 'message_json' do |data|
750
+ config = data[:config]
751
+ options = data[:options]
752
+ @d = d = create_driver(config)
753
+
754
+ time_i = event_time("2011-01-02 13:14:15 UTC")
755
+
756
+ events = [
757
+ ["tag1", time_i, {"a"=>1}],
758
+ ["tag2", time_i, {"a"=>2}]
759
+ ]
760
+
761
+ expected_acks = []
762
+
763
+ d.run(expect_records: events.size, timeout: 20) do
764
+ events.each {|tag, _time, record|
765
+ op = { 'chunk' => Base64.encode64(record.object_id.to_s) }
766
+ expected_acks << op['chunk']
767
+ send_data [tag, _time, record, op].to_json, try_to_receive_response: true, **options
768
+ }
769
+ end
770
+
771
+ assert_equal events, d.events
772
+ assert_equal expected_acks, @responses.map { |res| JSON.parse(res)['ack'] }
773
+ end
774
+ end
775
+
776
+ sub_test_case 'not respond without required ack' do
777
+ data(tcp: {
778
+ config: CONFIG,
779
+ options: {
780
+ auth: false
781
+ }
782
+ },
783
+ auth: {
784
+ config: CONFIG_AUTH,
785
+ options: {
786
+ auth: true
787
+ }
788
+ })
789
+ test 'message' do |data|
790
+ config = data[:config]
791
+ options = data[:options]
792
+ @d = d = create_driver(config)
793
+
794
+ time = event_time("2011-01-02 13:14:15 UTC")
795
+
796
+ events = [
797
+ ["tag1", time, {"a"=>1}],
798
+ ["tag2", time, {"a"=>2}]
799
+ ]
800
+
801
+ d.run(expect_records: events.size, timeout: 20) do
802
+ events.each {|tag, _time, record|
803
+ send_data [tag, _time, record].to_msgpack, try_to_receive_response: true, **options
804
+ }
805
+ end
806
+
807
+ assert_equal events, d.events
808
+ assert_equal [nil, nil], @responses
809
+ end
810
+
811
+ data(tcp: {
812
+ config: CONFIG,
813
+ options: {
814
+ auth: false
815
+ }
816
+ },
817
+ auth: {
818
+ config: CONFIG_AUTH,
819
+ options: {
820
+ auth: true
821
+ }
822
+ })
823
+ test 'forward' do |data|
824
+ config = data[:config]
825
+ options = data[:options]
826
+ @d = d = create_driver(config)
827
+
828
+ time = event_time("2011-01-02 13:14:15 UTC")
829
+
830
+ events = [
831
+ ["tag1", time, {"a"=>1}],
832
+ ["tag1", time, {"a"=>2}]
833
+ ]
834
+
835
+ d.run(expect_records: events.size, timeout: 20) do
836
+ entries = []
837
+ events.each {|tag, _time, record|
838
+ entries << [_time, record]
839
+ }
840
+ send_data ["tag1", entries].to_msgpack, try_to_receive_response: true, **options
841
+ end
842
+
843
+ assert_equal events, d.events
844
+ assert_equal [nil], @responses
845
+ end
846
+
847
+ data(tcp: {
848
+ config: CONFIG,
849
+ options: {
850
+ auth: false
851
+ }
852
+ },
853
+ auth: {
854
+ config: CONFIG_AUTH,
855
+ options: {
856
+ auth: true
857
+ }
858
+ })
859
+ test 'packed_forward' do |data|
860
+ config = data[:config]
861
+ options = data[:options]
862
+ @d = d = create_driver(config)
863
+
864
+ time = event_time("2011-01-02 13:14:15 UTC")
865
+
866
+ events = [
867
+ ["tag1", time, {"a"=>1}],
868
+ ["tag1", time, {"a"=>2}]
869
+ ]
870
+
871
+ d.run(expect_records: events.size, timeout: 20) do
872
+ entries = ''
873
+ events.each {|tag, _time, record|
874
+ [_time, record].to_msgpack(entries)
875
+ }
876
+ send_data ["tag1", entries].to_msgpack, try_to_receive_response: true, **options
877
+ end
878
+
879
+ assert_equal events, d.events
880
+ assert_equal [nil], @responses
881
+ end
882
+
883
+ data(
884
+ tcp: {
885
+ config: CONFIG,
886
+ options: {
887
+ auth: false
888
+ }
889
+ },
890
+ ### Auth is not supported with json
891
+ # auth: {
892
+ # config: CONFIG_AUTH,
893
+ # options: {
894
+ # auth: true
895
+ # }
896
+ # },
897
+ )
898
+ test 'message_json' do |data|
899
+ config = data[:config]
900
+ options = data[:options]
901
+ @d = d = create_driver(config)
902
+
903
+ time_i = event_time("2011-01-02 13:14:15 UTC").to_i
904
+
905
+ events = [
906
+ ["tag1", time_i, {"a"=>1}],
907
+ ["tag2", time_i, {"a"=>2}]
908
+ ]
909
+
910
+ d.run(expect_records: events.size, timeout: 20) do
911
+ events.each {|tag, _time, record|
912
+ send_data [tag, _time, record].to_json, try_to_receive_response: true, **options
913
+ }
914
+ end
915
+
916
+ assert_equal events, d.events
917
+ assert_equal [nil, nil], @responses
918
+ end
919
+ end
920
+
921
+ def packer(*args)
922
+ Fluent::Engine.msgpack_factory.packer(*args)
923
+ end
924
+
925
+ def unpacker
926
+ Fluent::Engine.msgpack_factory.unpacker
927
+ end
928
+
929
+ # res
930
+ # '' : socket is disconnected without any data
931
+ # nil: socket read timeout
932
+ def read_data(io, timeout, &block)
933
+ res = ''
934
+ select_timeout = 2
935
+ clock_id = Process::CLOCK_MONOTONIC_RAW rescue Process::CLOCK_MONOTONIC
936
+ timeout_at = Process.clock_gettime(clock_id) + timeout
937
+ begin
938
+ buf = ''
939
+ io_activated = false
940
+ while Process.clock_gettime(clock_id) < timeout_at
941
+ if IO.select([io], nil, nil, select_timeout)
942
+ io_activated = true
943
+ buf = io.readpartial(2048)
944
+ res ||= ''
945
+ res << buf
946
+
947
+ break if block.call(res)
948
+ end
949
+ end
950
+ res = nil unless io_activated # timeout without no data arrival
951
+ rescue Errno::EAGAIN
952
+ sleep 0.01
953
+ retry if res == ''
954
+ # if res is not empty, all data in socket buffer are read, so do not retry
955
+ rescue IOError, EOFError, Errno::ECONNRESET
956
+ # socket disconnected
957
+ end
958
+ res
959
+ end
960
+
961
+ def simulate_auth_sequence(io, shared_key=SHARED_KEY, username=USER_NAME, password=USER_PASSWORD)
962
+ auth_response_timeout = 30
963
+ shared_key_salt = 'salt'
964
+
965
+ # reading helo
966
+ helo_data = read_data(io, auth_response_timeout){|data| MessagePack.unpack(data) rescue nil }
967
+ raise "Authentication packet timeout" unless helo_data
968
+ raise "Authentication connection closed" if helo_data == ''
969
+ # ['HELO', options(hash)]
970
+ helo = MessagePack.unpack(helo_data)
971
+ raise "Invalid HELO header" unless helo[0] == 'HELO'
972
+ raise "Invalid HELO option object" unless helo[1].is_a?(Hash)
973
+ @options = helo[1]
974
+
975
+ # sending ping
976
+ ping = [
977
+ 'PING',
978
+ 'selfhostname',
979
+ shared_key_salt,
980
+ Digest::SHA512.new
981
+ .update(shared_key_salt)
982
+ .update('selfhostname')
983
+ .update(@options['nonce'])
984
+ .update(shared_key).hexdigest,
985
+ ]
986
+ if @options['auth'] # auth enabled -> value is auth salt
987
+ pass_digest = Digest::SHA512.new.update(@options['auth']).update(username).update(password).hexdigest
988
+ ping.push(username, pass_digest)
989
+ else
990
+ ping.push('', '')
991
+ end
992
+ io.write ping.to_msgpack
993
+ io.flush
994
+
995
+ # reading pong
996
+ pong_data = read_data(io, auth_response_timeout){|data| MessagePack.unpack(data) rescue nil }
997
+ raise "PONG packet timeout" unless pong_data
998
+ raise "PONG connection closed" if pong_data == ''
999
+ # ['PING', bool(auth_result), string(reason_if_failed), self_hostname, shared_key_digest]
1000
+ pong = MessagePack.unpack(pong_data)
1001
+ raise "Invalid PONG header" unless pong[0] == 'PONG'
1002
+ raise "Authentication Failure: #{pong[2]}" unless pong[1]
1003
+ clientside_calculated = Digest::SHA512.new
1004
+ .update(shared_key_salt)
1005
+ .update(pong[3])
1006
+ .update(@options['nonce'])
1007
+ .update(shared_key).hexdigest
1008
+ raise "Shared key digest mismatch" unless clientside_calculated == pong[4]
1009
+
1010
+ # authentication success
1011
+ true
1012
+ end
1013
+
1014
+ def connect
1015
+ TCPSocket.new('127.0.0.1', PORT)
1016
+ end
1017
+
1018
+ # Data ordering is not assured:
1019
+ # Records in different sockets are processed on different thread, so its scheduling make effect
1020
+ # on order of emitted records.
1021
+ # So, we MUST sort emitted records in different `send_data` before assertion.
1022
+ def send_data(data, try_to_receive_response: false, response_timeout: 5, auth: false)
1023
+ io = connect
1024
+
1025
+ if auth
1026
+ simulate_auth_sequence(io)
1027
+ end
1028
+
1029
+ io.write data
1030
+ io.flush
1031
+ if try_to_receive_response
1032
+ @responses << read_data(io, response_timeout){|d| MessagePack.unpack(d) rescue nil }
1033
+ end
1034
+ ensure
1035
+ io.close rescue nil # SSL socket requires any writes to close sockets
1036
+ end
1037
+
1038
+ sub_test_case 'source_hostname_key and source_address_key features' do
1039
+ data(
1040
+ both: [:hostname, :address],
1041
+ hostname: [:hostname],
1042
+ address: [:address],
1043
+ )
1044
+ test 'message protocol' do |keys|
1045
+ execute_test_with_source_hostname_key(*keys) { |events|
1046
+ events.each { |tag, time, record|
1047
+ send_data [tag, time, record].to_msgpack
1048
+ }
1049
+ }
1050
+ end
1051
+
1052
+ data(
1053
+ both: [:hostname, :address],
1054
+ hostname: [:hostname],
1055
+ address: [:address],
1056
+ )
1057
+ test 'forward protocol' do |keys|
1058
+ execute_test_with_source_hostname_key(*keys) { |events|
1059
+ entries = []
1060
+ events.each {|tag,time,record|
1061
+ entries << [time, record]
1062
+ }
1063
+ send_data ['tag1', entries].to_msgpack
1064
+ }
1065
+ end
1066
+
1067
+ data(
1068
+ both: [:hostname, :address],
1069
+ hostname: [:hostname],
1070
+ address: [:address],
1071
+ )
1072
+ test 'packed forward protocol' do |keys|
1073
+ execute_test_with_source_hostname_key(*keys) { |events|
1074
+ entries = ''
1075
+ events.each { |tag, time, record|
1076
+ Fluent::Engine.msgpack_factory.packer(entries).write([time, record]).flush
1077
+ }
1078
+ send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", entries]).to_s
1079
+ }
1080
+ end
1081
+ end
1082
+
1083
+ def execute_test_with_source_hostname_key(*keys, &block)
1084
+ conf = CONFIG.dup
1085
+ if keys.include?(:hostname)
1086
+ conf << <<EOL
1087
+ source_hostname_key source_hostname
1088
+ EOL
1089
+ end
1090
+ if keys.include?(:address)
1091
+ conf << <<EOL
1092
+ source_address_key source_address
1093
+ EOL
1094
+ end
1095
+ @d = d = create_driver(conf)
1096
+
1097
+ time = event_time("2011-01-02 13:14:15 UTC")
1098
+ events = [
1099
+ ["tag1", time, {"a"=>1}],
1100
+ ["tag1", time, {"a"=>2}]
1101
+ ]
1102
+
1103
+ d.run(expect_records: events.size) do
1104
+ block.call(events)
1105
+ end
1106
+
1107
+ d.events.each { |tag, _time, record|
1108
+ if keys.include?(:hostname)
1109
+ assert_true record.has_key?('source_hostname')
1110
+ assert_equal DUMMY_SOCK.remote_host, record['source_hostname']
1111
+ end
1112
+ if keys.include?(:address)
1113
+ assert_true record.has_key?('source_address')
1114
+ assert_equal DUMMY_SOCK.remote_addr, record['source_address']
1115
+ end
1116
+ }
1117
+ end
1118
+
1119
+ # TODO heartbeat
1120
+ end