fluentd 0.14.1 → 0.14.2

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 (129) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +110 -1
  3. data/Rakefile +5 -1
  4. data/appveyor.yml +7 -1
  5. data/example/in_forward.conf +4 -0
  6. data/lib/fluent/compat/exec_util.rb +129 -0
  7. data/lib/fluent/compat/file_util.rb +54 -0
  8. data/lib/fluent/compat/filter.rb +21 -3
  9. data/lib/fluent/compat/formatter.rb +4 -2
  10. data/lib/fluent/compat/formatter_utils.rb +85 -0
  11. data/lib/fluent/compat/handle_tag_and_time_mixin.rb +60 -0
  12. data/lib/fluent/compat/input.rb +1 -3
  13. data/lib/fluent/compat/output.rb +95 -39
  14. data/lib/fluent/compat/parser.rb +17 -0
  15. data/lib/fluent/compat/parser_utils.rb +40 -0
  16. data/lib/fluent/compat/socket_util.rb +165 -0
  17. data/lib/fluent/compat/string_util.rb +34 -0
  18. data/lib/fluent/{test/driver/owner.rb → compat/structured_format_mixin.rb} +5 -11
  19. data/lib/fluent/config/element.rb +2 -2
  20. data/lib/fluent/configurable.rb +2 -1
  21. data/lib/fluent/event.rb +61 -7
  22. data/lib/fluent/event_router.rb +1 -1
  23. data/lib/fluent/plugin.rb +7 -7
  24. data/lib/fluent/plugin/buf_file.rb +5 -2
  25. data/lib/fluent/plugin/buffer.rb +194 -64
  26. data/lib/fluent/plugin/buffer/chunk.rb +28 -3
  27. data/lib/fluent/plugin/buffer/file_chunk.rb +5 -21
  28. data/lib/fluent/plugin/buffer/memory_chunk.rb +1 -11
  29. data/lib/fluent/plugin/exec_util.rb +2 -112
  30. data/lib/fluent/plugin/file_util.rb +3 -38
  31. data/lib/fluent/plugin/file_wrapper.rb +1 -1
  32. data/lib/fluent/plugin/filter_grep.rb +3 -7
  33. data/lib/fluent/plugin/filter_record_transformer.rb +5 -5
  34. data/lib/fluent/plugin/filter_stdout.rb +18 -11
  35. data/lib/fluent/plugin/formatter.rb +0 -48
  36. data/lib/fluent/plugin/formatter_csv.rb +7 -8
  37. data/lib/fluent/plugin/formatter_hash.rb +1 -4
  38. data/lib/fluent/plugin/formatter_json.rb +1 -4
  39. data/lib/fluent/plugin/formatter_ltsv.rb +5 -6
  40. data/lib/fluent/plugin/formatter_msgpack.rb +1 -4
  41. data/lib/fluent/plugin/formatter_out_file.rb +36 -3
  42. data/lib/fluent/plugin/formatter_stdout.rb +36 -1
  43. data/lib/fluent/plugin/in_dummy.rb +9 -2
  44. data/lib/fluent/plugin/in_exec.rb +20 -57
  45. data/lib/fluent/plugin/in_forward.rb +4 -3
  46. data/lib/fluent/plugin/in_object_space.rb +8 -44
  47. data/lib/fluent/plugin/in_syslog.rb +13 -24
  48. data/lib/fluent/plugin/in_tail.rb +3 -0
  49. data/lib/fluent/plugin/out_buffered_stdout.rb +14 -4
  50. data/lib/fluent/plugin/out_exec.rb +7 -5
  51. data/lib/fluent/plugin/out_exec_filter.rb +10 -10
  52. data/lib/fluent/plugin/out_file.rb +1 -3
  53. data/lib/fluent/plugin/out_forward.rb +38 -57
  54. data/lib/fluent/plugin/out_stdout.rb +14 -5
  55. data/lib/fluent/plugin/out_stream.rb +3 -0
  56. data/lib/fluent/plugin/output.rb +31 -14
  57. data/lib/fluent/plugin/parser.rb +0 -69
  58. data/lib/fluent/plugin/parser_apache.rb +10 -6
  59. data/lib/fluent/plugin/parser_apache_error.rb +8 -3
  60. data/lib/fluent/plugin/parser_csv.rb +3 -1
  61. data/lib/fluent/plugin/parser_json.rb +1 -1
  62. data/lib/fluent/plugin/parser_multiline.rb +5 -3
  63. data/lib/fluent/plugin/parser_nginx.rb +10 -6
  64. data/lib/fluent/plugin/parser_regexp.rb +73 -0
  65. data/lib/fluent/plugin/socket_util.rb +2 -148
  66. data/lib/fluent/plugin/storage_local.rb +1 -1
  67. data/lib/fluent/plugin/string_util.rb +3 -18
  68. data/lib/fluent/plugin_helper.rb +1 -0
  69. data/lib/fluent/plugin_helper/compat_parameters.rb +166 -41
  70. data/lib/fluent/plugin_helper/formatter.rb +30 -19
  71. data/lib/fluent/plugin_helper/inject.rb +25 -12
  72. data/lib/fluent/plugin_helper/parser.rb +22 -13
  73. data/lib/fluent/plugin_helper/storage.rb +22 -13
  74. data/lib/fluent/registry.rb +19 -6
  75. data/lib/fluent/supervisor.rb +27 -1
  76. data/lib/fluent/test/driver/base.rb +16 -92
  77. data/lib/fluent/test/driver/base_owned.rb +17 -53
  78. data/lib/fluent/test/driver/base_owner.rb +125 -0
  79. data/lib/fluent/test/driver/filter.rb +24 -2
  80. data/lib/fluent/test/driver/input.rb +2 -2
  81. data/lib/fluent/test/driver/multi_output.rb +2 -2
  82. data/lib/fluent/test/driver/output.rb +3 -5
  83. data/lib/fluent/test/helpers.rb +25 -0
  84. data/lib/fluent/test/input_test.rb +4 -4
  85. data/lib/fluent/test/output_test.rb +3 -3
  86. data/lib/fluent/version.rb +1 -1
  87. data/test/config/test_element.rb +135 -6
  88. data/test/plugin/test_buf_file.rb +71 -3
  89. data/test/plugin/test_buffer.rb +305 -86
  90. data/test/plugin/test_buffer_chunk.rb +60 -2
  91. data/test/plugin/test_buffer_file_chunk.rb +4 -3
  92. data/test/plugin/test_filter_grep.rb +25 -21
  93. data/test/plugin/test_filter_record_transformer.rb +75 -67
  94. data/test/plugin/test_filter_stdout.rb +171 -74
  95. data/test/plugin/test_formatter_csv.rb +94 -0
  96. data/test/plugin/test_formatter_json.rb +30 -0
  97. data/test/plugin/test_formatter_ltsv.rb +52 -0
  98. data/test/plugin/test_formatter_msgpack.rb +28 -0
  99. data/test/plugin/test_formatter_out_file.rb +95 -0
  100. data/test/plugin/test_formatter_single_value.rb +38 -0
  101. data/test/plugin/test_in_dummy.rb +95 -0
  102. data/test/plugin/test_in_exec.rb +27 -31
  103. data/test/plugin/test_in_forward.rb +24 -0
  104. data/test/plugin/test_in_gc_stat.rb +5 -5
  105. data/test/plugin/test_in_object_space.rb +4 -4
  106. data/test/plugin/test_in_syslog.rb +60 -35
  107. data/test/plugin/test_out_buffered_stdout.rb +17 -3
  108. data/test/plugin/test_out_forward.rb +93 -5
  109. data/test/plugin/test_out_stdout.rb +14 -3
  110. data/test/plugin/test_output_as_buffered_retries.rb +20 -0
  111. data/test/plugin/test_output_as_buffered_secondary.rb +16 -0
  112. data/test/plugin/test_output_as_standard.rb +22 -22
  113. data/test/plugin/test_parser_apache.rb +13 -9
  114. data/test/plugin/test_parser_apache_error.rb +11 -6
  115. data/test/plugin/test_parser_csv.rb +35 -25
  116. data/test/plugin/test_parser_nginx.rb +11 -5
  117. data/test/plugin/test_parser_regexp.rb +235 -68
  118. data/test/plugin/test_parser_tsv.rb +54 -58
  119. data/test/plugin_helper/test_compat_parameters.rb +111 -46
  120. data/test/plugin_helper/test_formatter.rb +40 -0
  121. data/test/plugin_helper/test_inject.rb +101 -2
  122. data/test/plugin_helper/test_parser.rb +40 -0
  123. data/test/plugin_helper/test_storage.rb +43 -0
  124. data/test/test_event.rb +93 -0
  125. data/test/test_event_router.rb +13 -4
  126. data/test/test_event_time.rb +0 -3
  127. data/test/test_formatter.rb +7 -164
  128. data/test/test_plugin_classes.rb +28 -1
  129. metadata +24 -3
