From bb8253c159ab4fb6f370ee39777622cdcc3b835a Mon Sep 17 00:00:00 2001 From: Vimal Kumar Date: Sat, 18 Apr 2020 11:17:36 +0530 Subject: [PATCH] Avoid duplicates in path config - removed duplicate in path config - added testcase Signed-off-by: Vimal Kumar --- lib/fluent/plugin/in_tail.rb | 4 ++-- test/plugin/test_in_tail.rb | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/fluent/plugin/in_tail.rb b/lib/fluent/plugin/in_tail.rb index e7135d59b8..6351fe6b6d 100644 --- a/lib/fluent/plugin/in_tail.rb +++ b/lib/fluent/plugin/in_tail.rb @@ -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 @@ -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. diff --git a/test/plugin/test_in_tail.rb b/test/plugin/test_in_tail.rb index 3cc71973c4..5203476197 100644 --- a/test/plugin/test_in_tail.rb +++ b/test/plugin/test_in_tail.rb @@ -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 @@ -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})