fluentd 1.8.0.rc2 → 1.8.0.rc3

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.

@@ -115,50 +115,12 @@ module Fluent
115
115
  s
116
116
  end
117
117
 
118
- def attach(supervisor)
119
- system = self
120
- supervisor.instance_eval {
121
- SYSTEM_CONFIG_PARAMETERS.each do |param|
122
- case param
123
- when :rpc_endpoint, :enable_get_dump, :process_name, :file_permission, :dir_permission, :counter_server, :counter_client
124
- next # doesn't exist in command line options
125
- when :emit_error_log_interval
126
- system.emit_error_log_interval = @suppress_interval if @suppress_interval
127
- when :log_level
128
- ll_value = instance_variable_get("@log_level")
129
- # info level can't be specified via command line option.
130
- # log_level is info here, it is default value and <system>'s log_level should be applied if exists.
131
- if ll_value != Fluent::Log::LEVEL_INFO
132
- system.log_level = ll_value
133
- end
134
- else
135
- next unless instance_variable_defined?("@#{param}")
136
- supervisor_value = instance_variable_get("@#{param}")
137
- next if supervisor_value.nil? # it's not configured by command line options
138
-
139
- system.__send__("#{param}=", supervisor_value)
140
- end
141
- end
142
- }
143
- end
144
-
145
- def apply(supervisor)
146
- system = self
147
- supervisor.instance_eval {
148
- SYSTEM_CONFIG_PARAMETERS.each do |param|
149
- param_value = system.__send__(param)
150
- next if param_value.nil?
151
-
152
- case param
153
- when :log_level
154
- @log.level = @log_level = param_value
155
- else
156
- instance_variable_set("@#{param}", param_value)
157
- end
118
+ def overwrite_variables(**opt)
119
+ SYSTEM_CONFIG_PARAMETERS.each do |param|
120
+ if opt.key?(param) && !opt[param].nil? && instance_variable_defined?("@#{param}")
121
+ instance_variable_set("@#{param}", opt[param])
158
122
  end
159
- #@counter_server = system.counter_server unless system.counter_server.nil?
160
- #@counter_client = system.counter_client unless system.counter_client.nil?
161
- }
123
+ end
162
124
  end
163
125
 
164
126
  module Mixin
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Fluent
18
18
 
19
- VERSION = '1.8.0.rc2'
19
+ VERSION = '1.8.0.rc3'
20
20
 
21
21
  end
@@ -317,7 +317,8 @@ CONF
317
317
  create_cmdline(conf_path),
318
318
  "fluentd worker is now running",
319
319
  'fluent.info: {"worker":0,"message":"fluentd worker is now running worker=0"}',
320
- patterns_not_match: ['[warn]: some tags for log events are not defined (to be ignored) tags=["fluent.trace", "fluent.debug"]'],
320
+ "define <match fluent.**> to capture fluentd logs in top level is deprecated. Use <label @FLUENT_LOG> instead",
321
+ patterns_not_match: ['[warn]: some tags for log events are not defined in top level (to be ignored) tags=["fluent.trace", "fluent.debug"]'],
321
322
  )
322
323
  end
323
324
 
@@ -331,7 +332,8 @@ CONF
331
332
  assert_log_matches(
332
333
  create_cmdline(conf_path),
333
334
  "fluentd worker is now running",
334
- '[warn]: #0 match for some tags of log events are not defined (to be ignored) tags=["fluent.trace", "fluent.debug", "fluent.info"]',
335
+ '[warn]: #0 match for some tags of log events are not defined in top level (to be ignored) tags=["fluent.trace", "fluent.debug", "fluent.info"]',
336
+ "define <match fluent.warn>, <match fluent.error>, <match fluent.fatal> to capture fluentd logs in top level is deprecated. Use <label @FLUENT_LOG> instead",
335
337
  '[warn]: #0 no patterns matched tag="fluent.info"',
336
338
  )
337
339
  end
@@ -349,7 +351,7 @@ CONF
349
351
  create_cmdline(conf_path),
350
352
  "fluentd worker is now running",
351
353
  'fluent.info: {"worker":0,"message":"fluentd worker is now running worker=0"}',
