Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid duplicates in path config #2961

Merged
merged 1 commit into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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