Skip to content

Commit

Permalink
in_tail: Add always option for handle most of the glob patterns
Browse files Browse the repository at this point in the history
I'm, not sure this commit makes to be able to handle the all of the glob
patterns but mostly seems OK.

Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Mar 26, 2024
1 parent 705d5ea commit 3ab56cc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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?('*')
Expand Down
37 changes: 37 additions & 0 deletions test/plugin/test_in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down

0 comments on commit 3ab56cc

Please sign in to comment.