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

Fix bug to ignore some command line options #1398

Merged
merged 2 commits into from
Jan 4, 2017
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
7 changes: 7 additions & 0 deletions example/suppress_config_dump.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<system>
suppress_config_dump false
</system>

<match data.*>
@type stdout
</match>
3 changes: 2 additions & 1 deletion lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def self.default_options
root_dir: nil,
suppress_interval: 0,
suppress_repeated_stacktrace: true,
without_source: false,
without_source: nil,
use_v1_config: true,
supervise: true,
standalone_worker: false,
Expand Down Expand Up @@ -695,6 +695,7 @@ def read_config

def set_system_config
@system_config = SystemConfig.create(@conf) # @conf is set in read_config
@system_config.attach(self)
@system_config.apply(self)
end

Expand Down
20 changes: 20 additions & 0 deletions lib/fluent/system_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@ def dup
s
end

def attach(supervisor)
system = self
supervisor.instance_eval {
SYSTEM_CONFIG_PARAMETERS.each do |param|
case param
when :rpc_endpoint, :enable_get_dump, :process_name, :file_permission, :dir_permission
next # doesn't exist in command line options
when :emit_error_log_interval
system.emit_error_log_interval = @suppress_interval if @suppress_interval
else
next unless instance_variable_defined?("@#{param}")
supervisor_value = instance_variable_get("@#{param}")
next if supervisor_value.nil? # it's not configured by command line options

system.send("#{param}=", supervisor_value)
end
end
}
end

def apply(supervisor)
system = self
supervisor.instance_eval {
Expand Down
59 changes: 58 additions & 1 deletion test/command/test_fluentd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def execute_command(cmdline, chdir=TMP_DIR)
null_stream.close rescue nil
end

def assert_log_matches(cmdline, *pattern_list, timeout: 10)
def assert_log_matches(cmdline, *pattern_list, patterns_not_match: [], timeout: 10)
matched = false
assert_error_msg = "matched correctly"
stdio_buf = ""
Expand Down Expand Up @@ -118,6 +118,18 @@ def assert_log_matches(cmdline, *pattern_list, timeout: 10)
assert_error_msg = "unexpected error in launching fluentd: #{e.inspect}\n" + stdio_buf
end
assert matched, assert_error_msg

unless patterns_not_match.empty?
lines = stdio_buf.split("\n")
patterns_not_match.each do |ptn|
matched_wrongly = if ptn.is_a? Regexp
lines.any?{|line| ptn.match(line) }
else
lines.any?{|line| line.include?(ptn) }
end
assert_false matched_wrongly, "pattern exists in logs wrongly:\n" + stdio_buf
end
end
end

def assert_fluentd_fails_to_start(cmdline, *pattern_list, timeout: 10)
Expand Down Expand Up @@ -244,6 +256,51 @@ def assert_fluentd_fails_to_start(cmdline, *pattern_list, timeout: 10)
end
end

sub_test_case 'configured to suppress configration dump' do
setup do
@basic_conf = <<CONF
<source>
@type dummy
@id dummy
@label @dummydata
tag dummy
dummy {"message": "yay!"}
</source>
<label @dummydata>
<match dummy>
@type null
@id blackhole
</match>
</label>
CONF
end

test 'configured by system config' do
conf = <<SYSTEM + @basic_conf
<system>
suppress_config_dump
</system>
SYSTEM
conf_path = create_conf_file('suppress_conf_dump_1.conf', conf)
assert_log_matches(create_cmdline(conf_path), "fluentd worker is now running", patterns_not_match: ["tag dummy"])
end

test 'configured by command line option' do
conf_path = create_conf_file('suppress_conf_dump_2.conf', @basic_conf)
assert_log_matches(create_cmdline(conf_path, '--suppress-config-dump'), "fluentd worker is now running", patterns_not_match: ["tag dummy"])
end

test 'configured as false by system config, but overridden as true by command line option' do
conf = <<SYSTEM + @basic_conf
<system>
suppress_config_dump false
</system>
SYSTEM
conf_path = create_conf_file('suppress_conf_dump_3.conf', conf)
assert_log_matches(create_cmdline(conf_path, '--suppress-config-dump'), "fluentd worker is now running", patterns_not_match: ["tag dummy"])
end
end

sub_test_case 'configuration with wrong plugin type' do
test 'failed to start' do
conf = <<CONF
Expand Down