fluentd 0.12.40 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (252) 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 +810 -237
  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 +51 -595
  101. data/lib/fluent/plugin/in_tcp.rb +8 -1
  102. data/lib/fluent/plugin/in_udp.rb +8 -14
  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 +19 -9
  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 +120 -114
  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 -234
  198. data/test/plugin/test_in_tcp.rb +14 -0
  199. data/test/plugin/test_in_udp.rb +21 -13
  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 +180 -54
  245. data/lib/fluent/buffer.rb +0 -365
  246. data/lib/fluent/plugin/filter_parser.rb +0 -107
  247. data/lib/fluent/plugin/in_status.rb +0 -76
  248. data/lib/fluent/test/helpers.rb +0 -86
  249. data/test/plugin/data/log/foo/bar2 +0 -0
  250. data/test/plugin/test_filter_parser.rb +0 -744
  251. data/test/plugin/test_in_status.rb +0 -38
  252. data/test/test_buffer.rb +0 -624
@@ -14,169 +14,148 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
+ require 'fluent/registry'
17
18
  require 'fluent/config/error'
18
19
 
19
20
  module Fluent
20
- class PluginClass
21
- # This class is refactored using Fluent::Registry at v0.14
21
+ module Plugin
22
+ SEARCH_PATHS = []
22
23
 
23
- def initialize
24
- @input = {}
25
- @output = {}
26
- @filter = {}
27
- @buffer = {}
28
- end
24
+ # plugins for fluentd: fluent/plugin/type_NAME.rb
25
+ # plugins for fluentd plugins: fluent/plugin/type/NAME.rb
26
+ # ex: storage, buffer chunk, ...
29
27
 
30
- def register_input(type, klass)
31
- register_impl('input', @input, type, klass)
32
- end
28
+ # first class plugins (instantiated by Engine)
29
+ INPUT_REGISTRY = Registry.new(:input, 'fluent/plugin/in_')
30
+ OUTPUT_REGISTRY = Registry.new(:output, 'fluent/plugin/out_')
31
+ FILTER_REGISTRY = Registry.new(:filter, 'fluent/plugin/filter_')
33
32
 
34
- def register_output(type, klass)
35
- register_impl('output', @output, type, klass)
36
- end
33
+ # feature plugin: second class plugins (instanciated by Plugins or Helpers)
34
+ BUFFER_REGISTRY = Registry.new(:buffer, 'fluent/plugin/buf_')
35
+ PARSER_REGISTRY = Registry.new(:parser, 'fluent/plugin/parser_')
36
+ FORMATTER_REGISTRY = Registry.new(:formatter, 'fluent/plugin/formatter_')
37
+ STORAGE_REGISTRY = Registry.new(:storage, 'fluent/plugin/storage_')
37
38
 
38
- def register_filter(type, klass)
39
- register_impl('filter', @filter, type, klass)
40
- end
39
+ REGISTRIES = [INPUT_REGISTRY, OUTPUT_REGISTRY, FILTER_REGISTRY, BUFFER_REGISTRY, PARSER_REGISTRY, FORMATTER_REGISTRY, STORAGE_REGISTRY]
41
40
 
42
- def register_buffer(type, klass)
43
- register_impl('buffer', @buffer, type, klass)
41
+ def self.register_input(type, klass)
42
+ register_impl('input', INPUT_REGISTRY, type, klass)
44
43
  end
45
44
 
46
- def register_parser(type, klass)
47
- TextParser.register_template(type, klass)
45
+ def self.register_output(type, klass)
46
+ register_impl('output', OUTPUT_REGISTRY, type, klass)
48
47
  end
49
48
 
50
- def register_formatter(type, klass)
51
- TextFormatter.register_template(type, klass)
49
+ def self.register_filter(type, klass)
50
+ register_impl('filter', FILTER_REGISTRY, type, klass)
52
51
  end
53
52
 
54
- def new_input(type)
55
- new_impl('input', @input, type)
53
+ def self.register_buffer(type, klass)
54
+ register_impl('buffer', BUFFER_REGISTRY, type, klass)
56
55
  end
