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,364 @@
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_helper/thread'
18
+ require 'fluent/plugin_helper/timer'
19
+ require 'fluent/clock'
20
+
21
+ require 'open3'
22
+ require 'timeout'
23
+
24
+ module Fluent
25
+ module PluginHelper
26
+ module ChildProcess
27
+ include Fluent::PluginHelper::Thread
28
+ include Fluent::PluginHelper::Timer
29
+
30
+ CHILD_PROCESS_LOOP_CHECK_INTERVAL = 0.2 # sec
31
+ CHILD_PROCESS_DEFAULT_EXIT_TIMEOUT = 10 # sec
32
+ CHILD_PROCESS_DEFAULT_KILL_TIMEOUT = 60 # sec
33
+
34
+ MODE_PARAMS = [:read, :write, :stderr, :read_with_stderr]
35
+ STDERR_OPTIONS = [:discard, :connect]
36
+
37
+ # stop : mark callback thread as stopped
38
+ # shutdown : close write IO to child processes (STDIN of child processes), send TERM (KILL for Windows) to all child processes
39
+ # close : send KILL to all child processes
40
+ # terminate: [-]
41
+
42
+ attr_reader :_child_process_processes # for tests
43
+
44
+ def child_process_running?
45
+ # checker for code in callback of child_process_execute
46
+ ::Thread.current[:_fluentd_plugin_helper_child_process_running] || false
47
+ end
48
+
49
+ def child_process_id
50
+ ::Thread.current[:_fluentd_plugin_helper_child_process_pid]
51
+ end
52
+
53
+ def child_process_exist?(pid)
54
+ pinfo = @_child_process_processes[pid]
55
+ return false unless pinfo
56
+
57
+ return false if pinfo.exit_status
58
+
59
+ true
60
+ end
61
+
62
+ # on_exit_callback = ->(status){ ... }
63
+ # status is an instance of Process::Status
64
+ # On Windows, exitstatus=0 and termsig=nil even when child process was killed.
65
+ def child_process_execute(
66
+ title, command,
67
+ arguments: nil, subprocess_name: nil, interval: nil, immediate: false, parallel: false,
68
+ mode: [:read, :write], stderr: :discard, env: {}, unsetenv: false, chdir: nil,
69
+ internal_encoding: 'utf-8', external_encoding: 'ascii-8bit', scrub: true, replace_string: nil,
70
+ wait_timeout: nil, on_exit_callback: nil,
71
+ &block
72
+ )
73
+ raise ArgumentError, "BUG: title must be a symbol" unless title.is_a? Symbol
74
+ raise ArgumentError, "BUG: arguments required if subprocess name is replaced" if subprocess_name && !arguments
75
+
76
+ mode ||= []
77
+ mode = [] unless block
78
+ raise ArgumentError, "BUG: invalid mode specification" unless mode.all?{|m| MODE_PARAMS.include?(m) }
79
+ raise ArgumentError, "BUG: read_with_stderr is exclusive with :read and :stderr" if mode.include?(:read_with_stderr) && (mode.include?(:read) || mode.include?(:stderr))
80
+ raise ArgumentError, "BUG: invalid stderr handling specification" unless STDERR_OPTIONS.include?(stderr)
81
+
82
+ raise ArgumentError, "BUG: number of block arguments are different from size of mode" if block && block.arity != mode.size
83
+
84
+ running = false
85
+ callback = ->(*args) {
86
+ running = true
87
+ begin
88
+ block && block.call(*args)
89
+ ensure
90
+ running = false
91
+ end
92
+ }
93
+
94
+ retval = nil
95
+ execute_child_process = ->(){
96
+ child_process_execute_once(
97
+ title, command, arguments,
98
+ subprocess_name, mode, stderr, env, unsetenv, chdir,
99
+ internal_encoding, external_encoding, scrub, replace_string,
100
+ wait_timeout, on_exit_callback,
101
+ &callback
102
+ )
103
+ }
104
+
105
+ if immediate || !interval
106
+ retval = execute_child_process.call
107
+ end
108
+
109
+ if interval
110
+ timer_execute(:child_process_execute, interval, repeat: true) do
111
+ if !parallel && running
112
+ log.warn "previous child process is still running. skipped.", title: title, command: command, arguments: arguments, interval: interval, parallel: parallel
113
+ else
114
+ execute_child_process.call
115
+ end
116
+ end
117
+ end
118
+
119
+ retval # nil if interval
120
+ end
121
+
122
+ def initialize
123
+ super
124
+ # plugins MAY configure this parameter
125
+ @_child_process_exit_timeout = CHILD_PROCESS_DEFAULT_EXIT_TIMEOUT
126
+ @_child_process_kill_timeout = CHILD_PROCESS_DEFAULT_KILL_TIMEOUT
127
+ @_child_process_mutex = Mutex.new
128
+ @_child_process_processes = {} # pid => ProcessInfo
129
+ end
130
+
131
+ def stop
132
+ @_child_process_mutex.synchronize{ @_child_process_processes.keys }.each do |pid|
133
+ process_info = @_child_process_processes[pid]
134
+ if process_info
135
+ process_info.thread[:_fluentd_plugin_helper_child_process_running] = false
136
+ end
137
+ end
138
+
139
+ super
140
+ end
141
+
142
+ def shutdown
143
+ @_child_process_mutex.synchronize{ @_child_process_processes.keys }.each do |pid|
144
+ process_info = @_child_process_processes[pid]
145
+ next if !process_info
146
+ process_info.writeio && process_info.writeio.close rescue nil
147
+ end
148
+
149
+ super
150
+
151
+ @_child_process_mutex.synchronize{ @_child_process_processes.keys }.each do |pid|
152
+ process_info = @_child_process_processes[pid]
153
+ next if !process_info
154
+ child_process_kill(process_info)
155
+ end
156
+
157
+ exit_wait_timeout = Fluent::Clock.now + @_child_process_exit_timeout
158
+ while Fluent::Clock.now < exit_wait_timeout
159
+ process_exists = false
160
+ @_child_process_mutex.synchronize{ @_child_process_processes.keys }.each do |pid|
161
+ unless @_child_process_processes[pid].exit_status
162
+ process_exists = true
163
+ break
164
+ end
165
+ end
166
+ if process_exists
167
+ sleep CHILD_PROCESS_LOOP_CHECK_INTERVAL
168
+ else
169
+ break
170
+ end
171
+ end
172
+ end
173
+
174
+ def close
175
+ while true
176
+ pids = @_child_process_mutex.synchronize{ @_child_process_processes.keys }
177
+ break if pids.size < 1
178
+
179
+ living_process_exist = false
180
+ pids.each do |pid|
181
+ process_info = @_child_process_processes[pid]
182
+ next if !process_info || process_info.exit_status
183
+
184
+ living_process_exist = true
185
+
186
+ process_info.killed_at ||= Fluent::Clock.now # for illegular case (e.g., created after shutdown)
187
+ timeout_at = process_info.killed_at + @_child_process_kill_timeout
188
+ now = Fluent::Clock.now
189
+ next if now < timeout_at
190
+
191
+ child_process_kill(process_info, force: true)
192
+ end
193
+
194
+ break if living_process_exist
195
+
196
+ sleep CHILD_PROCESS_LOOP_CHECK_INTERVAL
197
+ end
198
+
199
+ super
200
+ end
201
+
202
+ def terminate
203
+ @_child_process_processes = {}
204
+
205
+ super
206
+ end
207
+
208
+ def child_process_kill(pinfo, force: false)
209
+ return if !pinfo
210
+ pinfo.killed_at = Fluent::Clock.now unless force
211
+
212
+ pid = pinfo.pid
213
+ begin
214
+ if !pinfo.exit_status && child_process_exist?(pid)
215
+ signal = (Fluent.windows? || force) ? :KILL : :TERM
216
+ Process.kill(signal, pinfo.pid)
217
+ end
218
+ rescue Errno::ECHILD, Errno::ESRCH
219
+ # ignore
220
+ end
221
+ end
222
+
223
+ ProcessInfo = Struct.new(
224
+ :title,
225
+ :thread, :pid,
226
+ :readio, :readio_in_use, :writeio, :writeio_in_use, :stderrio, :stderrio_in_use,
227
+ :wait_thread, :alive, :killed_at, :exit_status,
228
+ :on_exit_callback, :on_exit_callback_mutex,
229
+ )
230
+
231
+ def child_process_execute_once(
232
+ title, command, arguments, subprocess_name, mode, stderr, env, unsetenv, chdir,
233
+ internal_encoding, external_encoding, scrub, replace_string, wait_timeout, on_exit_callback, &block
234
+ )
235
+ spawn_args = if arguments || subprocess_name
236
+ [ env, (subprocess_name ? [command, subprocess_name] : command), *(arguments || []) ]
237
+ else
238
+ [ env, command ]
239
+ end
240
+ spawn_opts = {
241
+ unsetenv_others: unsetenv,
242
+ }
243
+ if chdir
244
+ spawn_opts[:chdir] = chdir
245
+ end
246
+
247
+ encoding_options = {}
248
+ if scrub
249
+ encoding_options[:invalid] = encoding_options[:undef] = :replace
250
+ if replace_string
251
+ encoding_options[:replace] = replace_string
252
+ end
253
+ end
254
+
255
+ log.debug "Executing command", title: title, spawn: spawn_args, mode: mode, stderr: stderr
256
+
257
+ readio = writeio = stderrio = wait_thread = nil
258
+ readio_in_use = writeio_in_use = stderrio_in_use = false
259
+
260
+ if !mode.include?(:stderr) && !mode.include?(:read_with_stderr) && stderr != :discard # connect
261
+ writeio, readio, wait_thread = *Open3.popen2(*spawn_args, spawn_opts)
262
+ elsif mode.include?(:read_with_stderr)
263
+ writeio, readio, wait_thread = *Open3.popen2e(*spawn_args, spawn_opts)
264
+ else
265
+ writeio, readio, stderrio, wait_thread = *Open3.popen3(*spawn_args, spawn_opts)
266
+ end
267
+
268
+ if mode.include?(:write)
269
+ writeio.set_encoding(external_encoding, internal_encoding, encoding_options)
270
+ writeio_in_use = true
271
+ else
272
+ writeio.reopen(IO::NULL) if writeio
273
+ end
274
+ if mode.include?(:read) || mode.include?(:read_with_stderr)
275
+ readio.set_encoding(external_encoding, internal_encoding, encoding_options)
276
+ readio_in_use = true
277
+ else
278
+ readio.reopen(IO::NULL) if readio
279
+ end
280
+ if mode.include?(:stderr)
281
+ stderrio.set_encoding(external_encoding, internal_encoding, encoding_options)
282
+ stderrio_in_use = true
283
+ else
284
+ stderrio.reopen(IO::NULL) if stderrio && stderrio == :discard
285
+ end
286
+
287
+ pid = wait_thread.pid # wait_thread => Process::Waiter
288
+
289
+ io_objects = []
290
+ mode.each do |m|
291
+ io_obj = case m
292
+ when :read then readio
293
+ when :write then writeio
294
+ when :read_with_stderr then readio
295
+ when :stderr then stderrio
296
+ else
297
+ raise "BUG: invalid mode must be checked before here: '#{m}'"
298
+ end
299
+ io_objects << io_obj
300
+ end
301
+
302
+ m = Mutex.new
303
+ m.lock
304
+ thread = thread_create :child_process_callback do
305
+ m.lock # run after plugin thread get pid, thread instance and i/o
306
+ m.unlock
307
+ begin
308
+ @_child_process_processes[pid].alive = true
309
+ block.call(*io_objects) if block_given?
310
+ writeio.close if writeio
311
+ rescue EOFError => e
312
+ log.debug "Process exit and I/O closed", title: title, pid: pid, command: command, arguments: arguments
313
+ rescue IOError => e
314
+ if e.message == 'stream closed' || e.message == 'closed stream' # "closed stream" is of ruby 2.1
315
+ log.debug "Process I/O stream closed", title: title, pid: pid, command: command, arguments: arguments
316
+ else
317
+ log.error "Unexpected I/O error for child process", title: title, pid: pid, command: command, arguments: arguments, error: e
318
+ end
319
+ rescue Errno::EPIPE => e
320
+ log.debug "Broken pipe, child process unexpectedly exits", title: title, pid: pid, command: command, arguments: arguments
321
+ rescue => e
322
+ log.warn "Unexpected error while processing I/O for child process", title: title, pid: pid, command: command, error: e
323
+ end
324
+
325
+ if wait_timeout
326
+ if wait_thread.join(wait_timeout) # Thread#join returns nil when limit expires
327
+ # wait_thread successfully exits
328
+ @_child_process_processes[pid].exit_status = wait_thread.value
329
+ else
330
+ log.warn "child process timed out", title: title, pid: pid, command: command, arguments: arguments
331
+ child_process_kill(@_child_process_processes[pid], force: true)
332
+ @_child_process_processes[pid].exit_status = wait_thread.value
333
+ end
334
+ else
335
+ @_child_process_processes[pid].exit_status = wait_thread.value # with join
336
+ end
337
+ process_info = @_child_process_mutex.synchronize{ @_child_process_processes.delete(pid) }
338
+
339
+ cb = process_info.on_exit_callback_mutex.synchronize do
340
+ cback = process_info.on_exit_callback
341
+ process_info.on_exit_callback = nil
342
+ cback
343
+ end
344
+ if cb
345
+ cb.call(process_info.exit_status) rescue nil
346
+ end
347
+ end
348
+ thread[:_fluentd_plugin_helper_child_process_running] = true
349
+ thread[:_fluentd_plugin_helper_child_process_pid] = pid
350
+ pinfo = ProcessInfo.new(
351
+ title, thread, pid,
352
+ readio, readio_in_use, writeio, writeio_in_use, stderrio, stderrio_in_use,
353
+ wait_thread, false, nil, nil, on_exit_callback, Mutex.new
354
+ )
355
+
356
+ @_child_process_mutex.synchronize do
357
+ @_child_process_processes[pid] = pinfo
358
+ end
359
+ m.unlock
360
+ pid
361
+ end
362
+ end
363
+ end
364
+ end
@@ -0,0 +1,331 @@
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/config/types'
18
+ require 'fluent/config/element'
19
+
20
+ module Fluent
21
+ module PluginHelper
22
+ module CompatParameters
23
+ # This plugin helper is to bring old-fashioned buffer/other
24
+ # configuration parameters to v0.14 plugin API configurations.
25
+ # This helper is mainly to convert plugins from v0.12 API
26
+ # to v0.14 API safely, without breaking user deployment.
27
+
28
+ BUFFER_PARAMS = {
29
+ "buffer_type" => "@type",
30
+ "buffer_path" => "path",
31
+ "num_threads" => "flush_thread_count",
32
+ "flush_interval" => "flush_interval",
33
+ "try_flush_interval" => "flush_thread_interval",
34
+ "queued_chunk_flush_interval" => "flush_thread_burst_interval",
35
+ "disable_retry_limit" => "retry_forever",
36
+ "retry_limit" => "retry_max_times",
37
+ "max_retry_wait" => "retry_max_interval",
38
+ "buffer_chunk_limit" => "chunk_limit_size",
39
+ "buffer_queue_limit" => "queue_limit_length",
40
+ "buffer_queue_full_action" => "overflow_action",
41
+ "flush_at_shutdown" => "flush_at_shutdown",
42
+ }
43
+
44
+ BUFFER_TIME_SLICED_PARAMS = {
45
+ "time_slice_format" => nil,
46
+ "time_slice_wait" => "timekey_wait",
47
+ "timezone" => "timekey_zone",
48
+ }
49
+
50
+ PARSER_PARAMS = {
51
+ "format" => nil,
52
+ "types" => nil,
53
+ "types_delimiter" => nil,
54
+ "types_label_delimiter" => nil,
55
+ "keys" => "keys", # CSVParser, TSVParser (old ValuesParser)
56
+ "time_key" => "time_key",
57
+ "time_format" => "time_format",
58
+ "localtim" => nil,
59
+ "utc" => nil,
60
+ "delimiter" => "delimiter",
61
+ "keep_time_key" => "keep_time_key",
62
+ "null_empty_string" => "null_empty_string",
63
+ "null_value_pattern" => "null_value_pattern",
64
+ "json_parser" => "json_parser", # JSONParser
65
+ "label_delimiter" => "label_delimiter", # LabeledTSVParser
66
+ "format_firstline" => "format_firstline", # MultilineParser
67
+ "message_key" => "message_key", # NoneParser
68
+ "with_priority" => "with_priority", # SyslogParser
69
+ # There has been no parsers which can handle timezone in v0.12
70
+ }
71
+
72
+ INJECT_PARAMS = {
73
+ "include_time_key" => nil,
74
+ "time_key" => "time_key",
75
+ "time_format" => "time_format",
76
+ "timezone" => "timezone",
77
+ "include_tag_key" => nil,
78
+ "tag_key" => "tag_key",
79
+ "localtime" => nil,
80
+ "utc" => nil,
81
+ }
82
+
83
+ EXTRACT_PARAMS = {
84
+ "time_key" => "time_key",
85
+ "time_format" => "time_format",
86
+ "timezone" => "timezone",
87
+ "tag_key" => "tag_key",
88
+ "localtime" => nil,
89
+ "utc" => nil,
90
+ }
91
+
92
+ FORMATTER_PARAMS = {
93
+ "format" => "@type",
94
+ "delimiter" => "delimiter",
95
+ "force_quotes" => "force_quotes", # CsvFormatter
96
+ "keys" => "keys", # TSVFormatter
97
+ "fields" => "fields", # CsvFormatter
98
+ "json_parser" => "json_parser", # JSONFormatter
99
+ "label_delimiter" => "label_delimiter", # LabeledTSVFormatter
100
+ "output_time" => "output_time", # OutFileFormatter
101
+ "output_tag" => "output_tag", # OutFileFormatter
102
+ "localtime" => "localtime", # OutFileFormatter
103
+ "utc" => "utc", # OutFileFormatter
104
+ "timezone" => "timezone", # OutFileFormatter
105
+ "message_key" => "message_key", # SingleValueFormatter
106
+ "add_newline" => "add_newline", # SingleValueFormatter
107
+ "output_type" => "output_type", # StdoutFormatter
108
+ }
109
+
110
+ def compat_parameters_convert(conf, *types, **kwargs)
111
+ types.each do |type|
112
+ case type
113
+ when :buffer
114
+ compat_parameters_buffer(conf, **kwargs)
115
+ when :inject
116
+ compat_parameters_inject(conf)
117
+ when :extract
118
+ compat_parameters_extract(conf)
119
+ when :parser
120
+ compat_parameters_parser(conf)
121
+ when :formatter
122
+ compat_parameters_formatter(conf)
123
+ else
124
+ raise "BUG: unknown compat_parameters type: #{type}"
125
+ end
126
+ end
127
+
128
+ conf
129
+ end
130
+
131
+ def compat_parameters_buffer(conf, default_chunk_key: '')
132
+ # return immediately if <buffer> section exists, or any buffer-related parameters don't exist
133
+ return unless conf.elements('buffer').empty?
134
+ return if (BUFFER_PARAMS.keys + BUFFER_TIME_SLICED_PARAMS.keys).all?{|k| !conf.has_key?(k) }
135
+
136
+ # TODO: warn obsolete parameters if these are deprecated
137
+ buffer_params = BUFFER_PARAMS.merge(BUFFER_TIME_SLICED_PARAMS)
138
+ hash = compat_parameters_copy_to_subsection_attributes(conf, buffer_params) do |compat_key, value|
139
+ if compat_key == 'buffer_queue_full_action' && value == 'exception'
140
+ 'throw_exception'
141
+ else
142
+ value
143
+ end
144
+ end
145
+
146
+ chunk_key = default_chunk_key
147
+
148
+ if conf.has_key?('time_slice_format')
149
+ chunk_key = 'time'
150
+ hash['timekey'] = case conf['time_slice_format']
151
+ when /\%S/ then 1
152
+ when /\%M/ then 60
153
+ when /\%H/ then 3600
154
+ when /\%d/ then 86400
155
+ else
156
+ raise Fluent::ConfigError, "time_slice_format only with %Y or %m is too long"
157
+ end
158
+ if conf.has_key?('localtime') || conf.has_key?('utc')
159
+ if conf.has_key?('localtime') && conf.has_key?('utc')
160
+ raise Fluent::ConfigError, "both of utc and localtime are specified, use only one of them"
161
+ elsif conf.has_key?('localtime')
162
+ hash['timekey_use_utc'] = !(Fluent::Config.bool_value(conf['localtime']))
163
+ elsif conf.has_key?('utc')
164
+ hash['timekey_use_utc'] = Fluent::Config.bool_value(conf['utc'])
165
+ end
166
+ end
167
+ else
168
+ if chunk_key == 'time'
169
+ hash['timekey'] = 86400 # TimeSliceOutput.time_slice_format default value is '%Y%m%d'
170
+ end
171
+ end
172
+
173
+ e = Fluent::Config::Element.new('buffer', chunk_key, hash, [])
174
+ conf.elements << e
175
+
176
+ conf
177
+ end
178
+
179
+ def compat_parameters_inject(conf)
180
+ return unless conf.elements('inject').empty?
181
+ return if INJECT_PARAMS.keys.all?{|k| !conf.has_key?(k) }
182
+
183
+ # TODO: warn obsolete parameters if these are deprecated
184
+ hash = compat_parameters_copy_to_subsection_attributes(conf, INJECT_PARAMS)
185
+
186
+ if conf.has_key?('include_time_key') && Fluent::Config.bool_value(conf['include_time_key'])
187
+ hash['time_key'] ||= 'time'
188
+ hash['time_type'] ||= 'string'
189
+ end
190
+ if conf.has_key?('time_as_epoch') && Fluent::Config.bool_value(conf['time_as_epoch'])
191
+ hash['time_key'] ||= 'time'
192
+ hash['time_type'] = 'unixtime'
193
+ end
194
+ if conf.has_key?('localtime') || conf.has_key?('utc')
195
+ if conf.has_key?('localtime') && conf.has_key?('utc')
196
+ raise Fluent::ConfigError, "both of utc and localtime are specified, use only one of them"
197
+ elsif conf.has_key?('localtime')
198
+ hash['localtime'] = Fluent::Config.bool_value(conf['localtime'])
199
+ elsif conf.has_key?('utc')
200
+ hash['localtime'] = !(Fluent::Config.bool_value(conf['utc']))
201
+ # Specifying "localtime false" means using UTC in TimeFormatter
202
+ # And specifying "utc" is different from specifying "timezone +0000"(it's not always UTC).
203
+ # There are difference between "Z" and "+0000" in timezone formatting.
204
+ # TODO: add kwargs to TimeFormatter to specify "using localtime", "using UTC" or "using specified timezone" in more explicit way
205
+ end
206
+ end
207
+
208
+ if conf.has_key?('include_tag_key') && Fluent::Config.bool_value(conf['include_tag_key'])
209
+ hash['tag_key'] ||= 'tag'
210
+ end
211
+
212
+ e = Fluent::Config::Element.new('inject', '', hash, [])
213
+ conf.elements << e
214
+
215
+ conf
216
+ end
217
+
218
+ def compat_parameters_extract(conf)
219
+ return unless conf.elements('extract').empty?
220
+ return if EXTRACT_PARAMS.keys.all?{|k| !conf.has_key?(k) } && !conf.has_key?('format')
221
+
222
+ # TODO: warn obsolete parameters if these are deprecated
223
+ hash = compat_parameters_copy_to_subsection_attributes(conf, EXTRACT_PARAMS)
224
+
225
+ if conf.has_key?('time_as_epoch') && Fluent::Config.bool_value(conf['time_as_epoch'])
226
+ hash['time_key'] ||= 'time'
227
+ hash['time_type'] = 'unixtime'
228
+ elsif conf.has_key?('format') && conf["format"].start_with?("/") && conf["format"].end_with?("/") # old-style regexp parser
229
+ hash['time_key'] ||= 'time'
230
+ hash['time_type'] ||= 'string'
231
+ end
232
+ if conf.has_key?('localtime') || conf.has_key?('utc')
233
+ if conf.has_key?('localtime') && conf.has_key?('utc')
234
+ raise Fluent::ConfigError, "both of utc and localtime are specified, use only one of them"
235
+ elsif conf.has_key?('localtime')
236
+ hash['localtime'] = Fluent::Config.bool_value(conf['localtime'])
237
+ elsif conf.has_key?('utc')
238
+ hash['localtime'] = !(Fluent::Config.bool_value(conf['utc']))
239
+ # Specifying "localtime false" means using UTC in TimeFormatter
240
+ # And specifying "utc" is different from specifying "timezone +0000"(it's not always UTC).
241
+ # There are difference between "Z" and "+0000" in timezone formatting.
242
+ # TODO: add kwargs to TimeFormatter to specify "using localtime", "using UTC" or "using specified timezone" in more explicit way
243
+ end
244
+ end
245
+
246
+ e = Fluent::Config::Element.new('extract', '', hash, [])
247
+ conf.elements << e
248
+
249
+ conf
250
+ end
251
+
252
+ def compat_parameters_parser(conf)
253
+ return unless conf.elements('parse').empty?
254
+ return if PARSER_PARAMS.keys.all?{|k| !conf.has_key?(k) }
255
+
256
+ # TODO: warn obsolete parameters if these are deprecated
257
+ hash = compat_parameters_copy_to_subsection_attributes(conf, PARSER_PARAMS)
258
+
259
+ if conf["format"]
260
+ if conf["format"].start_with?("/") && conf["format"].end_with?("/")
261
+ hash["@type"] = "regexp"
262
+ hash["expression"] = conf["format"][1..-2]
263
+ else
264
+ hash["@type"] = conf["format"]
265
+ end
266
+ end
267
+
268
+ if conf["types"]
269
+ delimiter = conf["types_delimiter"] || ','
270
+ label_delimiter = conf["types_label_delimiter"] || ':'
271
+ types = {}
272
+ conf['types'].split(delimiter).each do |pair|
273
+ key, value = pair.split(label_delimiter, 2)
274
+ types[key] = value
275
+ end
276
+ hash["types"] = JSON.dump(types)
277
+ end
278
+ if conf.has_key?('localtime') || conf.has_key?('utc')
279
+ if conf.has_key?('localtime') && conf.has_key?('utc')
280
+ raise Fluent::ConfigError, "both of utc and localtime are specified, use only one of them"
281
+ elsif conf.has_key?('localtime')
282
+ hash['localtime'] = Fluent::Config.bool_value(conf['localtime'])
283
+ elsif conf.has_key?('utc')
284
+ hash['localtime'] = !(Fluent::Config.bool_value(conf['utc']))
285
+ # Specifying "localtime false" means using UTC in TimeFormatter
286
+ # And specifying "utc" is different from specifying "timezone +0000"(it's not always UTC).
287
+ # There are difference between "Z" and "+0000" in timezone formatting.
288
+ # TODO: add kwargs to TimeFormatter to specify "using localtime", "using UTC" or "using specified timezone" in more explicit way
289
+ end
290
+ end
291
+
292
+ e = Fluent::Config::Element.new('parse', '', hash, [])
293
+ conf.elements << e
294
+
295
+ conf
296
+ end
297
+
298
+ def compat_parameters_formatter(conf)
299
+ return unless conf.elements('format').empty?
300
+ return if FORMATTER_PARAMS.keys.all?{|k| !conf.has_key?(k) }
301
+
302
+ # TODO: warn obsolete parameters if these are deprecated
303
+ hash = compat_parameters_copy_to_subsection_attributes(conf, FORMATTER_PARAMS)
304
+
305
+ if conf.has_key?('time_as_epoch') && Fluent::Config.bool_value(conf['time_as_epoch'])
306
+ hash['time_type'] = 'unixtime'
307
+ end
308
+
309
+ e = Fluent::Config::Element.new('format', '', hash, [])
310
+ conf.elements << e
311
+
312
+ conf
313
+ end
314
+
315
+ def compat_parameters_copy_to_subsection_attributes(conf, params, &block)
316
+ hash = {}
317
+ params.each do |compat, current|
318
+ next unless current
319
+ if conf.has_key?(compat)
320
+ if block_given?
321
+ hash[current] = block.call(compat, conf[compat])
322
+ else
323
+ hash[current] = conf[compat]
324
+ end
325
+ end
326
+ end
327
+ hash
328
+ end
329
+ end
330
+ end
331
+ end