Skip to content

Commit

Permalink
Merge pull request #1869 from eagletmt/multi-worker-debug
Browse files Browse the repository at this point in the history
Support multi worker environment in in_debug_agent
  • Loading branch information
repeatedly authored Feb 27, 2018
2 parents f8428ff + 9aa3865 commit 9428766
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/fluent/plugin/in_debug_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,20 @@ def initialize

def configure(conf)
super
if system_config.workers > 1
@port += fluentd_worker_id
end
if @unix_path
unless ::Fluent::FileUtil.writable?(@unix_path)
raise Fluent::ConfigError, "in_debug_agent: `#{@unix_path}` is not writable"
end
end
end

def multi_workers_ready?
@unix_path.nil?
end

def start
super

Expand All @@ -50,7 +57,7 @@ def start
else
uri = "druby://#{@bind}:#{@port}"
end
log.info "listening dRuby", uri: uri, object: @object
log.info "listening dRuby", uri: uri, object: @object, worker: fluentd_worker_id
obj = eval(@object)
@server = DRb::DRbServer.new(uri, obj)
end
Expand Down
21 changes: 21 additions & 0 deletions test/plugin/test_in_debug_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,25 @@ def test_unix_path_writable
create_driver %[unix_path #{TMP_DIR}/does_not_exist/test_path]
end
end

def test_multi_worker_environment_with_port
Fluent::SystemConfig.overwrite_system_config('workers' => 4) do
d = Fluent::Test::Driver::Input.new(Fluent::Plugin::DebugAgentInput)
d.instance.instance_eval { @_fluentd_worker_id = 2 }
d.configure('port 24230')

assert_true d.instance.multi_workers_ready?
assert_equal(24232, d.instance.instance_variable_get(:@port))
end
end

def test_multi_worker_environment_with_unix_path
Fluent::SystemConfig.overwrite_system_config('workers' => 4) do
d = Fluent::Test::Driver::Input.new(Fluent::Plugin::DebugAgentInput)
d.instance.instance_eval { @_fluentd_worker_id = 2 }
d.configure("unix_path #{TMP_DIR}/test_path")

assert_false d.instance.multi_workers_ready?
end
end
end

0 comments on commit 9428766

Please sign in to comment.