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

Fix bug in suppress_emit_error_log_interval #2069

Merged
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/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
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