From 15fd99e66b38192f872d91ba4167265ca5b93df9 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Tue, 25 May 2021 10:50:48 +0900 Subject: [PATCH 1/4] in_tail: position_file: Define path based equalities on TargetInfo In the previous Fluentd v1.11.x implementation uses path based tailing keys. We wouldn't rewrite tailing mechanism entirely. And also we're implicitly assuming path based equality for TargetInfo in tailing logic. We should handle TargetInfo with path based equality instead of path and inode based equality. Signed-off-by: Hiroshi Hatake --- lib/fluent/plugin/in_tail/position_file.rb | 16 +++++++++++++- test/plugin/in_tail/test_position_file.rb | 25 ++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/fluent/plugin/in_tail/position_file.rb b/lib/fluent/plugin/in_tail/position_file.rb index 88614d2802..faf27e95ee 100644 --- a/lib/fluent/plugin/in_tail/position_file.rb +++ b/lib/fluent/plugin/in_tail/position_file.rb @@ -248,6 +248,20 @@ def read_inode end end - TargetInfo = Struct.new(:path, :ino) + TargetInfo = Struct.new(:path, :ino) do + def ==(other) + return false unless other.is_a?(TargetInfo) + self.path == other.path + end + + def hash + self.path.hash + end + + def eql?(other) + return false unless other.is_a?(TargetInfo) + self.path == other.path + end + end end end diff --git a/test/plugin/in_tail/test_position_file.rb b/test/plugin/in_tail/test_position_file.rb index eb07eeb4b9..844dd2b38c 100644 --- a/test/plugin/in_tail/test_position_file.rb +++ b/test/plugin/in_tail/test_position_file.rb @@ -282,4 +282,29 @@ def build_files(file) assert_equal 2, f.read_inode end end + + sub_test_case "TargetInfo" do + def test_equal + t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234) + t2 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1235) + + assert_equal t1, t2 + end + + def test_eql? + t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234) + t2 = Fluent::Plugin::TailInput::TargetInfo.new("test", 5321) + + assert do + t1.eql? t2 + end + end + + def test_hash + t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234) + t2 = Fluent::Plugin::TailInput::TargetInfo.new("test", 7321) + + assert_equal t1.hash, t2.hash + end + end end From 42972c8d75aff23da4bd646935c288755bf2f1d2 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Wed, 26 May 2021 12:12:16 +0900 Subject: [PATCH 2/4] in_tail: position_file: test: Add not equal testcases Signed-off-by: Hiroshi Hatake --- test/plugin/in_tail/test_position_file.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test/plugin/in_tail/test_position_file.rb b/test/plugin/in_tail/test_position_file.rb index 844dd2b38c..cfde21d4a9 100644 --- a/test/plugin/in_tail/test_position_file.rb +++ b/test/plugin/in_tail/test_position_file.rb @@ -291,6 +291,13 @@ def test_equal assert_equal t1, t2 end + def test_not_equal + t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234) + t2 = Fluent::Plugin::TailInput::TargetInfo.new("test2", 1234) + + assert_not_equal t1, t2 + end + def test_eql? t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234) t2 = Fluent::Plugin::TailInput::TargetInfo.new("test", 5321) @@ -300,9 +307,14 @@ def test_eql? end end - def test_hash - t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234) - t2 = Fluent::Plugin::TailInput::TargetInfo.new("test", 7321) + def test_not_eql? + t1 = Fluent::Plugin::TailInput::TargetInfo.new("test2", 1234) + t2 = Fluent::Plugin::TailInput::TargetInfo.new("test3", 1234) + + assert do + !t1.eql? t2 + end + end assert_equal t1.hash, t2.hash end From 07ed033e27665d7e1703dd0a7b2642740b046c6a Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Wed, 26 May 2021 12:14:18 +0900 Subject: [PATCH 3/4] in_tail: position_file: test: Extract testcases for equality rule as sub_test_case Signed-off-by: Hiroshi Hatake --- test/plugin/in_tail/test_position_file.rb | 61 +++++++++++++++-------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/test/plugin/in_tail/test_position_file.rb b/test/plugin/in_tail/test_position_file.rb index cfde21d4a9..0715ab2996 100644 --- a/test/plugin/in_tail/test_position_file.rb +++ b/test/plugin/in_tail/test_position_file.rb @@ -283,40 +283,57 @@ def build_files(file) end end - sub_test_case "TargetInfo" do - def test_equal - t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234) - t2 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1235) + sub_test_case "TargetInfo equality rules" do + sub_test_case "== operator" do + def test_equal + t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234) + t2 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1235) - assert_equal t1, t2 - end + assert_equal t1, t2 + end - def test_not_equal - t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234) - t2 = Fluent::Plugin::TailInput::TargetInfo.new("test2", 1234) + def test_not_equal + t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234) + t2 = Fluent::Plugin::TailInput::TargetInfo.new("test2", 1234) - assert_not_equal t1, t2 + assert_not_equal t1, t2 + end end - def test_eql? - t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234) - t2 = Fluent::Plugin::TailInput::TargetInfo.new("test", 5321) + sub_test_case "eql? method" do + def test_eql? + t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234) + t2 = Fluent::Plugin::TailInput::TargetInfo.new("test", 5321) - assert do - t1.eql? t2 + assert do + t1.eql? t2 + end end - end - def test_not_eql? - t1 = Fluent::Plugin::TailInput::TargetInfo.new("test2", 1234) - t2 = Fluent::Plugin::TailInput::TargetInfo.new("test3", 1234) + def test_not_eql? + t1 = Fluent::Plugin::TailInput::TargetInfo.new("test2", 1234) + t2 = Fluent::Plugin::TailInput::TargetInfo.new("test3", 1234) - assert do - !t1.eql? t2 + assert do + !t1.eql? t2 + end end end - assert_equal t1.hash, t2.hash + sub_test_case "hash" do + def test_equal + t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234) + t2 = Fluent::Plugin::TailInput::TargetInfo.new("test", 7321) + + assert_equal t1.hash, t2.hash + end + + def test_not_equal + t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234) + t2 = Fluent::Plugin::TailInput::TargetInfo.new("test2", 1234) + + assert_not_equal t1.hash, t2.hash + end end end end From 3c6ba5caa828560f3876f4458f3a2fb5585448f2 Mon Sep 17 00:00:00 2001 From: Takuro Ashie Date: Wed, 26 May 2021 13:32:11 +0900 Subject: [PATCH 4/4] v1.12.4 Signed-off-by: Takuro Ashie --- CHANGELOG.md | 6 ++++++ lib/fluent/version.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b91c19fabe..0e1cdc48c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # v1.12 +## Release v1.12.4 - 2021/05/26 + +### Bug fix + +* in_tail: Fix a bug that refresh_watcher fails to handle file rotations + ## Release v1.12.3 - 2021/04/23 ### Enhancement diff --git a/lib/fluent/version.rb b/lib/fluent/version.rb index 7413ca114f..4325fde1f9 100644 --- a/lib/fluent/version.rb +++ b/lib/fluent/version.rb @@ -16,6 +16,6 @@ module Fluent - VERSION = '1.12.3' + VERSION = '1.12.4' end