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,617 @@
1
+ #
2
+ # Fluentd
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'fluent/plugin/base'
18
+ require 'fluent/plugin/owned_by_mixin'
19
+ require 'fluent/unique_id'
20
+
21
+ require 'monitor'
22
+
23
+ module Fluent
24
+ module Plugin
25
+ class Buffer < Base
26
+ include OwnedByMixin
27
+ include UniqueId::Mixin
28
+ include MonitorMixin
29
+
30
+ class BufferError < StandardError; end
31
+ class BufferOverflowError < BufferError; end
32
+ class BufferChunkOverflowError < BufferError; end # A record size is larger than chunk size limit
33
+
34
+ MINIMUM_APPEND_ATTEMPT_RECORDS = 10
35
+
36
+ DEFAULT_CHUNK_LIMIT_SIZE = 8 * 1024 * 1024 # 8MB
37
+ DEFAULT_TOTAL_LIMIT_SIZE = 512 * 1024 * 1024 # 512MB, same with v0.12 (BufferedOutput + buf_memory: 64 x 8MB)
38
+
39
+ DEFAULT_CHUNK_FULL_THRESHOLD = 0.95
40
+
41
+ configured_in :buffer
42
+
43
+ # TODO: system total buffer limit size in bytes by SystemConfig
44
+
45
+ config_param :chunk_limit_size, :size, default: DEFAULT_CHUNK_LIMIT_SIZE
46
+ config_param :total_limit_size, :size, default: DEFAULT_TOTAL_LIMIT_SIZE
47
+
48
+ # If user specify this value and (chunk_size * queue_length) is smaller than total_size,
49
+ # then total_size is automatically configured to that value
50
+ config_param :queue_limit_length, :integer, default: nil
51
+
52
+ # optional new limitations
53
+ config_param :chunk_limit_records, :integer, default: nil
54
+
55
+ # if chunk size (or records) is 95% or more after #write, then that chunk will be enqueued
56
+ config_param :chunk_full_threshold, :float, default: DEFAULT_CHUNK_FULL_THRESHOLD
57
+
58
+ desc 'Compress buffered data.'
59
+ config_param :compress, :enum, list: [:text, :gzip], default: :text
60
+
61
+ Metadata = Struct.new(:timekey, :tag, :variables) do
62
+ def empty?
63
+ timekey.nil? && tag.nil? && variables.nil?
64
+ end
65
+ end
66
+
67
+ # for tests
68
+ attr_accessor :stage_size, :queue_size
69
+ attr_reader :stage, :queue, :dequeued, :queued_num
70
+
71
+ def initialize
72
+ super
73
+
74
+ @chunk_limit_size = nil
75
+ @total_limit_size = nil
76
+ @queue_limit_length = nil
77
+ @chunk_limit_records = nil
78
+
79
+ @stage = {} #=> Hash (metadata -> chunk) : not flushed yet
80
+ @queue = [] #=> Array (chunks) : already flushed (not written)
81
+ @dequeued = {} #=> Hash (unique_id -> chunk): already written (not purged)
82
+ @queued_num = {} # metadata => int (number of queued chunks)
83
+
84
+ @stage_size = @queue_size = 0
85
+ @metadata_list = [] # keys of @stage
86
+ end
87
+
88
+ def persistent?
89
+ false
90
+ end
91
+
92
+ def configure(conf)
93
+ super
94
+
95
+ unless @queue_limit_length.nil?
96
+ @total_limit_size = @chunk_limit_size * @queue_limit_length
97
+ end
98
+ end
99
+
100
+ def start
101
+ super
102
+
103
+ @stage, @queue = resume
104
+ @stage.each_pair do |metadata, chunk|
105
+ @metadata_list << metadata unless @metadata_list.include?(metadata)
106
+ @stage_size += chunk.bytesize
107
+ end
108
+ @queue.each do |chunk|
109
+ @metadata_list << chunk.metadata unless @metadata_list.include?(chunk.metadata)
110
+ @queued_num[chunk.metadata] ||= 0
111
+ @queued_num[chunk.metadata] += 1
112
+ @queue_size += chunk.bytesize
113
+ end
114
+ log.debug "buffer started", instance: self.object_id, stage_size: @stage_size, queue_size: @queue_size
115
+ end
116
+
117
+ def close
118
+ super
119
+ synchronize do
120
+ log.debug "closing buffer", instance: self.object_id
121
+ @dequeued.each_pair do |chunk_id, chunk|
122
+ chunk.close
123
+ end
124
+ until @queue.empty?
125
+ @queue.shift.close
126
+ end
127
+ @stage.each_pair do |metadata, chunk|
128
+ chunk.close
129
+ end
130
+ end
131
+ end
132
+
133
+ def terminate
134
+ super
135
+ @dequeued = @stage = @queue = @queued_num = @metadata_list = nil
136
+ @stage_size = @queue_size = 0
137
+ end
138
+
139
+ def storable?
140
+ @total_limit_size > @stage_size + @queue_size
141
+ end
142
+
143
+ ## TODO: for back pressure feature
144
+ # def used?(ratio)
145
+ # @total_limit_size * ratio > @stage_size + @queue_size
146
+ # end
147
+
148
+ def resume
149
+ # return {}, []
150
+ raise NotImplementedError, "Implement this method in child class"
151
+ end
152
+
153
+ def generate_chunk(metadata)
154
+ raise NotImplementedError, "Implement this method in child class"
155
+ end
156
+
157
+ def metadata_list
158
+ synchronize do
159
+ @metadata_list.dup
160
+ end
161
+ end
162
+
163
+ # it's too dangerous, and use it so carefully to remove metadata for tests
164
+ def metadata_list_clear!
165
+ synchronize do
166
+ @metadata_list.clear
167
+ end
168
+ end
169
+
170
+ def new_metadata(timekey: nil, tag: nil, variables: nil)
171
+ Metadata.new(timekey, tag, variables)
172
+ end
173
+
174
+ def add_metadata(metadata)
175
+ log.trace "adding metadata", instance: self.object_id, metadata: metadata
176
+ synchronize do
177
+ if i = @metadata_list.index(metadata)
178
+ @metadata_list[i]
179
+ else
180
+ @metadata_list << metadata
181
+ metadata
182
+ end
183
+ end
184
+ end
185
+
186
+ def metadata(timekey: nil, tag: nil, variables: nil)
187
+ meta = new_metadata(timekey: timekey, tag: tag, variables: variables)
188
+ add_metadata(meta)
189
+ end
190
+
191
+ # metadata MUST have consistent object_id for each variation
192
+ # data MUST be Array of serialized events, or EventStream
193
+ # metadata_and_data MUST be a hash of { metadata => data }
194
+ def write(metadata_and_data, format: nil, size: nil, enqueue: false)
195
+ return if metadata_and_data.size < 1
196
+ raise BufferOverflowError, "buffer space has too many data" unless storable?
197
+
198
+ log.trace "writing events into buffer", instance: self.object_id, metadata_size: metadata_and_data.size
199
+
200
+ staged_bytesize = 0
201
+ operated_chunks = []
202
+ unstaged_chunks = {} # metadata => [chunk, chunk, ...]
203
+ chunks_to_enqueue = []
204
+
205
+ begin
206
+ metadata_and_data.each do |metadata, data|
207
+ write_once(metadata, data, format: format, size: size) do |chunk, adding_bytesize|
208
+ chunk.mon_enter # add lock to prevent to be committed/rollbacked from other threads
209
+ operated_chunks << chunk
210
+ if chunk.staged?
211
+ staged_bytesize += adding_bytesize
212
+ elsif chunk.unstaged?
213
+ unstaged_chunks[metadata] ||= []
214
+ unstaged_chunks[metadata] << chunk
215
+ end
216
+ end
217
+ end
218
+
219
+ return if operated_chunks.empty?
220
+
221
+ # Now, this thread acquires many locks of chunks... getting buffer-global lock causes dead lock.
222
+ # Any operations needs buffer-global lock (including enqueueing) should be done after releasing locks.
223
+
224
+ first_chunk = operated_chunks.shift
225
+ # Following commits for other chunks also can finish successfully if the first commit operation
226
+ # finishes without any exceptions.
227
+ # In most cases, #commit just requires very small disk spaces, so major failure reason are
228
+ # permission errors, disk failures and other permanent(fatal) errors.
229
+ begin
230
+ first_chunk.commit
231
+ if enqueue || first_chunk.unstaged? || chunk_size_full?(first_chunk)
232
+ chunks_to_enqueue << first_chunk
233
+ end
234
+ first_chunk.mon_exit
235
+ rescue
236
+ operated_chunks.unshift(first_chunk)
237
+ raise
238
+ end
239
+
240
+ errors = []
241
+ # Buffer plugin estimates there's no serious error cause: will commit for all chunks eigher way
242
+ operated_chunks.each do |chunk|
243
+ begin
244
+ chunk.commit
245
+ if enqueue || chunk.unstaged? || chunk_size_full?(chunk)
246
+ chunks_to_enqueue << chunk
247
+ end
248
+ chunk.mon_exit
249
+ rescue => e
250
+ chunk.rollback
251
+ chunk.mon_exit
252
+ errors << e
253
+ end
254
+ end
255
+
256
+ # All locks about chunks are released.
257
+
258
+ synchronize do
259
+ # At here, staged chunks may be enqueued by other threads.
260
+ @stage_size += staged_bytesize
261
+
262
+ chunks_to_enqueue.each do |c|
263
+ if c.staged? && (enqueue || chunk_size_full?(c))
264
+ m = c.metadata
265
+ enqueue_chunk(m)
266
+ if unstaged_chunks[m]
267
+ u = unstaged_chunks[m].pop
268
+ if u.unstaged? && !chunk_size_full?(u)
269
+ @stage[m] = u.staged!
270
+ @stage_size += u.bytesize
271
+ end
272
+ end
273
+ elsif c.unstaged?
274
+ enqueue_unstaged_chunk(c)
275
+ else
276
+ # previously staged chunk is already enqueued, closed or purged.
277
+ # no problem.
278
+ end
279
+ end
280
+ end
281
+
282
+ operated_chunks.clear if errors.empty?
283
+
284
+ if errors.size > 0
285
+ log.warn "error occurs in committing chunks: only first one raised", errors: errors.map(&:class)
286
+ raise errors.first
287
+ end
288
+ ensure
289
+ operated_chunks.each do |chunk|
290
+ chunk.rollback rescue nil # nothing possible to do for #rollback failure
291
+ if chunk.unstaged?
292
+ chunk.purge rescue nil # to prevent leakage of unstaged chunks
293
+ end
294
+ chunk.mon_exit rescue nil # this may raise ThreadError for chunks already committed
295
+ end
296
+ end
297
+ end
298
+
299
+ def queued_records
300
+ synchronize { @queue.reduce(0){|r, chunk| r + chunk.size } }
301
+ end
302
+
303
+ def queued?(metadata=nil)
304
+ synchronize do
305
+ if metadata
306
+ n = @queued_num[metadata]
307
+ n && n.nonzero?
308
+ else
309
+ !@queue.empty?
310
+ end
311
+ end
312
+ end
313
+
314
+ def enqueue_chunk(metadata)
315
+ log.trace "enqueueing chunk", instance: self.object_id, metadata: metadata
316
+ synchronize do
317
+ chunk = @stage.delete(metadata)
318
+ return nil unless chunk
319
+
320
+ chunk.synchronize do
321
+ if chunk.empty?
322
+ chunk.close
323
+ else
324
+ @queue << chunk
325
+ @queued_num[metadata] = @queued_num.fetch(metadata, 0) + 1
326
+ chunk.enqueued! if chunk.respond_to?(:enqueued!)
327
+ end
328
+ end
329
+ bytesize = chunk.bytesize
330
+ @stage_size -= bytesize
331
+ @queue_size += bytesize
332
+ end
333
+ nil
334
+ end
335
+
336
+ def enqueue_unstaged_chunk(chunk)
337
+ log.trace "enqueueing unstaged chunk", instance: self.object_id, metadata: chunk.metadata
338
+ synchronize do
339
+ chunk.synchronize do
340
+ metadata = chunk.metadata
341
+ @queue << chunk
342
+ @queued_num[metadata] = @queued_num.fetch(metadata, 0) + 1
343
+ chunk.enqueued! if chunk.respond_to?(:enqueued!)
344
+ end
345
+ @queue_size += chunk.bytesize
346
+ end
347
+ end
348
+
349
+ def enqueue_all
350
+ log.trace "enqueueing all chunks in buffer", instance: self.object_id
351
+ synchronize do
352
+ if block_given?
353
+ @stage.keys.each do |metadata|
354
+ chunk = @stage[metadata]
355
+ v = yield metadata, chunk
356
+ enqueue_chunk(metadata) if v
357
+ end
358
+ else
359
+ @stage.keys.each do |metadata|
360
+ enqueue_chunk(metadata)
361
+ end
362
+ end
363
+ end
364
+ end
365
+
366
+ def dequeue_chunk
367
+ return nil if @queue.empty?
368
+ log.trace "dequeueing a chunk", instance: self.object_id
369
+ synchronize do
370
+ chunk = @queue.shift
371
+
372
+ # this buffer is dequeued by other thread just before "synchronize" in this thread
373
+ return nil unless chunk
374
+
375
+ @dequeued[chunk.unique_id] = chunk
376
+ @queued_num[chunk.metadata] -= 1 # BUG if nil, 0 or subzero
377
+ log.trace "chunk dequeued", instance: self.object_id, metadata: chunk.metadata
378
+ chunk
379
+ end
380
+ end
381
+
382
+ def takeback_chunk(chunk_id)
383
+ log.trace "taking back a chunk", instance: self.object_id, chunk_id: dump_unique_id_hex(chunk_id)
384
+ synchronize do
385
+ chunk = @dequeued.delete(chunk_id)
386
+ return false unless chunk # already purged by other thread
387
+ @queue.unshift(chunk)
388
+ log.trace "chunk taken back", instance: self.object_id, chunk_id: dump_unique_id_hex(chunk_id), metadata: chunk.metadata
389
+ @queued_num[chunk.metadata] += 1 # BUG if nil
390
+ end
391
+ true
392
+ end
393
+
394
+ def purge_chunk(chunk_id)
395
+ synchronize do
396
+ chunk = @dequeued.delete(chunk_id)
397
+ return nil unless chunk # purged by other threads
398
+
399
+ metadata = chunk.metadata
400
+ log.trace "purging a chunk", instance: self.object_id, chunk_id: dump_unique_id_hex(chunk_id), metadata: metadata
401
+ begin
402
+ bytesize = chunk.bytesize
403
+ chunk.purge
404
+ @queue_size -= bytesize
405
+ rescue => e
406
+ log.error "failed to purge buffer chunk", chunk_id: dump_unique_id_hex(chunk_id), error_class: e.class, error: e
407
+ log.error_backtrace
408
+ end
409
+
410
+ if metadata && !@stage[metadata] && (!@queued_num[metadata] || @queued_num[metadata] < 1)
411
+ @metadata_list.delete(metadata)
412
+ end
413
+ log.trace "chunk purged", instance: self.object_id, chunk_id: dump_unique_id_hex(chunk_id), metadata: metadata
414
+ end
415
+ nil
416
+ end
417
+
418
+ def clear_queue!
419
+ log.trace "clearing queue", instance: self.object_id
420
+ synchronize do
421
+ until @queue.empty?
422
+ begin
423
+ q = @queue.shift
424
+ log.trace("purging a chunk in queue"){ {id: dump_unique_id_hex(chunk.unique_id), bytesize: chunk.bytesize, size: chunk.size} }
425
+ q.purge
426
+ rescue => e
427
+ log.error "unexpected error while clearing buffer queue", error_class: e.class, error: e
428
+ log.error_backtrace
429
+ end
430
+ end
431
+ @queue_size = 0
432
+ end
433
+ end
434
+
435
+ def chunk_size_over?(chunk)
436
+ chunk.bytesize > @chunk_limit_size || (@chunk_limit_records && chunk.size > @chunk_limit_records)
437
+ end
438
+
439
+ def chunk_size_full?(chunk)
440
+ chunk.bytesize >= @chunk_limit_size * @chunk_full_threshold || (@chunk_limit_records && chunk.size >= @chunk_limit_records * @chunk_full_threshold)
441
+ end
442
+
443
+ class ShouldRetry < StandardError; end
444
+
445
+ # write once into a chunk
446
+ # 1. append whole data into existing chunk
447
+ # 2. commit it & return unless chunk_size_over?
448
+ # 3. enqueue existing chunk & retry whole method if chunk was not empty
449
+ # 4. go to step_by_step writing
450
+
451
+ def write_once(metadata, data, format: nil, size: nil, &block)
452
+ return if data.empty?
453
+
454
+ stored = false
455
+ adding_bytesize = nil
456
+
457
+ chunk = synchronize { @stage[metadata] ||= generate_chunk(metadata).staged! }
458
+ enqueue_chunk_before_retry = false
459
+ chunk.synchronize do
460
+ # retry this method if chunk is already queued (between getting chunk and entering critical section)
461
+ raise ShouldRetry unless chunk.staged?
462
+
463
+ empty_chunk = chunk.empty?
464
+
465
+ original_bytesize = chunk.bytesize
466
+ begin
467
+ if format
468
+ serialized = format.call(data)
469
+ chunk.concat(serialized, size ? size.call : data.size)
470
+ else
471
+ chunk.append(data, compress: @compress)
472
+ end
473
+ adding_bytesize = chunk.bytesize - original_bytesize
474
+
475
+ if chunk_size_over?(chunk)
476
+ if format && empty_chunk
477
+ log.warn "chunk bytes limit exceeds for an emitted event stream: #{adding_bytesize}bytes"
478
+ end
479
+ chunk.rollback
480
+
481
+ if format && !empty_chunk
482
+ # Event streams should be appended into a chunk at once
483
+ # as far as possible, to improve performance of formatting.
484
+ # Event stream may be a MessagePackEventStream. We don't want to split it into
485
+ # 2 or more chunks (except for a case that the event stream is larger than chunk limit).
486
+ enqueue_chunk_before_retry = true
487
+ raise ShouldRetry
488
+ end
489
+ else
490
+ stored = true
491
+ end
492
+ rescue
493
+ chunk.rollback
494
+ raise
495
+ end
496
+
497
+ if stored
498
+ block.call(chunk, adding_bytesize)
499
+ end
500
+ end
501
+
502
+ unless stored
503
+ # try step-by-step appending if data can't be stored into existing a chunk in non-bulk mode
504
+ #
505
+ # 1/10 size of original event stream (splits_count == 10) seems enough small
506
+ # to try emitting events into existing chunk.
507
+ # it does not matter to split event stream into very small splits, because chunks have less
508
+ # overhead to write data many times (even about file buffer chunks).
509
+ write_step_by_step(metadata, data, format, 10, &block)
510
+ end
511
+ rescue ShouldRetry
512
+ enqueue_chunk(metadata) if enqueue_chunk_before_retry
513
+ retry
514
+ end
515
+
516
+ # EventStream can be split into many streams
517
+ # because (es1 + es2).to_msgpack_stream == es1.to_msgpack_stream + es2.to_msgpack_stream
518
+
519
+ # 1. split event streams into many (10 -> 100 -> 1000 -> ...) chunks
520
+ # 2. append splits into the staged chunks as much as possible
521
+ # 3. create unstaged chunk and append rest splits -> repeat it for all splits
522
+
523
+ def write_step_by_step(metadata, data, format, splits_count, &block)
524
+ splits = []
525
+ if splits_count > data.size
526
+ splits_count = data.size
527
+ end
528
+ slice_size = if data.size % splits_count == 0
529
+ data.size / splits_count
530
+ else
531
+ data.size / (splits_count - 1)
532
+ end
533
+ slice_origin = 0
534
+ while slice_origin < data.size
535
+ splits << data.slice(slice_origin, slice_size)
536
+ slice_origin += slice_size
537
+ end
538
+
539
+ # This method will append events into the staged chunk at first.
540
+ # Then, will generate chunks not staged (not queued) to append rest data.
541
+ staged_chunk_used = false
542
+ modified_chunks = []
543
+ get_next_chunk = ->(){
544
+ c = if staged_chunk_used
545
+ # Staging new chunk here is bad idea:
546
+ # Recovering whole state including newly staged chunks is much harder than current implementation.
547
+ generate_chunk(metadata)
548
+ else
549
+ synchronize{ @stage[metadata] ||= generate_chunk(metadata).staged! }
550
+ end
551
+ modified_chunks << c
552
+ c
553
+ }
554
+
555
+ writing_splits_index = 0
556
+ enqueue_chunk_before_retry = false
557
+
558
+ while writing_splits_index < splits.size
559
+ chunk = get_next_chunk.call
560
+ chunk.synchronize do
561
+ raise ShouldRetry unless chunk.writable?
562
+ staged_chunk_used = true if chunk.staged?
563
+
564
+ original_bytesize = chunk.bytesize
565
+ begin
566
+ while writing_splits_index < splits.size
567
+ split = splits[writing_splits_index]
568
+ if format
569
+ chunk.concat(format.call(split), split.size)
570
+ else
571
+ chunk.append(split, compress: @compress)
572
+ end
573
+
574
+ if chunk_size_over?(chunk) # split size is larger than difference between size_full? and size_over?
575
+ chunk.rollback
576
+
577
+ if split.size == 1 && original_bytesize == 0
578
+ big_record_size = format ? format.call(split).bytesize : split.first.bytesize
579
+ raise BufferChunkOverflowError, "a #{big_record_size}bytes record is larger than buffer chunk limit size"
580
+ end
581
+
582
+ if chunk_size_full?(chunk) || split.size == 1
583
+ enqueue_chunk_before_retry = true
584
+ else
585
+ splits_count *= 10
586
+ end
587
+
588
+ raise ShouldRetry
589
+ end
590
+
591
+ writing_splits_index += 1
592
+
593
+ if chunk_size_full?(chunk)
594
+ break
595
+ end
596
+ end
597
+ rescue
598
+ chunk.purge if chunk.unstaged? # unstaged chunk will leak unless purge it
599
+ raise
600
+ end
601
+
602
+ block.call(chunk, chunk.bytesize - original_bytesize)
603
+ end
604
+ end
605
+ rescue ShouldRetry
606
+ modified_chunks.each do |mc|
607
+ mc.rollback rescue nil
608
+ if mc.unstaged?
609
+ mc.purge rescue nil
610
+ end
611
+ end
612
+ enqueue_chunk(metadata) if enqueue_chunk_before_retry
613
+ retry
614
+ end
615
+ end
616
+ end
617
+ end