352
- patterns_not_match: ['[warn]: some tags for log events are not defined (to be ignored)'],
354
+ patterns_not_match: ['[warn]: some tags for log events are not defined in @FLUENT_LOG label (to be ignored)'],
353
355
  )
354
356
  end
355
357
 
@@ -368,7 +370,7 @@ CONF
368
370
  assert_log_matches(
369
371
  create_cmdline(conf_path),
370
372
  "fluentd worker is now running",
371
- '[warn]: #0 match for some tags of log events are not defined (to be ignored) tags=["fluent.info", "fluent.fatal"]',
373
+ '[warn]: #0 match for some tags of log events are not defined in @FLUENT_LOG label (to be ignored) tags=["fluent.info", "fluent.fatal"]',
372
374
  patterns_not_match: ['[warn]: no patterns matched tag="fluent.info"'],
373
375
  )
374
376
  end
@@ -625,7 +627,8 @@ CONF
625
627
  workers 2
626
628
  </system>
627
629
  <source>
628
- @type single
630
+ @type dummy
631
+ tag dummy
629
632
  @id single
630
633
  @label @dummydata
631
634
  </source>
@@ -669,7 +672,8 @@ EOC
669
672
  workers 2
670
673
  </system>
671
674
  <source>
672
- @type single
675
+ @type dummy
676
+ tag dummy
673
677
  @id single
674
678
  @label @dummydata
675
679
  </source>
@@ -793,7 +797,7 @@ CONF
793
797
  @id blackhole
794
798
  <buffer>
795
799
  @type file
796
- path #{File.join(@root_path, "buf", "file.*.log")}
800
+ path #{File.join(@root_path, "buf")}
797
801
  </buffer>
798
802
  </match>
799
803
  </worker>
@@ -863,6 +867,7 @@ module Fluent::Plugin
863
867
  class FakeInput < Input
864
868
  Fluent::Plugin.register_input('fake', self)
865
869
  config_param :secret, :string, secret: true
870
+ def multi_workers_ready?; true; end
866
871
  end
867
872
  end
868
873
  EOC
@@ -15,20 +15,41 @@ module Fluent::Config
15
15
  class FakeSupervisor
16
16
  attr_writer :log_level
17
17
 
18
- def initialize
19
- @workers = nil
20
- @root_dir = nil
21
- @log = FakeLoggerInitializer.new
22
- @log_level = Fluent::Log::LEVEL_INFO
23
- @suppress_interval = nil
24
- @suppress_config_dump = nil
25
- @suppress_repeated_stacktrace = nil
26
- @log_event_label = nil
27
- @log_event_verbose = nil
28
- @without_source = nil
29
- @emit_error_log_interval = nil
30
- @file_permission = nil
31
- @dir_permission = nil
18
+ def initialize(**opt)
19
+ @system_config = nil
20
+ @cl_opt = {
21
+ wokers: nil,
22
+ root_dir: nil,
23
+ log: FakeLoggerInitializer.new,
24
+ log_level: Fluent::Log::LEVEL_INFO,
25
+ suppress_interval: nil,
26
+ suppress_config_dump: nil,
27
+ suppress_repeated_stacktrace: nil,
28
+ log_event_label: nil,
29
+ log_event_verbose: nil,
30
+ without_source: nil,
31
+ emit_error_log_interval: nil,
32
+ file_permission: nil,
33
+ dir_permission: nil,
34
+ }.merge(opt)
35
+ end
36
+
37
+ def for_system_config
38
+ opt = {}
39
+ # this is copy from Supervisor#build_system_config
40
+ Fluent::SystemConfig::SYSTEM_CONFIG_PARAMETERS.each do |param|
41
+ if @cl_opt.key?(param) && !@cl_opt[param].nil?
42
+ if param == :log_level && @cl_opt[:log_level] == Fluent::Log::LEVEL_INFO
43
+ # info level can't be specified via command line option.
44
+ # log_level is info here, it is default value and <system>'s log_level should be applied if exists.
45
+ next
46
+ end
47
+
48
+ opt[param] = @cl_opt[param]
49
+ end
50
+ end
51
+
52
+ opt
32
53
  end
