fluentd 0.12.43 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fluentd might be problematic. Click here for more details.

Files changed (253) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +6 -0
  3. data/.gitignore +2 -0
  4. data/.travis.yml +33 -21
  5. data/CONTRIBUTING.md +1 -0
  6. data/ChangeLog +1239 -0
  7. data/README.md +0 -25
  8. data/Rakefile +2 -1
  9. data/Vagrantfile +17 -0
  10. data/appveyor.yml +35 -0
  11. data/example/filter_stdout.conf +5 -5
  12. data/example/in_forward.conf +2 -2
  13. data/example/in_http.conf +2 -2
  14. data/example/in_out_forward.conf +17 -0
  15. data/example/in_syslog.conf +2 -2
  16. data/example/in_tail.conf +2 -2
  17. data/example/in_tcp.conf +2 -2
  18. data/example/in_udp.conf +2 -2
  19. data/example/out_copy.conf +4 -4
  20. data/example/out_file.conf +2 -2
  21. data/example/out_forward.conf +2 -2
  22. data/example/out_forward_buf_file.conf +23 -0
  23. data/example/v0_12_filter.conf +8 -8
  24. data/fluent.conf +29 -0
  25. data/fluentd.gemspec +18 -11
  26. data/lib/fluent/agent.rb +60 -58
  27. data/lib/fluent/command/cat.rb +1 -1
  28. data/lib/fluent/command/debug.rb +7 -5
  29. data/lib/fluent/command/fluentd.rb +97 -2
  30. data/lib/fluent/compat/call_super_mixin.rb +67 -0
  31. data/lib/fluent/compat/filter.rb +50 -0
  32. data/lib/fluent/compat/formatter.rb +109 -0
  33. data/lib/fluent/compat/input.rb +50 -0
  34. data/lib/fluent/compat/output.rb +617 -0
  35. data/lib/fluent/compat/output_chain.rb +60 -0
  36. data/lib/fluent/compat/parser.rb +163 -0
  37. data/lib/fluent/compat/propagate_default.rb +62 -0
  38. data/lib/fluent/config.rb +23 -20
  39. data/lib/fluent/config/configure_proxy.rb +119 -70
  40. data/lib/fluent/config/dsl.rb +5 -18
  41. data/lib/fluent/config/element.rb +72 -8
  42. data/lib/fluent/config/error.rb +0 -3
  43. data/lib/fluent/config/literal_parser.rb +0 -2
  44. data/lib/fluent/config/parser.rb +4 -4
  45. data/lib/fluent/config/section.rb +39 -28
  46. data/lib/fluent/config/types.rb +2 -13
  47. data/lib/fluent/config/v1_parser.rb +1 -3
  48. data/lib/fluent/configurable.rb +48 -16
  49. data/lib/fluent/daemon.rb +15 -0
  50. data/lib/fluent/engine.rb +26 -52
  51. data/lib/fluent/env.rb +6 -4
  52. data/lib/fluent/event.rb +58 -11
  53. data/lib/fluent/event_router.rb +5 -5
  54. data/lib/fluent/filter.rb +2 -50
  55. data/lib/fluent/formatter.rb +4 -293
  56. data/lib/fluent/input.rb +2 -32
  57. data/lib/fluent/label.rb +2 -2
  58. data/lib/fluent/load.rb +3 -2
  59. data/lib/fluent/log.rb +107 -38
  60. data/lib/fluent/match.rb +0 -36
  61. data/lib/fluent/mixin.rb +117 -7
  62. data/lib/fluent/msgpack_factory.rb +62 -0
  63. data/lib/fluent/output.rb +7 -612
  64. data/lib/fluent/output_chain.rb +23 -0
  65. data/lib/fluent/parser.rb +4 -800
  66. data/lib/fluent/plugin.rb +100 -121
  67. data/lib/fluent/plugin/bare_output.rb +63 -0
  68. data/lib/fluent/plugin/base.rb +121 -0
  69. data/lib/fluent/plugin/buf_file.rb +101 -182
  70. data/lib/fluent/plugin/buf_memory.rb +9 -92
  71. data/lib/fluent/plugin/buffer.rb +473 -0
  72. data/lib/fluent/plugin/buffer/chunk.rb +135 -0
  73. data/lib/fluent/plugin/buffer/file_chunk.rb +339 -0
  74. data/lib/fluent/plugin/buffer/memory_chunk.rb +100 -0
  75. data/lib/fluent/plugin/exec_util.rb +80 -75
  76. data/lib/fluent/plugin/file_util.rb +33 -28
  77. data/lib/fluent/plugin/file_wrapper.rb +120 -0
  78. data/lib/fluent/plugin/filter.rb +51 -0
  79. data/lib/fluent/plugin/filter_grep.rb +13 -40
  80. data/lib/fluent/plugin/filter_record_transformer.rb +22 -18
  81. data/lib/fluent/plugin/formatter.rb +93 -0
  82. data/lib/fluent/plugin/formatter_csv.rb +48 -0
  83. data/lib/fluent/plugin/formatter_hash.rb +32 -0
  84. data/lib/fluent/plugin/formatter_json.rb +47 -0
  85. data/lib/fluent/plugin/formatter_ltsv.rb +42 -0
  86. data/lib/fluent/plugin/formatter_msgpack.rb +32 -0
  87. data/lib/fluent/plugin/formatter_out_file.rb +45 -0
  88. data/lib/fluent/plugin/formatter_single_value.rb +34 -0
  89. data/lib/fluent/plugin/formatter_stdout.rb +39 -0
  90. data/lib/fluent/plugin/in_debug_agent.rb +4 -0
  91. data/lib/fluent/plugin/in_dummy.rb +22 -18
  92. data/lib/fluent/plugin/in_exec.rb +18 -8
  93. data/lib/fluent/plugin/in_forward.rb +36 -79
  94. data/lib/fluent/plugin/in_gc_stat.rb +4 -0
  95. data/lib/fluent/plugin/in_http.rb +21 -18
  96. data/lib/fluent/plugin/in_monitor_agent.rb +15 -48
  97. data/lib/fluent/plugin/in_object_space.rb +6 -1
  98. data/lib/fluent/plugin/in_stream.rb +7 -3
  99. data/lib/fluent/plugin/in_syslog.rb +46 -95
  100. data/lib/fluent/plugin/in_tail.rb +58 -640
  101. data/lib/fluent/plugin/in_tcp.rb +8 -1
  102. data/lib/fluent/plugin/in_udp.rb +8 -18
  103. data/lib/fluent/plugin/input.rb +33 -0
  104. data/lib/fluent/plugin/multi_output.rb +95 -0
  105. data/lib/fluent/plugin/out_buffered_null.rb +59 -0
  106. data/lib/fluent/plugin/out_copy.rb +11 -7
  107. data/lib/fluent/plugin/out_exec.rb +15 -11
  108. data/lib/fluent/plugin/out_exec_filter.rb +18 -10
  109. data/lib/fluent/plugin/out_file.rb +34 -5
  110. data/lib/fluent/plugin/out_forward.rb +25 -19
  111. data/lib/fluent/plugin/out_null.rb +0 -14
  112. data/lib/fluent/plugin/out_roundrobin.rb +11 -7
  113. data/lib/fluent/plugin/out_stdout.rb +5 -7
  114. data/lib/fluent/plugin/out_stream.rb +3 -1
  115. data/lib/fluent/plugin/output.rb +979 -0
  116. data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
  117. data/lib/fluent/plugin/parser.rb +244 -0
  118. data/lib/fluent/plugin/parser_apache.rb +24 -0
  119. data/lib/fluent/plugin/parser_apache2.rb +84 -0
  120. data/lib/fluent/plugin/parser_apache_error.rb +21 -0
  121. data/lib/fluent/plugin/parser_csv.rb +31 -0
  122. data/lib/fluent/plugin/parser_json.rb +79 -0
  123. data/lib/fluent/plugin/parser_ltsv.rb +50 -0
  124. data/lib/fluent/plugin/parser_multiline.rb +102 -0
  125. data/lib/fluent/plugin/parser_nginx.rb +24 -0
  126. data/lib/fluent/plugin/parser_none.rb +36 -0
  127. data/lib/fluent/plugin/parser_syslog.rb +82 -0
  128. data/lib/fluent/plugin/parser_tsv.rb +37 -0
  129. data/lib/fluent/plugin/socket_util.rb +119 -117
  130. data/lib/fluent/plugin/storage.rb +84 -0
  131. data/lib/fluent/plugin/storage_local.rb +116 -0
  132. data/lib/fluent/plugin/string_util.rb +16 -13
  133. data/lib/fluent/plugin_helper.rb +39 -0
  134. data/lib/fluent/plugin_helper/child_process.rb +298 -0
  135. data/lib/fluent/plugin_helper/compat_parameters.rb +99 -0
  136. data/lib/fluent/plugin_helper/event_emitter.rb +80 -0
  137. data/lib/fluent/plugin_helper/event_loop.rb +118 -0
  138. data/lib/fluent/plugin_helper/retry_state.rb +177 -0
  139. data/lib/fluent/plugin_helper/storage.rb +308 -0
  140. data/lib/fluent/plugin_helper/thread.rb +147 -0
  141. data/lib/fluent/plugin_helper/timer.rb +85 -0
  142. data/lib/fluent/plugin_id.rb +63 -0
  143. data/lib/fluent/process.rb +21 -30
  144. data/lib/fluent/registry.rb +21 -9
  145. data/lib/fluent/root_agent.rb +115 -40
  146. data/lib/fluent/supervisor.rb +330 -320
  147. data/lib/fluent/system_config.rb +42 -18
  148. data/lib/fluent/test.rb +6 -1
  149. data/lib/fluent/test/base.rb +23 -3
  150. data/lib/fluent/test/driver/base.rb +247 -0
  151. data/lib/fluent/test/driver/event_feeder.rb +98 -0
  152. data/lib/fluent/test/driver/filter.rb +35 -0
  153. data/lib/fluent/test/driver/input.rb +31 -0
  154. data/lib/fluent/test/driver/output.rb +78 -0
  155. data/lib/fluent/test/driver/test_event_router.rb +45 -0
  156. data/lib/fluent/test/filter_test.rb +0 -1
  157. data/lib/fluent/test/formatter_test.rb +2 -1
  158. data/lib/fluent/test/input_test.rb +23 -17
  159. data/lib/fluent/test/output_test.rb +28 -39
  160. data/lib/fluent/test/parser_test.rb +1 -1
  161. data/lib/fluent/time.rb +104 -1
  162. data/lib/fluent/{status.rb → unique_id.rb} +15 -24
  163. data/lib/fluent/version.rb +1 -1
  164. data/lib/fluent/winsvc.rb +72 -0
  165. data/test/compat/test_calls_super.rb +164 -0
  166. data/test/config/test_config_parser.rb +83 -0
  167. data/test/config/test_configurable.rb +547 -274
  168. data/test/config/test_configure_proxy.rb +146 -29
  169. data/test/config/test_dsl.rb +3 -181
  170. data/test/config/test_element.rb +274 -0
  171. data/test/config/test_literal_parser.rb +1 -1
  172. data/test/config/test_section.rb +79 -7
  173. data/test/config/test_system_config.rb +21 -0
  174. data/test/config/test_types.rb +3 -26
  175. data/test/helper.rb +78 -8
  176. data/test/plugin/test_bare_output.rb +118 -0
  177. data/test/plugin/test_base.rb +75 -0
  178. data/test/plugin/test_buf_file.rb +420 -521
  179. data/test/plugin/test_buf_memory.rb +32 -194
  180. data/test/plugin/test_buffer.rb +981 -0
  181. data/test/plugin/test_buffer_chunk.rb +110 -0
  182. data/test/plugin/test_buffer_file_chunk.rb +770 -0
  183. data/test/plugin/test_buffer_memory_chunk.rb +265 -0
  184. data/test/plugin/test_filter.rb +255 -0
  185. data/test/plugin/test_filter_grep.rb +2 -73
  186. data/test/plugin/test_filter_record_transformer.rb +24 -68
  187. data/test/plugin/test_filter_stdout.rb +6 -6
  188. data/test/plugin/test_in_debug_agent.rb +2 -0
  189. data/test/plugin/test_in_dummy.rb +11 -17
  190. data/test/plugin/test_in_exec.rb +6 -25
  191. data/test/plugin/test_in_forward.rb +112 -151
  192. data/test/plugin/test_in_gc_stat.rb +2 -0
  193. data/test/plugin/test_in_http.rb +106 -157
  194. data/test/plugin/test_in_object_space.rb +21 -5
  195. data/test/plugin/test_in_stream.rb +14 -13
  196. data/test/plugin/test_in_syslog.rb +30 -275
  197. data/test/plugin/test_in_tail.rb +95 -282
  198. data/test/plugin/test_in_tcp.rb +14 -0
  199. data/test/plugin/test_in_udp.rb +21 -67
  200. data/test/plugin/test_input.rb +122 -0
  201. data/test/plugin/test_multi_output.rb +180 -0
  202. data/test/plugin/test_out_buffered_null.rb +79 -0
  203. data/test/plugin/test_out_copy.rb +15 -2
  204. data/test/plugin/test_out_exec.rb +75 -25
  205. data/test/plugin/test_out_exec_filter.rb +74 -8
  206. data/test/plugin/test_out_file.rb +61 -7
  207. data/test/plugin/test_out_forward.rb +92 -15
  208. data/test/plugin/test_out_roundrobin.rb +1 -0
  209. data/test/plugin/test_out_stdout.rb +22 -13
  210. data/test/plugin/test_out_stream.rb +18 -0
  211. data/test/plugin/test_output.rb +515 -0
  212. data/test/plugin/test_output_as_buffered.rb +1540 -0
  213. data/test/plugin/test_output_as_buffered_overflow.rb +247 -0
  214. data/test/plugin/test_output_as_buffered_retries.rb +808 -0
  215. data/test/plugin/test_output_as_buffered_secondary.rb +776 -0
  216. data/test/plugin/test_output_as_standard.rb +362 -0
  217. data/test/plugin/test_owned_by.rb +35 -0
  218. data/test/plugin/test_storage.rb +167 -0
  219. data/test/plugin/test_storage_local.rb +8 -0
  220. data/test/plugin_helper/test_child_process.rb +599 -0
  221. data/test/plugin_helper/test_compat_parameters.rb +175 -0
  222. data/test/plugin_helper/test_event_emitter.rb +51 -0
  223. data/test/plugin_helper/test_event_loop.rb +52 -0
  224. data/test/plugin_helper/test_retry_state.rb +399 -0
  225. data/test/plugin_helper/test_storage.rb +411 -0
  226. data/test/plugin_helper/test_thread.rb +164 -0
  227. data/test/plugin_helper/test_timer.rb +100 -0
  228. data/test/scripts/exec_script.rb +0 -6
  229. data/test/scripts/fluent/plugin/out_test.rb +3 -0
  230. data/test/test_config.rb +13 -4
  231. data/test/test_event.rb +24 -13
  232. data/test/test_event_router.rb +8 -7
  233. data/test/test_event_time.rb +187 -0
  234. data/test/test_formatter.rb +13 -51
  235. data/test/test_input.rb +1 -1
  236. data/test/test_log.rb +239 -16
  237. data/test/test_mixin.rb +1 -1
  238. data/test/test_output.rb +53 -66
  239. data/test/test_parser.rb +105 -323
  240. data/test/test_plugin_helper.rb +81 -0
  241. data/test/test_root_agent.rb +4 -52
  242. data/test/test_supervisor.rb +272 -0
  243. data/test/test_unique_id.rb +47 -0
  244. metadata +181 -55
  245. data/CHANGELOG.md +0 -710
  246. data/lib/fluent/buffer.rb +0 -365
  247. data/lib/fluent/plugin/filter_parser.rb +0 -107
  248. data/lib/fluent/plugin/in_status.rb +0 -76
  249. data/lib/fluent/test/helpers.rb +0 -86
  250. data/test/plugin/data/log/foo/bar2 +0 -0
  251. data/test/plugin/test_filter_parser.rb +0 -744
  252. data/test/plugin/test_in_status.rb +0 -38
  253. data/test/test_buffer.rb +0 -624