@@ -14,6 +14,7 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
+ require 'fluent/config/types'
17
18
  require 'fluent/config/element'
18
19
 
19
20
  module Fluent
@@ -24,7 +25,7 @@ module Fluent
24
25
  # This helper is mainly to convert plugins from v0.12 API
25
26
  # to v0.14 API safely, without breaking user deployment.
26
27
 
27
- PARAMS_MAP = {
28
+ BUFFER_PARAMS = {
28
29
  "buffer_type" => "@type",
29
30
  "buffer_path" => "path",
30
31
  "num_threads" => "flush_thread_count",
@@ -40,59 +41,183 @@ module Fluent
40
41
  "flush_at_shutdown" => "flush_at_shutdown",
41
42
  }
42
43
 
43
- TIME_SLICED_PARAMS = {
44
+ BUFFER_TIME_SLICED_PARAMS = {
44
45
  "time_slice_format" => nil,
45
46
  "time_slice_wait" => "timekey_wait",
46
47
  }
47
48
 
48
- def compat_parameters_default_chunk_key
49
- # '', 'time' or 'tag'
50
- raise NotImplementedError, "return one of '', 'time' or 'tag'"
49
+ PARSER_PARAMS = {
50
+ "format" => "@type",
51
+ "time_key" => "time_key",
52
+ "time_format" => "time_format",
53
+ "delimiter" => "delimiter",
54
+ "json_parser" => "json_parser", # JSONParser
55
+ "label_delimiter" => "label_delimiter", # LabeledTSVParser
56
+ "format_firstline" => "format_firstline", # MultilineParser
57
+ "message_key" => "message_key", # NoneParser
58
+ "with_priority" => "with_priority", # SyslogParser
59
+ }
60
+
61
+ INJECT_PARAMS = {
62
+ "include_time_key" => nil,
63
+ "time_key" => "time_key",
64
+ "time_format" => "time_format",
65
+ "timezone" => "timezone",
66
+ "include_tag_key" => nil,
67
+ "tag_key" => "tag_key",
68
+ "localtime" => nil,
69
+ "utc" => nil,
70
+ }
71
+
72
+ FORMATTER_PARAMS = {
73
+ "format" => "@type",
74
+ "delimiter" => "delimiter",
75
+ "force_quotes" => "force_quotes", # CsvFormatter
76
+ "fields" => "fields", # CsvFormatter
77
+ "json_parser" => "json_parser", # JSONFormatter
78
+ "label_delimiter" => "label_delimiter", # LabeledTSVFormatter
79
+ "output_time" => "output_time", # OutFileFormatter
80
+ "output_tag" => "output_tag", # OutFileFormatter
81
+ "message_key" => "message_key", # SingleValueFormatter
82
+ "add_newline" => "add_newline", # SingleValueFormatter
83
+ "output_type" => "output_type", # StdoutFormatter
84
+ }
85
+
86
+ def compat_parameters_convert(conf, *types, **kwargs)
87
+ types.each do |type|
88
+ case type
89
+ when :buffer
90
+ compat_parameters_buffer(conf, **kwargs)
91
+ when :inject
92
+ compat_parameters_inject(conf)
93
+ when :parser
94
+ compat_parameters_parser(conf)
95
+ when :formatter
96
+ compat_parameters_formatter(conf)
97
+ else
98
+ raise "BUG: unknown compat_parameters type: #{type}"
99
+ end
100
+ end
101
+
102
+ conf
51
103
  end
52
104
 
53
- def configure(conf)
54
- if conf.elements('buffer').empty? && PARAMS_MAP.keys.any?{|k| conf.has_key?(k) } || TIME_SLICED_PARAMS.keys.any?{|k| conf.has_key?(k) }
55
- # TODO: warn obsolete parameters if these are deprecated
56
- attr = {}
57
- PARAMS_MAP.each do |compat, current|
58
- next unless current
59
- if conf.has_key?(compat)
60
- if compat == 'buffer_queue_full_action' && conf[compat] == 'exception'
61
- attr[current] = 'throw_exception'
62
- else
63
- attr[current] = conf[compat]
64
- end
65
- end
105
+ def compat_parameters_buffer(conf, default_chunk_key: '')
106
+ # return immediately if <buffer> section exists, or any buffer-related parameters don't exist
107
+ return unless conf.elements('buffer').empty?
108
+ return if (BUFFER_PARAMS.keys + BUFFER_TIME_SLICED_PARAMS.keys).all?{|k| !conf.has_key?(k) }
109
+
110
+ # TODO: warn obsolete parameters if these are deprecated
111
+ buffer_params = BUFFER_PARAMS.merge(BUFFER_TIME_SLICED_PARAMS)
112
+ attr = compat_parameters_copy_to_subsection_attributes(conf, buffer_params) do |compat_key, value|
113
+ if compat_key == 'buffer_queue_full_action' && value == 'exception'
114
+ 'throw_exception'
115
+ else
116
+ value
66
117
  end
67
- TIME_SLICED_PARAMS.each do |compat, current|
68
- next unless current
69
- attr[current] = conf[compat] if conf.has_key?(compat)
118
+ end
119
+
120
+ chunk_key = default_chunk_key
121
+
122
+ if conf.has_key?('time_slice_format')
123
+ chunk_key = 'time'
124
+ attr['timekey'] = case conf['time_slice_format']
125
+ when /\%S/ then 1
126
+ when /\%M/ then 60
127
+ when /\%H/ then 3600
128
+ when /\%d/ then 86400
129
+ else
130
+ raise Fluent::ConfigError, "time_slice_format only with %Y or %m is too long"
131
+ end
132
+ else
133
+ if chunk_key == 'time'
134
+ attr['timekey'] = 86400 # TimeSliceOutput.time_slice_format default value is '%Y%m%d'
70
135
  end
136
+ end
71
137
 
72
- chunk_key = nil
73
-
74
- if conf.has_key?('time_slice_format')
75
- chunk_key = 'time'
76
- attr['timekey'] = case conf['time_slice_format']
77
- when /\%S/ then 1
78
- when /\%M/ then 60
79
- when /\%H/ then 3600
80
- when /\%d/ then 86400
81
- else
82
- raise Fluent::ConfigError, "time_slice_format only with %Y or %m is too long"
83
- end
84
- else
85
- chunk_key = compat_parameters_default_chunk_key
86
- if chunk_key == 'time'
87
- attr['timekey'] = 86400 # TimeSliceOutput.time_slice_format default value is '%Y%m%d'
88
- end
138
+ e = Fluent::Config::Element.new('buffer', chunk_key, attr, [])
139
+ conf.elements << e
140
+
141
+ conf
142
+ end
143
+
144
+ def compat_parameters_inject(conf)
145
+ return unless conf.elements('inject').empty?
146
+ return if INJECT_PARAMS.keys.all?{|k| !conf.has_key?(k) }
147
+
148
+ # TODO: warn obsolete parameters if these are deprecated
149
+ attr = compat_parameters_copy_to_subsection_attributes(conf, INJECT_PARAMS)
150
+
151
+ if conf.has_key?('include_time_key') && Fluent::Config.bool_value(conf['include_time_key'])
152
+ attr['time_key'] ||= 'time'
153
+ attr['time_type'] ||= 'string'
154
+ end
155
+ if conf.has_key?('time_as_epoch') && Fluent::Config.bool_value(conf['time_as_epoch'])
156
+ attr['time_type'] = 'unixtime'
157
+ end
158
+ if conf.has_key?('localtime') || conf.has_key?('utc')
159
+ if conf.has_key?('localtime') && conf.has_key?('utc')
160
+ raise Fluent::ConfigError, "both of utc and localtime are specified, use only one of them"
161
+ elsif conf.has_key?('localtime')
162
+ attr['localtime'] = Fluent::Config.bool_value(conf['localtime'])
163
+ elsif conf.has_key?('utc')
164
+ attr['localtime'] = !(Fluent::Config.bool_value(conf['utc']))
165
+ # Specifying "localtime false" means using UTC in TimeFormatter
166
+ # And specifying "utc" is different from specifying "timezone +0000"(it's not always UTC).
167
+ # There are difference between "Z" and "+0000" in timezone formatting.
168
+ # TODO: add kwargs to TimeFormatter to specify "using localtime", "using UTC" or "using specified timezone" in more explicit way
89
169
  end
170
+ end
90
171
 
91
- e = Fluent::Config::Element.new('buffer', chunk_key, attr, [])
92
- conf.elements << e
172
+ if conf.has_key?('include_tag_key') && Fluent::Config.bool_value(conf['include_tag_key'])
173
+ attr['tag_key'] ||= 'tag'
93
174
  end
94
175
 
95
- super
176
+ e = Fluent::Config::Element.new('inject', '', attr, [])
177
+ conf.elements << e
178
+
179
+ conf
180
+ end
181
+
182
+ def compat_parameters_parser(conf)
183
+ return unless conf.elements('parse').empty?
184
+ return if PARSER_PARAMS.keys.all?{|k| !conf.has_key?(k) }
185
+
186
+ # TODO: warn obsolete parameters if these are deprecated
187
+ attr = compat_parameters_copy_to_subsection_attributes(conf, PARSER_PARAMS)
188
+
189
+ e = Fluent::Config::Element.new('parse', '', attr, [])
190
+ conf.elements << e
191
+
192
+ conf
193
+ end
194
+
195
+ def compat_parameters_formatter(conf)
196
+ return unless conf.elements('format').empty?
197
+ return if FORMATTER_PARAMS.keys.all?{|k| !conf.has_key?(k) }
198
+
199
+ # TODO: warn obsolete parameters if these are deprecated
200
+ attr = compat_parameters_copy_to_subsection_attributes(conf, FORMATTER_PARAMS)
201
+
202
+ e = Fluent::Config::Element.new('format', '', attr, [])
203
+ conf.elements << e
204
+
205
+ conf
206
+ end
207
+
208
+ def compat_parameters_copy_to_subsection_attributes(conf, params, &block)
209
+ attr = {}
210
+ params.each do |compat, current|
211
+ next unless current
212
+ if conf.has_key?(compat)
213
+ if block_given?
214
+ attr[current] = block.call(compat, conf[compat])
215
+ else
216
+ attr[current] = conf[compat]
217
+ end
218
+ end
219
+ end
220
+ attr
96
221
  end
97
222
  end
98
223
  end
@@ -17,19 +17,25 @@
17
17
  require 'fluent/plugin'
18
18
  require 'fluent/plugin/formatter'
19
19
  require 'fluent/config/element'
20
+ require 'fluent/configurable'
20
21
 
21
22
  module Fluent
22
23
  module PluginHelper
23
24
  module Formatter
24
- def formatter_create(usage: '', type: nil, conf: nil)
25
+ def formatter_create(usage: '', type: nil, conf: nil, default_type: nil)
25
26
  formatter = @_formatters[usage]
26
27
  return formatter if formatter
27
28
 
28
- if !type
29
- raise ArgumentError, "BUG: both type and conf are not specified" unless conf
30
- raise Fluent::ConfigError, "@type is required in <format>" unless conf['@type']
31
- type = conf['@type']
32
- end
29
+ type = if type
30
+ type
31
+ elsif conf && conf.respond_to?(:[])
32
+ raise Fluent::ConfigError, "@type is required in <format>" unless conf['@type']
33
+ conf['@type']
34
+ elsif default_type
35
+ default_type
36
+ else
37
+ raise ArgumentError, "BUG: both type and conf are not specified"
38
+ end
33
39
  formatter = Fluent::Plugin.new_formatter(type, parent: self)
34
40
  config = case conf
35
41
  when Fluent::Config::Element
@@ -52,16 +58,19 @@ module Fluent
52
58
  formatter
53
59
  end
54
60
 
55
- def self.included(mod)
56
- mod.instance_eval do
57
- # minimum section definition to instantiate formatter plugin instances
58
- config_section :format, required: false, multi: true, param_name: :formatter_configs do
59
- config_argument :usage, :string, default: ''
60
- config_param :@type, :string
61
- end
61
+ module FormatterParams
62
+ include Fluent::Configurable
63
+ # minimum section definition to instantiate formatter plugin instances
64
+ config_section :format, required: false, multi: true, param_name: :formatter_configs do
65
+ config_argument :usage, :string, default: ''
66
+ config_param :@type, :string
62
67
  end
63
68
  end
64
69
 
70
+ def self.included(mod)
71
+ mod.include FormatterParams
72
+ end
73
+
65
74
  attr_reader :_formatters # for tests
66
75
 
67
76
  def initialize
@@ -73,13 +82,15 @@ module Fluent
73
82
  def configure(conf)
74
83
  super
75
84
 
76
- @formatter_configs.each do |section|
77
- if @_formatters[section.usage]
78
- raise Fluent::ConfigError, "duplicated formatter configured: #{section.usage}"
85
+ if @formatter_configs
86
+ @formatter_configs.each do |section|
87
+ if @_formatters[section.usage]
88
+ raise Fluent::ConfigError, "duplicated formatter configured: #{section.usage}"
89
+ end
90
+ formatter = Plugin.new_formatter(section[:@type], parent: self)
91
+ formatter.configure(section.corresponding_config_element)
92
+ @_formatters[section.usage] = formatter
79
93
  end
80
- formatter = Plugin.new_formatter(section[:@type], parent: self)
81
- formatter.configure(section.corresponding_config_element)
82
- @_formatters[section.usage] = formatter
83
94
  end
84
95
  end
85
96
 
@@ -16,6 +16,7 @@
16
16
 
17
17
  require 'fluent/event'
18
18
  require 'time'
19
+ require 'fluent/configurable'
19
20
 
20
21
  module Fluent
21
22
  module PluginHelper
@@ -58,22 +59,28 @@ module Fluent
58
59
  new_es
59
60
  end
60
61
 
61
- def self.included(mod)
62
- mod.instance_eval do
63
- config_section :inject, required: false, multi: false, param_name: :inject_config do
64
- config_param :hostname_key, :string, default: nil
65
- config_param :hostname, :string, default: nil
66
- config_param :tag_key, :string, default: nil
67
- config_param :time_key, :string, default: nil
68
- config_param :time_type, :enum, list: [:float, :unixtime, :string], default: :float
69
- config_param :time_format, :string, default: nil
70
- config_param :timezone, :string, default: "#{Time.now.strftime('%z')}" # localtime
71
- end
62
+ module InjectParams
63
+ include Fluent::Configurable
64
+ config_section :inject, required: false, multi: false, param_name: :inject_config do
65
+ config_param :hostname_key, :string, default: nil
66
+ config_param :hostname, :string, default: nil
67
+ config_param :tag_key, :string, default: nil
68
+ config_param :time_key, :string, default: nil
69
+ config_param :time_type, :enum, list: [:float, :unixtime, :string], default: :float
70
+ config_param :time_format, :string, default: nil
71
+ config_param :localtime, :bool, default: true # if localtime is false and timezone is nil, then utc
72
+ config_param :utc, :bool, default: false # placeholder to turn localtime to false
73
+ config_param :timezone, :string, default: nil
72
74
  end
73
75
  end
74
76
 
77
+ def self.included(mod)
78
+ mod.include InjectParams
79
+ end
80
+
75
81
  def initialize
76
82
  super
83
+ @_inject_enabled = false
77
84
  @_inject_hostname_key = nil
78
85
  @_inject_hostname = nil
79
86
  @_inject_tag_key = nil
@@ -82,6 +89,12 @@ module Fluent
82
89
  end
83
90
 
84
91
  def configure(conf)
92
+ conf.elements('inject').each do |e|
93
+ if e.has_key?('utc') && Fluent::Config.bool_value(e['utc'])
94
+ e['localtime'] = 'false'
95
+ end
96
+ end
97
+
85
98
  super
86
99
 
87
100
  if @inject_config
@@ -100,7 +113,7 @@ module Fluent
100
113
  when :float then ->(time){ time.to_r.truncate(+6).to_f } # microsecond floating point value
101
114
  when :unixtime then ->(time){ time.to_i }
102
115
  else
103
- Fluent::TimeFormatter.new(@inject_config.time_format, false, @inject_config.timezone)
116
+ Fluent::TimeFormatter.new(@inject_config.time_format, @inject_config.localtime, @inject_config.timezone)
104
117
  end
105
118
  end
106
119
 
@@ -17,19 +17,25 @@
17
17
  require 'fluent/plugin'
18
18
  require 'fluent/plugin/parser'
19
19
  require 'fluent/config/element'
20
+ require 'fluent/configurable'
20
21
 
21
22
  module Fluent
22
23
  module PluginHelper
23
24
  module Parser
24
- def parser_create(usage: '', type: nil, conf: nil)
25
+ def parser_create(usage: '', type: nil, conf: nil, default_type: nil)
25
26
  parser = @_parsers[usage]
26
27
  return parser if parser
27
28
 
28
- if !type
29
- raise ArgumentError, "BUG: both type and conf are not specified" unless conf
30
- raise Fluent::ConfigError, "@type is required in <parse>" unless conf['@type']
31
- type = conf['@type']
32
- end
29
+ type = if type
30
+ type
31
+ elsif conf && conf.respond_to?(:[])
32
+ raise Fluent::ConfigError, "@type is required in <parse>" unless conf['@type']
33
+ conf['@type']
34
+ elsif default_type
35
+ default_type
36
+ else
37
+ raise ArgumentError, "BUG: both type and conf are not specified"
38
+ end
33
39
  parser = Fluent::Plugin.new_parser(type, parent: self)
34
40
  config = case conf
35
41
  when Fluent::Config::Element
@@ -52,16 +58,19 @@ module Fluent
52
58
  parser
53
59
  end
54
60
 
55
- def self.included(mod)
56
- mod.instance_eval do
57
- # minimum section definition to instantiate parser plugin instances
58
- config_section :parse, required: false, multi: true, param_name: :parser_configs do
59
- config_argument :usage, :string, default: ''
60
- config_param :@type, :string
61
- end
61
+ module ParserParams
62
+ include Fluent::Configurable
63
+ # minimum section definition to instantiate parser plugin instances
64
+ config_section :parse, required: false, multi: true, param_name: :parser_configs do
65
+ config_argument :usage, :string, default: ''
66
+ config_param :@type, :string
62
67
  end
63
68
  end
64
69
 
70
+ def self.included(mod)
71
+ mod.include ParserParams
72
+ end
73
+
65
74
  attr_reader :_parsers # for tests
66
75
 
67
76
  def initialize
@@ -20,6 +20,7 @@ require 'fluent/plugin'
20
20
  require 'fluent/plugin/storage'
21
21
  require 'fluent/plugin_helper/timer'
22
22
  require 'fluent/config/element'
23
+ require 'fluent/configurable'
23
24
 
24
25
  module Fluent
25
26
  module PluginHelper
@@ -28,18 +29,23 @@ module Fluent
28
29
 
29
30
  StorageState = Struct.new(:storage, :running)
30
31
 
31
- def storage_create(usage: '', type: nil, conf: nil)
32
+ def storage_create(usage: '', type: nil, conf: nil, default_type: nil)
32
33
  s = @_storages[usage]
33
34
  if s && s.running
34
35
  return s.storage
35
36
  elsif s
36
37
  # storage is already created, but not loaded / started
37
38
  else # !s
38
- if !type
39
- raise ArgumentError, "BUG: both type and conf are not specified" unless conf
40
- raise Fluent::ConfigError, "@type is not specified for <storage>" unless conf['@type']
41
- type = conf['@type']
42
- end
39
+ type = if type
40
+ type
41
+ elsif conf && conf.respond_to?(:[])
42
+ raise Fluent::ConfigError, "@type is required in <storage>" unless conf['@type']
43
+ conf['@type']
44
+ elsif default_type
45
+ default_type
46
+ else
47
+ raise ArgumentError, "BUG: both type and conf are not specified"
48
+ end
43
49
  storage = Plugin.new_storage(type, parent: self)
44
50
  config = case conf
45
51
  when Fluent::Config::Element
@@ -63,16 +69,19 @@ module Fluent
63
69
  s.storage
64
70
  end
65
71
 
66
- def self.included(mod)
67
- mod.instance_eval do
68
- # minimum section definition to instantiate storage plugin instances
69
- config_section :storage, required: false, multi: true, param_name: :storage_configs do
70
- config_argument :usage, :string, default: ''
71
- config_param :@type, :string, default: Fluent::Plugin::Storage::DEFAULT_TYPE
72
- end
72
+ module StorageParams
73
+ include Fluent::Configurable
74
+ # minimum section definition to instantiate storage plugin instances
75
+ config_section :storage, required: false, multi: true, param_name: :storage_configs do
76
+ config_argument :usage, :string, default: ''
77
+ config_param :@type, :string, default: Fluent::Plugin::Storage::DEFAULT_TYPE
73
78
  end
74
79
  end
75
80
 
81
+ def self.included(mod)
82
+ mod.include StorageParams
83
+ end
84
+
76
85
  attr_reader :_storages # for tests
77
86
 
78
87
  def initialize