Skip to content

Commit

Permalink
Fix bug in suppress_emit_error_log_interval
Browse files Browse the repository at this point in the history
Ensure time is in epoch format before comparison
  • Loading branch information
Patrick Robinson committed Jul 13, 2018
1 parent 029bb4b commit c25393d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/fluent/root_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def handle_emits_error(tag, es, error)
log.warn "send an error event stream to @ERROR:", error_info
@error_collector.emit_stream(tag, es)
else
now = Time.now
now = Time.now.to_i
if @suppress_emit_error_log_interval.zero? || now > @next_emit_error_log_time
log.warn "emit transaction failed:", error_info
log.warn_backtrace
Expand Down Expand Up @@ -347,7 +347,7 @@ def emit_error_event(tag, time, record, error)
end

def handle_emits_error(tag, es, e)
now = EventTime.now
now = EventTime.now.to_i
if @suppress_emit_error_log_interval.zero? || now > @next_emit_error_log_time
log.warn "emit transaction failed in @ERROR:", error: e, tag: tag
log.warn_backtrace
Expand Down
33 changes: 33 additions & 0 deletions test/test_root_agent.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require_relative 'helper'
require 'fluent/event_router'
require 'fluent/system_config'
require 'timecop'
require_relative 'test_plugin_classes'

class RootAgentTest < ::Test::Unit::TestCase
Expand Down Expand Up @@ -609,6 +610,38 @@ def setup_root_agent(conf)
end
end

sub_test_case 'configure emit_error_interval' do
setup do
system_config = SystemConfig.new
system_config.emit_error_log_interval = 30
@ra = RootAgent.new(log: $log, system_config: system_config)
stub(Engine).root_agent { @ra }
@ra.log.out.reset
one_minute_ago = Time.now.to_i - 60
Timecop.freeze(one_minute_ago)
end

teardown do
Timecop.return
end

test 'suppresses errors' do
mock(@ra.log).warn_backtrace()
e = StandardError.new('standard error')
begin
@ra.handle_emits_error("tag", nil, e)
rescue => e
end

begin
@ra.handle_emits_error("tag", nil, e)
rescue
end

assert_equal 1, @ra.log.out.logs.size
end
end

sub_test_case 'configured at worker2 with 4 workers environment' do
setup do
ENV['SERVERENGINE_WORKER_ID'] = '2'
Expand Down

0 comments on commit c25393d

Please sign in to comment.