Skip to content

Commit

Permalink
unify dry_run method and make @dry_run immutable
Browse files Browse the repository at this point in the history
Signed-off-by: Yuta Iwama <[email protected]>
  • Loading branch information
ganmacs committed Oct 31, 2019
1 parent 6f0ae3b commit a1d6f36
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 33 deletions.
6 changes: 3 additions & 3 deletions lib/fluent/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ def initialize

MAINLOOP_SLEEP_INTERVAL = 0.3

attr_reader :root_agent, :system_config, :supervisor_mode
attr_accessor :dry_run_mode
attr_reader :root_agent, :system_config, :supervisor_mode, :dry_run_mode

def init(system_config, supervisor_mode: false)
def init(system_config, supervisor_mode: false, dry_run_mode: false)
@system_config = system_config
@supervisor_mode = supervisor_mode
@dry_run_mode = dry_run_mode

@suppress_config_dump = system_config.suppress_config_dump unless system_config.suppress_config_dump.nil?
@without_source = system_config.without_source unless system_config.without_source.nil?
Expand Down
54 changes: 24 additions & 30 deletions lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,30 @@ def run_supervisor
end
end
end
dry_run_cmd if @dry_run

begin
if @dry_run
$log.info "starting fluentd-#{Fluent::VERSION} as dry run mode", ruby: RUBY_VERSION
end

ServerEngine::Privilege.change(@chuser, @chgroup)
MessagePackFactory.init
Fluent::Engine.init(@system_config, supervisor: true, dry_run_mode: @dry_run)
Fluent::Engine.run_configure(@conf)

if @dry_run
$log.info 'finsihed dry run mode'
exit 0
end
rescue Fluent::ConfigError => e
$log.error 'config error', file: @config_path, error: e
$log.debug_backtrace
exit!(1)
rescue => e
$log.error(e)
exit(1)
end

supervise
end

Expand Down Expand Up @@ -588,42 +611,13 @@ def create_socket_manager
ENV['SERVERENGINE_SOCKETMANAGER_PATH'] = socket_manager_path.to_s
end

def dry_run_cmd
$log.info "starting fluentd-#{Fluent::VERSION} as dry run mode", ruby: RUBY_VERSION
dry_run
exit 0
rescue => e
$log.error "dry run failed: #{e}"
exit 1
end

## Set Engine's dry_run_mode true to override all target_id of worker sections
def dry_run
begin
Fluent::Engine.dry_run_mode = true
ServerEngine::Privilege.change(@chuser, @chgroup)
MessagePackFactory.init
Fluent::Engine.init(@system_config, supervisor: true)
Fluent::Engine.run_configure(@conf)
rescue Fluent::ConfigError => e
$log.error "config error", file: @config_path, error: e
$log.debug_backtrace
exit!(1)
ensure
Fluent::Engine.dry_run_mode = false
end
end

def show_plugin_config
name, type = @show_plugin_config.split(":") # input:tail
$log.info "show_plugin_config option is deprecated. Use fluent-plugin-config-format --format=txt #{name} #{type}"
exit 0
end

def supervise
# Make dumpable conf, which is set corresponding_proxies for all elements in all worker sections
dry_run

Process.setproctitle("supervisor:#{@system_config.process_name}") if @system_config.process_name
$log.info "starting fluentd-#{Fluent::VERSION}", pid: Process.pid, ruby: RUBY_VERSION

Expand Down

0 comments on commit a1d6f36

Please sign in to comment.