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

Add an option to disable shared socket forcedly #3250

Merged
merged 3 commits into from
Feb 16, 2021
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
4 changes: 4 additions & 0 deletions lib/fluent/command/fluentd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@
opts[:conf_encoding] = s
}

op.on('--disable-shared-socket', "Don't open shared socket for multiple workers") { |b|
opts[:disable_shared_socket] = b
}

if Fluent.windows?
require 'windows/library'
include Windows::Library
Expand Down
16 changes: 12 additions & 4 deletions lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module Fluent
module ServerModule
def before_run
@fluentd_conf = config[:fluentd_conf]
@rpc_endpoint = nil
@rpc_server = nil
@counter = nil

Expand All @@ -64,9 +65,13 @@ def before_run
run_counter_server(counter)
end

socket_manager_path = ServerEngine::SocketManager::Server.generate_path
ServerEngine::SocketManager::Server.open(socket_manager_path)
ENV['SERVERENGINE_SOCKETMANAGER_PATH'] = socket_manager_path.to_s
if config[:disable_shared_socket]
$log.info "shared socket for multiple workers is disabled"
else
socket_manager_path = ServerEngine::SocketManager::Server.generate_path
ServerEngine::SocketManager::Server.open(socket_manager_path)
ENV['SERVERENGINE_SOCKETMANAGER_PATH'] = socket_manager_path.to_s
end
end

def after_run
Expand Down Expand Up @@ -452,6 +457,7 @@ def self.load_config(path, params = {})
config_path: path,
main_cmd: params['main_cmd'],
signame: params['signame'],
disable_shared_socket: params['disable_shared_socket']
}
if daemonize
se_config[:pid_path] = pid_path
Expand Down Expand Up @@ -567,7 +573,8 @@ def self.default_options
supervise: true,
standalone_worker: false,
signame: nil,
conf_encoding: 'utf-8'
conf_encoding: 'utf-8',
disable_shared_socket: nil
}
end

Expand Down Expand Up @@ -795,6 +802,7 @@ def supervise
'counter_server' => @system_config.counter_server,
'log_format' => @system_config.log.format,
'log_time_format' => @system_config.log.time_format,
'disable_shared_socket' => @system_config.disable_shared_socket
}

se = ServerEngine.create(ServerModule, WorkerModule){
Expand Down
3 changes: 2 additions & 1 deletion lib/fluent/system_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SystemConfig
:log_event_verbose, :ignore_repeated_log_interval, :ignore_same_log_interval,
:without_source, :rpc_endpoint, :enable_get_dump, :process_name,
:file_permission, :dir_permission, :counter_server, :counter_client,
:strict_config_value, :enable_msgpack_time_support
:strict_config_value, :enable_msgpack_time_support, :disable_shared_socket
]

config_param :workers, :integer, default: 1
Expand All @@ -45,6 +45,7 @@ class SystemConfig
config_param :process_name, :string, default: nil
config_param :strict_config_value, :bool, default: nil
config_param :enable_msgpack_time_support, :bool, default: nil
config_param :disable_shared_socket, :bool, default: nil
config_param :file_permission, default: nil do |v|
v.to_i(8)
end
Expand Down
30 changes: 30 additions & 0 deletions test/command/test_fluentd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1065,4 +1065,34 @@ def multi_workers_ready?; true; end
"secret xxxxxx", patterns_not_match: ["secret secret0", "secret secret1"])
end
end

sub_test_case 'sahred socket options' do
test 'enable shared socket by default' do
conf = ""
conf_path = create_conf_file('empty.conf', conf)
assert File.exist?(conf_path)
assert_log_matches(create_cmdline(conf_path),
patterns_not_match: ["shared socket for multiple workers is disabled"])
end

test 'disable shared socket by command line option' do
conf = ""
conf_path = create_conf_file('empty.conf', conf)
assert File.exist?(conf_path)
assert_log_matches(create_cmdline(conf_path, "--disable-shared-socket"),
"shared socket for multiple workers is disabled",)
end

test 'disable shared socket by system config' do
conf = <<CONF
<system>
disable_shared_socket
</system>
CONF
conf_path = create_conf_file('empty.conf', conf)
assert File.exist?(conf_path)
assert_log_matches(create_cmdline(conf_path, "--disable-shared-socket"),
"shared socket for multiple workers is disabled",)
end
end
end
31 changes: 31 additions & 0 deletions test/test_supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,37 @@ def test_log_level_affects
assert_equal Fluent::Log::LEVEL_ERROR, $log.level
end

def test_enable_shared_socket
server = DummyServer.new
begin
ENV.delete('SERVERENGINE_SOCKETMANAGER_PATH')
server.before_run
sleep 0.1 if Fluent.windows? # Wait for starting windows event thread
assert_not_nil(ENV['SERVERENGINE_SOCKETMANAGER_PATH'])
ensure
server.after_run
ENV.delete('SERVERENGINE_SOCKETMANAGER_PATH')
end
end

def test_disable_shared_socket
server = DummyServer.new
def server.config
{
:disable_shared_socket => true,
}
end
begin
ENV.delete('SERVERENGINE_SOCKETMANAGER_PATH')
server.before_run
sleep 0.1 if Fluent.windows? # Wait for starting windows event thread
assert_nil(ENV['SERVERENGINE_SOCKETMANAGER_PATH'])
ensure
server.after_run
ENV.delete('SERVERENGINE_SOCKETMANAGER_PATH')
end
end

def create_debug_dummy_logger
dl_opts = {}
dl_opts[:log_level] = ServerEngine::DaemonLogger::DEBUG
Expand Down