Skip to content

Commit

Permalink
Add an option to disable shared socket forcedly
Browse files Browse the repository at this point in the history
Fluentd always creates ServerEngine::SocketManager's shared socket even
if it's not required. The shared socket isn't needed if there is no
plugin that uses it such as in_forward, in_http and in_syslog.
Although it can be disabled if Fluentd doesn't use multiple workers,
this patch adds `disable_shared_socket` instead of checking number of
workers to keep backward compatibility for third-party plugins
(PluginHelper::Server.create_server_connection uses shared socket by
default).

Signed-off-by: Takuro Ashie <ashie@clear-code.com>
  • Loading branch information
ashie committed Feb 15, 2021
1 parent 3191563 commit ab2a328
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
14 changes: 10 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,11 @@ 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
unless config[:disable_shared_socket]
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 +455,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 +571,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 +800,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
25 changes: 25 additions & 0 deletions test/test_supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,31 @@ def server.config
assert_equal('{"ok":true}', response)
end

def test_enable_shared_socket
server = DummyServer.new
begin
server.before_run
assert_not_nil(ENV['SERVERENGINE_SOCKETMANAGER_PATH'])
ensure
server.after_run
end
end

def test_disable_shared_socket
server = DummyServer.new
def server.config
{
:disable_shared_socket => true,
}
end
begin
server.before_run
assert_nil(ENV['SERVERENGINE_SOCKETMANAGER_PATH'])
ensure
server.after_run
end
end

def test_load_config
tmp_dir = "#{TMP_DIR}/dir/test_load_config.conf"
conf_info_str = %[
Expand Down

0 comments on commit ab2a328

Please sign in to comment.