-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1172 from ganmacs/support-data-compression-in-buffer
Support data compression in buffer plugins
- Loading branch information
Showing
19 changed files
with
761 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<source> | ||
@type dummy | ||
@label @main | ||
tag "test.data" | ||
size 2 | ||
rate 10 | ||
dummy {"message":"yaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay"} | ||
auto_increment_key number | ||
</source> | ||
|
||
<label @main> | ||
<match test.data> | ||
@type buffered_stdout | ||
<buffer> | ||
@type file | ||
path "#{Dir.pwd}/compressed_buffers" | ||
flush_at_shutdown false | ||
chunk_limit_size 1m | ||
flush_interval 10s | ||
compress gzip | ||
</buffer> | ||
</match> | ||
</label> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# | ||
# Fluentd | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
require 'zlib' | ||
|
||
module Fluent | ||
module Plugin | ||
module Compressable | ||
def compress(data, **kwargs) | ||
output_io = kwargs[:output_io] | ||
io = output_io || StringIO.new | ||
Zlib::GzipWriter.wrap(io) do |gz| | ||
gz.write data | ||
end | ||
|
||
output_io || io.string | ||
end | ||
|
||
# compressed_data is String like `compress(data1) + compress(data2) + ... + compress(dataN)` | ||
# https://www.ruby-forum.com/topic/971591#979503 | ||
def decompress(compressed_data = nil, output_io: nil, input_io: nil) | ||
case | ||
when input_io && output_io | ||
io_decompress(input_io, output_io) | ||
when input_io | ||
output_io = StringIO.new | ||
io = io_decompress(input_io, output_io) | ||
io.string | ||
when compressed_data.nil? || compressed_data.empty? | ||
# check compressed_data(String) is 0 length | ||
compressed_data | ||
when output_io | ||
# exeucte after checking compressed_data is empty or not | ||
io = StringIO.new(compressed_data) | ||
io_decompress(io, output_io) | ||
else | ||
string_decompress(compressed_data) | ||
end | ||
end | ||
|
||
private | ||
|
||
def string_decompress(compressed_data) | ||
io = StringIO.new(compressed_data) | ||
|
||
out = '' | ||
loop do | ||
gz = Zlib::GzipReader.new(io) | ||
out += gz.read | ||
unused = gz.unused | ||
gz.finish | ||
|
||
break if unused.nil? | ||
adjust = unused.length | ||
io.pos -= adjust | ||
end | ||
|
||
out | ||
end | ||
|
||
def io_decompress(input, output) | ||
loop do | ||
gz = Zlib::GzipReader.new(input) | ||
v = gz.read | ||
output.write(v) | ||
unused = gz.unused | ||
gz.finish | ||
|
||
break if unused.nil? | ||
adjust = unused.length | ||
input.pos -= adjust | ||
end | ||
|
||
output | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.