fluentd 0.14.1 → 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog +110 -1
- data/Rakefile +5 -1
- data/appveyor.yml +7 -1
- data/example/in_forward.conf +4 -0
- data/lib/fluent/compat/exec_util.rb +129 -0
- data/lib/fluent/compat/file_util.rb +54 -0
- data/lib/fluent/compat/filter.rb +21 -3
- data/lib/fluent/compat/formatter.rb +4 -2
- data/lib/fluent/compat/formatter_utils.rb +85 -0
- data/lib/fluent/compat/handle_tag_and_time_mixin.rb +60 -0
- data/lib/fluent/compat/input.rb +1 -3
- data/lib/fluent/compat/output.rb +95 -39
- data/lib/fluent/compat/parser.rb +17 -0
- data/lib/fluent/compat/parser_utils.rb +40 -0
- data/lib/fluent/compat/socket_util.rb +165 -0
- data/lib/fluent/compat/string_util.rb +34 -0
- data/lib/fluent/{test/driver/owner.rb → compat/structured_format_mixin.rb} +5 -11
- data/lib/fluent/config/element.rb +2 -2
- data/lib/fluent/configurable.rb +2 -1
- data/lib/fluent/event.rb +61 -7
- data/lib/fluent/event_router.rb +1 -1
- data/lib/fluent/plugin.rb +7 -7
- data/lib/fluent/plugin/buf_file.rb +5 -2
- data/lib/fluent/plugin/buffer.rb +194 -64
- data/lib/fluent/plugin/buffer/chunk.rb +28 -3
- data/lib/fluent/plugin/buffer/file_chunk.rb +5 -21
- data/lib/fluent/plugin/buffer/memory_chunk.rb +1 -11
- data/lib/fluent/plugin/exec_util.rb +2 -112
- data/lib/fluent/plugin/file_util.rb +3 -38
- data/lib/fluent/plugin/file_wrapper.rb +1 -1
- data/lib/fluent/plugin/filter_grep.rb +3 -7
- data/lib/fluent/plugin/filter_record_transformer.rb +5 -5
- data/lib/fluent/plugin/filter_stdout.rb +18 -11
- data/lib/fluent/plugin/formatter.rb +0 -48
- data/lib/fluent/plugin/formatter_csv.rb +7 -8
- data/lib/fluent/plugin/formatter_hash.rb +1 -4
- data/lib/fluent/plugin/formatter_json.rb +1 -4
- data/lib/fluent/plugin/formatter_ltsv.rb +5 -6
- data/lib/fluent/plugin/formatter_msgpack.rb +1 -4
- data/lib/fluent/plugin/formatter_out_file.rb +36 -3
- data/lib/fluent/plugin/formatter_stdout.rb +36 -1
- data/lib/fluent/plugin/in_dummy.rb +9 -2
- data/lib/fluent/plugin/in_exec.rb +20 -57
- data/lib/fluent/plugin/in_forward.rb +4 -3
- data/lib/fluent/plugin/in_object_space.rb +8 -44
- data/lib/fluent/plugin/in_syslog.rb +13 -24
- data/lib/fluent/plugin/in_tail.rb +3 -0
- data/lib/fluent/plugin/out_buffered_stdout.rb +14 -4
- data/lib/fluent/plugin/out_exec.rb +7 -5
- data/lib/fluent/plugin/out_exec_filter.rb +10 -10
- data/lib/fluent/plugin/out_file.rb +1 -3
- data/lib/fluent/plugin/out_forward.rb +38 -57
- data/lib/fluent/plugin/out_stdout.rb +14 -5
- data/lib/fluent/plugin/out_stream.rb +3 -0
- data/lib/fluent/plugin/output.rb +31 -14
- data/lib/fluent/plugin/parser.rb +0 -69
- data/lib/fluent/plugin/parser_apache.rb +10 -6
- data/lib/fluent/plugin/parser_apache_error.rb +8 -3
- data/lib/fluent/plugin/parser_csv.rb +3 -1
- data/lib/fluent/plugin/parser_json.rb +1 -1
- data/lib/fluent/plugin/parser_multiline.rb +5 -3
- data/lib/fluent/plugin/parser_nginx.rb +10 -6
- data/lib/fluent/plugin/parser_regexp.rb +73 -0
- data/lib/fluent/plugin/socket_util.rb +2 -148
- data/lib/fluent/plugin/storage_local.rb +1 -1
- data/lib/fluent/plugin/string_util.rb +3 -18
- data/lib/fluent/plugin_helper.rb +1 -0
- data/lib/fluent/plugin_helper/compat_parameters.rb +166 -41
- data/lib/fluent/plugin_helper/formatter.rb +30 -19
- data/lib/fluent/plugin_helper/inject.rb +25 -12
- data/lib/fluent/plugin_helper/parser.rb +22 -13
- data/lib/fluent/plugin_helper/storage.rb +22 -13
- data/lib/fluent/registry.rb +19 -6
- data/lib/fluent/supervisor.rb +27 -1
- data/lib/fluent/test/driver/base.rb +16 -92
- data/lib/fluent/test/driver/base_owned.rb +17 -53
- data/lib/fluent/test/driver/base_owner.rb +125 -0
- data/lib/fluent/test/driver/filter.rb +24 -2
- data/lib/fluent/test/driver/input.rb +2 -2
- data/lib/fluent/test/driver/multi_output.rb +2 -2
- data/lib/fluent/test/driver/output.rb +3 -5
- data/lib/fluent/test/helpers.rb +25 -0
- data/lib/fluent/test/input_test.rb +4 -4
- data/lib/fluent/test/output_test.rb +3 -3
- data/lib/fluent/version.rb +1 -1
- data/test/config/test_element.rb +135 -6
- data/test/plugin/test_buf_file.rb +71 -3
- data/test/plugin/test_buffer.rb +305 -86
- data/test/plugin/test_buffer_chunk.rb +60 -2
- data/test/plugin/test_buffer_file_chunk.rb +4 -3
- data/test/plugin/test_filter_grep.rb +25 -21
- data/test/plugin/test_filter_record_transformer.rb +75 -67
- data/test/plugin/test_filter_stdout.rb +171 -74
- data/test/plugin/test_formatter_csv.rb +94 -0
- data/test/plugin/test_formatter_json.rb +30 -0
- data/test/plugin/test_formatter_ltsv.rb +52 -0
- data/test/plugin/test_formatter_msgpack.rb +28 -0
- data/test/plugin/test_formatter_out_file.rb +95 -0
- data/test/plugin/test_formatter_single_value.rb +38 -0
- data/test/plugin/test_in_dummy.rb +95 -0
- data/test/plugin/test_in_exec.rb +27 -31
- data/test/plugin/test_in_forward.rb +24 -0
- data/test/plugin/test_in_gc_stat.rb +5 -5
- data/test/plugin/test_in_object_space.rb +4 -4
- data/test/plugin/test_in_syslog.rb +60 -35
- data/test/plugin/test_out_buffered_stdout.rb +17 -3
- data/test/plugin/test_out_forward.rb +93 -5
- data/test/plugin/test_out_stdout.rb +14 -3
- data/test/plugin/test_output_as_buffered_retries.rb +20 -0
- data/test/plugin/test_output_as_buffered_secondary.rb +16 -0
- data/test/plugin/test_output_as_standard.rb +22 -22
- data/test/plugin/test_parser_apache.rb +13 -9
- data/test/plugin/test_parser_apache_error.rb +11 -6
- data/test/plugin/test_parser_csv.rb +35 -25
- data/test/plugin/test_parser_nginx.rb +11 -5
- data/test/plugin/test_parser_regexp.rb +235 -68
- data/test/plugin/test_parser_tsv.rb +54 -58
- data/test/plugin_helper/test_compat_parameters.rb +111 -46
- data/test/plugin_helper/test_formatter.rb +40 -0
- data/test/plugin_helper/test_inject.rb +101 -2
- data/test/plugin_helper/test_parser.rb +40 -0
- data/test/plugin_helper/test_storage.rb +43 -0
- data/test/test_event.rb +93 -0
- data/test/test_event_router.rb +13 -4
- data/test/test_event_time.rb +0 -3
- data/test/test_formatter.rb +7 -164
- data/test/test_plugin_classes.rb +28 -1
- metadata +24 -3
data/lib/fluent/plugin/parser.rb
CHANGED
|
@@ -97,75 +97,6 @@ module Fluent
|
|
|
97
97
|
end
|
|
98
98
|
end
|
|
99
99
|
|
|
100
|
-
class RegexpParser < Parser
|
|
101
|
-
include Fluent::TypeConverter
|
|
102
|
-
|
|
103
|
-
config_param :time_key, :string, default: 'time'
|
|
104
|
-
config_param :time_format, :string, default: nil
|
|
105
|
-
|
|
106
|
-
def initialize(regexp, conf={})
|
|
107
|
-
super()
|
|
108
|
-
|
|
109
|
-
unless conf.empty?
|
|
110
|
-
unless conf.is_a?(Config::Element)
|
|
111
|
-
conf = Config::Element.new('default_regexp_conf', '', conf, [])
|
|
112
|
-
end
|
|
113
|
-
configure(conf)
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
@regexp = regexp
|
|
117
|
-
@time_parser = TimeParser.new(@time_format)
|
|
118
|
-
@mutex = Mutex.new
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
def configure(conf)
|
|
122
|
-
super
|
|
123
|
-
@time_parser = TimeParser.new(@time_format)
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
def patterns
|
|
127
|
-
{'format' => @regexp, 'time_format' => @time_format}
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
def parse(text)
|
|
131
|
-
m = @regexp.match(text)
|
|
132
|
-
unless m
|
|
133
|
-
yield nil, nil
|
|
134
|
-
return
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
time = nil
|
|
138
|
-
record = {}
|
|
139
|
-
|
|
140
|
-
m.names.each do |name|
|
|
141
|
-
if value = m[name]
|
|
142
|
-
if name == @time_key
|
|
143
|
-
time = @mutex.synchronize { @time_parser.parse(value) }
|
|
144
|
-
if @keep_time_key
|
|
145
|
-
record[name] = if @type_converters.nil?
|
|
146
|
-
value
|
|
147
|
-
else
|
|
148
|
-
convert_type(name, value)
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
else
|
|
152
|
-
record[name] = if @type_converters.nil?
|
|
153
|
-
value
|
|
154
|
-
else
|
|
155
|
-
convert_type(name, value)
|
|
156
|
-
end
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
if @estimate_current_event
|
|
162
|
-
time ||= Fluent::EventTime.now
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
yield time, record
|
|
166
|
-
end
|
|
167
|
-
end
|
|
168
|
-
|
|
169
100
|
class ValuesParser < Parser
|
|
170
101
|
include Fluent::TypeConverter
|
|
171
102
|
|
|
@@ -16,9 +16,13 @@
|
|
|
16
16
|
|
|
17
17
|
require 'fluent/plugin/parser'
|
|
18
18
|
|
|
19
|
-
Fluent
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
19
|
+
module Fluent
|
|
20
|
+
module Plugin
|
|
21
|
+
class ApacheParser < RegexpParser
|
|
22
|
+
Plugin.register_parser("apache", self)
|
|
23
|
+
|
|
24
|
+
config_set_default :expression, %q{/^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?$/}
|
|
25
|
+
config_set_default :time_format, "%d/%b/%Y:%H:%M:%S %z"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -16,6 +16,11 @@
|
|
|
16
16
|
|
|
17
17
|
require 'fluent/plugin/parser'
|
|
18
18
|
|
|
19
|
-
Fluent
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
module Fluent
|
|
20
|
+
module Plugin
|
|
21
|
+
class ApacheErrorParser < RegexpParser
|
|
22
|
+
Plugin.register_parser("apache_error", self)
|
|
23
|
+
config_set_default :expression, %q{/^\[[^ ]* (?<time>[^\]]*)\] \[(?<level>[^\]]*)\](?: \[pid (?<pid>[^\]]*)\])?( \[client (?<client>[^\]]*)\])? (?<message>.*)$/}
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -23,8 +23,10 @@ module Fluent
|
|
|
23
23
|
class CSVParser < ValuesParser
|
|
24
24
|
Plugin.register_parser('csv', self)
|
|
25
25
|
|
|
26
|
+
config_param :delimiter, :string, default: ','
|
|
27
|
+
|
|
26
28
|
def parse(text)
|
|
27
|
-
yield values_map(CSV.parse_line(text))
|
|
29
|
+
yield values_map(CSV.parse_line(text, col_sep: @delimiter))
|
|
28
30
|
end
|
|
29
31
|
end
|
|
30
32
|
end
|
|
@@ -39,7 +39,7 @@ module Fluent
|
|
|
39
39
|
begin
|
|
40
40
|
raise LoadError unless @json_parser == 'oj'
|
|
41
41
|
require 'oj'
|
|
42
|
-
Oj.default_options = {bigdecimal_load: :float}
|
|
42
|
+
Oj.default_options = {bigdecimal_load: :float, mode: :strict}
|
|
43
43
|
@load_proc = Oj.method(:load)
|
|
44
44
|
@error_class = Oj::ParseError
|
|
45
45
|
rescue LoadError
|
|
@@ -30,11 +30,13 @@ module Fluent
|
|
|
30
30
|
|
|
31
31
|
formats = parse_formats(conf).compact.map { |f| f[1..-2] }.join
|
|
32
32
|
begin
|
|
33
|
-
|
|
34
|
-
if
|
|
33
|
+
regexp = Regexp.new(formats, Regexp::MULTILINE)
|
|
34
|
+
if regexp.named_captures.empty?
|
|
35
35
|
raise "No named captures"
|
|
36
36
|
end
|
|
37
|
-
|
|
37
|
+
regexp_conf = Fluent::Config::Element.new("", "", { "expression" => "/#{formats}/", "multiline" => true }, [])
|
|
38
|
+
@parser = Fluent::Plugin::RegexpParser.new
|
|
39
|
+
@parser.configure(conf + regexp_conf)
|
|
38
40
|
rescue => e
|
|
39
41
|
raise ConfigError, "Invalid regexp '#{formats}': #{e}"
|
|
40
42
|
end
|
|
@@ -16,9 +16,13 @@
|
|
|
16
16
|
|
|
17
17
|
require 'fluent/plugin/parser'
|
|
18
18
|
|
|
19
|
-
Fluent
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
19
|
+
module Fluent
|
|
20
|
+
module Plugin
|
|
21
|
+
class NginxParser < RegexpParser
|
|
22
|
+
Plugin.register_parser("nginx", self)
|
|
23
|
+
|
|
24
|
+
config_set_default :expression, %q{/^(?<remote>[^ ]*) (?<host>[^ ]*) (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^\"]*?)(?: +\S*)?)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?$/}
|
|
25
|
+
config_set_default :time_format, "%d/%b/%Y:%H:%M:%S %z"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
module Fluent
|
|
2
|
+
module Plugin
|
|
3
|
+
class RegexpParser < Parser
|
|
4
|
+
include Fluent::Compat::TypeConverter
|
|
5
|
+
|
|
6
|
+
Plugin.register_parser("regexp", self)
|
|
7
|
+
|
|
8
|
+
config_param :expression, :string, default: ""
|
|
9
|
+
config_param :ignorecase, :bool, default: false
|
|
10
|
+
config_param :multiline, :bool, default: false
|
|
11
|
+
config_param :time_key, :string, default: 'time'
|
|
12
|
+
config_param :time_format, :string, default: nil
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
super
|
|
16
|
+
@mutex = Mutex.new
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def configure(conf)
|
|
20
|
+
super
|
|
21
|
+
@time_parser = TimeParser.new(@time_format)
|
|
22
|
+
unless @expression.empty?
|
|
23
|
+
if @expression[0] == "/" && @expression[-1] == "/"
|
|
24
|
+
regexp_option = 0
|
|
25
|
+
regexp_option |= Regexp::IGNORECASE if @ignorecase
|
|
26
|
+
regexp_option |= Regexp::MULTILINE if @multiline
|
|
27
|
+
@regexp = Regexp.new(@expression[1..-2], regexp_option)
|
|
28
|
+
else
|
|
29
|
+
raise Fluent::ConfigError, "expression must start with `/` and end with `/`: #{@expression}"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def parse(text)
|
|
35
|
+
m = @regexp.match(text)
|
|
36
|
+
unless m
|
|
37
|
+
yield nil, nil
|
|
38
|
+
return
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
time = nil
|
|
42
|
+
record = {}
|
|
43
|
+
|
|
44
|
+
m.names.each do |name|
|
|
45
|
+
if value = m[name]
|
|
46
|
+
if name == @time_key
|
|
47
|
+
time = @mutex.synchronize { @time_parser.parse(value) }
|
|
48
|
+
if @keep_time_key
|
|
49
|
+
record[name] = if @type_converters.nil?
|
|
50
|
+
value
|
|
51
|
+
else
|
|
52
|
+
convert_type(name, value)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
else
|
|
56
|
+
record[name] = if @type_converters.nil?
|
|
57
|
+
value
|
|
58
|
+
else
|
|
59
|
+
convert_type(name, value)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
if @estimate_current_event
|
|
66
|
+
time ||= Fluent::EventTime.now
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
yield time, record
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -14,155 +14,9 @@
|
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
#
|
|
16
16
|
|
|
17
|
-
require '
|
|
18
|
-
|
|
19
|
-
require 'cool.io'
|
|
20
|
-
|
|
21
|
-
require 'fluent/plugin'
|
|
22
|
-
require 'fluent/input'
|
|
17
|
+
require 'fluent/compat/socket_util'
|
|
23
18
|
|
|
24
19
|
module Fluent
|
|
25
|
-
module Plugin
|
|
26
|
-
module SocketUtil
|
|
27
|
-
def create_udp_socket(host)
|
|
28
|
-
if IPAddr.new(IPSocket.getaddress(host)).ipv4?
|
|
29
|
-
UDPSocket.new
|
|
30
|
-
else
|
|
31
|
-
UDPSocket.new(Socket::AF_INET6)
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
module_function :create_udp_socket
|
|
35
|
-
|
|
36
|
-
class UdpHandler < Coolio::IO
|
|
37
|
-
def initialize(io, log, body_size_limit, callback)
|
|
38
|
-
super(io)
|
|
39
|
-
@io = io
|
|
40
|
-
@log = log
|
|
41
|
-
@body_size_limit = body_size_limit
|
|
42
|
-
@callback = callback
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def on_readable
|
|
46
|
-
msg, addr = @io.recvfrom_nonblock(@body_size_limit)
|
|
47
|
-
msg.chomp!
|
|
48
|
-
@callback.call(msg, addr)
|
|
49
|
-
rescue => e
|
|
50
|
-
@log.error "unexpected error", error: e
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
class TcpHandler < Coolio::Socket
|
|
55
|
-
PEERADDR_FAILED = ["?", "?", "name resolusion failed", "?"]
|
|
56
|
-
|
|
57
|
-
def initialize(io, log, delimiter, callback)
|
|
58
|
-
super(io)
|
|
59
|
-
@timeout = 0
|
|
60
|
-
if io.is_a?(TCPSocket)
|
|
61
|
-
@addr = (io.peeraddr rescue PEERADDR_FAILED)
|
|
62
|
-
|
|
63
|
-
opt = [1, @timeout.to_i].pack('I!I!') # { int l_onoff; int l_linger; }
|
|
64
|
-
io.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, opt)
|
|
65
|
-
end
|
|
66
|
-
@delimiter = delimiter
|
|
67
|
-
@callback = callback
|
|
68
|
-
@log = log
|
|
69
|
-
@log.trace { "accepted fluent socket object_id=#{self.object_id}" }
|
|
70
|
-
@buffer = "".force_encoding('ASCII-8BIT')
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def on_connect
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def on_read(data)
|
|
77
|
-
@buffer << data
|
|
78
|
-
pos = 0
|
|
79
|
-
|
|
80
|
-
while i = @buffer.index(@delimiter, pos)
|
|
81
|
-
msg = @buffer[pos...i]
|
|
82
|
-
@callback.call(msg, @addr)
|
|
83
|
-
pos = i + @delimiter.length
|
|
84
|
-
end
|
|
85
|
-
@buffer.slice!(0, pos) if pos > 0
|
|
86
|
-
rescue => e
|
|
87
|
-
@log.error "unexpected error", error: e
|
|
88
|
-
close
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def on_close
|
|
92
|
-
@log.trace { "closed fluent socket object_id=#{self.object_id}" }
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
class BaseInput < Fluent::Input
|
|
97
|
-
def initialize
|
|
98
|
-
super
|
|
99
|
-
require 'fluent/parser'
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
desc 'Tag of output events.'
|
|
103
|
-
config_param :tag, :string
|
|
104
|
-
desc 'The format of the payload.'
|
|
105
|
-
config_param :format, :string
|
|
106
|
-
desc 'The port to listen to.'
|
|
107
|
-
config_param :port, :integer, default: 5150
|
|
108
|
-
desc 'The bind address to listen to.'
|
|
109
|
-
config_param :bind, :string, default: '0.0.0.0'
|
|
110
|
-
desc "The field name of the client's hostname."
|
|
111
|
-
config_param :source_host_key, :string, default: nil
|
|
112
|
-
config_param :blocking_timeout, :time, default: 0.5
|
|
113
|
-
|
|
114
|
-
def configure(conf)
|
|
115
|
-
super
|
|
116
|
-
|
|
117
|
-
@parser = Plugin.new_parser(@format)
|
|
118
|
-
@parser.configure(conf)
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
def start
|
|
122
|
-
super
|
|
123
|
-
|
|
124
|
-
@loop = Coolio::Loop.new
|
|
125
|
-
@handler = listen(method(:on_message))
|
|
126
|
-
@loop.attach(@handler)
|
|
127
|
-
@thread = Thread.new(&method(:run))
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
def shutdown
|
|
131
|
-
@loop.watchers.each { |w| w.detach }
|
|
132
|
-
@loop.stop if @loop.instance_variable_get("@running")
|
|
133
|
-
@handler.close
|
|
134
|
-
@thread.join
|
|
135
|
-
|
|
136
|
-
super
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
def run
|
|
140
|
-
@loop.run(@blocking_timeout)
|
|
141
|
-
rescue => e
|
|
142
|
-
log.error "unexpected error", error: e
|
|
143
|
-
log.error_backtrace
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
private
|
|
147
|
-
|
|
148
|
-
def on_message(msg, addr)
|
|
149
|
-
@parser.parse(msg) { |time, record|
|
|
150
|
-
unless time && record
|
|
151
|
-
log.warn "pattern not match: #{msg.inspect}"
|
|
152
|
-
return
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
record[@source_host_key] = addr[3] if @source_host_key
|
|
156
|
-
router.emit(@tag, time, record)
|
|
157
|
-
}
|
|
158
|
-
rescue => e
|
|
159
|
-
log.error msg.dump, error: e, host: addr[3]
|
|
160
|
-
log.error_backtrace
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
end
|
|
165
|
-
|
|
166
20
|
# obsolete
|
|
167
|
-
SocketUtil = Fluent::
|
|
21
|
+
SocketUtil = Fluent::Compat::SocketUtil
|
|
168
22
|
end
|
|
@@ -58,7 +58,7 @@ module Fluent
|
|
|
58
58
|
raise Fluent::ConfigError, "Unexpected error: failed to read data from plugin storage file: '#{@path}'"
|
|
59
59
|
end
|
|
60
60
|
else
|
|
61
|
-
raise Fluent::ConfigError, "Directory is not writable for plugin storage file '#{
|
|
61
|
+
raise Fluent::ConfigError, "Directory is not writable for plugin storage file '#{dir}'" unless File.writable?(dir)
|
|
62
62
|
end
|
|
63
63
|
end
|
|
64
64
|
end
|
|
@@ -14,24 +14,9 @@
|
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
#
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
module Plugin
|
|
19
|
-
module StringUtil
|
|
20
|
-
def match_regexp(regexp, string)
|
|
21
|
-
begin
|
|
22
|
-
return regexp.match(string)
|
|
23
|
-
rescue ArgumentError => e
|
|
24
|
-
raise e unless e.message.index("invalid byte sequence in".freeze).zero?
|
|
25
|
-
$log.info "invalid byte sequence is replaced in `#{string}`"
|
|
26
|
-
string = string.scrub('?')
|
|
27
|
-
retry
|
|
28
|
-
end
|
|
29
|
-
return true
|
|
30
|
-
end
|
|
31
|
-
module_function :match_regexp
|
|
32
|
-
end
|
|
33
|
-
end
|
|
17
|
+
require 'fluent/compat/string_util'
|
|
34
18
|
|
|
19
|
+
module Fluent
|
|
35
20
|
# obsolete
|
|
36
|
-
StringUtil = Fluent::
|
|
21
|
+
StringUtil = Fluent::Compat::StringUtil
|
|
37
22
|
end
|
data/lib/fluent/plugin_helper.rb
CHANGED
|
@@ -22,6 +22,7 @@ require 'fluent/plugin_helper/child_process'
|
|
|
22
22
|
require 'fluent/plugin_helper/storage'
|
|
23
23
|
require 'fluent/plugin_helper/parser'
|
|
24
24
|
require 'fluent/plugin_helper/formatter'
|
|
25
|
+
require 'fluent/plugin_helper/inject'
|
|
25
26
|
require 'fluent/plugin_helper/retry_state'
|
|
26
27
|
require 'fluent/plugin_helper/compat_parameters'
|
|
27
28
|
|