diff --git a/example/suppress_config_dump.conf b/example/suppress_config_dump.conf new file mode 100644 index 0000000000..c52569a536 --- /dev/null +++ b/example/suppress_config_dump.conf @@ -0,0 +1,7 @@ + + suppress_config_dump false + + + + @type stdout + diff --git a/lib/fluent/supervisor.rb b/lib/fluent/supervisor.rb index 45065afac5..ef96389a04 100644 --- a/lib/fluent/supervisor.rb +++ b/lib/fluent/supervisor.rb @@ -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, @@ -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 diff --git a/lib/fluent/system_config.rb b/lib/fluent/system_config.rb index d7c2b80efd..0b93875162 100644 --- a/lib/fluent/system_config.rb +++ b/lib/fluent/system_config.rb @@ -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 { diff --git a/test/command/test_fluentd.rb b/test/command/test_fluentd.rb index 37c234f80d..0f50f6f9d7 100644 --- a/test/command/test_fluentd.rb +++ b/test/command/test_fluentd.rb @@ -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 = "" @@ -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) @@ -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 = < + @type dummy + @id dummy + @label @dummydata + tag dummy + dummy {"message": "yay!"} + + +CONF + end + + test 'configured by system config' do + conf = < + suppress_config_dump + +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 = < + suppress_config_dump false + +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 = <