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

in_tail: position_file: Define path based equalities on TargetInfo #3391

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 15 additions & 1 deletion lib/fluent/plugin/in_tail/position_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure follow_inodes feature but does it work well also on @follow_inodes?
I think that keys of @tails should be inode on @follow_inodes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or paths are updated by update_watcher on rotation so paths are never duplicate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a look on this.

Copy link
Member

@ashie ashie May 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still checking it too.
Probably above my concern is wrong, it should be path maybe.
Otherwise update_watcher can't discard old TailWather from @tails.

Copy link
Member

@ashie ashie May 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Memo:

Instead of overriding them, I thought using target_info.path as a key is more straightforward and understandable: @tails[target_info.path]

But it's also wrong.
TargetInfo is referred by each_keys so keys have to be TargetInfo.

Copy link
Member

@ashie ashie May 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, probably it's O.K. as a first aid but I think more refactoring is needed to make easy to understand in the future 🤔

Copy link
Contributor Author

@cosmo0920 cosmo0920 May 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of overriding them, I thought using target_info.path as a key is more straightforward and understandable: @tails[target_info.path]

But it's also wrong.
TargetInfo is referred by each_keys so keys have to be TargetInfo.

Yes! I'm also considering to use it to be made easier to understand, but overriding equality on TargetInfo is one of the simplest way to dispose discarded old TailWatcher correctly. (This strategy doesn't request more refactoring.)

end

def eql?(other)
return false unless other.is_a?(TargetInfo)
self.path == other.path
end
end
end
end
25 changes: 25 additions & 0 deletions test/plugin/in_tail/test_position_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Contributor

@kenhys kenhys May 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To emphasize the difference of eql? and equal? behavior, how about adding one more test case using assert_not_same t1, t2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be done in ab36738 and 2f2214b.

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