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 available_buffer_space_ratios which is set 0 or 1 #2882

Merged
merged 1 commit into from
Mar 16, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/fluent/plugin/buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -758,13 +758,13 @@ def write_step_by_step(metadata, data, format, splits_count, &block)

def statistics
stage_size, queue_size = @stage_size, @queue_size
buffer_space = 1.0 - ((stage_size + queue_size * 1.0) / @total_limit_size).round
buffer_space = 1.0 - ((stage_size + queue_size * 1.0) / @total_limit_size)
stats = {
'stage_length' => @stage.size,
'stage_byte_size' => stage_size,
'queue_length' => @queue.size,
'queue_byte_size' => queue_size,
'available_buffer_space_ratios' => buffer_space * 100,
'available_buffer_space_ratios' => (buffer_space * 100).round(1),
'total_queued_size' => stage_size + queue_size,
}

Expand Down
20 changes: 20 additions & 0 deletions test/plugin/test_buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1202,4 +1202,24 @@ def create_chunk_es(metadata, es)
assert chunk.singleton_class.ancestors.include?(Fluent::Plugin::Buffer::Chunk::Decompressable)
end
end

sub_test_case '#statistics' do
setup do
@p = create_buffer({ "total_limit_size" => 1024 })
dm = create_metadata(Time.parse('2020-03-13 16:00:00 +0000').to_i, nil, nil)

(class << @p; self; end).module_eval do
define_method(:resume) {
queued = [create_chunk(dm, ["a" * (1024 - 102)]).enqueued!]
return {}, queued
}
end

@p.start
end

test 'returns available_buffer_space_ratios' do
assert_equal 10.0, @p.statistics['buffer']['available_buffer_space_ratios']
end
end
end