@@ -0,0 +1,35 @@
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/test/driver/base'
18
+ require 'fluent/test/driver/event_feeder'
19
+
20
+ require 'fluent/plugin/filter'
21
+
22
+ module Fluent
23
+ module Test
24
+ module Driver
25
+ class Filter < Base
26
+ include EventFeeder
27
+
28
+ def initialize(klass, opts: {}, &block)
29
+ super
30
+ raise ArgumentError, "plugin is not an instance of Fluent::Plugin::Filter" unless @instance.is_a? Fluent::Plugin::Filter
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,31 @@
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/test/driver/base'
18
+ require 'fluent/plugin/input'
19
+
20
+ module Fluent
21
+ module Test
22
+ module Driver
23
+ class Input < Base
24
+ def initialize(klass, opts: {}, &block)
25
+ super
26
+ raise ArgumentError, "plugin is not an instance of Fluent::Plugin::Input" unless @instance.is_a? Fluent::Plugin::Input
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,78 @@
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/test/driver/base'
18
+ require 'fluent/test/driver/event_feeder'
19
+
20
+ require 'fluent/plugin/output'
21
+
22
+ module Fluent
23
+ module Test
24
+ module Driver
25
+ class Output < Base
26
+ include EventFeeder
27
+
28
+ def initialize(klass, opts: {}, &block)
29
+ super
30
+ raise ArgumentError, "plugin is not an instance of Fluent::Plugin::Output" unless @instance.is_a? Fluent::Plugin::Output
31
+ @instance.in_tests = true
32
+ @flush_buffer_at_cleanup = nil
33
+ @format_hook = nil
34
+ @format_results = []
35
+ end
36
+
37
+ def run(flush: true, **kwargs, &block)
38
+ @flush_buffer_at_cleanup = flush
39
+ super(**kwargs, &block)
40
+ end
41
+
42
+ def run_actual(**kwargs, &block)
43
+ super(**kwargs, &block)
44
+ if @flush_buffer_at_cleanup
45
+ @instance.force_flush
46
+ end
47
+ end
48
+
49
+ def formatted
50
+ @format_results
51
+ end
52
+
53
+ def flush
54
+ @instance.force_flush
55
+ end
56
+
57
+ def instance_hook_after_started
58
+ super
59
+
60
+ # it's decided after #start whether output plugin instances use @custom_format or not.
61
+ if @instance.instance_eval{ @custom_format }
62
+ @format_hook = format_hook = ->(result){ @format_results << result }
63
+ m = Module.new do
64
+ define_method(:format) do |tag, time, record|
65
+ result = super(tag, time, record)
66
+ format_hook.call(result)
67
+ result
68
+ end
69
+ end
70
+ @instance.singleton_class.module_eval do
71
+ prepend m
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,45 @@
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/event'
18
+
19
+ module Fluent
20
+ module Test
21
+ module Driver
22
+ class TestEventRouter
23
+ def initialize(driver)
24
+ @driver = driver
25
+ end
26
+
27
+ def emit(tag, time, record)
28
+ @driver.emit_event_stream(tag, OneEventStream.new(time, record))
29
+ end
30
+
31
+ def emit_array(tag, array)
32
+ @driver.emit_event_stream(tag, ArrayEventStream.new(array))
33
+ end
34
+
35
+ def emit_stream(tag, es)
36
+ @driver.emit_event_stream(tag, es)
37
+ end
38
+
39
+ def emit_error_event(tag, time, record, error)
40
+ @driver.emit_error_event(tag, time, record, error)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -16,7 +16,6 @@
16
16
 
