Skip to content

Commit

Permalink
in_tail: test: Expand glob capability
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Feb 15, 2024
1 parent 8735ad2 commit 1bbcece
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ def have_read_capability?
@capability.have_capability?(:effective, :dac_override)
end

# 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)
path.include?('*') || path.include?('?') || /\[.*\]/.match(path)
end

def expand_paths
date = Fluent::EventTime.now
paths = []
Expand All @@ -292,7 +298,7 @@ def expand_paths
else
date.to_time.strftime(path)
end
if path.include?('*') || /\[.*\]/.match(path)
if use_glob?(path)
paths += Dir.glob(path).select { |p|
begin
is_file = !File.directory?(p)
Expand Down
22 changes: 22 additions & 0 deletions test/plugin/test_in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,28 @@ def test_expand_paths
assert_equal(ex_paths - [ex_paths.last], plugin.expand_paths.values.sort_by { |path_ino| path_ino.path })
end

sub_test_case "expand_paths with glob" do |data|
data("square brackets" => "test/plugin/data/log_numeric/[0-1][2-4].log",
"asterisk" => "test/plugin/data/log/*.log",
"one character matcher" => "test/plugin/data/log/tes?.log",
)
def test_expand_paths_with_use_glob_p
path = data
config = config_element("", "", {
"tag" => "tail",
"path" => path,
"format" => "none",
"pos_file" => "#{@tmp_dir}/tail.pos",
"read_from_head" => true,
"refresh_interval" => 30,
"rotate_wait" => "#{EX_ROTATE_WAIT}s",
"follow_inodes" => "#{EX_FOLLOW_INODES}",
})
plugin = create_driver(config, false).instance
assert_true(!!plugin.use_glob?(path))
end
end

def ex_config_with_brackets
config_element("", "", {
"tag" => "tail",
Expand Down

0 comments on commit 1bbcece

Please sign in to comment.