-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
231 additions
and
39 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
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,111 @@ | ||
# | ||
# 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 'fileutils' | ||
require 'uri' | ||
|
||
require 'fluent/buffer' | ||
require 'fluent/env' | ||
require 'fluent/plugin' | ||
require 'fluent/system_config' | ||
|
||
module Fluent | ||
module Plugin | ||
class FileBuffer < Fluent::Plugin::Buffer | ||
Plugin.register_buffer('file2', self) | ||
|
||
include SystemConfig::Mixin | ||
|
||
DEFAULT_CHUNK_BYTES_LIMIT = 256 * 1024 * 1024 # 256MB | ||
DEFAULT_TOTAL_BYTES_LIMIT = 64 * 1024 * 1024 * 1024 # 64GB, same with v0.12 (TimeSlicedOutput + buf_file) | ||
|
||
# TODO: buffer_path based on system config | ||
desc 'The path where buffer chunks are stored.' | ||
config_param :path, :string | ||
|
||
config_set_default :chunk_bytes_limit, DEFAULT_CHUNK_BYTES_LIMIT | ||
config_set_default :total_bytes_limit, DEFAULT_TOTAL_BYTES_LIMIT | ||
|
||
##TODO: Buffer plugin cannot handle symlinks because new API @stage has many writing buffer chunks | ||
## re-implement this feature on out_file, w/ enqueue_chunk(or generate_chunk) hook + chunk.path | ||
# attr_accessor :symlink_path | ||
|
||
@@buffer_paths = {} | ||
|
||
def initialize | ||
super | ||
@uri_parser = URI::Parser.new | ||
@symlink_path = nil | ||
@dir_permission = system_config.dir_permission || DIR_PERMISSION | ||
end | ||
|
||
def configure(conf) | ||
super | ||
|
||
type_of_owner = Plugin.lookup_type_from_class(@_owner.class) | ||
if @@buffer_paths.has_key?(@path) | ||
type_using_this_path = Plugin.lookup_type_from_class(@@buffer_paths[@path]) | ||
raise ConfigError, "Other '#{type_using_this_path}' plugin already use same buffer path: type = #{type_of_owner}, buffer path = #{@path}" | ||
end | ||
|
||
@@buffer_paths[@path] = type_of_owner | ||
|
||
unless @path.include?('*') | ||
@path += '.*.log' | ||
end | ||
end | ||
|
||
def start | ||
FileUtils.mkdir_p File.dirname(@buffer_path_prefix + "path"), mode: @dir_permission | ||
|
||
super | ||
end | ||
|
||
def persistent? | ||
true | ||
end | ||
|
||
def resume | ||
stage = {} | ||
queue = [] | ||
|
||
Dir.glob(@path) do |path| | ||
m = new_metadata() | ||
mode = Fluent::Plugin::Buffer::FileChunk.assume_chunk_state(path) | ||
chunk = Fluent::Plugin::Buffer::FileChunk.new(m, path, mode) # file chunk resumes contents of metadata | ||
case chunk.state | ||
when :staged | ||
stage[chunk.metadata] = chunk | ||
when :queued, :blocked | ||
queue << chunk | ||
else | ||
raise "BUG: unexpected chunk state '#{chunk.state}' for path '#{path}'" | ||
end | ||
add_metadata(chunk.metadata) | ||
end | ||
|
||
queue.sort_by!{ |chunk| chunk.modified_at } | ||
|
||
return stage, queue | ||
end | ||
|
||
def generate_chunk(metadata) | ||
# FileChunk generates real path with unique_id | ||
Fluent::Plugin::Buffer::FileChunk.new(metadata, @path, :create) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# | ||
# 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 'fluent/plugin/buffer' | ||
require 'fluent/plugin/buffer/memory_chunk' | ||
|
||
module Fluent | ||
module Plugin | ||
class MemoryBuffer < Fluent::Plugin::Buffer | ||
Plugin.register_buffer('memory2', self) | ||
|
||
def resume | ||
return {}, [] | ||
end | ||
|
||
def generate_chunk(metadata) | ||
Fluent::Plugin::Buffer::MemoryChunk.new(metadata) | ||
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
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