17
17
  require 'fluent/test/base'
18
18
  require 'fluent/event'
19
- require 'fluent/filter'
20
19
 
21
20
  module Fluent
22
21
  module Test
@@ -16,6 +16,7 @@
16
16
 
17
17
  require 'fluent/formatter'
18
18
  require 'fluent/config'
19
+ require 'fluent/plugin'
19
20
 
20
21
  module Fluent
21
22
  module Test
@@ -30,7 +31,7 @@ module Fluent
30
31
  end
31
32
  @instance = klass_or_str.new
32
33
  elsif klass_or_str.is_a?(String)
33
- @instance = TextFormatter::TEMPLATE_REGISTRY.lookup(klass_or_str).call
34
+ @instance = Fluent::Plugin.new_formatter(klass_or_str)
34
35
  else
35
36
  @instance = klass_or_str
36
37
  end
@@ -14,29 +14,21 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
- require 'fluent/input'
18
- require 'fluent/buffer'
19
17
  require 'fluent/engine'
20
18
  require 'fluent/time'
21
19
  require 'fluent/test/base'
22
20
 
23
21
  module Fluent
24
- class FileBuffer < BasicBuffer
25
- def self.clear_buffer_paths
26
- @@buffer_paths = {}
27
- end
28
- end
29
-
30
22
  module Test
