Skip to content

Commit

Permalink
inline_config is replaced with the input value when user specify -
Browse files Browse the repository at this point in the history
Current implementation calling `STDIN.read` in supervisors and workers.
it cause blocking in worker side.

Signed-off-by: Yuta Iwama <[email protected]>
  • Loading branch information
ganmacs committed Nov 27, 2019
1 parent 4eed081 commit bc06b94
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,7 @@ def self.load_config(path, params = {})
# Assume fluent.conf encoding is UTF-8
config_data = File.open(path, "r:#{params['conf_encoding']}:utf-8") {|f| f.read }
inline_config = params['inline_config']
if inline_config == '-'
config_data << "\n" << STDIN.read
elsif inline_config
if inline_config
config_data << "\n" << inline_config.gsub("\\n","\n")
end
fluentd_conf = Fluent::Config.parse(config_data, config_fname, config_basedir, params['use_v1_config'])
Expand Down Expand Up @@ -572,6 +570,10 @@ def configure(supervisor: false)
show_plugin_config
end

if @inline_config == '-'
@inline_config = STDIN.read
end

@conf = read_config
@system_config = build_system_config(@conf)

Expand Down Expand Up @@ -783,10 +785,8 @@ def read_config
config_fname = File.basename(@config_path)
config_basedir = File.dirname(@config_path)
config_data = File.open(@config_path, "r:#{@conf_encoding}:utf-8") {|f| f.read }
if @inline_config == '-'
config_data << "\n" << STDIN.read
elsif @inline_config
config_data << "\n" << @inline_config.gsub("\\n","\n")
if @inline_config
config_data << "\n" << @inline_config.gsub("\\n", "\n")
end
Fluent::Config.parse(config_data, config_fname, config_basedir, @use_v1_config)
end
Expand Down
18 changes: 18 additions & 0 deletions test/test_supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ def test_load_config_for_daemonize
assert_equal Fluent::Log::LEVEL_INFO, se_config[:log_level]
end

def test_wiht_inline_config
end

def test_load_config_with_multibyte_string
tmp_path = "#{TMP_DIR}/dir/test_multibyte_config.conf"
conf_str = %[
Expand Down Expand Up @@ -448,6 +451,21 @@ def test_logger_with_rotate_age_and_rotate_size(rotate_age)
assert_equal 10, $log.out.instance_variable_get(:@shift_size)
end

def test_inline_config
opts = Fluent::Supervisor.default_options
opts[:inline_config] = '-'
sv = Fluent::Supervisor.new(opts)
assert_equal '-', sv.instance_variable_get(:@inline_config)

inline_config = '<match *>\n@type stdout\n</match>'
stub(STDIN).read { inline_config }
stub(sv).read_config # to skip
stub(sv).build_system_config { Fluent::SystemConfig.new } # to skip

sv.configure
assert_equal inline_config, sv.instance_variable_get(:@inline_config)
end

def create_debug_dummy_logger
dl_opts = {}
dl_opts[:log_level] = ServerEngine::DaemonLogger::DEBUG
Expand Down

0 comments on commit bc06b94

Please sign in to comment.