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,873 @@
1
+ require_relative '../helper'
2
+ require 'fluent/test/driver/output'
3
+ require 'fluent/plugin/out_file'
4
+ require 'fileutils'
5
+ require 'time'
6
+ require 'timecop'
7
+ require 'zlib'
8
+
9
+ class FileOutputTest < Test::Unit::TestCase
10
+ def setup
11
+ Fluent::Test.setup
12
+ FileUtils.rm_rf(TMP_DIR)
13
+ FileUtils.mkdir_p(TMP_DIR)
14
+ end
15
+
16
+ TMP_DIR = File.expand_path(File.dirname(__FILE__) + "/../tmp/out_file#{ENV['TEST_ENV_NUMBER']}")
17
+ SYMLINK_PATH = File.expand_path("#{TMP_DIR}/current")
18
+
19
+ CONFIG = %[
20
+ path #{TMP_DIR}/out_file_test
21
+ compress gz
22
+ utc
23
+ ]
24
+
25
+ def create_driver(conf = CONFIG, opts = {})
26
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::FileOutput, opts: opts).configure(conf)
27
+ end
28
+
29
+ sub_test_case 'configuration' do
30
+ test 'basic configuration' do
31
+ d = create_driver %[
32
+ path test_path
33
+ compress gz
34
+ ]
35
+ assert_equal 'test_path', d.instance.path
36
+ assert_equal :gz, d.instance.compress
37
+ assert_equal :gzip, d.instance.instance_eval{ @compress_method }
38
+ end
39
+
40
+ test 'using root_dir for buffer path' do
41
+ system_conf_opts = {'root_dir' => File.join(TMP_DIR, 'testrootdir')}
42
+ buf_conf = config_element('buffer', '', {'flush_interval' => '1s'})
43
+ conf = config_element('match', '**', {'@id' => 'myout', 'path' => 'test_path', 'append' => 'true'}, [buf_conf])
44
+ d = create_driver(conf, system_conf_opts)
45
+
46
+ assert_equal 'test_path', d.instance.path
47
+ assert d.instance.append
48
+
49
+ assert d.instance.buffer.respond_to?(:path) # file buffer
50
+ assert_equal 1, d.instance.buffer_config.flush_interval
51
+
52
+ assert_equal File.join(TMP_DIR, 'testrootdir', 'worker0', 'myout'), d.instance.plugin_root_dir
53
+
54
+ buffer_path_under_root_dir = File.join(TMP_DIR, 'testrootdir', 'worker0', 'myout', 'buffer', 'buffer.*.log')
55
+ assert_equal buffer_path_under_root_dir, d.instance.buffer.path
56
+ end
57
+
58
+ test 'path should be writable' do
59
+ assert_raise(Fluent::ConfigError.new("'path' parameter is required")) do
60
+ create_driver ""
61
+ end
62
+
63
+ assert_nothing_raised do
64
+ create_driver %[path #{TMP_DIR}/test_path]
65
+ end
66
+
67
+ assert_nothing_raised do
68
+ FileUtils.mkdir_p("#{TMP_DIR}/test_dir")
69
+ File.chmod(0777, "#{TMP_DIR}/test_dir")
70
+ create_driver %[path #{TMP_DIR}/test_dir/foo/bar/baz]
71
+ end
72
+
73
+ assert_raise(Fluent::ConfigError) do
74
+ FileUtils.mkdir_p("#{TMP_DIR}/test_dir")
75
+ File.chmod(0555, "#{TMP_DIR}/test_dir")
76
+ create_driver %[path #{TMP_DIR}/test_dir/foo/bar/baz]
77
+ end
78
+ end
79
+
80
+ test 'default timezone is localtime' do
81
+ d = create_driver(%[path #{TMP_DIR}/out_file_test])
82
+ time = event_time("2011-01-02 13:14:15 UTC")
83
+
84
+ with_timezone(Fluent.windows? ? 'NST-8' : 'Asia/Taipei') do
85
+ d.run(default_tag: 'test') do
86
+ d.feed(time, {"a"=>1})
87
+ end
88
+ end
89
+ assert_equal 1, d.formatted.size
90
+ assert_equal %[2011-01-02T21:14:15+08:00\ttest\t{"a":1}\n], d.formatted[0]
91
+ end
92
+
93
+ test 'no configuration error raised for basic configuration using "*" (v0.12 style)' do
94
+ conf = config_element('match', '**', {
95
+ 'path' => "#{TMP_DIR}/test_out.*.log",
96
+ 'time_slice_format' => '%Y%m%d',
97
+ })
98
+ assert_nothing_raised do
99
+ create_driver(conf)
100
+ end
101
+ end
102
+
103
+ test 'configuration error raised if specified directory via template is not writable' do
104
+ Timecop.freeze(Time.parse("2016-10-04 21:33:27 UTC")) do
105
+ conf = config_element('match', '**', {
106
+ 'path' => "#{TMP_DIR}/prohibited/${tag}/file.%Y%m%d.log",
107
+ }, [ config_element('buffer', 'time,tag', {'timekey' => 86400, 'timekey_zone' => '+0000'}) ])
108
+ FileUtils.mkdir_p("#{TMP_DIR}/prohibited")
109
+ File.chmod(0555, "#{TMP_DIR}/prohibited")
110
+ assert_raise Fluent::ConfigError.new("out_file: `#{TMP_DIR}/prohibited/a/file.20161004.log_**.log` is not writable") do
111
+ create_driver(conf)
112
+ end
113
+ end
114
+ end
115
+
116
+ test 'configuration using inject/format/buffer sections fully' do
117
+ conf = config_element('match', '**', {
118
+ 'path' => "#{TMP_DIR}/${tag}/${type}/conf_test.%Y%m%d.%H%M.log",
119
+ 'add_path_suffix' => 'false',
120
+ 'append' => "true",
121
+ 'symlink_path' => "#{TMP_DIR}/conf_test.current.log",
122
+ 'compress' => 'gzip',
123
+ 'recompress' => 'true',
124
+ }, [
125
+ config_element('inject', '', {
126
+ 'hostname_key' => 'hostname',
127
+ 'hostname' => 'testing.local',
128
+ 'tag_key' => 'tag',
129
+ 'time_key' => 'time',
130
+ 'time_type' => 'string',
131
+ 'time_format' => '%Y/%m/%d %H:%M:%S %z',
132
+ 'timezone' => '+0900',
133
+ }),
134
+ config_element('format', '', {
135
+ '@type' => 'out_file',
136
+ 'include_tag' => 'true',
137
+ 'include_time' => 'true',
138
+ 'delimiter' => 'COMMA',
139
+ 'time_type' => 'string',
140
+ 'time_format' => '%Y-%m-%d %H:%M:%S %z',
141
+ 'utc' => 'true',
142
+ }),
143
+ config_element('buffer', 'time,tag,type', {
144
+ '@type' => 'file',
145
+ 'timekey' => '15m',
146
+ 'timekey_wait' => '5s',
147
+ 'timekey_zone' => '+0000',
148
+ 'path' => "#{TMP_DIR}/buf_conf_test",
149
+ 'chunk_limit_size' => '50m',
150
+ 'total_limit_size' => '1g',
151
+ 'compress' => 'gzip',
152
+ }),
153
+ ])
154
+ assert_nothing_raised do
155
+ create_driver(conf)
156
+ end
157
+ end
158
+
159
+ test 'configured as secondary with primary using chunk_key_tag and not using chunk_key_time' do
160
+ require 'fluent/plugin/out_null'
161
+ conf = config_element('match', '**', {
162
+ }, [
163
+ config_element('buffer', 'tag', {
164
+ }),
165
+ config_element('secondary', '', {
166
+ '@type' => 'file',
167
+ 'path' => "#{TMP_DIR}/testing_to_dump_by_out_file",
168
+ }),
169
+ ])
170
+ assert_nothing_raised do
171
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::NullOutput).configure(conf)
172
+ end
173
+ end
174
+ end
175
+
176
+ sub_test_case 'fully configured output' do
177
+ setup do
178
+ Timecop.freeze(Time.parse("2016-10-03 23:58:00 UTC"))
179
+ conf = config_element('match', '**', {
180
+ 'path' => "#{TMP_DIR}/${tag}/${type}/full.%Y%m%d.%H%M.log",
181
+ 'add_path_suffix' => 'false',
182
+ 'append' => "true",
183
+ 'symlink_path' => "#{TMP_DIR}/full.current.log",
184
+ 'compress' => 'gzip',
185
+ 'recompress' => 'true',
186
+ }, [
187
+ config_element('inject', '', {
188
+ 'hostname_key' => 'hostname',
189
+ 'hostname' => 'testing.local',
190
+ 'tag_key' => 'tag',
191
+ 'time_key' => 'time',
192
+ 'time_type' => 'string',
193
+ 'time_format' => '%Y/%m/%d %H:%M:%S %z',
194
+ 'timezone' => '+0900',
195
+ }),
196
+ config_element('format', '', {
197
+ '@type' => 'out_file',
198
+ 'include_tag' => 'true',
199
+ 'include_time' => 'true',
200
+ 'delimiter' => 'COMMA',
201
+ 'time_type' => 'string',
202
+ 'time_format' => '%Y-%m-%d %H:%M:%S %z',
203
+ 'utc' => 'true',
204
+ }),
205
+ config_element('buffer', 'time,tag,type', {
206
+ '@type' => 'file',
207
+ 'timekey' => '15m',
208
+ 'timekey_wait' => '5s',
209
+ 'timekey_zone' => '+0000',
210
+ 'path' => "#{TMP_DIR}/buf_full",
211
+ 'chunk_limit_size' => '50m',
212
+ 'total_limit_size' => '1g',
213
+ 'compress' => 'gzip',
214
+ }),
215
+ ])
216
+ @d = create_driver(conf)
217
+ end
218
+
219
+ teardown do
220
+ FileUtils.rm_rf("#{TMP_DIR}/buf_full")
221
+ FileUtils.rm_rf("#{TMP_DIR}/my.data")
222
+ FileUtils.rm_rf("#{TMP_DIR}/your.data")
223
+ FileUtils.rm_rf("#{TMP_DIR}/full.current.log")
224
+ Timecop.return
225
+ end
226
+
227
+ test 'can format/write data correctly' do
228
+ d = @d
229
+
230
+ assert_equal 50*1024*1024, d.instance.buffer.chunk_limit_size
231
+ assert_equal 1*1024*1024*1024, d.instance.buffer.total_limit_size
232
+
233
+ assert !(File.symlink?("#{TMP_DIR}/full.current.log"))
234
+
235
+ t1 = event_time("2016-10-03 23:58:09 UTC")
236
+ t2 = event_time("2016-10-03 23:59:33 UTC")
237
+ t3 = event_time("2016-10-03 23:59:57 UTC")
238
+ t4 = event_time("2016-10-04 00:00:17 UTC")
239
+ t5 = event_time("2016-10-04 00:01:59 UTC")
240
+
241
+ Timecop.freeze(Time.parse("2016-10-03 23:58:30 UTC"))
242
+
243
+ d.run(start: true, flush: false, shutdown: false) do
244
+ d.feed('my.data', t1, {"type" => "a", "message" => "data raw content"})
245
+ d.feed('my.data', t2, {"type" => "a", "message" => "data raw content"})
246
+ d.feed('your.data', t3, {"type" => "a", "message" => "data raw content"})
247
+ end
248
+
249
+ assert_equal 3, d.formatted.size
250
+
251
+ assert Dir.exist?("#{TMP_DIR}/buf_full")
252
+ assert !(Dir.exist?("#{TMP_DIR}/my.data/a"))
253
+ assert !(Dir.exist?("#{TMP_DIR}/your.data/a"))
254
+ buffer_files = Dir.entries("#{TMP_DIR}/buf_full").reject{|e| e =~ /^\.+$/ }
255
+ assert_equal 2, buffer_files.select{|n| n.end_with?('.meta') }.size
256
+ assert_equal 2, buffer_files.select{|n| !n.end_with?('.meta') }.size
257
+
258
+ m1 = d.instance.metadata('my.data', t1, {"type" => "a"})
259
+ m2 = d.instance.metadata('your.data', t3, {"type" => "a"})
260
+
261
+ assert_equal 2, d.instance.buffer.stage.size
262
+ b1_path = d.instance.buffer.stage[m1].path
263
+ b1_size = File.lstat(b1_path).size
264
+
265
+ unless Fluent.windows?
266
+ assert File.symlink?("#{TMP_DIR}/full.current.log")
267
+ assert_equal d.instance.buffer.stage[m2].path, File.readlink("#{TMP_DIR}/full.current.log")
268
+ end
269
+
270
+ Timecop.freeze(Time.parse("2016-10-04 00:00:06 UTC"))
271
+
272
+ d.run(start: false, flush: true, shutdown: true) do
273
+ d.feed('my.data', t4, {"type" => "a", "message" => "data raw content"})
274
+ d.feed('your.data', t5, {"type" => "a", "message" => "data raw content"})
275
+ end
276
+
277
+ assert Dir.exist?("#{TMP_DIR}/buf_full")
278
+ assert Dir.exist?("#{TMP_DIR}/my.data/a")
279
+ assert Dir.exist?("#{TMP_DIR}/your.data/a")
280
+
281
+ buffer_files = Dir.entries("#{TMP_DIR}/buf_full").reject{|e| e =~ /^\.+$/ }
282
+ assert_equal 0, buffer_files.size
283
+
284
+ assert File.exist?("#{TMP_DIR}/my.data/a/full.20161003.2345.log.gz")
285
+ assert File.exist?("#{TMP_DIR}/my.data/a/full.20161004.0000.log.gz")
286
+ assert File.exist?("#{TMP_DIR}/your.data/a/full.20161003.2345.log.gz")
287
+ assert File.exist?("#{TMP_DIR}/your.data/a/full.20161004.0000.log.gz")
288
+
289
+ assert{ File.lstat("#{TMP_DIR}/my.data/a/full.20161003.2345.log.gz").size < b1_size } # recompress
290
+
291
+ assert_equal 5, d.formatted.size
292
+
293
+ r1 = %!2016-10-03 23:58:09 +0000,my.data,{"type":"a","message":"data raw content","hostname":"testing.local","tag":"my.data","time":"2016/10/04 08:58:09 +0900"}\n!
294
+ r2 = %!2016-10-03 23:59:33 +0000,my.data,{"type":"a","message":"data raw content","hostname":"testing.local","tag":"my.data","time":"2016/10/04 08:59:33 +0900"}\n!
295
+ r3 = %!2016-10-03 23:59:57 +0000,your.data,{"type":"a","message":"data raw content","hostname":"testing.local","tag":"your.data","time":"2016/10/04 08:59:57 +0900"}\n!
296
+ r4 = %!2016-10-04 00:00:17 +0000,my.data,{"type":"a","message":"data raw content","hostname":"testing.local","tag":"my.data","time":"2016/10/04 09:00:17 +0900"}\n!
297
+ r5 = %!2016-10-04 00:01:59 +0000,your.data,{"type":"a","message":"data raw content","hostname":"testing.local","tag":"your.data","time":"2016/10/04 09:01:59 +0900"}\n!
298
+ assert_equal r1, d.formatted[0]
299
+ assert_equal r2, d.formatted[1]
300
+ assert_equal r3, d.formatted[2]
301
+ assert_equal r4, d.formatted[3]
302
+ assert_equal r5, d.formatted[4]
303
+
304
+ read_gunzip = ->(path){ File.open(path){|fio| Zlib::GzipReader.open(fio){|io| io.read } } }
305
+ assert_equal r1 + r2, read_gunzip.call("#{TMP_DIR}/my.data/a/full.20161003.2345.log.gz")
306
+ assert_equal r3, read_gunzip.call("#{TMP_DIR}/your.data/a/full.20161003.2345.log.gz")
307
+ assert_equal r4, read_gunzip.call("#{TMP_DIR}/my.data/a/full.20161004.0000.log.gz")
308
+ assert_equal r5, read_gunzip.call("#{TMP_DIR}/your.data/a/full.20161004.0000.log.gz")
309
+ end
310
+ end
311
+
312
+ sub_test_case 'format' do
313
+ test 'timezone UTC specified' do
314
+ d = create_driver
315
+
316
+ time = event_time("2011-01-02 13:14:15 UTC")
317
+ d.run(default_tag: 'test') do
318
+ d.feed(time, {"a"=>1})
319
+ d.feed(time, {"a"=>2})
320
+ end
321
+ assert_equal 2, d.formatted.size
322
+ assert_equal %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n], d.formatted[0]
323
+ assert_equal %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n], d.formatted[1]
324
+ end
325
+
326
+ test 'time formatted with specified timezone, using area name' do
327
+ d = create_driver %[
328
+ path #{TMP_DIR}/out_file_test
329
+ timezone Asia/Taipei
330
+ ]
331
+
332
+ time = event_time("2011-01-02 13:14:15 UTC")
333
+ d.run(default_tag: 'test') do
334
+ d.feed(time, {"a"=>1})
335
+ end
336
+ assert_equal 1, d.formatted.size
337
+ assert_equal %[2011-01-02T21:14:15+08:00\ttest\t{"a":1}\n], d.formatted[0]
338
+ end
339
+
340
+ test 'time formatted with specified timezone, using offset' do
341
+ d = create_driver %[
342
+ path #{TMP_DIR}/out_file_test
343
+ timezone -03:30
344
+ ]
345
+
346
+ time = event_time("2011-01-02 13:14:15 UTC")
347
+ d.run(default_tag: 'test') do
348
+ d.feed(time, {"a"=>1})
349
+ end
350
+ assert_equal 1, d.formatted.size
351
+ assert_equal %[2011-01-02T09:44:15-03:30\ttest\t{"a":1}\n], d.formatted[0]
352
+ end
353
+
354
+ test 'configuration error raised for invalid timezone' do
355
+ assert_raise(Fluent::ConfigError) do
356
+ create_driver %[
357
+ path #{TMP_DIR}/out_file_test
358
+ timezone Invalid/Invalid
359
+ ]
360
+ end
361
+ end
362
+ end
363
+
364
+ def check_gzipped_result(path, expect)
365
+ # Zlib::GzipReader has a bug of concatenated file: https://bugs.ruby-lang.org/issues/9790
366
+ # Following code from https://www.ruby-forum.com/topic/971591#979520
367
+ result = ''
368
+ File.open(path, "rb") { |io|
369
+ loop do
370
+ gzr = Zlib::GzipReader.new(io)
371
+ result << gzr.read
372
+ unused = gzr.unused
373
+ gzr.finish
374
+ break if unused.nil?
375
+ io.pos -= unused.length
376
+ end
377
+ }
378
+
379
+ assert_equal expect, result
380
+ end
381
+
382
+ sub_test_case 'write' do
383
+ test 'basic case' do
384
+ d = create_driver
385
+
386
+ assert_false File.exist?("#{TMP_DIR}/out_file_test.20110102_0.log.gz")
387
+
388
+ time = event_time("2011-01-02 13:14:15 UTC")
389
+ d.run(default_tag: 'test') do
390
+ d.feed(time, {"a"=>1})
391
+ d.feed(time, {"a"=>2})
392
+ end
393
+
394
+ assert File.exist?("#{TMP_DIR}/out_file_test.20110102_0.log.gz")
395
+ check_gzipped_result("#{TMP_DIR}/out_file_test.20110102_0.log.gz", %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n] + %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n])
396
+ end
397
+ end
398
+
399
+ sub_test_case 'file/directory permissions' do
400
+ TMP_DIR_WITH_SYSTEM = File.expand_path(File.dirname(__FILE__) + "/../tmp/out_file_system#{ENV['TEST_ENV_NUMBER']}")
401
+ # 0750 interprets as "488". "488".to_i(8) # => 4. So, it makes wrong permission. Umm....
402
+ OVERRIDE_DIR_PERMISSION = 750
403
+ OVERRIDE_FILE_PERMISSION = 0620
404
+ CONFIG_WITH_SYSTEM = %[
405
+ path #{TMP_DIR_WITH_SYSTEM}/out_file_test
406
+ compress gz
407
+ utc
408
+ <system>
409
+ file_permission #{OVERRIDE_FILE_PERMISSION}
410
+ dir_permission #{OVERRIDE_DIR_PERMISSION}
411
+ </system>
412
+ ]
413
+
414
+ setup do
415
+ omit "NTFS doesn't support UNIX like permissions" if Fluent.windows?
416
+ FileUtils.rm_rf(TMP_DIR_WITH_SYSTEM)
417
+ end
418
+
419
+ def parse_system(text)
420
+ basepath = File.expand_path(File.dirname(__FILE__) + '/../../')
421
+ Fluent::Config.parse(text, '(test)', basepath, true).elements.find { |e| e.name == 'system' }
422
+ end
423
+
424
+ test 'write to file with permission specifications' do
425
+ system_conf = parse_system(CONFIG_WITH_SYSTEM)
426
+ sc = Fluent::SystemConfig.new(system_conf)
427
+ Fluent::Engine.init(sc)
428
+ d = create_driver CONFIG_WITH_SYSTEM
429
+
430
+ assert_false File.exist?("#{TMP_DIR_WITH_SYSTEM}/out_file_test.20110102_0.log.gz")
431
+
432
+ time = event_time("2011-01-02 13:14:15 UTC")
433
+ d.run(default_tag: 'test') do
434
+ d.feed(time, {"a"=>1})
435
+ d.feed(time, {"a"=>2})
436
+ end
437
+
438
+ assert File.exist?("#{TMP_DIR_WITH_SYSTEM}/out_file_test.20110102_0.log.gz")
439
+
440
+ check_gzipped_result("#{TMP_DIR_WITH_SYSTEM}/out_file_test.20110102_0.log.gz", %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n] + %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n])
441
+ dir_mode = "%o" % File::stat(TMP_DIR_WITH_SYSTEM).mode
442
+ assert_equal(OVERRIDE_DIR_PERMISSION, dir_mode[-3, 3].to_i)
443
+ file_mode = "%o" % File::stat("#{TMP_DIR_WITH_SYSTEM}/out_file_test.20110102_0.log.gz").mode
444
+ assert_equal(OVERRIDE_FILE_PERMISSION, file_mode[-3, 3].to_i)
445
+ end
446
+ end
447
+
448
+ sub_test_case 'format specified' do
449
+ test 'json' do
450
+ d = create_driver [CONFIG, 'format json', 'include_time_key true', 'time_as_epoch'].join("\n")
451
+
452
+ time = event_time("2011-01-02 13:14:15 UTC")
453
+ d.run(default_tag: 'test') do
454
+ d.feed(time, {"a"=>1})
455
+ d.feed(time, {"a"=>2})
456
+ end
457
+
458
+ path = d.instance.last_written_path
459
+ check_gzipped_result(path, %[#{Yajl.dump({"a" => 1, 'time' => time.to_i})}\n] + %[#{Yajl.dump({"a" => 2, 'time' => time.to_i})}\n])
460
+ end
461
+
462
+ test 'ltsv' do
463
+ d = create_driver [CONFIG, 'format ltsv', 'include_time_key true'].join("\n")
464
+
465
+ time = event_time("2011-01-02 13:14:15 UTC")
466
+ d.run(default_tag: 'test') do
467
+ d.feed(time, {"a"=>1})
468
+ d.feed(time, {"a"=>2})
469
+ end
470
+
471
+ path = d.instance.last_written_path
472
+ check_gzipped_result(path, %[a:1\ttime:2011-01-02T13:14:15Z\n] + %[a:2\ttime:2011-01-02T13:14:15Z\n])
473
+ end
474
+
475
+ test 'single_value' do
476
+ d = create_driver [CONFIG, 'format single_value', 'message_key a'].join("\n")
477
+
478
+ time = event_time("2011-01-02 13:14:15 UTC")
479
+ d.run(default_tag: 'test') do
480
+ d.feed(time, {"a"=>1})
481
+ d.feed(time, {"a"=>2})
482
+ end
483
+
484
+ path = d.instance.last_written_path
485
+ check_gzipped_result(path, %[1\n] + %[2\n])
486
+ end
487
+ end
488
+
489
+ test 'path with index number' do
490
+ time = event_time("2011-01-02 13:14:15 UTC")
491
+ formatted_lines = %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n] + %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n]
492
+
493
+ write_once = ->(){
494
+ d = create_driver
495
+ d.run(default_tag: 'test'){
496
+ d.feed(time, {"a"=>1})
497
+ d.feed(time, {"a"=>2})
498
+ }
499
+ d.instance.last_written_path
500
+ }
501
+
502
+ assert !File.exist?("#{TMP_DIR}/out_file_test.20110102_0.log.gz")
503
+
504
+ path = write_once.call
505
+ assert_equal "#{TMP_DIR}/out_file_test.20110102_0.log.gz", path
506
+ check_gzipped_result(path, formatted_lines)
507
+ assert_equal 1, Dir.glob("#{TMP_DIR}/out_file_test.*").size
508
+
509
+ path = write_once.call
510
+ assert_equal "#{TMP_DIR}/out_file_test.20110102_1.log.gz", path
511
+ check_gzipped_result(path, formatted_lines)
512
+ assert_equal 2, Dir.glob("#{TMP_DIR}/out_file_test.*").size
513
+
514
+ path = write_once.call
515
+ assert_equal "#{TMP_DIR}/out_file_test.20110102_2.log.gz", path
516
+ check_gzipped_result(path, formatted_lines)
517
+ assert_equal 3, Dir.glob("#{TMP_DIR}/out_file_test.*").size
518
+ end
519
+
520
+ test 'append' do
521
+ time = event_time("2011-01-02 13:14:15 UTC")
522
+ formatted_lines = %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n] + %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n]
523
+
524
+ write_once = ->(){
525
+ d = create_driver %[
526
+ path #{TMP_DIR}/out_file_test
527
+ compress gz
528
+ utc
529
+ append true
530
+ ]
531
+ d.run(default_tag: 'test'){
532
+ d.feed(time, {"a"=>1})
533
+ d.feed(time, {"a"=>2})
534
+ }
535
+ d.instance.last_written_path
536
+ }
537
+
538
+ path = write_once.call
539
+ assert_equal "#{TMP_DIR}/out_file_test.20110102.log.gz", path
540
+ check_gzipped_result(path, formatted_lines)
541
+
542
+ path = write_once.call
543
+ assert_equal "#{TMP_DIR}/out_file_test.20110102.log.gz", path
544
+ check_gzipped_result(path, formatted_lines * 2)
545
+
546
+ path = write_once.call
547
+ assert_equal "#{TMP_DIR}/out_file_test.20110102.log.gz", path
548
+ check_gzipped_result(path, formatted_lines * 3)
549
+ end
550
+
551
+ test 'symlink' do
552
+ omit "Windows doesn't support symlink" if Fluent.windows?
553
+ conf = CONFIG + %[
554
+ symlink_path #{SYMLINK_PATH}
555
+ ]
556
+ symlink_path = "#{SYMLINK_PATH}"
557
+
558
+ d = create_driver(conf)
559
+ begin
560
+ d.run(default_tag: 'tag') do
561
+ es = Fluent::OneEventStream.new(event_time("2011-01-02 13:14:15 UTC"), {"a"=>1})
562
+ d.feed(es)
563
+
564
+ assert File.symlink?(symlink_path)
565
+ assert File.exist?(symlink_path) # This checks dest of symlink exists or not.
566
+
567
+ es = Fluent::OneEventStream.new(event_time("2011-01-03 14:15:16 UTC"), {"a"=>2})
568
+ d.feed(es)
569
+
570
+ assert File.symlink?(symlink_path)
571
+ assert File.exist?(symlink_path)
572
+
573
+ meta = d.instance.metadata('tag', event_time("2011-01-03 14:15:16 UTC"), {})
574
+ assert_equal d.instance.buffer.instance_eval{ @stage[meta].path }, File.readlink(symlink_path)
575
+ end
576
+ ensure
577
+ FileUtils.rm_rf(symlink_path)
578
+ end
579
+ end
580
+
581
+ sub_test_case 'path' do
582
+ test 'normal' do
583
+ d = create_driver(%[
584
+ path #{TMP_DIR}/out_file_test
585
+ time_slice_format %Y-%m-%d-%H
586
+ utc true
587
+ ])
588
+ time = event_time("2011-01-02 13:14:15 UTC")
589
+ d.run(default_tag: 'test') do
590
+ d.feed(time, {"a"=>1})
591
+ end
592
+ path = d.instance.last_written_path
593
+ assert_equal "#{TMP_DIR}/out_file_test.2011-01-02-13_0.log", path
594
+ end
595
+
596
+ test 'normal with append' do
597
+ d = create_driver(%[
598
+ path #{TMP_DIR}/out_file_test
599
+ time_slice_format %Y-%m-%d-%H
600
+ utc true
601
+ append true
602
+ ])
603
+ time = event_time("2011-01-02 13:14:15 UTC")
604
+ d.run(default_tag: 'test') do
605
+ d.feed(time, {"a"=>1})
606
+ end
607
+ path = d.instance.last_written_path
608
+ assert_equal "#{TMP_DIR}/out_file_test.2011-01-02-13.log", path
609
+ end
610
+
611
+ test '*' do
612
+ d = create_driver(%[
613
+ path #{TMP_DIR}/out_file_test.*.txt
614
+ time_slice_format %Y-%m-%d-%H
615
+ utc true
616
+ ])
617
+ time = event_time("2011-01-02 13:14:15 UTC")
618
+ d.run(default_tag: 'test') do
619
+ d.feed(time, {"a"=>1})
620
+ end
621
+ path = d.instance.last_written_path
622
+ assert_equal "#{TMP_DIR}/out_file_test.2011-01-02-13_0.txt", path
623
+ end
624
+
625
+ test '* with append' do
626
+ d = create_driver(%[
627
+ path #{TMP_DIR}/out_file_test.*.txt
628
+ time_slice_format %Y-%m-%d-%H
629
+ utc true
630
+ append true
631
+ ])
632
+ time = event_time("2011-01-02 13:14:15 UTC")
633
+ d.run(default_tag: 'test') do
634
+ d.feed(time, {"a"=>1})
635
+ end
636
+ path = d.instance.last_written_path
637
+ assert_equal "#{TMP_DIR}/out_file_test.2011-01-02-13.txt", path
638
+ end
639
+ end
640
+
641
+ sub_test_case '#timekey_to_timeformat' do
642
+ setup do
643
+ @d = create_driver
644
+ @i = @d.instance
645
+ end
646
+
647
+ test 'returns empty string for nil' do
648
+ assert_equal '', @i.timekey_to_timeformat(nil)
649
+ end
650
+
651
+ test 'returns timestamp string with seconds for timekey smaller than 60' do
652
+ assert_equal '%Y%m%d%H%M%S', @i.timekey_to_timeformat(1)
653
+ assert_equal '%Y%m%d%H%M%S', @i.timekey_to_timeformat(30)
654
+ assert_equal '%Y%m%d%H%M%S', @i.timekey_to_timeformat(59)
655
+ end
656
+
657
+ test 'returns timestamp string with minutes for timekey smaller than 3600' do
658
+ assert_equal '%Y%m%d%H%M', @i.timekey_to_timeformat(60)
659
+ assert_equal '%Y%m%d%H%M', @i.timekey_to_timeformat(180)
660
+ assert_equal '%Y%m%d%H%M', @i.timekey_to_timeformat(1800)
661
+ assert_equal '%Y%m%d%H%M', @i.timekey_to_timeformat(3599)
662
+ end
663
+
664
+ test 'returns timestamp string with hours for timekey smaller than 86400 (1 day)' do
665
+ assert_equal '%Y%m%d%H', @i.timekey_to_timeformat(3600)
666
+ assert_equal '%Y%m%d%H', @i.timekey_to_timeformat(7200)
667
+ assert_equal '%Y%m%d%H', @i.timekey_to_timeformat(86399)
668
+ end
669
+
670
+ test 'returns timestamp string with days for timekey equal or greater than 86400' do
671
+ assert_equal '%Y%m%d', @i.timekey_to_timeformat(86400)
672
+ assert_equal '%Y%m%d', @i.timekey_to_timeformat(1000000)
673
+ assert_equal '%Y%m%d', @i.timekey_to_timeformat(1000000000)
674
+ end
675
+ end
676
+
677
+ sub_test_case '#compression_suffix' do
678
+ setup do
679
+ @i = create_driver.instance
680
+ end
681
+
682
+ test 'returns empty string for nil (no compression method specified)' do
683
+ assert_equal '', @i.compression_suffix(nil)
684
+ end
685
+
686
+ test 'returns .gz for gzip' do
687
+ assert_equal '.gz', @i.compression_suffix(:gzip)
688
+ end
689
+ end
690
+
691
+ sub_test_case '#generate_path_template' do
692
+ setup do
693
+ @i = create_driver.instance
694
+ end
695
+
696
+ data(
697
+ 'day' => [86400, '%Y%m%d', '%Y-%m-%d'],
698
+ 'hour' => [3600, '%Y%m%d%H', '%Y-%m-%d_%H'],
699
+ 'minute' => [60, '%Y%m%d%H%M', '%Y-%m-%d_%H%M'],
700
+ )
701
+ test 'generates path with timestamp placeholder for original path with tailing star with timekey' do |data|
702
+ timekey, placeholder, time_slice_format = data
703
+ # with index placeholder, without compression suffix when append disabled and compression disabled
704
+ assert_equal "/path/to/file.#{placeholder}_**", @i.generate_path_template('/path/to/file.*', timekey, false, nil)
705
+ # with index placeholder, with .gz suffix when append disabled and gzip compression enabled
706
+ assert_equal "/path/to/file.#{placeholder}_**.gz", @i.generate_path_template('/path/to/file.*', timekey, false, :gzip)
707
+ # without index placeholder, without compression suffix when append enabled and compression disabled
708
+ assert_equal "/path/to/file.#{placeholder}", @i.generate_path_template('/path/to/file.*', timekey, true, nil)
709
+ # without index placeholder, with .gz suffix when append disabled and gzip compression enabled
710
+ assert_equal "/path/to/file.#{placeholder}.gz", @i.generate_path_template('/path/to/file.*', timekey, true, :gzip)
711
+
712
+ # time_slice_format will used instead of computed placeholder if specified
713
+ assert_equal "/path/to/file.#{time_slice_format}_**", @i.generate_path_template('/path/to/file.*', timekey, false, nil, time_slice_format: time_slice_format)
714
+ assert_equal "/path/to/file.#{time_slice_format}_**.gz", @i.generate_path_template('/path/to/file.*', timekey, false, :gzip, time_slice_format: time_slice_format)
715
+ assert_equal "/path/to/file.#{time_slice_format}", @i.generate_path_template('/path/to/file.*', timekey, true, nil, time_slice_format: time_slice_format)
716
+ assert_equal "/path/to/file.#{time_slice_format}.gz", @i.generate_path_template('/path/to/file.*', timekey, true, :gzip, time_slice_format: time_slice_format)
717
+ end
718
+
719
+ data(
720
+ 'day' => [86400 * 2, '%Y%m%d', '%Y-%m-%d'],
721
+ 'hour' => [7200, '%Y%m%d%H', '%Y-%m-%d_%H'],
722
+ 'minute' => [180, '%Y%m%d%H%M', '%Y-%m-%d_%H%M'],
723
+ )
724
+ test 'generates path with timestamp placeholder for original path with star and suffix with timekey' do |data|
725
+ timekey, placeholder, time_slice_format = data
726
+ # with index placeholder, without compression suffix when append disabled and compression disabled
727
+ assert_equal "/path/to/file.#{placeholder}_**.data", @i.generate_path_template('/path/to/file.*.data', timekey, false, nil)
728
+ # with index placeholder, with .gz suffix when append disabled and gzip compression enabled
729
+ assert_equal "/path/to/file.#{placeholder}_**.data.gz", @i.generate_path_template('/path/to/file.*.data', timekey, false, :gzip)
730
+ # without index placeholder, without compression suffix when append enabled and compression disabled
731
+ assert_equal "/path/to/file.#{placeholder}.data", @i.generate_path_template('/path/to/file.*.data', timekey, true, nil)
732
+ # without index placeholder, with .gz suffix when append disabled and gzip compression enabled
733
+ assert_equal "/path/to/file.#{placeholder}.data.gz", @i.generate_path_template('/path/to/file.*.data', timekey, true, :gzip)
734
+
735
+ # time_slice_format will used instead of computed placeholder if specified
736
+ assert_equal "/path/to/file.#{time_slice_format}_**.data", @i.generate_path_template('/path/to/file.*.data', timekey, false, nil, time_slice_format: time_slice_format)
737
+ assert_equal "/path/to/file.#{time_slice_format}_**.data.gz", @i.generate_path_template('/path/to/file.*.data', timekey, false, :gzip, time_slice_format: time_slice_format)
738
+ assert_equal "/path/to/file.#{time_slice_format}.data", @i.generate_path_template('/path/to/file.*.data', timekey, true, nil, time_slice_format: time_slice_format)
739
+ assert_equal "/path/to/file.#{time_slice_format}.data.gz", @i.generate_path_template('/path/to/file.*.data', timekey, true, :gzip, time_slice_format: time_slice_format)
740
+ end
741
+
742
+ test 'raise error to show it is a bug when path including * specified without timekey' do
743
+ assert_raise RuntimeError.new("BUG: configuration error must be raised for path including '*' without timekey") do
744
+ @i.generate_path_template('/path/to/file.*.log', nil, false, nil)
745
+ end
746
+ end
747
+
748
+ data(
749
+ 'day' => [86400 * 7, '%Y%m%d', '%Y-%m-%d'],
750
+ 'hour' => [3600 * 6, '%Y%m%d%H', '%Y-%m-%d_%H'],
751
+ 'minute' => [60 * 15, '%Y%m%d%H%M', '%Y-%m-%d_%H%M'],
752
+ )
753
+ test 'generates path with timestamp placeholder for original path without time placeholders & star with timekey, and path_suffix configured' do |data|
754
+ timekey, placeholder, time_slice_format = data
755
+ # with index placeholder, without compression suffix when append disabled and compression disabled
756
+ assert_equal "/path/to/file.#{placeholder}_**.log", @i.generate_path_template('/path/to/file', timekey, false, nil, path_suffix: '.log')
757
+ # with index placeholder, with .gz suffix when append disabled and gzip compression enabled
758
+ assert_equal "/path/to/file.#{placeholder}_**.log.gz", @i.generate_path_template('/path/to/file', timekey, false, :gzip, path_suffix: '.log')
759
+ # without index placeholder, without compression suffix when append enabled and compression disabled
760
+ assert_equal "/path/to/file.#{placeholder}.log", @i.generate_path_template('/path/to/file', timekey, true, nil, path_suffix: '.log')
761
+ # without index placeholder, with compression suffix when append enabled and gzip compression enabled
762
+ assert_equal "/path/to/file.#{placeholder}.log.gz", @i.generate_path_template('/path/to/file', timekey, true, :gzip, path_suffix: '.log')
763
+
764
+ # time_slice_format will be appended always if it's specified
765
+ assert_equal "/path/to/file.#{time_slice_format}_**.log", @i.generate_path_template('/path/to/file', timekey, false, nil, path_suffix: '.log', time_slice_format: time_slice_format)
766
+ assert_equal "/path/to/file.#{time_slice_format}_**.log.gz", @i.generate_path_template('/path/to/file', timekey, false, :gzip, path_suffix: '.log', time_slice_format: time_slice_format)
767
+ assert_equal "/path/to/file.#{time_slice_format}.log", @i.generate_path_template('/path/to/file', timekey, true, nil, path_suffix: '.log', time_slice_format: time_slice_format)
768
+ assert_equal "/path/to/file.#{time_slice_format}.log.gz", @i.generate_path_template('/path/to/file', timekey, true, :gzip, path_suffix: '.log', time_slice_format: time_slice_format)
769
+ end
770
+
771
+ data(
772
+ 'day' => [86400, '%Y%m%d'],
773
+ 'hour' => [3600, '%Y%m%d%H'],
774
+ 'minute' => [60, '%Y%m%d%H%M'],
775
+ )
776
+ test 'generates path with timestamp placeholder for original path without star with timekey, and path_suffix not configured' do |data|
777
+ timekey, placeholder = data
778
+ # with index placeholder, without compression suffix when append disabled and compression disabled
779
+ assert_equal "/path/to/file.#{placeholder}_**", @i.generate_path_template('/path/to/file', timekey, false, nil)
780
+ # with index placeholder, with .gz suffix when append disabled and gzip compression enabled
781
+ assert_equal "/path/to/file.#{placeholder}_**.gz", @i.generate_path_template('/path/to/file', timekey, false, :gzip)
782
+ # without index placeholder, without compression suffix when append enabled and compression disabled
783
+ assert_equal "/path/to/file.#{placeholder}", @i.generate_path_template('/path/to/file', timekey, true, nil)
784
+ # without index placeholder, with compression suffix when append enabled and gzip compression enabled
785
+ assert_equal "/path/to/file.#{placeholder}.gz", @i.generate_path_template('/path/to/file', timekey, true, :gzip)
786
+ end
787
+
788
+ test 'generates path without adding timestamp placeholder part if original path has enough placeholders for specified timekey' do
789
+ assert_equal "/path/to/file.%Y%m%d", @i.generate_path_template('/path/to/file.%Y%m%d', 86400, true, nil)
790
+ assert_equal "/path/to/%Y%m%d/file", @i.generate_path_template('/path/to/%Y%m%d/file', 86400, true, nil)
791
+
792
+ assert_equal "/path/to/%Y%m%d/file_**", @i.generate_path_template('/path/to/%Y%m%d/file', 86400, false, nil)
793
+
794
+ assert_raise Fluent::ConfigError.new("insufficient timestamp placeholders in path") do
795
+ @i.generate_path_template('/path/to/%Y%m/file', 86400, true, nil)
796
+ end
797
+ assert_raise Fluent::ConfigError.new("insufficient timestamp placeholders in path") do
798
+ @i.generate_path_template('/path/to/file.%Y%m%d.log', 3600, true, nil)
799
+ end
800
+
801
+ assert_equal "/path/to/file.%Y%m%d_%H_**.log.gz", @i.generate_path_template('/path/to/file.%Y%m%d_%H', 7200, false, :gzip, path_suffix: '.log')
802
+ assert_equal "/path/to/${tag}/file.%Y%m%d_%H_**.log.gz", @i.generate_path_template('/path/to/${tag}/file.%Y%m%d_%H', 7200, false, :gzip, path_suffix: '.log')
803
+ end
804
+
805
+ test 'generates path with specified time_slice_format appended even if path has sufficient timestamp placeholders' do
806
+ assert_equal "/path/to/%Y%m%d/file.%Y-%m-%d_%H_**", @i.generate_path_template('/path/to/%Y%m%d/file', 86400, false, nil, time_slice_format: '%Y-%m-%d_%H')
807
+ assert_equal "/path/to/%Y%m%d/file.%Y-%m-%d_%H", @i.generate_path_template('/path/to/%Y%m%d/file', 86400, true, nil, time_slice_format: '%Y-%m-%d_%H')
808
+ assert_equal "/path/to/%Y%m%d/file.%Y-%m-%d_%H_**.log", @i.generate_path_template('/path/to/%Y%m%d/file', 86400, false, nil, time_slice_format: '%Y-%m-%d_%H', path_suffix: '.log')
809
+ assert_equal "/path/to/%Y%m%d/file.%Y-%m-%d_%H.log", @i.generate_path_template('/path/to/%Y%m%d/file', 86400, true, nil, time_slice_format: '%Y-%m-%d_%H', path_suffix: '.log')
810
+ assert_equal "/path/to/%Y%m%d/file.%Y-%m-%d_%H.log.gz", @i.generate_path_template('/path/to/%Y%m%d/file', 86400, true, :gzip, time_slice_format: '%Y-%m-%d_%H', path_suffix: '.log')
811
+ end
812
+
813
+ test 'generates path without timestamp placeholder when path does not include * and timekey not specified' do
814
+ assert_equal '/path/to/file.log', @i.generate_path_template('/path/to/file.log', nil, true, nil)
815
+ assert_equal '/path/to/file.log_**', @i.generate_path_template('/path/to/file.log', nil, false, nil)
816
+ assert_equal '/path/to/file.${tag}.log_**', @i.generate_path_template('/path/to/file.${tag}.log', nil, false, nil)
817
+ assert_equal '/path/to/file.${tag}_**.log', @i.generate_path_template('/path/to/file.${tag}', nil, false, nil, path_suffix: '.log')
818
+ end
819
+ end
820
+
821
+ sub_test_case '#find_filepath_available' do
822
+ setup do
823
+ @tmp = File.join(TMP_DIR, 'find_filepath_test')
824
+ FileUtils.mkdir_p @tmp
825
+ @i = create_driver.instance
826
+ end
827
+
828
+ teardown do
829
+ FileUtils.rm_rf @tmp
830
+ end
831
+
832
+ test 'raise error if argument path does not include index placeholder' do
833
+ assert_raise RuntimeError.new("BUG: index placeholder not found in path: #{@tmp}/myfile") do
834
+ @i.find_filepath_available("#{@tmp}/myfile") do |path|
835
+ # ...
836
+ end
837
+ end
838
+ end
839
+
840
+ data(
841
+ 'without suffix' => ['myfile_0', 'myfile_**'],
842
+ 'with timestamp' => ['myfile_20161003_0', 'myfile_20161003_**'],
843
+ 'with base suffix' => ['myfile_0.log', 'myfile_**.log'],
844
+ 'with compression suffix' => ['myfile_0.log.gz', 'myfile_**.log.gz'],
845
+ )
846
+ test 'returns filepath with _0 at first' do |data|
847
+ expected, argument = data
848
+ @i.find_filepath_available(File.join(@tmp, argument)) do |path|
849
+ assert_equal File.join(@tmp, expected), path
850
+ end
851
+ end
852
+
853
+ test 'returns filepath with index which does not exist yet' do
854
+ 5.times do |i|
855
+ File.open(File.join(@tmp, "exist_#{i}.log"), 'a'){|f| } # open(create) and close
856
+ end
857
+ @i.find_filepath_available(File.join(@tmp, "exist_**.log")) do |path|
858
+ assert_equal File.join(@tmp, "exist_5.log"), path
859
+ end
860
+ end
861
+
862
+ test 'creates lock directory when with_lock is true to exclude operations of other worker process' do
863
+ 5.times do |i|
864
+ File.open(File.join(@tmp, "exist_#{i}.log"), 'a')
865
+ end
866
+ Dir.mkdir(File.join(@tmp, "exist_5.log.lock"))
867
+ @i.find_filepath_available(File.join(@tmp, "exist_**.log"), with_lock: true) do |path|
868
+ assert Dir.exist?(File.join(@tmp, "exist_6.log.lock"))
869
+ assert_equal File.join(@tmp, "exist_6.log"), path
870
+ end
871
+ end
872
+ end
873
+ end