31
23
  class InputTestDriver < TestDriver
32
24
  def initialize(klass, &block)
33
- FileBuffer.clear_buffer_paths
34
25
  super(klass, &block)
35
26
  @emit_streams = []
36
27
  @expects = nil
37
28
  # for checking only the number of emitted records during run
38
29
  @expected_emits_length = nil
39
30
  @run_timeout = 5
31
+ @run_post_conditions = []
40
32
  end
41
33
 
42
34
  def expect_emit(tag, time, record)
@@ -82,7 +74,6 @@ module Fluent
82
74
 
83
75
  def register_run_post_condition(&block)
84
76
  if block
85
- @run_post_conditions ||= []
86
77
  @run_post_conditions << block
87
78
  end
88
79
  end
@@ -108,14 +99,26 @@ module Fluent
108
99
  false
109
100
  end
110
101
 
102
+ module EmitStreamWrapper
103
+ def emit_stream_callee=(method)
104
+ @emit_stream_callee = method
105
+ end
106
+ def emit_stream(tag, es)
107
+ @emit_stream_callee.call(tag, es)
108
+ end
109
+ end
110
+
111
111
  def run(num_waits = 10, &block)
112
112
  m = method(:emit_stream)
113
- Engine.define_singleton_method(:emit_stream) {|tag,es|
114
- m.call(tag, es)
115
- }
116
- instance.router.define_singleton_method(:emit_stream) {|tag,es|
117
- m.call(tag, es)
118
- }
113
+ (class << Engine; self; end).module_eval do
114
+ prepend EmitStreamWrapper
115
+ end
116
+ Engine.emit_stream_callee = m
117
+ (class << instance.router; self; end).module_eval do
118
+ prepend EmitStreamWrapper
119
+ end
120
+ instance.router.emit_stream_callee = m
121
+
119
122
  super(num_waits) {
120
123
  block.call if block
121
124
 
@@ -146,7 +149,10 @@ module Fluent
146
149
 
147
150
  tag, events = @emit_streams[j]
148
151
  events.each do |time, record|
149
- assert_equal(@expects[i], [tag, time, record]) if @expects
152
+ if @expects
153
+ assert_equal(@expects[i], [tag, time, record])
154
+ assert_equal_event_time(@expects[i][1], time) if @expects[i][1].is_a?(Fluent::EventTime)
155
+ end
150
156
  i += 1
151
157
  end
152
158
  j += 1
@@ -41,11 +41,9 @@ module Fluent
41
41
 
42
42
  attr_accessor :tag
43
43
 
44
- def emit(record, time=Time.now)
45
- es = OneEventStream.new(time.to_i, record)
46
- chain = TestOutputChain.new
47
- @instance.emit(@tag, es, chain)
48
- assert_equal 1, chain.called
44
+ def emit(record, time=Engine.now)
45
+ es = OneEventStream.new(time, record)
46
+ @instance.emit_events(@tag, es)
49
47
  end
50
48
  end
51
49
 
@@ -64,8 +62,8 @@ module Fluent
64
62
 
65
63
  attr_accessor :tag
66
64
 
67
- def emit(record, time=Time.now)
68
- @entries << [time.to_i, record]
65
+ def emit(record, time=Engine.now)
66
+ @entries << [time, record]
69
67
  self
70
68
  end
71
69
 
@@ -85,18 +83,13 @@ module Fluent
85
83
  assert_equal(@expected_buffer, buffer)
86
84
  end
87
85
 
88
- case
89
- when @instance.is_a?(Fluent::ObjectBufferedOutput)
90
- key = @tag
91
- when @instance.respond_to?(:time_slicer)
92
- # this block is only for test_out_file
93
- time, _record = @entries.first
94
- key = @instance.time_slicer.call(time)
95
- else
96
- key = ''
97
- end
98
- chunk = @instance.buffer.new_chunk(key)
99
- chunk << buffer
86
+ chunk = if @instance.instance_eval{ @chunk_key_tag }
87
+ @instance.buffer.generate_chunk(@instance.metadata(@tag, nil, nil))
88
+ else
89
+ @instance.buffer.generate_chunk(@instance.metadata(nil, nil, nil))
90
+ end
91
+ chunk.concat(buffer, es.size)
92
+
100
93
  begin
101
94
  result = @instance.write(chunk)
102
95
  ensure
@@ -110,18 +103,15 @@ module Fluent
110
103
  class TimeSlicedOutputTestDriver < InputTestDriver
111
104
  def initialize(klass, tag='test', &block)
112
105
  super(klass, &block)
113
- @entries = {}
106
+ @entries = []
114
107
  @expected_buffer = nil
115
108
  @tag = tag
116
109
  end
117
110
 
118
111
  attr_accessor :tag
119
112
 
120
- def emit(record, time=Time.now)
121
- slicer = @instance.instance_eval{@time_slicer}
122
- key = slicer.call(time.to_i)
123
- @entries[key] = [] unless @entries.has_key?(key)
124
- @entries[key] << [time.to_i, record]
113
+ def emit(record, time=Engine.now)
114
+ @entries << [time, record]
125
115
  self
126
116
  end
127
117
 
@@ -135,30 +125,29 @@ module Fluent
135
125
  block.call if block
136
126
 
137
127
  buffer = ''
138
- @entries.keys.each {|key|
139
- es = ArrayEventStream.new(@entries[key])
140
- @instance.emit(@tag, es, NullOutputChain.instance)
141
- buffer << @instance.format_stream(@tag, es)
142
- }
128
+ lines = {}
129
+ # v0.12 TimeSlicedOutput doesn't call #format_stream
130
+ @entries.each do |time, record|
131
+ meta = @instance.metadata(@tag, time, record)
132
+ line = @instance.format(@tag, time, record)
133
+ buffer << line
134
+ lines[meta] ||= []
135
+ lines[meta] << line
136
+ end
143
137
 
144
138
  if @expected_buffer
145
139
  assert_equal(@expected_buffer, buffer)
146
140
  end
147
141
 
148
- chunks = []
149
- @instance.instance_eval do
150
- @buffer.instance_eval{ @map.keys }.each do |key|
151
- @buffer.push(key)
152
- chunks << @buffer.instance_eval{ @queue.pop }
153
- end
154
- end
155
- chunks.each { |chunk|
142
+ lines.keys.each do |meta|
143
+ chunk = @instance.buffer.generate_chunk(meta)
144
+ chunk.append(lines[meta])
156
145
  begin
157
146
  result.push(@instance.write(chunk))
158
147
  ensure
159
148
  chunk.purge
160
149
  end
161
- }
150
+ end
162
151
  }
