fluentd 1.16.5-x64-mingw-ucrt → 1.16.7-x64-mingw-ucrt
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +8 -1
- data/CHANGELOG.md +50 -0
- data/README.md +0 -2
- data/fluentd.gemspec +9 -1
- data/lib/fluent/command/fluentd.rb +1 -1
- data/lib/fluent/config/yaml_parser/parser.rb +4 -0
- data/lib/fluent/plugin/out_file.rb +8 -0
- data/lib/fluent/plugin/parser_json.rb +4 -12
- data/lib/fluent/supervisor.rb +1 -1
- data/lib/fluent/version.rb +1 -1
- data/lib/fluent/winsvc.rb +28 -3
- data/test/command/test_cat.rb +2 -2
- data/test/command/test_fluentd.rb +57 -10
- data/test/helper.rb +27 -7
- data/test/plugin/in_tail/test_io_handler.rb +13 -14
- data/test/plugin/in_tail/test_position_file.rb +6 -7
- data/test/plugin/out_forward/test_ack_handler.rb +3 -3
- data/test/plugin/out_forward/test_socket_cache.rb +3 -3
- data/test/plugin/test_in_forward.rb +2 -1
- data/test/plugin/test_in_http.rb +1 -1
- data/test/plugin/test_in_monitor_agent.rb +6 -6
- data/test/plugin/test_in_syslog.rb +25 -18
- data/test/plugin/test_in_tail.rb +4 -12
- data/test/plugin/test_in_tcp.rb +1 -1
- data/test/plugin/test_in_udp.rb +16 -10
- data/test/plugin/test_out_exec_filter.rb +12 -7
- data/test/plugin/test_out_file.rb +22 -2
- data/test/plugin/test_out_forward.rb +2 -3
- data/test/plugin/test_out_stream.rb +1 -1
- data/test/plugin/test_parser_json.rb +31 -0
- data/test/plugin_helper/test_http_server_helper.rb +1 -1
- data/test/plugin_helper/test_server.rb +64 -41
- data/test/plugin_helper/test_socket.rb +1 -1
- data/test/test_config.rb +6 -0
- data/test/test_event_router.rb +2 -2
- metadata +37 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f16846a608f3956616ce5937e1f585253309dfaf4e12f249efa8cd700136e57
|
4
|
+
data.tar.gz: e746ebc044f59fd28e238268af9e8d96ac1b3dc145f13695450f1ce7748b3c17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 349dbad6bd1e176408e90db75e34c989663ffc00e9d370f2832679490bb3294a6bd4d61cf78196b9b7d061b627da18e6a378886356cc021389caa182dd916e7c
|
7
|
+
data.tar.gz: a07e37342332987957e256c560d6a2358625e842c20f617d5d12dc609b55aaf2071fb5c8b7d486152f80e3a1f012ec328158f458c45a4dd323e28c0a8d90c6d3
|
data/.github/workflows/test.yml
CHANGED
@@ -3,8 +3,14 @@ name: Test
|
|
3
3
|
on:
|
4
4
|
push:
|
5
5
|
branches: [v1.16]
|
6
|
+
paths-ignore:
|
7
|
+
- '*.md'
|
8
|
+
- 'lib/fluent/version.rb'
|
6
9
|
pull_request:
|
7
10
|
branches: [v1.16]
|
11
|
+
paths-ignore:
|
12
|
+
- '*.md'
|
13
|
+
- 'lib/fluent/version.rb'
|
8
14
|
|
9
15
|
jobs:
|
10
16
|
test:
|
@@ -23,10 +29,11 @@ jobs:
|
|
23
29
|
uses: ruby/setup-ruby@v1
|
24
30
|
with:
|
25
31
|
ruby-version: ${{ matrix.ruby-version }}
|
32
|
+
rubygems: latest
|
26
33
|
- name: Install addons
|
27
34
|
if: ${{ matrix.os == 'ubuntu-latest' }}
|
28
35
|
run: sudo apt-get install libgmp3-dev libcap-ng-dev
|
29
36
|
- name: Install dependencies
|
30
37
|
run: bundle install
|
31
38
|
- name: Run tests
|
32
|
-
run: bundle exec rake test TESTOPTS
|
39
|
+
run: bundle exec rake test TESTOPTS="-v --no-show-detail-immediately"
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,55 @@
|
|
1
1
|
# v1.16
|
2
2
|
|
3
|
+
## Release v1.16.7 - 2025/01/29
|
4
|
+
|
5
|
+
### Bug Fix
|
6
|
+
|
7
|
+
* Windows: Fix `NoMethodError` of `--daemon` option
|
8
|
+
https://github.com/fluent/fluentd/pull/4796
|
9
|
+
* Windows: Fixed an issue where stopping the service immediately after startup could leave the processes
|
10
|
+
https://github.com/fluent/fluentd/pull/4782
|
11
|
+
* Windows: Fixed an issue where stopping service sometimes can not be completed forever
|
12
|
+
https://github.com/fluent/fluentd/pull/4782
|
13
|
+
|
14
|
+
### Misc
|
15
|
+
|
16
|
+
* Windows: Add workaround for unexpected exception
|
17
|
+
https://github.com/fluent/fluentd/pull/4747
|
18
|
+
* README: remove deprecated google analytics beacon
|
19
|
+
https://github.com/fluent/fluentd/pull/4797
|
20
|
+
* CI improvemnts
|
21
|
+
https://github.com/fluent/fluentd/pull/4723
|
22
|
+
https://github.com/fluent/fluentd/pull/4788
|
23
|
+
https://github.com/fluent/fluentd/pull/4789
|
24
|
+
https://github.com/fluent/fluentd/pull/4790
|
25
|
+
https://github.com/fluent/fluentd/pull/4791
|
26
|
+
https://github.com/fluent/fluentd/pull/4793
|
27
|
+
https://github.com/fluent/fluentd/pull/4794
|
28
|
+
https://github.com/fluent/fluentd/pull/4795
|
29
|
+
https://github.com/fluent/fluentd/pull/4798
|
30
|
+
https://github.com/fluent/fluentd/pull/4799
|
31
|
+
https://github.com/fluent/fluentd/pull/4800
|
32
|
+
https://github.com/fluent/fluentd/pull/4801
|
33
|
+
https://github.com/fluent/fluentd/pull/4803
|
34
|
+
|
35
|
+
## Release v1.16.6 - 2024/08/16
|
36
|
+
|
37
|
+
### Bug Fix
|
38
|
+
|
39
|
+
* YAML config syntax: Fix issue where `$log_level` element was not supported correctly
|
40
|
+
https://github.com/fluent/fluentd/pull/4486
|
41
|
+
* parser_json: Fix wrong LoadError warning
|
42
|
+
https://github.com/fluent/fluentd/pull/4592
|
43
|
+
* `fluentd` command: Fix `--plugin` (`-p`) option not to overwrite default value
|
44
|
+
https://github.com/fluent/fluentd/pull/4605
|
45
|
+
|
46
|
+
### Misc
|
47
|
+
|
48
|
+
* out_file: Add warn message for symlink_path setting
|
49
|
+
https://github.com/fluent/fluentd/pull/4512
|
50
|
+
* Keep console gem v1.23 to avoid LoadError
|
51
|
+
https://github.com/fluent/fluentd/pull/4510
|
52
|
+
|
3
53
|
## Release v1.16.5 - 2024/03/27
|
4
54
|
|
5
55
|
### Bug Fix
|
data/README.md
CHANGED
@@ -71,5 +71,3 @@ See [SECURITY](SECURITY.md) to contact us about vulnerability.
|
|
71
71
|
## Contributors:
|
72
72
|
|
73
73
|
Patches contributed by [great developers](https://github.com/fluent/fluentd/contributors).
|
74
|
-
|
75
|
-
[<img src="https://ga-beacon.appspot.com/UA-24890265-6/fluent/fluentd" />](https://github.com/fluent/fluentd)
|
data/fluentd.gemspec
CHANGED
@@ -29,6 +29,12 @@ Gem::Specification.new do |gem|
|
|
29
29
|
gem.add_runtime_dependency("tzinfo-data", ["~> 1.0"])
|
30
30
|
gem.add_runtime_dependency("strptime", [">= 0.2.4", "< 1.0.0"])
|
31
31
|
gem.add_runtime_dependency("webrick", ["~> 1.4"])
|
32
|
+
gem.add_runtime_dependency("console", ["< 1.24"])
|
33
|
+
|
34
|
+
# gems that aren't default gems as of Ruby 3.5
|
35
|
+
# logger 1.6.3 or later cause bug on windows,
|
36
|
+
# hold on 1.6.2 for a while. see https://github.com/ruby/logger/issues/107
|
37
|
+
gem.add_runtime_dependency("logger", ["1.6.2"])
|
32
38
|
|
33
39
|
# build gem for a certain platform. see also Rakefile
|
34
40
|
fake_platform = ENV['GEM_BUILD_FAKE_PLATFORM'].to_s
|
@@ -45,7 +51,9 @@ Gem::Specification.new do |gem|
|
|
45
51
|
gem.add_development_dependency("parallel_tests", ["~> 0.15.3"])
|
46
52
|
gem.add_development_dependency("simplecov", ["~> 0.7"])
|
47
53
|
gem.add_development_dependency("rr", ["~> 3.0"])
|
48
|
-
|
54
|
+
# timecop v0.9.9 supports `Process.clock_gettime`. It breaks some tests.
|
55
|
+
# (https://github.com/fluent/fluentd/pull/4521)
|
56
|
+
gem.add_development_dependency("timecop", ["< 0.9.9"])
|
49
57
|
gem.add_development_dependency("test-unit", ["~> 3.3"])
|
50
58
|
gem.add_development_dependency("test-unit-rr", ["~> 1.0"])
|
51
59
|
gem.add_development_dependency("oj", [">= 2.14", "< 4"])
|
@@ -46,7 +46,7 @@ op.on('--show-plugin-config=PLUGIN', "[DEPRECATED] Show PLUGIN configuration and
|
|
46
46
|
}
|
47
47
|
|
48
48
|
op.on('-p', '--plugin DIR', "add plugin directory") {|s|
|
49
|
-
(cmd_opts[:plugin_dirs] ||= []) << s
|
49
|
+
(cmd_opts[:plugin_dirs] ||= default_opts[:plugin_dirs]) << s
|
50
50
|
}
|
51
51
|
|
52
52
|
op.on('-I PATH', "add library path") {|s|
|
@@ -172,6 +172,14 @@ module Fluent::Plugin
|
|
172
172
|
log.warn "symlink_path is unavailable on Windows platform. disabled."
|
173
173
|
@symlink_path = nil
|
174
174
|
else
|
175
|
+
placeholder_validators(:symlink_path, @symlink_path).reject{ |v| v.type == :time }.each do |v|
|
176
|
+
begin
|
177
|
+
v.validate!
|
178
|
+
rescue Fluent::ConfigError => e
|
179
|
+
log.warn "#{e}. This means multiple chunks are competing for a single symlink_path, so some logs may not be taken from the symlink."
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
175
183
|
@buffer.extend SymlinkBufferMixin
|
176
184
|
@buffer.symlink_path = @symlink_path
|
177
185
|
@buffer.output_plugin_for_symlink = self
|
@@ -50,23 +50,15 @@ module Fluent
|
|
50
50
|
def configure_json_parser(name)
|
51
51
|
case name
|
52
52
|
when :oj
|
53
|
-
|
54
|
-
|
53
|
+
return [Oj.method(:load), Oj::ParseError] if Fluent::OjOptions.available?
|
54
|
+
|
55
|
+
log&.info "Oj is not installed, and failing back to Yajl for json parser"
|
56
|
+
configure_json_parser(:yajl)
|
55
57
|
when :json then [JSON.method(:load), JSON::ParserError]
|
56
58
|
when :yajl then [Yajl.method(:load), Yajl::ParseError]
|
57
59
|
else
|
58
60
|
raise "BUG: unknown json parser specified: #{name}"
|
59
61
|
end
|
60
|
-
rescue LoadError => ex
|
61
|
-
name = :yajl
|
62
|
-
if log
|
63
|
-
if /\boj\z/.match?(ex.message)
|
64
|
-
log.info "Oj is not installed, and failing back to Yajl for json parser"
|
65
|
-
else
|
66
|
-
log.warn ex.message
|
67
|
-
end
|
68
|
-
end
|
69
|
-
retry
|
70
62
|
end
|
71
63
|
|
72
64
|
def parse(text)
|
data/lib/fluent/supervisor.rb
CHANGED
@@ -440,7 +440,7 @@ module Fluent
|
|
440
440
|
stop_immediately_at_unrecoverable_exit: true,
|
441
441
|
root_dir: params['root_dir'],
|
442
442
|
logger: $log,
|
443
|
-
log: $log
|
443
|
+
log: $log&.out,
|
444
444
|
log_level: params['log_level'],
|
445
445
|
chuser: params['chuser'],
|
446
446
|
chgroup: params['chgroup'],
|
data/lib/fluent/version.rb
CHANGED
data/lib/fluent/winsvc.rb
CHANGED
@@ -63,10 +63,12 @@ begin
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def service_stop
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
if @pid <= 0
|
67
|
+
set_event(@service_name)
|
68
|
+
return
|
69
69
|
end
|
70
|
+
|
71
|
+
wait_supervisor_finished
|
70
72
|
end
|
71
73
|
|
72
74
|
def service_paramchange
|
@@ -91,6 +93,29 @@ begin
|
|
91
93
|
ev.set
|
92
94
|
ev.close
|
93
95
|
end
|
96
|
+
|
97
|
+
def repeat_set_event_several_times_until_success(event_name)
|
98
|
+
retries = 0
|
99
|
+
max_retries = 10
|
100
|
+
delay_sec = 3
|
101
|
+
|
102
|
+
begin
|
103
|
+
set_event(event_name)
|
104
|
+
rescue Errno::ENOENT
|
105
|
+
# This error occurs when the supervisor process has not yet created the event.
|
106
|
+
# If STOP is immediately executed, this state will occur.
|
107
|
+
# Retry `set_event' to wait for the initialization of the supervisor.
|
108
|
+
retries += 1
|
109
|
+
raise if max_retries < retries
|
110
|
+
sleep(delay_sec)
|
111
|
+
retry
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def wait_supervisor_finished
|
116
|
+
repeat_set_event_several_times_until_success(@service_name)
|
117
|
+
Process.waitpid(@pid)
|
118
|
+
end
|
94
119
|
end
|
95
120
|
|
96
121
|
FluentdService.new(opts[:service_name]).mainloop
|
data/test/command/test_cat.rb
CHANGED
@@ -18,7 +18,7 @@ class TestFluentCat < ::Test::Unit::TestCase
|
|
18
18
|
@primary = create_primary
|
19
19
|
metadata = @primary.buffer.new_metadata
|
20
20
|
@chunk = create_chunk(@primary, metadata, @es)
|
21
|
-
@port = unused_port
|
21
|
+
@port = unused_port(protocol: :all)
|
22
22
|
end
|
23
23
|
|
24
24
|
def teardown
|
@@ -87,7 +87,7 @@ class TestFluentCat < ::Test::Unit::TestCase
|
|
87
87
|
d = create_driver
|
88
88
|
d.run(expect_records: 1) do
|
89
89
|
Open3.pipeline_w("#{ServerEngine.ruby_bin_path} #{FLUENT_CAT_COMMAND} --port #{@port} --format msgpack secondary") do |stdin|
|
90
|
-
stdin.write(File.read(path))
|
90
|
+
stdin.write(File.read(path, File.size(path)))
|
91
91
|
stdin.close
|
92
92
|
end
|
93
93
|
end
|
@@ -128,11 +128,14 @@ class TestFluentdCommand < ::Test::Unit::TestCase
|
|
128
128
|
|
129
129
|
# ATTENTION: This stops taking logs when all `pattern_list` match or timeout,
|
130
130
|
# so `patterns_not_match` can test only logs up to that point.
|
131
|
+
# You can pass a block to assert something after log matching.
|
131
132
|
def assert_log_matches(cmdline, *pattern_list, patterns_not_match: [], timeout: 20, env: {})
|
132
133
|
matched = false
|
133
134
|
matched_wrongly = false
|
134
|
-
|
135
|
+
error_msg_match = ""
|
135
136
|
stdio_buf = ""
|
137
|
+
succeeded_block = true
|
138
|
+
error_msg_block = ""
|
136
139
|
begin
|
137
140
|
execute_command(cmdline, @tmp_dir, env) do |pid, stdout|
|
138
141
|
begin
|
@@ -163,6 +166,13 @@ class TestFluentdCommand < ::Test::Unit::TestCase
|
|
163
166
|
end
|
164
167
|
end
|
165
168
|
end
|
169
|
+
|
170
|
+
begin
|
171
|
+
yield if block_given?
|
172
|
+
rescue => e
|
173
|
+
succeeded_block = false
|
174
|
+
error_msg_block = "failed block execution after matching: #{e}"
|
175
|
+
end
|
166
176
|
ensure
|
167
177
|
if SUPERVISOR_PID_PATTERN =~ stdio_buf
|
168
178
|
@supervisor_pid = $1.to_i
|
@@ -173,19 +183,19 @@ class TestFluentdCommand < ::Test::Unit::TestCase
|
|
173
183
|
end
|
174
184
|
end
|
175
185
|
rescue Timeout::Error
|
176
|
-
|
186
|
+
error_msg_match = "execution timeout"
|
177
187
|
# https://github.com/fluent/fluentd/issues/4095
|
178
188
|
# On Windows, timeout without `@supervisor_pid` means that the test is invalid,
|
179
189
|
# since the supervisor process will survive without being killed correctly.
|
180
190
|
flunk("Invalid test: The pid of supervisor could not be taken, which is necessary on Windows.") if Fluent.windows? && @supervisor_pid.nil?
|
181
191
|
rescue => e
|
182
|
-
|
192
|
+
error_msg_match = "unexpected error in launching fluentd: #{e.inspect}"
|
183
193
|
else
|
184
|
-
|
194
|
+
error_msg_match = "log doesn't match" unless matched
|
185
195
|
end
|
186
196
|
|
187
197
|
if patterns_not_match.empty?
|
188
|
-
|
198
|
+
error_msg_match = build_message(error_msg_match,
|
189
199
|
"<?>\nwas expected to include:\n<?>",
|
190
200
|
stdio_buf, pattern_list)
|
191
201
|
else
|
@@ -197,16 +207,17 @@ class TestFluentdCommand < ::Test::Unit::TestCase
|
|
197
207
|
lines.any?{|line| line.include?(ptn) }
|
198
208
|
end
|
199
209
|
if matched_wrongly
|
200
|
-
|
201
|
-
|
210
|
+
error_msg_match << "\n" unless error_msg_match.empty?
|
211
|
+
error_msg_match << "pattern exists in logs wrongly: #{ptn}"
|
202
212
|
end
|
203
213
|
end
|
204
|
-
|
214
|
+
error_msg_match = build_message(error_msg_match,
|
205
215
|
"<?>\nwas expected to include:\n<?>\nand not include:\n<?>",
|
206
216
|
stdio_buf, pattern_list, patterns_not_match)
|
207
217
|
end
|
208
218
|
|
209
|
-
assert matched && !matched_wrongly,
|
219
|
+
assert matched && !matched_wrongly, error_msg_match
|
220
|
+
assert succeeded_block, error_msg_block if block_given?
|
210
221
|
end
|
211
222
|
|
212
223
|
def assert_fluentd_fails_to_start(cmdline, *pattern_list, timeout: 20)
|
@@ -1164,7 +1175,7 @@ CONF
|
|
1164
1175
|
end
|
1165
1176
|
end
|
1166
1177
|
|
1167
|
-
sub_test_case '
|
1178
|
+
sub_test_case 'shared socket options' do
|
1168
1179
|
test 'enable shared socket by default' do
|
1169
1180
|
conf = ""
|
1170
1181
|
conf_path = create_conf_file('empty.conf', conf)
|
@@ -1288,4 +1299,40 @@ CONF
|
|
1288
1299
|
"[debug]")
|
1289
1300
|
end
|
1290
1301
|
end
|
1302
|
+
|
1303
|
+
sub_test_case "plugin option" do
|
1304
|
+
test "should be the default value when not specifying" do
|
1305
|
+
conf_path = create_conf_file('test.conf', <<~CONF)
|
1306
|
+
<source>
|
1307
|
+
@type monitor_agent
|
1308
|
+
</source>
|
1309
|
+
CONF
|
1310
|
+
assert File.exist?(conf_path)
|
1311
|
+
cmdline = create_cmdline(conf_path)
|
1312
|
+
|
1313
|
+
assert_log_matches(cmdline, "fluentd worker is now running") do
|
1314
|
+
response = Net::HTTP.get(URI.parse("http://localhost:24220/api/config.json"))
|
1315
|
+
actual_conf = JSON.parse(response)
|
1316
|
+
assert_equal Fluent::Supervisor.default_options[:plugin_dirs], actual_conf["plugin_dirs"]
|
1317
|
+
end
|
1318
|
+
end
|
1319
|
+
|
1320
|
+
data(short: "-p")
|
1321
|
+
data(long: "--plugin")
|
1322
|
+
test "can be added by specifying the option" do |option_name|
|
1323
|
+
conf_path = create_conf_file('test.conf', <<~CONF)
|
1324
|
+
<source>
|
1325
|
+
@type monitor_agent
|
1326
|
+
</source>
|
1327
|
+
CONF
|
1328
|
+
assert File.exist?(conf_path)
|
1329
|
+
cmdline = create_cmdline(conf_path, option_name, @tmp_dir, option_name, @tmp_dir)
|
1330
|
+
|
1331
|
+
assert_log_matches(cmdline, "fluentd worker is now running") do
|
1332
|
+
response = Net::HTTP.get(URI.parse("http://localhost:24220/api/config.json"))
|
1333
|
+
actual_conf = JSON.parse(response)
|
1334
|
+
assert_equal Fluent::Supervisor.default_options[:plugin_dirs] + [@tmp_dir, @tmp_dir], actual_conf["plugin_dirs"]
|
1335
|
+
end
|
1336
|
+
end
|
1337
|
+
end
|
1291
1338
|
end
|
data/test/helper.rb
CHANGED
@@ -71,17 +71,31 @@ end
|
|
71
71
|
|
72
72
|
include Fluent::Test::Helpers
|
73
73
|
|
74
|
-
def unused_port(num = 1, protocol
|
74
|
+
def unused_port(num = 1, protocol:, bind: "0.0.0.0")
|
75
75
|
case protocol
|
76
|
-
when :tcp
|
76
|
+
when :tcp, :tls
|
77
77
|
unused_port_tcp(num)
|
78
78
|
when :udp
|
79
79
|
unused_port_udp(num, bind: bind)
|
80
|
+
when :all
|
81
|
+
unused_port_tcp_udp(num)
|
80
82
|
else
|
81
83
|
raise ArgumentError, "unknown protocol: #{protocol}"
|
82
84
|
end
|
83
85
|
end
|
84
86
|
|
87
|
+
def unused_port_tcp_udp(num = 1)
|
88
|
+
raise "not support num > 1" if num > 1
|
89
|
+
|
90
|
+
# The default maximum number of file descriptors in macOS is 256.
|
91
|
+
# It might need to set num to a smaller value than that.
|
92
|
+
tcp_ports = unused_port_tcp(200)
|
93
|
+
port = unused_port_udp(1, port_list: tcp_ports)
|
94
|
+
raise "can't find unused port" unless port
|
95
|
+
|
96
|
+
port
|
97
|
+
end
|
98
|
+
|
85
99
|
def unused_port_tcp(num = 1)
|
86
100
|
ports = []
|
87
101
|
sockets = []
|
@@ -90,7 +104,7 @@ def unused_port_tcp(num = 1)
|
|
90
104
|
sockets << s
|
91
105
|
ports << s.addr[1]
|
92
106
|
end
|
93
|
-
sockets.each
|
107
|
+
sockets.each(&:close)
|
94
108
|
if num == 1
|
95
109
|
return ports.first
|
96
110
|
else
|
@@ -100,12 +114,15 @@ end
|
|
100
114
|
|
101
115
|
PORT_RANGE_AVAILABLE = (1024...65535)
|
102
116
|
|
103
|
-
def unused_port_udp(num = 1, bind: "0.0.0.0")
|
117
|
+
def unused_port_udp(num = 1, port_list: [], bind: "0.0.0.0")
|
104
118
|
family = IPAddr.new(IPSocket.getaddress(bind)).ipv4? ? ::Socket::AF_INET : ::Socket::AF_INET6
|
105
119
|
ports = []
|
106
120
|
sockets = []
|
107
|
-
|
108
|
-
|
121
|
+
|
122
|
+
use_random_port = port_list.empty?
|
123
|
+
i = 0
|
124
|
+
loop do
|
125
|
+
port = use_random_port ? rand(PORT_RANGE_AVAILABLE) : port_list[i]
|
109
126
|
u = UDPSocket.new(family)
|
110
127
|
if (u.bind(bind, port) rescue nil)
|
111
128
|
ports << port
|
@@ -113,8 +130,11 @@ def unused_port_udp(num = 1, bind: "0.0.0.0")
|
|
113
130
|
else
|
114
131
|
u.close
|
115
132
|
end
|
133
|
+
i += 1
|
134
|
+
break if ports.size >= num
|
135
|
+
break if !use_random_port && i >= port_list.size
|
116
136
|
end
|
117
|
-
sockets.each
|
137
|
+
sockets.each(&:close)
|
118
138
|
if num == 1
|
119
139
|
return ports.first
|
120
140
|
else
|
@@ -5,20 +5,19 @@ require 'fluent/plugin/metrics_local'
|
|
5
5
|
require 'tempfile'
|
6
6
|
|
7
7
|
class IntailIOHandlerTest < Test::Unit::TestCase
|
8
|
-
setup
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
@file.unlink rescue nil
|
8
|
+
def setup
|
9
|
+
Tempfile.create('intail_io_handler') do |file|
|
10
|
+
file.binmode
|
11
|
+
@file = file
|
12
|
+
opened_file_metrics = Fluent::Plugin::LocalMetrics.new
|
13
|
+
opened_file_metrics.configure(config_element('metrics', '', {}))
|
14
|
+
closed_file_metrics = Fluent::Plugin::LocalMetrics.new
|
15
|
+
closed_file_metrics.configure(config_element('metrics', '', {}))
|
16
|
+
rotated_file_metrics = Fluent::Plugin::LocalMetrics.new
|
17
|
+
rotated_file_metrics.configure(config_element('metrics', '', {}))
|
18
|
+
@metrics = Fluent::Plugin::TailInput::MetricsInfo.new(opened_file_metrics, closed_file_metrics, rotated_file_metrics)
|
19
|
+
yield
|
20
|
+
end
|
22
21
|
end
|
23
22
|
|
24
23
|
def create_target_info
|
@@ -6,13 +6,12 @@ require 'fileutils'
|
|
6
6
|
require 'tempfile'
|
7
7
|
|
8
8
|
class IntailPositionFileTest < Test::Unit::TestCase
|
9
|
-
setup
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
@file.unlink rescue nil
|
9
|
+
def setup
|
10
|
+
Tempfile.create('intail_position_file_test') do |file|
|
11
|
+
file.binmode
|
12
|
+
@file = file
|
13
|
+
yield
|
14
|
+
end
|
16
15
|
end
|
17
16
|
|
18
17
|
UNWATCHED_STR = '%016x' % Fluent::Plugin::TailInput::PositionFile::UNWATCHED_POSITION
|
@@ -111,11 +111,11 @@ class AckHandlerTest < Test::Unit::TestCase
|
|
111
111
|
r, w = IO.pipe
|
112
112
|
begin
|
113
113
|
w.write(chunk_id)
|
114
|
-
|
114
|
+
def r.recv(arg)
|
115
115
|
sleep(1) # To ensure that multiple threads select the socket before closing.
|
116
|
-
raise IOError, 'stream closed in another thread' if
|
116
|
+
raise IOError, 'stream closed in another thread' if self.closed?
|
117
117
|
MessagePack.pack({ 'ack' => Base64.encode64('chunk_id 111') })
|
118
|
-
|
118
|
+
end
|
119
119
|
ack.enqueue(r)
|
120
120
|
|
121
121
|
threads = []
|
@@ -17,7 +17,7 @@ class SocketCacheTest < Test::Unit::TestCase
|
|
17
17
|
assert_equal(socket, c.checkout_or('key') { socket })
|
18
18
|
c.checkin(socket)
|
19
19
|
|
20
|
-
sock =
|
20
|
+
sock = mock!.open.never.subject
|
21
21
|
assert_equal(socket, c.checkout_or('key') { sock.open })
|
22
22
|
end
|
23
23
|
|
@@ -130,7 +130,7 @@ class SocketCacheTest < Test::Unit::TestCase
|
|
130
130
|
|
131
131
|
c = Fluent::Plugin::ForwardOutput::SocketCache.new(10, $log)
|
132
132
|
sock = mock!.close { 'closed' }.subject
|
133
|
-
sock2 =
|
133
|
+
sock2 = mock!.close.never.subject
|
134
134
|
stub(sock).inspect
|
135
135
|
stub(sock2).inspect
|
136
136
|
|
@@ -154,7 +154,7 @@ class SocketCacheTest < Test::Unit::TestCase
|
|
154
154
|
Timecop.freeze(Time.parse('2016-04-13 14:00:00 +0900'))
|
155
155
|
|
156
156
|
c = Fluent::Plugin::ForwardOutput::SocketCache.new(10, $log)
|
157
|
-
sock =
|
157
|
+
sock = mock!.close.never.subject
|
158
158
|
stub(sock).inspect
|
159
159
|
c.checkout_or('key') { sock }
|
160
160
|
|
@@ -18,7 +18,8 @@ class ForwardInputTest < Test::Unit::TestCase
|
|
18
18
|
Fluent::Test.setup
|
19
19
|
@responses = [] # for testing responses after sending data
|
20
20
|
@d = nil
|
21
|
-
|
21
|
+
# forward plugin uses TCP and UDP sockets on the same port number
|
22
|
+
@port = unused_port(protocol: :all)
|
22
23
|
end
|
23
24
|
|
24
25
|
def teardown
|
data/test/plugin/test_in_http.rb
CHANGED
@@ -392,7 +392,7 @@ EOC
|
|
392
392
|
end
|
393
393
|
|
394
394
|
test "emit" do
|
395
|
-
port = unused_port
|
395
|
+
port = unused_port(protocol: :tcp)
|
396
396
|
d = create_driver("
|
397
397
|
@type monitor_agent
|
398
398
|
bind '127.0.0.1'
|
@@ -451,7 +451,7 @@ EOC
|
|
451
451
|
|
452
452
|
sub_test_case "servlets" do
|
453
453
|
setup do
|
454
|
-
@port = unused_port
|
454
|
+
@port = unused_port(protocol: :tcp)
|
455
455
|
# check @type and type in one configuration
|
456
456
|
conf = <<-EOC
|
457
457
|
<source>
|
@@ -759,7 +759,7 @@ plugin_id:test_filter\tplugin_category:filter\ttype:test_filter\toutput_plugin:f
|
|
759
759
|
end
|
760
760
|
|
761
761
|
setup do
|
762
|
-
@port = unused_port
|
762
|
+
@port = unused_port(protocol: :tcp)
|
763
763
|
# check @type and type in one configuration
|
764
764
|
conf = <<-EOC
|
765
765
|
<source>
|
@@ -840,7 +840,7 @@ plugin_id:test_filter\tplugin_category:filter\ttype:test_filter\toutput_plugin:f
|
|
840
840
|
|
841
841
|
sub_test_case "check the port number of http server" do
|
842
842
|
test "on single worker environment" do
|
843
|
-
port = unused_port
|
843
|
+
port = unused_port(protocol: :tcp)
|
844
844
|
d = create_driver("
|
845
845
|
@type monitor_agent
|
846
846
|
bind '127.0.0.1'
|
@@ -851,7 +851,7 @@ plugin_id:test_filter\tplugin_category:filter\ttype:test_filter\toutput_plugin:f
|
|
851
851
|
end
|
852
852
|
|
853
853
|
test "worker_id = 2 on multi worker environment" do
|
854
|
-
port = unused_port
|
854
|
+
port = unused_port(protocol: :tcp)
|
855
855
|
Fluent::SystemConfig.overwrite_system_config('workers' => 4) do
|
856
856
|
d = Fluent::Test::Driver::Input.new(Fluent::Plugin::MonitorAgentInput)
|
857
857
|
d.instance.instance_eval{ @_fluentd_worker_id = 2 }
|
@@ -905,7 +905,7 @@ EOC
|
|
905
905
|
end
|
906
906
|
|
907
907
|
test "plugins have a variable named buffer does not throws NoMethodError" do
|
908
|
-
port = unused_port
|
908
|
+
port = unused_port(protocol: :tcp)
|
909
909
|
d = create_driver("
|
910
910
|
@type monitor_agent
|
911
911
|
bind '127.0.0.1'
|