Skip to content

Commit

Permalink
config: test: Specify guess type as default value of config-file-type
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed May 18, 2022
1 parent 49ec023 commit 6574387
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
8 changes: 5 additions & 3 deletions lib/fluent/command/fluentd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,13 @@
opts[:without_source] = b
}

op.on('--guess-config-file-type VALU', 'guessing file type of fluentd configuration. yaml or yml') { |s|
op.on('--config-file-type VALU', 'guessing file type of fluentd configuration. yaml/yml or guess') { |s|
if (s == 'yaml') || (s == 'yml')
opts[:guess_config_file_type] = s.to_sym
opts[:config_file_type] = s.to_sym
elsif (s == 'guess')
opts[:config_file_type] = s.to_sym
else
usage '--guess-config-file-type accepts yaml or yml'
usage '--config-file-type accepts yaml/yml or guess'
end
}

Expand Down
8 changes: 5 additions & 3 deletions lib/fluent/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ module Config
# @param use_v1_config [Bool] config is formatted with v1 or not
# @return [Fluent::Config]
def self.build(config_path:, encoding: 'utf-8', additional_config: nil, use_v1_config: true, type: nil)
config_file_ext = File.extname(config_path)
if config_file_ext == '.yaml' || config_file_ext == '.yml'
type = :yaml
if type == :guess
config_file_ext = File.extname(config_path)
if config_file_ext == '.yaml' || config_file_ext == '.yml'
type = :yaml
end
end

if type == :yaml || type == :yml
Expand Down
10 changes: 5 additions & 5 deletions lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ def self.default_options
signame: nil,
conf_encoding: 'utf-8',
disable_shared_socket: nil,
guess_config_file_type: nil,
config_file_type: :guess,
}
end

Expand All @@ -594,7 +594,7 @@ def self.cleanup_resources
end

def initialize(opt)
@guess_config_file_type = opt[:guess_config_file_type]
@config_file_type = opt[:config_file_type]
@daemonize = opt[:daemonize]
@standalone_worker= opt[:standalone_worker]
@config_path = opt[:config_path]
Expand All @@ -621,7 +621,7 @@ def initialize(opt)
encoding: @conf_encoding ? @conf_encoding : 'utf-8',
additional_config: @inline_config ? @inline_config : nil,
use_v1_config: !!@use_v1_config,
type: @guess_config_file_type,
type: @config_file_type,
)
@system_config = build_system_config(@conf)
if @system_config.log
Expand Down Expand Up @@ -753,7 +753,7 @@ def configure(supervisor: false)
encoding: @conf_encoding,
additional_config: @inline_config,
use_v1_config: @use_v1_config,
type: @guess_config_file_type,
type: @config_file_type,
)
@system_config = build_system_config(@conf)

Expand Down Expand Up @@ -939,7 +939,7 @@ def reload_config
encoding: @conf_encoding,
additional_config: @inline_config,
use_v1_config: @use_v1_config,
type: @guess_config_file_type,
type: @config_file_type,
)

Fluent::VariableStore.try_to_reset do
Expand Down
2 changes: 1 addition & 1 deletion test/test_supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ def test_override_default_log_rotate_with_yaml_config
file.puts(config)
file.flush
opts = Fluent::Supervisor.default_options.merge(
log_path: "#{TMP_DIR}/test.log", config_path: file.path, guess_config_file_type: :yaml,
log_path: "#{TMP_DIR}/test.log", config_path: file.path, config_file_type: :yaml,
)
sv = Fluent::Supervisor.new(opts)

Expand Down

0 comments on commit 6574387

Please sign in to comment.