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

Support multi worker environment in in_debug_agent #1869

Merged
merged 1 commit into from
Feb 27, 2018
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
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