Skip to content

Commit

Permalink
Merge pull request #2882 from ganmacs/fix-round
Browse files Browse the repository at this point in the history
Fix bug available_buffer_space_ratios which is set 0 or 1
  • Loading branch information
ganmacs committed Mar 16, 2020
2 parents eb9c49e + 2ae0b41 commit fffc2cc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
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

0 comments on commit fffc2cc

Please sign in to comment.