57
56
 
58
- def new_output(type)
59
- new_impl('output', @output, type)
57
+ def self.register_parser(type, klass_or_proc)
58
+ if klass_or_proc.is_a?(Regexp)
59
+ # This usage is not recommended for new API
60
+ require 'fluent/parser'
61
+ register_impl('parser', PARSER_REGISTRY, type, Proc.new { Fluent::TextParser::RegexpParser.new(klass_or_proc) })
62
+ else
63
+ register_impl('parser', PARSER_REGISTRY, type, klass_or_proc)
64
+ end
60
65
  end
61
66
 
62
- def new_filter(type)
63
- new_impl('filter', @filter, type)
67
+ def self.register_formatter(type, klass_or_proc)
68
+ if klass_or_proc.respond_to?(:call) && klass_or_proc.arity == 3 # Proc.new { |tag, time, record| }
69
+ # This usage is not recommended for new API
70
+ require 'fluent/formatter'
71
+ register_impl('formatter', FORMATTER_REGISTRY, type, Proc.new { Fluent::TextFormatter::ProcWrappedFormatter.new(klass_or_proc) })
72
+ else
73
+ register_impl('formatter', FORMATTER_REGISTRY, type, klass_or_proc)
74
+ end
64
75
  end
65
76
 
66
- def new_buffer(type)
67
- new_impl('buffer', @buffer, type)
77
+ def self.register_storage(type, klass)
78
+ register_impl('storage', STORAGE_REGISTRY, type, klass)
68
79
  end
69
80
 
70
- def new_parser(type)
71
- require 'fluent/parser'
72
- TextParser.lookup(type)
81
+ def self.lookup_type_from_class(klass_or_its_name)
82
+ klass = if klass_or_its_name.is_a? Class
83
+ klass_or_its_name
84
+ elsif klass_or_its_name.is_a? String
85
+ eval(klass_or_its_name) # const_get can't handle qualified klass name (ex: A::B)
86
+ else
87
+ raise ArgumentError, "invalid argument type #{klass_or_its_name.class}: #{klass_or_its_name}"
88
+ end
89
+ REGISTRIES.reduce(nil){|a, r| a || r.reverse_lookup(klass) }
73
90
  end
74
91
 
75
- def new_formatter(type)
76
- require 'fluent/formatter'
77
- TextFormatter.lookup(type)
92
+ def self.add_plugin_dir(dir)
93
+ REGISTRIES.each do |r|
94
+ r.paths.push(dir)
95
+ end
96
+ nil
78
97
  end
79
98
 
80
- def load_plugins
81
- dir = File.join(File.dirname(__FILE__), "plugin")
82
- load_plugin_dir(dir)
99
+ def self.new_input(type)
100
+ new_impl('input', INPUT_REGISTRY, type)
83
101
  end
84
102
 
85
- def load_plugin_dir(dir)
86
- dir = File.expand_path(dir)
87
- Dir.entries(dir).sort.each {|fname|
88
- if fname =~ /\.rb$/
89
- require File.join(dir, fname)
90
- end
91
- }
92
- nil
103
+ def self.new_output(type)
104
+ new_impl('output', OUTPUT_REGISTRY, type)
93
105
  end
94
106
 
95
- def load_plugin(type, name)
96
- try_load_plugin(name, type)
107
+ def self.new_filter(type)
108
+ new_impl('filter', FILTER_REGISTRY, type)
97
109
  end
98
110
 
99
- def lookup_name_from_class(klass_or_str)
100
- klass = if klass_or_str.class == String
101
- eval(klass_or_str) # const_get can't handle A::B
102
- else
103
- klass_or_str
104
- end
111
+ def self.new_buffer(type, parent: nil)
112
+ new_impl('buffer', BUFFER_REGISTRY, type, parent)
113
+ end
105
114
 
106
- @input.each { |name, plugin|
107
- return name if plugin == klass
108
- }
109
- @output.each { |name, plugin|
110
- return name if plugin == klass
111
- }
112
- @filter.each { |name, plugin|
113
- return name if plugin == klass
114
- }
115
+ def self.new_parser(type, parent: nil)
116
+ require 'fluent/parser'
115
117
 