33
54
  end
34
55
 
@@ -47,7 +68,7 @@ module Fluent::Config
47
68
  EOS
48
69
  s = FakeSupervisor.new
49
70
  sc = Fluent::SystemConfig.new(conf)
50
- sc.apply(s)
71
+ sc.overwrite_variables(s.for_system_config)
51
72
  assert_equal(1, sc.workers)
52
73
  assert_nil(sc.root_dir)
53
74
  assert_nil(sc.log_level)
@@ -57,16 +78,6 @@ module Fluent::Config
57
78
  assert_nil(sc.without_source)
58
79
  assert_equal(:text, sc.log.format)
59
80
  assert_equal('%Y-%m-%d %H:%M:%S %z', sc.log.time_format)
60
- assert_equal(1, s.instance_variable_get(:@workers))
61
- assert_nil(s.instance_variable_get(:@root_dir))
62
- assert_equal(Fluent::Log::LEVEL_INFO, s.instance_variable_get(:@log_level))
63
- assert_nil(s.instance_variable_get(:@suppress_repeated_stacktrace))
64
- assert_nil(s.instance_variable_get(:@emit_error_log_interval))
65
- assert_nil(s.instance_variable_get(:@suppress_config_dump))
66
- assert_nil(s.instance_variable_get(:@log_event_verbose))
67
- assert_nil(s.instance_variable_get(:@without_source))
68
- assert_nil(s.instance_variable_get(:@file_permission))
69
- assert_nil(s.instance_variable_get(:@dir_permission))
70
81
  end
71
82
 
