Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Aug 13, 2024
1 parent 5618dd0 commit 2b1c88d
Show file tree
Hide file tree
Showing 37 changed files with 184 additions and 111 deletions.
4 changes: 3 additions & 1 deletion lib/fluent/command/ctl.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -67,7 +69,7 @@ def initialize(argv = ARGV)
end

def help_text
text = "\n"
text = +"\n"
if Fluent.windows?
text << "Usage: #{$PROGRAM_NAME} COMMAND [PID_OR_SVCNAME]\n"
else
Expand Down
12 changes: 7 additions & 5 deletions lib/fluent/command/plugin_config_formatter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -79,7 +81,7 @@ def call
private

def dump_txt(dumped_config)
dumped = ""
dumped = +""
plugin_helpers = dumped_config.delete(:plugin_helpers)
if plugin_helpers && !plugin_helpers.empty?
dumped << "helpers: #{plugin_helpers.join(',')}\n"
Expand All @@ -101,7 +103,7 @@ def dump_txt(dumped_config)
end

def dump_section_txt(base_section, level = 0)
dumped = ""
dumped = +""
indent = " " * level
if base_section[:section]
sections = []
Expand Down Expand Up @@ -135,10 +137,10 @@ def dump_section_txt(base_section, level = 0)
end

def dump_markdown(dumped_config)
dumped = ""
dumped = +""
plugin_helpers = dumped_config.delete(:plugin_helpers)
if plugin_helpers && !plugin_helpers.empty?
dumped = "## Plugin helpers\n\n"
dumped = +"## Plugin helpers\n\n"
plugin_helpers.each do |plugin_helper|
dumped << "* #{plugin_helper_markdown_link(plugin_helper)}\n"
end
Expand All @@ -156,7 +158,7 @@ def dump_markdown(dumped_config)
end

def dump_section_markdown(base_section, level = 0)
dumped = ""
dumped = +""
if base_section[:section]
sections = []
params = base_section
Expand Down
4 changes: 3 additions & 1 deletion lib/fluent/compat/record_filter_mixin.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand All @@ -21,7 +23,7 @@ def filter_record(tag, time, record)
end