116
- nil
118
+ if type[0] == '/' && type[-1] == '/'
119
+ # This usage is not recommended for new API... create RegexpParser directly
120
+ require 'fluent/parser'
121
+ Fluent::TextParser.lookup(type)
122
+ else
123
+ new_impl('parser', PARSER_REGISTRY, type, parent)
124
+ end
117
125
  end
118
126
 
119
- private
120
- def register_impl(name, map, type, klass)
121
- map[type] = klass
122
- $log.trace { "registered #{name} plugin '#{type}'" }
123
- nil
127
+ def self.new_formatter(type, parent: nil)
128
+ new_impl('formatter', FORMATTER_REGISTRY, type, parent)
124
129
  end
125
130
 
126
- def new_impl(name, map, type)
127
- if klass = map[type]
128
- return klass.new
129
- end
130
- try_load_plugin(name, type)
131
- if klass = map[type]
132
- return klass.new
133
- end
134
- raise ConfigError, "Unknown #{name} plugin '#{type}'. Run 'gem search -rd fluent-plugin' to find plugins"
135
- end
136
-
137
- def try_load_plugin(name, type)
138
- case name
139
- when 'input'
140
- path = "fluent/plugin/in_#{type}"
141
- when 'output'
142
- path = "fluent/plugin/out_#{type}"
143
- when 'filter'
144
- path = "fluent/plugin/filter_#{type}"
145
- when 'buffer'
146
- path = "fluent/plugin/buf_#{type}"
147
- else
148
- return
149
- end
131
+ def self.new_storage(type, parent: nil)
132
+ new_impl('storage', STORAGE_REGISTRY, type, parent)
133
+ end
150
134
 
151
- # prefer LOAD_PATH than gems
152
- files = $LOAD_PATH.map {|lp|
153
- lpath = File.join(lp, "#{path}.rb")
154
- File.exist?(lpath) ? lpath : nil
155
- }.compact
156
- unless files.empty?
157
- # prefer newer version
158
- require File.expand_path(files.sort.last)
159
- return
135
+ def self.register_impl(kind, registry, type, value)
136
+ if !value.is_a?(Class) && !value.respond_to?(:call)
137
+ raise Fluent::ConfigError, "Invalid implementation as #{kind} plugin: '#{type}'. It must be a Class, or callable."
160
138
  end
139
+ registry.register(type, value)
140
+ $log.trace "registered #{kind} plugin '#{type}'" if defined?($log)
141
+ nil
142
+ end
161
143
 
162
- # search gems
163
- specs = Gem::Specification.find_all { |spec|
164
- spec.contains_requirable_file? path
165
- }
166
-
167
- # prefer newer version
168
- specs = specs.sort_by { |spec| spec.version }
169
- if spec = specs.last
170
- spec.require_paths.each { |lib|
171
- file = "#{spec.full_gem_path}/#{lib}/#{path}"
172
- if File.exist?("#{file}.rb")
173
- require file
174
- return
175
- end
176
- }
144
+ def self.new_impl(kind, registry, type, parent=nil)
145
+ # "'type' not found" is handled by registry
146
+ obj = registry.lookup(type)
147
+ impl = case
148
+ when obj.is_a?(Class)
149
+ obj.new
150
+ when obj.respond_to?(:call) && obj.arity == 0
151
+ obj.call
152
+ else
153
+ raise Fluent::ConfigError, "#{kind} plugin '#{type}' is not a Class nor callable (without arguments)."
154
+ end
155
+ if parent && impl.respond_to?("owner=")
156
+ impl.owner = parent
177
157
  end
158
+ impl
178
159
  end
179
160
  end
180
-
181
- Plugin = PluginClass.new
182
161
  end