72
83
  data(
@@ -86,10 +97,12 @@ module Fluent::Config
86
97
  EOS
87
98
  s = FakeSupervisor.new
88
99
  sc = Fluent::SystemConfig.new(conf)
89
- sc.apply(s)
90
- assert_not_nil(sc.instance_variable_get("@#{k}"))
91
- key = (k == 'emit_error_log_interval' ? 'suppress_interval' : k)
92
- assert_not_nil(s.instance_variable_get("@#{key}"))
100
+ sc.overwrite_variables(s.for_system_config)
101
+ if k == 'log_level'
102
+ assert_equal(Fluent::Log::LEVEL_ERROR, sc.__send__(k))
103
+ else
104
+ assert_equal(v, sc.__send__(k))
105
+ end
93
106
  end
94
107
 
95
108
  test "log parameters" do
@@ -103,50 +116,11 @@ module Fluent::Config
103
116
  EOS
104
117
  s = FakeSupervisor.new
105
118
  sc = Fluent::SystemConfig.new(conf)
106
- sc.apply(s)
119
+ sc.overwrite_variables(s.for_system_config)
107
120
  assert_equal(:json, sc.log.format)
108
121
  assert_equal('%Y', sc.log.time_format)
109
122
  end
110
123
 
111
- data(
112
- 'foo' => ['foo', 'bar'],
113
- 'hoge' => ['hoge', 'fuga'],
114
- )
115
- test "should not affect settable parameters with unknown parameters" do |(k, v)|
116
- s = FakeSupervisor.new
117
- sc = Fluent::SystemConfig.new({k => v})
118
- sc.apply(s)
119
- assert_equal(1, s.instance_variable_get(:@workers))
120
- assert_nil(s.instance_variable_get(:@root_dir))
121
- assert_equal(Fluent::Log::LEVEL_INFO, s.instance_variable_get(:@log_level))
122
- assert_nil(s.instance_variable_get(:@suppress_repeated_stacktrace))
123
- assert_nil(s.instance_variable_get(:@emit_error_log_interval))
124
- assert_nil(s.instance_variable_get(:@suppress_config_dump))
125
- assert_nil(s.instance_variable_get(:@log_event_verbose))
126
- assert_nil(s.instance_variable_get(:@without_source))
127
- assert_nil(s.instance_variable_get(:@file_permission))
128
- assert_nil(s.instance_variable_get(:@dir_permission))
129
- end
130
-
131
- data('trace' => Fluent::Log::LEVEL_TRACE,
132
- 'debug' => Fluent::Log::LEVEL_DEBUG,
133
- 'info' => Fluent::Log::LEVEL_INFO,
134
- 'warn' => Fluent::Log::LEVEL_WARN,
135
- 'error' => Fluent::Log::LEVEL_ERROR,
136
- 'fatal' => Fluent::Log::LEVEL_FATAL)
137
- test 'log_level is applied when log_level related command line option is not passed' do |level|
138
- conf = parse_text(<<-EOS)
139
- <system>
140
- log_level #{Fluent::Log::LEVEL_TEXT[level]}
141
- </system>
142
- EOS
143
- s = FakeSupervisor.new
144
- sc = Fluent::SystemConfig.new(conf)
145
- sc.attach(s)
146
- sc.apply(s)
147
- assert_equal(level, s.instance_variable_get("@log").level)
148
- end
149
-
150
124
  # info is removed because info level can't be specified via command line
151
125
  data('trace' => Fluent::Log::LEVEL_TRACE,
152
126
  'debug' => Fluent::Log::LEVEL_DEBUG,
@@ -159,27 +133,10 @@ module Fluent::Config
159
133
  log_level info
160
134
  </system>
161
135
  EOS
162
- s = FakeSupervisor.new
163
- s.log_level = level
164
- sc = Fluent::SystemConfig.new(conf)
165
- sc.attach(s)
166
- sc.apply(s)
167
- assert_equal(level, s.instance_variable_get("@log").level)
168
- end
169
-
170
- test 'process global overridable variables' do
171
- conf = parse_text(<<-EOS)
172
- <system>
173
- file_permission 0655
174
- dir_permission 0765
175
- </system>
176
- EOS
177
- s = FakeSupervisor.new
136
+ s = FakeSupervisor.new(log_level: level)
178
137
  sc = Fluent::SystemConfig.new(conf)
179
- sc.attach(s)
180
- sc.apply(s)
181
- assert_equal(0655, s.instance_variable_get(:@file_permission))
182
- assert_equal(0765, s.instance_variable_get(:@dir_permission))
138
+ sc.overwrite_variables(s.for_system_config)
139
+ assert_equal(level, sc.log_level)
183
140
  end
184
141
  end
185
142
  end
@@ -327,6 +327,46 @@ class FileBufferTest < Test::Unit::TestCase
327
327
  plugin.stop; plugin.before_shutdown; plugin.shutdown; plugin.after_shutdown; plugin.close; plugin.terminate
328
328
  FileUtils.rm_r bufdir
329
329
  end
330
+
331
+ test '#generate_chunk generates blank file chunk with specified permission with system_config' do
332
+ omit "NTFS doesn't support UNIX like permissions" if Fluent.windows?
333
+
334
+ begin
335
+ plugin = Fluent::Plugin::FileBuffer.new
336
+ plugin.owner = @d
337
+ rand_num = rand(0..100)
338
+ bufpath = File.join(File.expand_path("../../tmp/buffer_file_#{rand_num}", __FILE__), 'testbuf.*.log')
339
+ bufdir = File.dirname(bufpath)
340
+
341
+ FileUtils.rm_r bufdir if File.exist?(bufdir)
342
+ assert !File.exist?(bufdir)
343
+
344
+ plugin.configure(config_element('buffer', '', { 'path' => bufpath }))
345
+
346
+ assert !File.exist?(bufdir)
347
+ plugin.start
348
+
349
+ m = metadata()
350
+ c = nil
351
+ Fluent::SystemConfig.overwrite_system_config("file_permission" => "700") do
352
+ c = plugin.generate_chunk(m)
353
+ end
354
+
355
+ assert c.is_a? Fluent::Plugin::Buffer::FileChunk
356
+ assert_equal m, c.metadata
357
+ assert c.empty?
358
+ assert_equal :unstaged, c.state
359
+ assert_equal 0700, c.permission
360
+ assert_equal bufpath.gsub('.*.', ".b#{Fluent::UniqueId.hex(c.unique_id)}."), c.path
361
+ assert{ File.stat(c.path).mode.to_s(8).end_with?('700') }
362
+
363
+ c.purge
364
+
365
+ plugin.stop; plugin.before_shutdown; plugin.shutdown; plugin.after_shutdown; plugin.close; plugin.terminate
366
+ ensure
367
+ FileUtils.rm_r bufdir
368
+ end
369
+ end
330
370
  end
331
371
 
332
372
  sub_test_case 'configured with system root directory and plugin @id' do
@@ -293,6 +293,38 @@ class FileSingleBufferTest < Test::Unit::TestCase
293
293
 
294
294
  c.purge
295
295
  end
296
+
297
+ test '#generate_chunk generates blank file chunk with specified permission with system_config' do
298
+ omit "NTFS doesn't support UNIX like permissions" if Fluent.windows?
299
+
300
+ @d = create_driver(%[
301
+ <buffer tag>
302
+ @type file_single
303
+ path #{PATH}
304
+ </buffer>
305
+ ])
306
+ @p = @d.instance.buffer
307
+
308
+ FileUtils.rm_r @bufdir if File.exist?(@bufdir)
309
+ assert !File.exist?(@bufdir)
310
+
311
+ @p.start
312
+
313
+ m = metadata()
314
+ c = nil
315
+ Fluent::SystemConfig.overwrite_system_config("file_permission" => "700") do
316
+ c = @p.generate_chunk(m)
317
+ end
318
+ assert c.is_a? Fluent::Plugin::Buffer::FileSingleChunk
319
+ assert_equal m, c.metadata
320
+ assert c.empty?
321
+ assert_equal :unstaged, c.state
322
+ assert_equal 0700, c.permission
323
+ assert_equal File.join(@bufdir, "fsb.testing.b#{Fluent::UniqueId.hex(c.unique_id)}.buf"), c.path
324
+ assert{ File.stat(c.path).mode.to_s(8).end_with?('700') }
325
+
326
+ c.purge
327
+ end
296
328
  end
297
329
 
298
330
  sub_test_case 'configured with system root directory and plugin @id' do
@@ -416,17 +416,6 @@ class BufferFileChunkTest < Test::Unit::TestCase
416
416
  assert_equal d4.to_json + "\n", lines[3]
417
417
  end
418
418
 
419
- test 'can refer system config for file permission' do
420
- omit "NTFS doesn't support UNIX like permissions" if Fluent.windows?
421
-
422
- chunk_path = File.join(@chunkdir, 'testperm.*.log')
423
- Fluent::SystemConfig.overwrite_system_config("file_permission" => "600") do
424
- c = Fluent::Plugin::Buffer::FileChunk.new(gen_metadata, chunk_path, :create)
425
- assert{ File.stat(c.path).mode.to_s(8).end_with?('600') }
426
- assert{ File.stat(c.path + '.meta').mode.to_s(8).end_with?('600') }
427
- end
428
- end
429
-
430
419
  test '#write_metadata tries to store metadata on file' do
431
420
  d1 = {"f1" => 'v1', "f2" => 'v2', "f3" => 'v3'}
432
421
  d2 = {"f1" => 'vv1', "f2" => 'vv2', "f3" => 'vv3'}
@@ -353,16 +353,6 @@ class BufferFileSingleChunkTest < Test::Unit::TestCase
353
353
  assert_equal d3.to_json + "\n", lines[2]
354
354
  assert_equal d4.to_json + "\n", lines[3]
355
355
  end
356
-
357
- test 'can refer system config for file permission' do
358
- omit "NTFS doesn't support UNIX like permissions" if Fluent.windows?
359
-
360
- chunk_path = File.join(@chunkdir, 'fsb.*.buf')
361
- Fluent::SystemConfig.overwrite_system_config("file_permission" => "600") do
362
- c = Fluent::Plugin::Buffer::FileSingleChunk.new(gen_metadata, chunk_path, :create, nil)
363
- assert{ File.stat(c.path).mode.to_s(8).end_with?('600') }
364
- end
365
- end
366
356
  end
367
357
 
368
358
  sub_test_case 'chunk with file for staged chunk' do
@@ -12,6 +12,8 @@ require_relative '../test_plugin_classes'
12
12
  class MonitorAgentInputTest < Test::Unit::TestCase
13
13
  include FuzzyAssert
14
14
 
15
+ CONFIG_DIR = File.expand_path('../tmp/in_monitor_agent', __dir__)
16
+
15
17
  def setup
16
18
  Fluent::Test.setup
17
19
  end
@@ -160,9 +162,20 @@ EOC
160
162
  test "fluentd opts" do
161
163
  d = create_driver
162
164
  opts = Fluent::Supervisor.default_options
163
- Fluent::Supervisor.new(opts)
165
+
166
+ filepath = nil
167
+ begin
168
+ FileUtils.mkdir_p(CONFIG_DIR)
169
+ filepath = File.expand_path('fluentd.conf', CONFIG_DIR)
170
+ FileUtils.touch(filepath)
171
+ s = Fluent::Supervisor.new(opts.merge(config_path: filepath))
172
+ s.configure
173
+ ensure
174
+ FileUtils.rm_r(CONFIG_DIR) rescue _
175
+ end
176
+
164
177
  expected_opts = {
165
- "config_path" => "/etc/fluent/fluent.conf",
178
+ "config_path" => filepath,
166
179
  "pid_file" => nil,
167
180
  "plugin_dirs" => ["/etc/fluent/plugin"],
168
181
  "log_path" => nil,
@@ -279,11 +292,25 @@ EOC
279
292
  </match>
280
293
  </label>
281
294
  EOC
282
- @ra = Fluent::RootAgent.new(log: $log)
283
- stub(Fluent::Engine).root_agent { @ra }
284
- @ra = configure_ra(@ra, conf)
285
- # store Supervisor instance to avoid collected by GC
286
- @supervisor = Fluent::Supervisor.new(Fluent::Supervisor.default_options)
295
+
296
+
297
+ begin
298
+ @ra = Fluent::RootAgent.new(log: $log)
299
+ stub(Fluent::Engine).root_agent { @ra }
300
+ @ra = configure_ra(@ra, conf)
301
+ # store Supervisor instance to avoid collected by GC
302
+
303
+ FileUtils.mkdir_p(CONFIG_DIR)
304
+ @filepath = File.expand_path('fluentd.conf', CONFIG_DIR)
305
+ File.open(@filepath, 'w') do |v|
306
+ v.puts(conf)
307
+ end
308
+
309
+ @supervisor = Fluent::Supervisor.new(Fluent::Supervisor.default_options.merge(config_path: @filepath))
310
+ @supervisor.configure
311
+ ensure
312
+ FileUtils.rm_r(CONFIG_DIR) rescue _
313
+ end
287
314
  end
288
315
 
289
316
  test "/api/plugins" do
@@ -469,8 +496,7 @@ plugin_id:test_filter\tplugin_category:filter\ttype:test_filter\toutput_plugin:f
469
496
  tag monitor
470
497
  ")
471
498
  d.instance.start
472
- expected_response_regex = /pid:\d+\tppid:\d+\tconfig_path:\/etc\/fluent\/fluent.conf\tpid_file:\tplugin_dirs:\/etc\/fluent\/plugin\tlog_path:/
473
-
499
+ expected_response_regex = %r{pid:\d+\tppid:\d+\tconfig_path:#{@filepath}\tpid_file:\tplugin_dirs:/etc/fluent/plugin\tlog_path:}
474
500
  assert_match(expected_response_regex,
475
501
  get("http://127.0.0.1:#{@port}/api/config").body)
476
502
  end
@@ -484,7 +510,7 @@ plugin_id:test_filter\tplugin_category:filter\ttype:test_filter\toutput_plugin:f
484
510
  ")
485
511
  d.instance.start
486
512
  res = JSON.parse(get("http://127.0.0.1:#{@port}/api/config.json").body)
487
- assert_equal("/etc/fluent/fluent.conf", res["config_path"])
513
+ assert_equal(@filepath, res["config_path"])
488
514
  assert_nil(res["pid_file"])
489
515
  assert_equal(["/etc/fluent/plugin"], res["plugin_dirs"])
490
516
  assert_nil(res["log_path"])