From e58da81b0d5cab61c07922a8996eae3f07986a64 Mon Sep 17 00:00:00 2001 From: Yuta Iwama Date: Fri, 7 Feb 2020 16:31:01 +0900 Subject: [PATCH 1/4] useless begin ~ end Signed-off-by: Yuta Iwama --- lib/fluent/plugin/in_tail.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/fluent/plugin/in_tail.rb b/lib/fluent/plugin/in_tail.rb index eb9f17ec18..64af0a10a9 100644 --- a/lib/fluent/plugin/in_tail.rb +++ b/lib/fluent/plugin/in_tail.rb @@ -892,14 +892,11 @@ def on_notify(stat) fsize = stat.size end - begin - if @inode != inode || fsize < @fsize - @on_rotate.call(stat) - end - @inode = inode - @fsize = fsize + if @inode != inode || fsize < @fsize + @on_rotate.call(stat) end - + @inode = inode + @fsize = fsize rescue @watcher.log.error $!.to_s @watcher.log.error_backtrace From 754d54457bd7923f9c8f47f768b7514ff961126c Mon Sep 17 00:00:00 2001 From: Yuta Iwama Date: Fri, 7 Feb 2020 16:32:09 +0900 Subject: [PATCH 2/4] Do not pass self Signed-off-by: Yuta Iwama --- lib/fluent/plugin/in_tail.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/fluent/plugin/in_tail.rb b/lib/fluent/plugin/in_tail.rb index 64af0a10a9..1262664476 100644 --- a/lib/fluent/plugin/in_tail.rb +++ b/lib/fluent/plugin/in_tail.rb @@ -540,10 +540,10 @@ def initialize(path, rotate_wait, pe, log, read_from_head, enable_watch_timer, e @receive_lines = receive_lines @update_watcher = update_watcher - @stat_trigger = @enable_stat_watcher ? StatWatcher.new(self, &method(:on_notify)) : nil + @stat_trigger = @enable_stat_watcher ? StatWatcher.new(path, log, &method(:on_notify)) : nil @timer_trigger = @enable_watch_timer ? TimerTrigger.new(1, log, &method(:on_notify)) : nil - @rotate_handler = RotateHandler.new(self, &method(:on_rotate)) + @rotate_handler = RotateHandler.new(log, &method(:on_rotate)) @io_handler = nil @log = log @@ -690,18 +690,18 @@ def on_timer end class StatWatcher < Coolio::StatWatcher - def initialize(watcher, &callback) - @watcher = watcher + def initialize(path, log, &callback) @callback = callback - super(watcher.path) + @log = log + super(path) end def on_change(prev, cur) @callback.call rescue # TODO log? - @watcher.log.error $!.to_s - @watcher.log.error_backtrace + @log.error $!.to_s + @log.error_backtrace end end @@ -876,8 +876,8 @@ def opened? end class RotateHandler - def initialize(watcher, &on_rotate) - @watcher = watcher + def initialize(log, &on_rotate) + @log = log @inode = nil @fsize = -1 # first @on_rotate = on_rotate @@ -898,8 +898,8 @@ def on_notify(stat) @inode = inode @fsize = fsize rescue - @watcher.log.error $!.to_s - @watcher.log.error_backtrace + @log.error $!.to_s + @log.error_backtrace end end From b8d362c5811121e6eaecd3718c031c879a3001e6 Mon Sep 17 00:00:00 2001 From: Yuta Iwama Date: Fri, 7 Feb 2020 16:46:31 +0900 Subject: [PATCH 3/4] Define line_buffer at initialize Signed-off-by: Yuta Iwama --- lib/fluent/plugin/in_tail.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/fluent/plugin/in_tail.rb b/lib/fluent/plugin/in_tail.rb index 1262664476..621e7e21d2 100644 --- a/lib/fluent/plugin/in_tail.rb +++ b/lib/fluent/plugin/in_tail.rb @@ -547,6 +547,7 @@ def initialize(path, rotate_wait, pe, log, read_from_head, enable_watch_timer, e @io_handler = nil @log = log + @line_buffer = nil @line_buffer_timer_flusher = line_buffer_timer_flusher @from_encoding = from_encoding @encoding = encoding From f4f5018dd565bdb72b89b9116651210174e44b7f Mon Sep 17 00:00:00 2001 From: Yuta Iwama Date: Fri, 7 Feb 2020 17:43:22 +0900 Subject: [PATCH 4/4] unnecessary begin ~ end Signed-off-by: Yuta Iwama --- lib/fluent/plugin/in_tail.rb | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/lib/fluent/plugin/in_tail.rb b/lib/fluent/plugin/in_tail.rb index 621e7e21d2..5230b0ce2d 100644 --- a/lib/fluent/plugin/in_tail.rb +++ b/lib/fluent/plugin/in_tail.rb @@ -835,26 +835,24 @@ def open end def with_io - begin - if @watcher.open_on_every_update - io = open - begin - yield io - ensure - io.close unless io.nil? - end - else - @io ||= open - yield @io + if @watcher.open_on_every_update + io = open + begin + yield io + ensure + io.close unless io.nil? end - rescue WatcherSetupError => e - close - raise e - rescue - @watcher.log.error $!.to_s - @watcher.log.error_backtrace - close + else + @io ||= open + yield @io end + rescue WatcherSetupError => e + close + raise e + rescue + @watcher.log.error $!.to_s + @watcher.log.error_backtrace + close end end