@@ -0,0 +1,63 @@
1
+ #
2
+ # Fluentd
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'fluent/plugin/base'
18
+
19
+ require 'fluent/log'
20
+ require 'fluent/plugin_id'
21
+ require 'fluent/plugin_helper'
22
+
23
+ module Fluent
24
+ module Plugin
25
+ class BareOutput < Base
26
+ # DO NOT USE THIS plugin for normal output plugin. Use Output instead.
27
+ # This output plugin base class is only for meta-output plugins
28
+ # which cannot be implemented on MultiOutput.
29
+ # E.g,: forest, config-expander
30
+
31
+ include PluginId
32
+ include PluginLoggerMixin
33
+ include PluginHelper::Mixin
34
+
35
+ attr_reader :num_errors, :emit_count, :emit_records
36
+
37
+ def process(tag, es)
38
+ raise NotImplementedError, "BUG: output plugins MUST implement this method"
39
+ end
40
+
41
+ def initialize
42
+ super
43
+ @counters_monitor = Monitor.new
44
+ # TODO: well organized counters
45
+ @num_errors = 0
46
+ @emit_count = 0
47
+ @emit_records = 0
48
+ end
49
+
50
+ def emit_sync(tag, es)
51
+ @counters_monitor.synchronize{ @emit_count += 1 }
52
+ begin
53
+ process(tag, es)
54
+ @counters_monitor.synchronize{ @emit_records += es.size }
55
+ rescue
56
+ @counters_monitor.synchronize{ @num_errors += 1 }
57
+ raise
58
+ end
59
+ end
60
+ alias :emit_events :emit_sync
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,121 @@
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'
18
+ require 'fluent/configurable'
19
+ require 'fluent/system_config'
20
+
21
+ module Fluent
22
+ module Plugin
23
+ class Base
24
+ include Configurable
25
+ include SystemConfig::Mixin
26
+
27
+ State = Struct.new(:configure, :start, :stop, :before_shutdown, :shutdown, :after_shutdown, :close, :terminate)
28
+
29
+ def initialize
30
+ super
31
+ @_state = State.new(false, false, false, false, false, false, false, false)
32
+ end
33
+
34
+ def has_router?
35
+ false
36
+ end
37
+
38
+ def configure(conf)
39
+ super
40
+ @_state ||= State.new(false, false, false, false, false, false, false, false)
41
+ @_state.configure = true
42
+ self
43
+ end
44
+
45
+ def start
46
+ @_state.start = true
47
+ self
48
+ end
49
+
50
+ def stop
51
+ @_state.stop = true
52
+ self
53
+ end
54
+
55
+ def before_shutdown
56
+ @_state.before_shutdown = true
57
+ self
58
+ end
59
+
60
+ def shutdown
61
+ @_state.shutdown = true
62
+ self
63
+ end
64
+
65
+ def after_shutdown
66
+ @_state.after_shutdown = true
67
+ self
68
+ end
69
+
70
+ def close
71
+ @_state.close = true
72
+ self
73
+ end
74
+
75
+ def terminate
76
+ @_state.terminate = true
77
+ self
78
+ end
79
+
80
+ def configured?
81
+ @_state.configure
82
+ end
83
+
84
+ def started?
85
+ @_state.start
86
+ end
87
+
88
+ def stopped?
89
+ @_state.stop
90
+ end
91
+
92
+ def before_shutdown?
93
+ @_state.before_shutdown
94
+ end
95
+
96
+ def shutdown?
97
+ @_state.shutdown
98
+ end
99
+
100
+ def after_shutdown?
101
+ @_state.after_shutdown
102
+ end
103
+
104
+ def closed?
105
+ @_state.close
106
+ end
107
+
108
+ def terminated?
109
+ @_state.terminate
110
+ end
111
+
112
+ def inspect
113
+ # Plugin instances are sometimes too big to dump because it may have too many thins (buffer,storage, ...)
114
+ # Original commit comment says that:
115
+ # To emulate normal inspect behavior `ruby -e'o=Object.new;p o;p (o.__id__<<1).to_s(16)'`.
116
+ # https://github.com/ruby/ruby/blob/trunk/gc.c#L788
117
+ "#<%s:%014x>" % [self.class.name, '0x%014x' % (__id__ << 1)]
118
+ end
119
+ end
120
+ end
121
+ end