fluentd 1.13.3 → 1.16.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/{bug_report.yaml → bug_report.yml} +2 -0
- data/.github/ISSUE_TEMPLATE/config.yml +2 -2
- data/.github/ISSUE_TEMPLATE/{feature_request.yaml → feature_request.yml} +1 -0
- data/.github/workflows/stale-actions.yml +11 -9
- data/.github/workflows/test.yml +32 -0
- data/CHANGELOG.md +490 -10
- data/CONTRIBUTING.md +2 -2
- data/MAINTAINERS.md +7 -5
- data/README.md +3 -23
- data/Rakefile +1 -1
- data/SECURITY.md +14 -0
- data/fluentd.gemspec +7 -8
- data/lib/fluent/command/cat.rb +13 -3
- data/lib/fluent/command/ctl.rb +6 -3
- data/lib/fluent/command/fluentd.rb +73 -65
- data/lib/fluent/command/plugin_config_formatter.rb +1 -1
- data/lib/fluent/compat/output.rb +9 -6
- data/lib/fluent/config/dsl.rb +1 -1
- data/lib/fluent/config/error.rb +12 -0
- data/lib/fluent/config/literal_parser.rb +2 -2
- data/lib/fluent/config/parser.rb +1 -1
- data/lib/fluent/config/v1_parser.rb +3 -3
- data/lib/fluent/config/yaml_parser/fluent_value.rb +47 -0
- data/lib/fluent/config/yaml_parser/loader.rb +108 -0
- data/lib/fluent/config/yaml_parser/parser.rb +166 -0
- data/lib/fluent/config/yaml_parser/section_builder.rb +107 -0
- data/lib/fluent/config/yaml_parser.rb +56 -0
- data/lib/fluent/config.rb +14 -1
- data/lib/fluent/counter/server.rb +1 -1
- data/lib/fluent/counter/validator.rb +3 -3
- data/lib/fluent/daemon.rb +2 -4
- data/lib/fluent/engine.rb +1 -1
- data/lib/fluent/env.rb +4 -0
- data/lib/fluent/error.rb +3 -0
- data/lib/fluent/event.rb +8 -4
- data/lib/fluent/event_router.rb +47 -2
- data/lib/fluent/file_wrapper.rb +137 -0
- data/lib/fluent/log/console_adapter.rb +66 -0
- data/lib/fluent/log.rb +44 -5
- data/lib/fluent/match.rb +1 -1
- data/lib/fluent/msgpack_factory.rb +6 -1
- data/lib/fluent/oj_options.rb +1 -2
- data/lib/fluent/plugin/bare_output.rb +49 -8
- data/lib/fluent/plugin/base.rb +26 -9
- data/lib/fluent/plugin/buf_file.rb +34 -5
- data/lib/fluent/plugin/buf_file_single.rb +32 -3
- data/lib/fluent/plugin/buffer/file_chunk.rb +1 -1
- data/lib/fluent/plugin/buffer.rb +216 -70
- data/lib/fluent/plugin/filter.rb +35 -1
- data/lib/fluent/plugin/filter_record_transformer.rb +1 -1
- data/lib/fluent/plugin/in_forward.rb +2 -2
- data/lib/fluent/plugin/in_http.rb +39 -10
- data/lib/fluent/plugin/in_monitor_agent.rb +4 -2
- data/lib/fluent/plugin/in_sample.rb +1 -1
- data/lib/fluent/plugin/in_syslog.rb +13 -1
- data/lib/fluent/plugin/in_tail/group_watch.rb +204 -0
- data/lib/fluent/plugin/in_tail/position_file.rb +33 -33
- data/lib/fluent/plugin/in_tail.rb +216 -84
- data/lib/fluent/plugin/in_tcp.rb +47 -2
- data/lib/fluent/plugin/input.rb +39 -1
- data/lib/fluent/plugin/metrics.rb +119 -0
- data/lib/fluent/plugin/metrics_local.rb +96 -0
- data/lib/fluent/plugin/multi_output.rb +43 -6
- data/lib/fluent/plugin/out_copy.rb +1 -1
- data/lib/fluent/plugin/out_exec_filter.rb +2 -2
- data/lib/fluent/plugin/out_file.rb +20 -2
- data/lib/fluent/plugin/out_forward/ack_handler.rb +19 -4
- data/lib/fluent/plugin/out_forward/socket_cache.rb +2 -0
- data/lib/fluent/plugin/out_forward.rb +17 -9
- data/lib/fluent/plugin/out_secondary_file.rb +39 -22
- data/lib/fluent/plugin/output.rb +167 -78
- data/lib/fluent/plugin/parser.rb +3 -4
- data/lib/fluent/plugin/parser_apache2.rb +1 -1
- data/lib/fluent/plugin/parser_json.rb +1 -1
- data/lib/fluent/plugin/parser_syslog.rb +1 -1
- data/lib/fluent/plugin/storage_local.rb +3 -5
- data/lib/fluent/plugin.rb +10 -1
- data/lib/fluent/plugin_helper/child_process.rb +3 -0
- data/lib/fluent/plugin_helper/event_emitter.rb +8 -1
- data/lib/fluent/plugin_helper/event_loop.rb +2 -2
- data/lib/fluent/plugin_helper/http_server/server.rb +2 -1
- data/lib/fluent/plugin_helper/metrics.rb +129 -0
- data/lib/fluent/plugin_helper/record_accessor.rb +1 -1
- data/lib/fluent/plugin_helper/retry_state.rb +14 -4
- data/lib/fluent/plugin_helper/server.rb +35 -6
- data/lib/fluent/plugin_helper/service_discovery.rb +2 -2
- data/lib/fluent/plugin_helper/socket.rb +13 -2
- data/lib/fluent/plugin_helper/thread.rb +3 -3
- data/lib/fluent/plugin_helper.rb +1 -0
- data/lib/fluent/plugin_id.rb +3 -2
- data/lib/fluent/registry.rb +2 -1
- data/lib/fluent/root_agent.rb +6 -0
- data/lib/fluent/rpc.rb +4 -3
- data/lib/fluent/supervisor.rb +283 -259
- data/lib/fluent/system_config.rb +13 -3
- data/lib/fluent/test/driver/base.rb +11 -5
- data/lib/fluent/test/driver/filter.rb +4 -0
- data/lib/fluent/test/startup_shutdown.rb +6 -8
- data/lib/fluent/time.rb +21 -20
- data/lib/fluent/version.rb +1 -1
- data/lib/fluent/win32api.rb +38 -0
- data/lib/fluent/winsvc.rb +5 -8
- data/templates/new_gem/test/helper.rb.erb +0 -1
- data/test/command/test_cat.rb +31 -2
- data/test/command/test_ctl.rb +1 -2
- data/test/command/test_fluentd.rb +209 -24
- data/test/command/test_plugin_config_formatter.rb +0 -1
- data/test/compat/test_parser.rb +6 -6
- data/test/config/test_system_config.rb +13 -11
- data/test/config/test_types.rb +1 -1
- data/test/log/test_console_adapter.rb +110 -0
- data/test/plugin/in_tail/test_io_handler.rb +26 -8
- data/test/plugin/in_tail/test_position_file.rb +48 -59
- data/test/plugin/out_forward/test_ack_handler.rb +39 -0
- data/test/plugin/out_forward/test_socket_cache.rb +26 -1
- data/test/plugin/test_bare_output.rb +14 -1
- data/test/plugin/test_base.rb +133 -1
- data/test/plugin/test_buf_file.rb +62 -23
- data/test/plugin/test_buf_file_single.rb +65 -0
- data/test/plugin/test_buffer.rb +267 -3
- data/test/plugin/test_buffer_chunk.rb +11 -0
- data/test/plugin/test_filter.rb +12 -1
- data/test/plugin/test_filter_parser.rb +1 -1
- data/test/plugin/test_filter_stdout.rb +2 -2
- data/test/plugin/test_in_forward.rb +9 -11
- data/test/plugin/test_in_http.rb +65 -3
- data/test/plugin/test_in_monitor_agent.rb +216 -11
- data/test/plugin/test_in_object_space.rb +9 -3
- data/test/plugin/test_in_syslog.rb +35 -0
- data/test/plugin/test_in_tail.rb +1393 -385
- data/test/plugin/test_in_tcp.rb +87 -2
- data/test/plugin/test_in_udp.rb +28 -0
- data/test/plugin/test_in_unix.rb +2 -2
- data/test/plugin/test_input.rb +12 -1
- data/test/plugin/test_metrics.rb +294 -0
- data/test/plugin/test_metrics_local.rb +96 -0
- data/test/plugin/test_multi_output.rb +25 -1
- data/test/plugin/test_out_exec.rb +6 -4
- data/test/plugin/test_out_exec_filter.rb +6 -2
- data/test/plugin/test_out_file.rb +34 -17
- data/test/plugin/test_out_forward.rb +78 -77
- data/test/plugin/test_out_http.rb +1 -0
- data/test/plugin/test_out_stdout.rb +2 -2
- data/test/plugin/test_output.rb +297 -12
- data/test/plugin/test_output_as_buffered.rb +44 -44
- data/test/plugin/test_output_as_buffered_compress.rb +32 -18
- data/test/plugin/test_output_as_buffered_retries.rb +54 -7
- data/test/plugin/test_output_as_buffered_secondary.rb +4 -4
- data/test/plugin/test_parser_regexp.rb +1 -6
- data/test/plugin/test_parser_syslog.rb +1 -1
- data/test/plugin_helper/test_cert_option.rb +1 -1
- data/test/plugin_helper/test_child_process.rb +38 -16
- data/test/plugin_helper/test_event_emitter.rb +29 -0
- data/test/plugin_helper/test_http_server_helper.rb +1 -1
- data/test/plugin_helper/test_metrics.rb +137 -0
- data/test/plugin_helper/test_retry_state.rb +602 -38
- data/test/plugin_helper/test_server.rb +78 -6
- data/test/plugin_helper/test_timer.rb +2 -2
- data/test/test_config.rb +191 -24
- data/test/test_event_router.rb +17 -0
- data/test/test_file_wrapper.rb +53 -0
- data/test/test_formatter.rb +24 -21
- data/test/test_log.rb +122 -40
- data/test/test_msgpack_factory.rb +32 -0
- data/test/test_plugin_classes.rb +102 -0
- data/test/test_root_agent.rb +30 -1
- data/test/test_supervisor.rb +477 -257
- data/test/test_time_parser.rb +22 -0
- metadata +55 -34
- data/.drone.yml +0 -35
- data/.github/workflows/issue-auto-closer.yml +0 -12
- data/.github/workflows/linux-test.yaml +0 -36
- data/.github/workflows/macos-test.yaml +0 -30
- data/.github/workflows/windows-test.yaml +0 -46
- data/.gitlab-ci.yml +0 -103
- data/lib/fluent/plugin/file_wrapper.rb +0 -187
- data/test/plugin/test_file_wrapper.rb +0 -126
- data/test/test_logger_initializer.rb +0 -46
@@ -1,187 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Fluentd
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
#
|
16
|
-
|
17
|
-
module Fluent
|
18
|
-
module FileWrapper
|
19
|
-
def self.open(*args)
|
20
|
-
io = WindowsFile.new(*args).io
|
21
|
-
if block_given?
|
22
|
-
v = yield io
|
23
|
-
io.close
|
24
|
-
v
|
25
|
-
else
|
26
|
-
io
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.stat(path)
|
31
|
-
f = WindowsFile.new(path)
|
32
|
-
s = f.stat
|
33
|
-
f.close
|
34
|
-
s
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
module WindowsFileExtension
|
39
|
-
attr_reader :path
|
40
|
-
|
41
|
-
def stat
|
42
|
-
s = super
|
43
|
-
s.instance_variable_set :@ino, @ino
|
44
|
-
def s.ino; @ino; end
|
45
|
-
s
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
class Win32Error < StandardError
|
50
|
-
require 'windows/error'
|
51
|
-
include Windows::Error
|
52
|
-
|
53
|
-
attr_reader :errcode, :msg
|
54
|
-
|
55
|
-
WSABASEERR = 10000
|
56
|
-
|
57
|
-
def initialize(errcode, msg = nil)
|
58
|
-
@errcode = errcode
|
59
|
-
@msg = msg
|
60
|
-
end
|
61
|
-
|
62
|
-
def format_english_message(errcode)
|
63
|
-
buf = 0.chr * 260
|
64
|
-
flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY
|
65
|
-
english_lang_id = 1033 # The result of MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)
|
66
|
-
FormatMessageA.call(flags, 0, errcode, english_lang_id, buf, buf.size, 0)
|
67
|
-
buf.force_encoding(Encoding.default_external).strip
|
68
|
-
end
|
69
|
-
|
70
|
-
def to_s
|
71
|
-
msg = super
|
72
|
-
msg << ": code: #{@errcode}, #{format_english_message(@errcode)}"
|
73
|
-
msg << " - #{@msg}" if @msg
|
74
|
-
msg
|
75
|
-
end
|
76
|
-
|
77
|
-
def inspect
|
78
|
-
"#<#{to_s}>"
|
79
|
-
end
|
80
|
-
|
81
|
-
def ==(other)
|
82
|
-
return false if other.class != Win32Error
|
83
|
-
@errcode == other.errcode && @msg == other.msg
|
84
|
-
end
|
85
|
-
|
86
|
-
def wsaerr?
|
87
|
-
@errcode >= WSABASEERR
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
# To open and get stat with setting FILE_SHARE_DELETE
|
92
|
-
class WindowsFile
|
93
|
-
require 'windows/file'
|
94
|
-
require 'windows/error'
|
95
|
-
require 'windows/handle'
|
96
|
-
require 'windows/nio'
|
97
|
-
|
98
|
-
include Windows::Error
|
99
|
-
include Windows::File
|
100
|
-
include Windows::Handle
|
101
|
-
include Windows::NIO
|
102
|
-
|
103
|
-
def initialize(path, mode='r', sharemode=FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE)
|
104
|
-
@path = path
|
105
|
-
@file_handle = INVALID_HANDLE_VALUE
|
106
|
-
@mode = mode
|
107
|
-
|
108
|
-
|
109
|
-
access, creationdisposition, seektoend = case mode.delete('b')
|
110
|
-
when "r" ; [FILE_GENERIC_READ , OPEN_EXISTING, false]
|
111
|
-
when "r+"; [FILE_GENERIC_READ | FILE_GENERIC_WRITE, OPEN_ALWAYS , false]
|
112
|
-
when "w" ; [FILE_GENERIC_WRITE , CREATE_ALWAYS, false]
|
113
|
-
when "w+"; [FILE_GENERIC_READ | FILE_GENERIC_WRITE, CREATE_ALWAYS, false]
|
114
|
-
when "a" ; [FILE_GENERIC_WRITE , OPEN_ALWAYS , true]
|
115
|
-
when "a+"; [FILE_GENERIC_READ | FILE_GENERIC_WRITE, OPEN_ALWAYS , true]
|
116
|
-
else raise "unknown mode '#{mode}'"
|
117
|
-
end
|
118
|
-
|
119
|
-
@file_handle = CreateFile.call(@path, access, sharemode,
|
120
|
-
0, creationdisposition, FILE_ATTRIBUTE_NORMAL, 0)
|
121
|
-
if @file_handle == INVALID_HANDLE_VALUE
|
122
|
-
win32err = Win32Error.new(Win32::API.last_error, path)
|
123
|
-
errno = ServerEngine::RbWinSock.rb_w32_map_errno(win32err.errcode)
|
124
|
-
if errno == Errno::EINVAL::Errno || win32err.wsaerr?
|
125
|
-
# maybe failed to map
|
126
|
-
raise win32err
|
127
|
-
else
|
128
|
-
raise SystemCallError.new(win32err.message, errno)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
def close
|
134
|
-
CloseHandle.call(@file_handle)
|
135
|
-
@file_handle = INVALID_HANDLE_VALUE
|
136
|
-
end
|
137
|
-
|
138
|
-
def io
|
139
|
-
fd = _open_osfhandle(@file_handle, 0)
|
140
|
-
raise Errno::ENOENT if fd == -1
|
141
|
-
io = File.for_fd(fd, @mode)
|
142
|
-
io.instance_variable_set :@ino, self.ino
|
143
|
-
io.instance_variable_set :@path, @path
|
144
|
-
io.extend WindowsFileExtension
|
145
|
-
io
|
146
|
-
end
|
147
|
-
|
148
|
-
def ino
|
149
|
-
by_handle_file_information = '\0'*(4+8+8+8+4+4+4+4+4+4) #72bytes
|
150
|
-
|
151
|
-
unless GetFileInformationByHandle.call(@file_handle, by_handle_file_information)
|
152
|
-
return 0
|
153
|
-
end
|
154
|
-
|
155
|
-
by_handle_file_information.unpack("I11Q1")[11] # fileindex
|
156
|
-
end
|
157
|
-
|
158
|
-
# DeletePending is a Windows-specific file state that roughly means
|
159
|
-
# "this file is queued for deletion, so close any open handlers"
|
160
|
-
#
|
161
|
-
# This flag can be retrieved via GetFileInformationByHandleEx().
|
162
|
-
#
|
163
|
-
# https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getfileinformationbyhandleex
|
164
|
-
#
|
165
|
-
def delete_pending
|
166
|
-
file_standard_info = 0x01
|
167
|
-
bufsize = 1024
|
168
|
-
buf = '\0' * bufsize
|
169
|
-
|
170
|
-
unless GetFileInformationByHandleEx.call(@file_handle, file_standard_info, buf, bufsize)
|
171
|
-
return false
|
172
|
-
end
|
173
|
-
|
174
|
-
return buf.unpack("QQICC")[3] != 0
|
175
|
-
end
|
176
|
-
|
177
|
-
private :delete_pending
|
178
|
-
|
179
|
-
def stat
|
180
|
-
raise Errno::ENOENT if delete_pending
|
181
|
-
s = File.stat(@path)
|
182
|
-
s.instance_variable_set :@ino, self.ino
|
183
|
-
def s.ino; @ino; end
|
184
|
-
s
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end if Fluent.windows?
|
@@ -1,126 +0,0 @@
|
|
1
|
-
require_relative '../helper'
|
2
|
-
require 'fluent/plugin/file_wrapper'
|
3
|
-
|
4
|
-
class FileWrapperTest < Test::Unit::TestCase
|
5
|
-
require 'windows/file'
|
6
|
-
require 'windows/error'
|
7
|
-
include Windows::File
|
8
|
-
include Windows::Error
|
9
|
-
|
10
|
-
TMP_DIR = File.dirname(__FILE__) + "/../tmp/file_wrapper#{ENV['TEST_ENV_NUMBER']}"
|
11
|
-
|
12
|
-
def setup
|
13
|
-
FileUtils.mkdir_p(TMP_DIR)
|
14
|
-
end
|
15
|
-
|
16
|
-
def teardown
|
17
|
-
FileUtils.rm_rf(TMP_DIR)
|
18
|
-
end
|
19
|
-
|
20
|
-
sub_test_case 'Win32Error' do
|
21
|
-
test 'equal' do
|
22
|
-
assert_equal(Fluent::Win32Error.new(ERROR_SHARING_VIOLATION, "message"),
|
23
|
-
Fluent::Win32Error.new(ERROR_SHARING_VIOLATION, "message"))
|
24
|
-
end
|
25
|
-
|
26
|
-
test 'different error code' do
|
27
|
-
assert_not_equal(Fluent::Win32Error.new(ERROR_FILE_NOT_FOUND),
|
28
|
-
Fluent::Win32Error.new(ERROR_SHARING_VIOLATION))
|
29
|
-
end
|
30
|
-
|
31
|
-
test 'different error message' do
|
32
|
-
assert_not_equal(Fluent::Win32Error.new(ERROR_FILE_NOT_FOUND, "message1"),
|
33
|
-
Fluent::Win32Error.new(ERROR_FILE_NOT_FOUND, "message2"))
|
34
|
-
end
|
35
|
-
|
36
|
-
test 'different class' do
|
37
|
-
assert_not_equal(Errno::EPIPE,
|
38
|
-
Fluent::Win32Error.new(ERROR_SHARING_VIOLATION))
|
39
|
-
end
|
40
|
-
|
41
|
-
test 'ERROR_SHARING_VIOLATION message' do
|
42
|
-
assert_equal(Fluent::Win32Error.new(ERROR_SHARING_VIOLATION).message,
|
43
|
-
"Fluent::Win32Error: code: 32, The process cannot access the file because it is being used by another process.")
|
44
|
-
end
|
45
|
-
|
46
|
-
test 'ERROR_SHARING_VIOLATION with a message' do
|
47
|
-
assert_equal(Fluent::Win32Error.new(ERROR_SHARING_VIOLATION, "cannot open the file").message,
|
48
|
-
"Fluent::Win32Error: code: 32, The process cannot access the file because it is being used by another process." +
|
49
|
-
" - cannot open the file")
|
50
|
-
end
|
51
|
-
|
52
|
-
test 'to_s' do
|
53
|
-
assert_equal("Fluent::Win32Error: code: 32, The process cannot access the file because it is being used by another process. - C:\file.txt",
|
54
|
-
Fluent::Win32Error.new(ERROR_SHARING_VIOLATION, "C:\file.txt").to_s)
|
55
|
-
end
|
56
|
-
|
57
|
-
test 'inspect' do
|
58
|
-
assert_equal("#<Fluent::Win32Error: code: 32, The process cannot access the file because it is being used by another process. - C:\file.txt>",
|
59
|
-
Fluent::Win32Error.new(ERROR_SHARING_VIOLATION, "C:\file.txt").inspect)
|
60
|
-
end
|
61
|
-
|
62
|
-
data('0' => [false, 0],
|
63
|
-
'9999' => [false, 9999],
|
64
|
-
'10000' => [true, 10000],
|
65
|
-
'10001' => [true, 10001])
|
66
|
-
test 'wsaerr?' do |data|
|
67
|
-
expected, code = data
|
68
|
-
assert_equal(expected, Fluent::Win32Error.new(code).wsaerr?)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
sub_test_case 'WindowsFile exceptions' do
|
73
|
-
test 'nothing raised' do
|
74
|
-
begin
|
75
|
-
path = "#{TMP_DIR}/test_windows_file.txt"
|
76
|
-
file1 = file2 = nil
|
77
|
-
file1 = File.open(path, "wb") do |f|
|
78
|
-
end
|
79
|
-
assert_nothing_raised do
|
80
|
-
file2 = Fluent::WindowsFile.new(path)
|
81
|
-
ensure
|
82
|
-
file2.close
|
83
|
-
end
|
84
|
-
ensure
|
85
|
-
file1.close if file1
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
test 'Errno::ENOENT raised' do
|
90
|
-
path = "#{TMP_DIR}/nofile.txt"
|
91
|
-
file = nil
|
92
|
-
assert_raise(Errno::ENOENT) do
|
93
|
-
file = Fluent::WindowsFile.new(path)
|
94
|
-
ensure
|
95
|
-
file.close if file
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
test 'Errno::ENOENT raised on DeletePending' do
|
100
|
-
path = "#{TMP_DIR}/deletepending.txt"
|
101
|
-
file = Fluent::WindowsFile.new(path, mode='w')
|
102
|
-
File.delete(path)
|
103
|
-
assert_raise(Errno::ENOENT) do
|
104
|
-
file.stat
|
105
|
-
ensure
|
106
|
-
file.close if file
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
test 'ERROR_SHARING_VIOLATION raised' do
|
111
|
-
begin
|
112
|
-
path = "#{TMP_DIR}/test_windows_file.txt"
|
113
|
-
file1 = file2 = nil
|
114
|
-
file1 = File.open(path, "wb")
|
115
|
-
win32err = Fluent::Win32Error.new(ERROR_SHARING_VIOLATION, path)
|
116
|
-
assert_raise(Errno::EACCES.new(win32err.message)) do
|
117
|
-
file2 = Fluent::WindowsFile.new(path, 'r', FILE_SHARE_READ)
|
118
|
-
ensure
|
119
|
-
file2.close if file2
|
120
|
-
end
|
121
|
-
ensure
|
122
|
-
file1.close if file1
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end if Fluent.windows?
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require_relative 'helper'
|
2
|
-
require 'fluent/supervisor'
|
3
|
-
require 'fileutils'
|
4
|
-
|
5
|
-
class LoggerInitializerTest < ::Test::Unit::TestCase
|
6
|
-
TMP_DIR = File.expand_path(File.dirname(__FILE__) + "/tmp/logger_initializer#{ENV['TEST_ENV_NUMBER']}")
|
7
|
-
|
8
|
-
teardown do
|
9
|
-
begin
|
10
|
-
FileUtils.rm_rf(TMP_DIR)
|
11
|
-
rescue => _
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
test 'when path is given' do
|
16
|
-
path = File.join(TMP_DIR, 'fluent_with_path.log')
|
17
|
-
|
18
|
-
assert_false File.exist?(TMP_DIR)
|
19
|
-
logger = Fluent::Supervisor::LoggerInitializer.new(path, Fluent::Log::LEVEL_DEBUG, nil, nil, {})
|
20
|
-
mock.proxy(File).chmod(0o777, TMP_DIR).never
|
21
|
-
|
22
|
-
assert_nothing_raised do
|
23
|
-
logger.init(:supervisor, 0)
|
24
|
-
end
|
25
|
-
|
26
|
-
assert_true File.exist?(TMP_DIR)
|
27
|
-
end
|
28
|
-
|
29
|
-
test 'apply_options with log_dir_perm' do
|
30
|
-
omit "NTFS doesn't support UNIX like permissions" if Fluent.windows?
|
31
|
-
|
32
|
-
path = File.join(TMP_DIR, 'fluent_with_path.log')
|
33
|
-
|
34
|
-
assert_false File.exist?(TMP_DIR)
|
35
|
-
logger = Fluent::Supervisor::LoggerInitializer.new(path, Fluent::Log::LEVEL_DEBUG, nil, nil, {})
|
36
|
-
mock.proxy(File).chmod(0o777, TMP_DIR).once
|
37
|
-
|
38
|
-
assert_nothing_raised do
|
39
|
-
logger.init(:supervisor, 0)
|
40
|
-
end
|
41
|
-
|
42
|
-
logger.apply_options(log_dir_perm: 0o777)
|
43
|
-
assert_true File.exist?(TMP_DIR)
|
44
|
-
assert_equal 0o777, (File.stat(TMP_DIR).mode & 0xFFF)
|
45
|
-
end
|
46
|
-
end
|