163
152
  result
164
153
  end
@@ -36,7 +36,7 @@ module Fluent
36
36
  @instance = klass_or_str.new(format, conf)
37
37
  end
38
38
  elsif klass_or_str.is_a?(String)
39
- @instance = TextParser::TEMPLATE_REGISTRY.lookup(klass_or_str).call
39
+ @instance = Fluent::Plugin.new_parser(klass_or_str)
40
40
  else
41
41
  @instance = klass_or_str
42
42
  end
data/lib/fluent/time.rb CHANGED
@@ -1 +1,104 @@
1
- # placeholder for v0.14 time module
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 'time'
18
+ require 'msgpack'
19
+
20
+ module Fluent
21
+ class EventTime
22
+ TYPE = 0
23
+
24
+ def initialize(sec, nsec = 0)
25
+ @sec = sec
26
+ @nsec = nsec
27
+ end
28
+
29
+ def ==(other)
30
+ if other.is_a?(Fluent::EventTime)
31
+ @sec == other.sec
32
+ else
33
+ @sec == other
34
+ end
35
+ end
36
+
37
+ def sec
38
+ @sec
39
+ end
40
+
41
+ def nsec
42
+ @nsec
43
+ end
44
+
45
+ def to_int
46
+ @sec
47
+ end
48
+
49
+ # for Time.at
50
+ def to_r
51
+ Rational(@sec * 1_000_000_000 + @nsec, 1_000_000_000)
52
+ end
53
+
54
+ # for > and others
55
+ def coerce(other)
56
+ [other, @sec]
57
+ end
58
+
59
+ def to_s
60
+ @sec.to_s
61
+ end
62
+
63
+ def to_json(*args)
64
+ @sec.to_s
65
+ end
66
+
67
+ def to_msgpack(io = nil)
68
+ @sec.to_msgpack(io)
69
+ end
70
+
71
+ def to_msgpack_ext
72
+ [@sec, @nsec].pack('NN')
73
+ end
74
+
75
+ def self.from_msgpack_ext(data)
76
+ new(*data.unpack('NN'))
77
+ end
78
+
79
+ def self.from_time(time)
80
+ Fluent::EventTime.new(time.to_i, time.nsec)
81
+ end
82
+
83
+ def self.eq?(a, b)
84
+ if a.is_a?(Fluent::EventTime) && b.is_a?(Fluent::EventTime)
85
+ a.sec == b.sec && a.nsec == b.nsec
86
+ else
87
+ a == b
88
+ end
89
+ end
90
+
91
+ def self.now
92
+ from_time(Time.now)
93
+ end
94
+
95
+ def self.parse(*args)
96
+ from_time(Time.parse(*args))
97
+ end
98
+
99
+ ## TODO: For performance, implement +, -, and so on
100
+ def method_missing(name, *args, &block)
101
+ @sec.send(name, *args, &block)
102
+ end
103
+ end
104
+ end