def format_stream(tag, es)
out = ''
out = +''
es.each {|time,record|
tag_temp = tag.dup
filter_record(tag_temp, time, record)
Expand Down
6 changes: 4 additions & 2 deletions lib/fluent/config/element.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -141,7 +143,7 @@ def check_not_fetched(&block)
def to_s(nest = 0)
indent = " " * nest
nindent = " " * (nest + 1)
out = ""
out = +""
if @arg.nil? || @arg.empty?
out << "#{indent}<#{@name}>\n"
else
Expand Down Expand Up @@ -230,7 +232,7 @@ def dump_value(k, v, nindent)
end

def self.unescape_parameter(v)
result = ''
result = +''
v.each_char { |c| result << LiteralParser.unescape_char(c) }
result
end
Expand Down
10 changes: 6 additions & 4 deletions lib/fluent/config/literal_parser.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -228,8 +230,8 @@ def scan_json(is_array)
# Yajl does not raise ParseError for incomplete json string, like '[1', '{"h"', '{"h":' or '{"h1":1'
# This is the reason to use JSON module.

buffer = (is_array ? "[" : "{")
line_buffer = ""
buffer = +(is_array ? "[" : "{")
line_buffer = +""

until result
char = getch
Expand All @@ -252,7 +254,7 @@ def scan_json(is_array)
# ignore comment char
end
buffer << line_buffer + "\n"
line_buffer = ""
line_buffer = +""
else
# '#' is a char in json string
line_buffer << char
Expand All @@ -263,7 +265,7 @@ def scan_json(is_array)

if char == "\n"
buffer << line_buffer + "\n"
line_buffer = ""
line_buffer = +""
next
end

Expand Down
4 changes: 3 additions & 1 deletion lib/fluent/config/types.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -100,7 +102,7 @@ def self.string_value(val, opts = {}, name = nil)
return nil if val.nil?

v = val.to_s
v = v.frozen? ? v.dup : v # config_param can't assume incoming string is mutable
v = v.frozen? ? v.dup : +v # config_param can't assume incoming string is mutable
v.force_encoding(Encoding::UTF_8)
end

Expand Down
4 changes: 3 additions & 1 deletion lib/fluent/log.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -550,7 +552,7 @@ def get_worker_id(type)

def event(level, args)
time = Time.now
message = @optional_header ? @optional_header.dup : ''
message = @optional_header ? @optional_header.dup : +''
map = @optional_attrs ? @optional_attrs.dup : {}
args.each {|a|
if a.is_a?(Hash)
Expand Down
8 changes: 5 additions & 3 deletions lib/fluent/match.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -43,7 +45,7 @@ def initialize(pat)
end

stack = []
regex = ['']
regex = [+'']
escape = false
dot = false

Expand Down Expand Up @@ -105,15 +107,15 @@ def initialize(pat)
elsif c == "{"
# or
stack.push []
regex.push ''
regex.push(+'')

elsif c == "}" && !stack.empty?
stack.last << regex.pop
regex.last << Regexp.union(*stack.pop.map {|r| Regexp.new(r) }).to_s

elsif c == "," && !stack.empty?
stack.last << regex.pop
regex.push ''
regex.push(+'')

elsif /[a-zA-Z0-9_]/.match?(c)
regex.last << c
Expand Down
4 changes: 3 additions & 1 deletion lib/fluent/plugin/buffer/file_chunk.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand All @@ -24,7 +26,7 @@ class Buffer
class FileChunk < Chunk
class FileChunkError < StandardError; end

BUFFER_HEADER = "\xc1\x00".force_encoding(Encoding::ASCII_8BIT).freeze
BUFFER_HEADER = (+"\xc1\x00").force_encoding(Encoding::ASCII_8BIT).freeze

### buffer path user specified : /path/to/directory/user_specified_prefix.*.log
### buffer chunk path : /path/to/directory/user_specified_prefix.b513b61c9791029c2513b61c9791029c2.log
Expand Down
6 changes: 4 additions & 2 deletions lib/fluent/plugin/buffer/memory_chunk.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand All @@ -22,7 +24,7 @@ class Buffer
class MemoryChunk < Chunk
def initialize(metadata, compress: :text)
super
@chunk = ''.force_encoding(Encoding::ASCII_8BIT)
@chunk = (+'').force_encoding(Encoding::ASCII_8BIT)
@chunk_bytes = 0
@adding_bytes = 0
@adding_size = 0
Expand Down Expand Up @@ -68,7 +70,7 @@ def empty?

def purge
super
@chunk = ''.force_encoding("ASCII-8BIT")
@chunk = (+'').force_encoding("ASCII-8BIT")
@chunk_bytes = @size = @adding_bytes = @adding_size = 0
true
end
Expand Down
4 changes: 3 additions & 1 deletion lib/fluent/plugin/compressable.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -57,7 +59,7 @@ def decompress(compressed_data = nil, output_io: nil, input_io: nil)
def string_decompress(compressed_data)
io = StringIO.new(compressed_data)

out = ''
out = +''
loop do
gz = Zlib::GzipReader.new(io)
out << gz.read
Expand Down
8 changes: 5 additions & 3 deletions lib/fluent/plugin/formatter_csv.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -50,13 +52,13 @@ def configure(conf)
end

@generate_opts = {col_sep: @delimiter, force_quotes: @force_quotes, headers: @fields,
row_sep: @add_newline ? :auto : "".force_encoding(Encoding::ASCII_8BIT)}
row_sep: @add_newline ? :auto : (+"").force_encoding(Encoding::ASCII_8BIT)}
# Cache CSV object per thread to avoid internal state sharing
@cache = {}
end

def format(tag, time, record)
csv = (@cache[Thread.current] ||= CSV.new("".force_encoding(Encoding::ASCII_8BIT), **@generate_opts))
csv = (@cache[Thread.current] ||= CSV.new((+"").force_encoding(Encoding::ASCII_8BIT), **@generate_opts))
line = (csv << record).string.dup
# Need manual cleanup because CSV writer doesn't provide such method.
csv.rewind
Expand All @@ -65,7 +67,7 @@ def format(tag, time, record)
end

def format_with_nested_fields(tag, time, record)
csv = (@cache[Thread.current] ||= CSV.new("".force_encoding(Encoding::ASCII_8BIT), **@generate_opts))
csv = (@cache[Thread.current] ||= CSV.new((+"").force_encoding(Encoding::ASCII_8BIT), **@generate_opts))
values = @accessors.map { |a| a.call(record) }
line = (csv << values).string.dup
# Need manual cleanup because CSV writer doesn't provide such method.
Expand Down
4 changes: 3 additions & 1 deletion lib/fluent/plugin/formatter_ltsv.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -31,7 +33,7 @@ class LabeledTSVFormatter < Formatter
config_param :add_newline, :bool, default: true

def format(tag, time, record)
formatted = ""
formatted = +""
record.each do |label, value|
formatted << @delimiter if formatted.length.nonzero?
formatted << "#{label}#{@label_delimiter}#{value.to_s.gsub(@delimiter, @replacement)}"
Expand Down
4 changes: 3 additions & 1 deletion lib/fluent/plugin/formatter_out_file.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -43,7 +45,7 @@ def configure(conf)
end

def format(tag, time, record)
header = ''
header = +''
header << "#{@timef.format(time)}#{@delimiter}" if @output_time
header << "#{tag}#{@delimiter}" if @output_tag
"#{header}#{Yajl.dump(record)}#{@newline}"
Expand Down
4 changes: 3 additions & 1 deletion lib/fluent/plugin/in_http.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -56,7 +58,7 @@ class HttpInput < Input

helpers :parser, :compat_parameters, :event_loop, :server

EMPTY_GIF_IMAGE = "GIF89a\u0001\u0000\u0001\u0000\x80\xFF\u0000\xFF\xFF\xFF\u0000\u0000\u0000,\u0000\u0000\u0000\u0000\u0001\u0000\u0001\u0000\u0000\u0002\u0002D\u0001\u0000;".force_encoding("UTF-8")
EMPTY_GIF_IMAGE = (+"GIF89a\u0001\u0000\u0001\u0000\x80\xFF\u0000\xFF\xFF\xFF\u0000\u0000\u0000,\u0000\u0000\u0000\u0000\u0001\u0000\u0001\u0000\u0000\u0002\u0002D\u0001\u0000;").force_encoding("UTF-8")

desc 'The port to listen to.'
config_param :port, :integer, default: 9880
Expand Down
4 changes: 3 additions & 1 deletion lib/fluent/plugin/in_monitor_agent.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -102,7 +104,7 @@ def render_json(obj, code: 200, pretty_json: nil)

def render_ltsv(obj, code: 200)
normalized = JSON.parse(obj.to_json)
text = ''
text = +''
normalized.each do |hash|
row = []
hash.each do |k, v|
Expand Down
4 changes: 3 additions & 1 deletion lib/fluent/plugin/in_syslog.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -187,7 +189,7 @@ def start_tcp_server(tls: false)
send_keepalive_packet: @send_keepalive_packet
) do |conn|
conn.data do |data|
buffer = conn.buffer
buffer = +conn.buffer
buffer << data
pos = 0
if octet_count_frame
Expand Down
7 changes: 5 additions & 2 deletions lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -1010,7 +1012,7 @@ def initialize(from_encoding, encoding, log, max_line_size=nil)
@from_encoding = from_encoding
@encoding = encoding
@need_enc = from_encoding != encoding
@buffer = ''.force_encoding(from_encoding)
@buffer = (+'').force_encoding(from_encoding)
@eol = "\n".encode(from_encoding).freeze
@max_line_size = max_line_size
@skip_current_line = false
Expand All @@ -1032,6 +1034,7 @@ def <<(chunk)
# quad-byte encoding to IO#readpartial as the second arguments results in an
# assertion failure on Ruby < 2.4.0 for unknown reasons.
orig_encoding = chunk.encoding
chunk = chunk.frozen? ? chunk.dup : chunk
chunk.force_encoding(from_encoding)
@buffer << chunk
# Thus the encoding needs to be reverted back here
Expand Down Expand Up @@ -1118,7 +1121,7 @@ def initialize(watcher, path:, read_lines_limit:, read_bytes_limit_per_second:,
@receive_lines = receive_lines
@open_on_every_update = open_on_every_update
@fifo = FIFO.new(from_encoding || Encoding::ASCII_8BIT, encoding || Encoding::ASCII_8BIT, log, max_line_size)
@iobuf = ''.force_encoding('ASCII-8BIT')
@iobuf = (+'').force_encoding('ASCII-8BIT')
@lines = []
@io = nil
@notify_mutex = Mutex.new
Expand Down
1 change: 1 addition & 0 deletions lib/fluent/plugin_helper/http_server/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def stop
HttpServer::Methods::ALL.map { |e| e.downcase.to_sym }.each do |name|
define_method(name) do |path, app = nil, &block|
unless path.end_with?('/')
path = path.frozen? ? path.dup : path
path << '/'
end

Expand Down
Loading

0 comments on commit 2b1c88d

Please sign in to comment.