diff --git a/lib/fluent/plugin/in_tail.rb b/lib/fluent/plugin/in_tail.rb index f3dcff4cf1..63ec165b96 100644 --- a/lib/fluent/plugin/in_tail.rb +++ b/lib/fluent/plugin/in_tail.rb @@ -64,8 +64,8 @@ def initialize config_param :path, :string desc 'path delimiter used for spliting path config' config_param :path_delimiter, :string, default: ',' - desc 'Choose using glob patterns. Adding whether a capability to handle [] and ? or not.' - config_param :glob_policy, :enum, list: [:backward_compatible, :extended], default: :backward_compatible + desc 'Choose using glob patterns. Adding capabilities to handle [] and ?, and {}.' + config_param :glob_policy, :enum, list: [:backward_compatible, :extended, :always], default: :backward_compatible desc 'The tag of the event.' config_param :tag, :string desc 'The paths to exclude the files from watcher list.' @@ -142,6 +142,10 @@ def configure(conf) raise Fluent::ConfigError, "either of enable_watch_timer or enable_stat_watcher must be true" end + if @glob_policy == :always && @path_delimiter == ',' + raise Fluent::ConfigError, "cannot use glob_policy as always with the default path_delimitor: `,\"" + end + if RESERVED_CHARS.include?(@path_delimiter) rc = RESERVED_CHARS.join(', ') raise Fluent::ConfigError, "#{rc} are reserved words: #{@path_delimiter}" @@ -288,7 +292,9 @@ def have_read_capability? # Curly braces is not supported for now because the default delimiter of path is ",". # This should be collided for wildcard pattern for curly braces. def use_glob?(path) - if @glob_policy == :extended + if @glob_policy == :always + path.include?('*') || path.include?('?') || /\[.*\]/.match(path) || /\{.*,.*\}/.match(path) + elsif @glob_policy == :extended path.include?('*') || path.include?('?') || /\[.*\]/.match(path) elsif @glob_policy == :backward_compatible path.include?('*') diff --git a/test/plugin/test_in_tail.rb b/test/plugin/test_in_tail.rb index 3e612ce55d..296386ffc6 100644 --- a/test/plugin/test_in_tail.rb +++ b/test/plugin/test_in_tail.rb @@ -1600,6 +1600,43 @@ def ex_config_with_brackets }) end + def test_config_with_always_with_default_delimiter + assert_raise(Fluent::ConfigError) do + config = config_element("", "", { + "tag" => "tail", + "path" => "test/plugin/data/log_numeric/[0-1][2-4].log", + "format" => "none", + "pos_file" => "#{@tmp_dir}/tail.pos", + "read_from_head" => true, + "refresh_interval" => 30, + "glob_policy" => "always", + "rotate_wait" => "#{EX_ROTATE_WAIT}s", + "follow_inodes" => "#{EX_FOLLOW_INODES}", + }) + + create_driver(config, false).instance + end + end + + def test_config_with_always_with_custom_delimiter + assert_nothing_raised do + config = config_element("", "", { + "tag" => "tail", + "path" => "test/plugin/data/log_numeric/[0-1][2-4].log", + "format" => "none", + "pos_file" => "#{@tmp_dir}/tail.pos", + "read_from_head" => true, + "refresh_interval" => 30, + "glob_policy" => "always", + "path_delimiter" => "|", + "rotate_wait" => "#{EX_ROTATE_WAIT}s", + "follow_inodes" => "#{EX_FOLLOW_INODES}", + }) + + create_driver(config, false).instance + end + end + def test_expand_paths_with_brackets expanded_paths = [ create_target_info('test/plugin/data/log_numeric/01.log'),