Skip to content

Commit

Permalink
Merge pull request #2961 from vimalk78/in-tail-avoid-duplicate-path
Browse files Browse the repository at this point in the history
Avoid duplicates in path config
  • Loading branch information
ganmacs authored Apr 22, 2020
2 parents cdedacf + bb8253c commit bc78d88
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def configure(conf)
raise Fluent::ConfigError, "#{rc} are reserved words: #{@path_delimiter}"
end

@paths = @path.split(@path_delimiter).map(&:strip)
@paths = @path.split(@path_delimiter).map(&:strip).uniq
if @paths.empty?
raise Fluent::ConfigError, "tail: 'path' parameter is required on tail input"
end
Expand Down Expand Up @@ -296,7 +296,7 @@ def expand_paths
end
path.include?('*') ? Dir.glob(path) : path
}.flatten.uniq
paths - excluded
paths.uniq - excluded
end

# in_tail with '*' path doesn't check rotation file equality at refresh phase.
Expand Down
17 changes: 17 additions & 0 deletions test/plugin/test_in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ def create_driver(conf = SINGLE_LINE_CONFIG, use_common_conf = true)
assert_equal ["tail.txt", "test2", "tmp,dev"], d.instance.paths
end

test "multi paths with same path configured twice" do
c = config_element("ROOT", "", { "path" => "test1.txt,test2.txt,test1.txt", "tag" => "t1", "path_delimiter" => "," })
d = create_driver(c + PARSE_SINGLE_LINE_CONFIG, false)
assert_equal ["test2.txt","test1.txt"].sort, d.instance.paths.sort
end

test "multi paths with invaid path_delimiter" do
c = config_element("ROOT", "", { "path" => "tail.txt|test2|tmp,dev", "tag" => "t1", "path_delimiter" => "*" })
assert_raise(Fluent::ConfigError) do
Expand Down Expand Up @@ -1022,6 +1028,17 @@ def test_expand_paths
assert_equal EX_PATHS - [EX_PATHS.last], plugin.expand_paths.sort
end

def test_expand_paths_with_duplicate_configuration
expanded_paths = [
'test/plugin/data/log/foo/bar.log',
'test/plugin/data/log/test.log'
]
duplicate_config = EX_CONFIG.dup
duplicate_config["path"]="test/plugin/data/log/**/*.log, test/plugin/data/log/**/*.log"
plugin = create_driver(EX_CONFIG, false).instance
assert_equal expanded_paths, plugin.expand_paths.sort
end

def test_expand_paths_with_timezone
['Asia/Taipei', '+08'].each do |tz_type|
taipei_config = EX_CONFIG + config_element("", "", {"path_timezone" => tz_type})
Expand Down

0 comments on commit bc78d88

Please sign in to comment.