From 9cfcf925f1abc89c7be4ef08e9ee27ab90b3542b Mon Sep 17 00:00:00 2001 From: TAGOMORI Satoshi Date: Wed, 4 Jan 2017 18:45:54 +0900 Subject: [PATCH] add ignore_network_errors_at_startup --- lib/fluent/plugin/out_forward.rb | 17 +++++++++++++++-- test/plugin/test_out_forward.rb | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/fluent/plugin/out_forward.rb b/lib/fluent/plugin/out_forward.rb index 064eb5b494..29a54f54b3 100644 --- a/lib/fluent/plugin/out_forward.rb +++ b/lib/fluent/plugin/out_forward.rb @@ -70,6 +70,9 @@ class ConnectionClosedError < Error; end desc 'Enable client-side DNS round robin.' config_param :dns_round_robin, :bool, default: false # heartbeat_type 'udp' is not available for this + desc 'Ignore DNS resolution and errors at startup time.' + config_param :ignore_network_errors_at_startup, :bool, default: false + desc 'Compress buffered data.' config_param :compress, :enum, list: [:text, :gzip], default: :text @@ -148,7 +151,14 @@ def configure(conf) if @heartbeat_type == :none @nodes << NoneHeartbeatNode.new(self, server, failure: failure) else - @nodes << Node.new(self, server, failure: failure) + node = Node.new(self, server, failure: failure) + begin + node.validate_host_resolution! + rescue => e + raise unless @ignore_network_errors_at_startup + log.warn "failed to resolve node name when configured", server: (server.name || server.host), error: e + end + @nodes << node end end @@ -453,7 +463,6 @@ def initialize(sender, server, failure:) @resolved_host = nil @resolved_time = 0 - resolved_host # check dns end attr_accessor :usock @@ -462,6 +471,10 @@ def initialize(sender, server, failure:) attr_reader :sockaddr # used by on_heartbeat attr_reader :failure, :available # for test + def validate_host_resolution! + resolved_host + end + def available? @available end diff --git a/test/plugin/test_out_forward.rb b/test/plugin/test_out_forward.rb index cad5fd566e..ef2ac9500d 100644 --- a/test/plugin/test_out_forward.rb +++ b/test/plugin/test_out_forward.rb @@ -135,6 +135,24 @@ def read_ack_from_sock(sock, unpacker) end end + test 'configure with ignore_network_errors_at_startup' do + normal_conf = config_element('match', '**', {}, [ + config_element('server', '', {'name' => 'test', 'host' => 'unexisting.yaaaaaaaaaaaaaay.host.example.com'}) + ]) + assert_raise SocketError.new("getaddrinfo: nodename nor servname provided, or not known") do + create_driver(normal_conf) + end + + conf = config_element('match', '**', {'ignore_network_errors_at_startup' => 'true'}, [ + config_element('server', '', {'name' => 'test', 'host' => 'unexisting.yaaaaaaaaaaaaaay.host.example.com'}) + ]) + @d = d = create_driver(conf) + expected_log = "failed to resolve node name when configured" + expected_detail = 'server="test" error_class=SocketError error="getaddrinfo: nodename nor servname provided, or not known"' + logs = d.logs + assert{ logs.any?{|log| log.include?(expected_log) && log.include?(expected_detail) } } + end + test 'compress_default_value' do @d = d = create_driver assert_equal :text, d.instance.compress