Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inline_config is replaced with the input value when user specify - #2708

Merged
merged 1 commit into from
Nov 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 15 additions & 0 deletions test/test_supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,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