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 TimeSlicedOutput does not flush with SIGUSR1 #533

Merged
merged 1 commit into from
Jan 13, 2015
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
14 changes: 10 additions & 4 deletions lib/fluent/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def format_stream(tag, es)
#def write(chunk)
#end

def enqueue_buffer
def enqueue_buffer(force = false)
@buffer.keys.each {|key|
@buffer.push(key)
}
Expand Down Expand Up @@ -383,7 +383,7 @@ def try_flush
end

def force_flush
enqueue_buffer
enqueue_buffer(true)
submit_flush
end

Expand Down Expand Up @@ -551,8 +551,14 @@ def emit(tag, es, chain)
}
end

def enqueue_buffer
@enqueue_buffer_proc.call
def enqueue_buffer(force = false)
Copy link
Member Author

Choose a reason for hiding this comment

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

added an argument to forcely enqueue

if force
@buffer.keys.each {|key|
@buffer.push(key)
}
else
@enqueue_buffer_proc.call
end
end

#def format(tag, event)
Expand Down
47 changes: 47 additions & 0 deletions test/test_output.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require_relative 'helper'
require 'fluent/test'
require 'fluent/output'
require 'timecop'
require 'flexmock'

module FluentOutputTest
include Fluent
Expand Down Expand Up @@ -160,4 +162,49 @@ def test_secondary
assert_not_nil d.instance.instance_variable_get(:@secondary).router
end
end

class TimeSlicedOutputTest < ::Test::Unit::TestCase
include FluentOutputTest
include FlexMock::TestCase

def setup
Fluent::Test.setup
FileUtils.rm_rf(TMP_DIR)
FileUtils.mkdir_p(TMP_DIR)
end

TMP_DIR = File.expand_path(File.dirname(__FILE__) + "/../tmp/time_sliced_output")

CONFIG = %[]

def create_driver(conf=CONFIG)
Fluent::Test::TimeSlicedOutputTestDriver.new(Fluent::TimeSlicedOutput).configure(conf, true)
end

sub_test_case "test_force_flush" do
setup do
time = Time.parse("2011-01-02 13:14:15 UTC")
Timecop.freeze(time)
@es = OneEventStream.new(time.to_i, {"message" => "foo"})
end

teardown do
Timecop.return
end

test "force_flush immediately flushes" do
d = create_driver(CONFIG + %[
time_format %Y%m%d%H%M%S
buffer_path #{TMP_DIR}/foo
])
d.instance.start
# buffer should be popped (flushed) immediately
flexmock(d.instance.instance_variable_get(:@buffer)).should_receive(:pop).once
# force_flush
d.instance.emit('test', @es, NullOutputChain.instance)
d.instance.force_flush
10.times { sleep 0.05 }
end
end
end
end