fluentd 1.15.3-x64-mingw-ucrt → 1.16.1-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/ISSUE_TEMPLATE/bug_report.yaml +1 -0
- data/.github/ISSUE_TEMPLATE/feature_request.yaml +1 -0
- data/.github/workflows/linux-test.yaml +2 -2
- data/.github/workflows/macos-test.yaml +2 -2
- data/.github/workflows/stale-actions.yml +24 -0
- data/.github/workflows/windows-test.yaml +2 -2
- data/CHANGELOG.md +114 -0
- data/CONTRIBUTING.md +1 -1
- data/MAINTAINERS.md +5 -3
- data/README.md +0 -1
- data/SECURITY.md +5 -9
- data/fluentd.gemspec +2 -2
- data/lib/fluent/command/fluentd.rb +55 -53
- data/lib/fluent/daemon.rb +2 -4
- data/lib/fluent/event.rb +2 -2
- data/lib/fluent/log/console_adapter.rb +66 -0
- data/lib/fluent/log.rb +35 -5
- data/lib/fluent/plugin/base.rb +5 -7
- data/lib/fluent/plugin/buf_file.rb +32 -3
- 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 +21 -0
- data/lib/fluent/plugin/in_tcp.rb +47 -2
- data/lib/fluent/plugin/out_forward/ack_handler.rb +19 -4
- data/lib/fluent/plugin/out_forward.rb +2 -2
- data/lib/fluent/plugin/out_secondary_file.rb +39 -22
- data/lib/fluent/plugin/output.rb +49 -12
- data/lib/fluent/plugin_helper/http_server/server.rb +2 -1
- data/lib/fluent/plugin_helper/server.rb +8 -0
- data/lib/fluent/supervisor.rb +157 -251
- 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/version.rb +1 -1
- data/templates/new_gem/test/helper.rb.erb +0 -1
- data/test/command/test_ctl.rb +1 -1
- data/test/command/test_fluentd.rb +137 -6
- data/test/command/test_plugin_config_formatter.rb +0 -1
- data/test/compat/test_parser.rb +5 -5
- data/test/config/test_system_config.rb +0 -8
- data/test/log/test_console_adapter.rb +110 -0
- data/test/plugin/out_forward/test_ack_handler.rb +39 -0
- data/test/plugin/test_base.rb +98 -0
- data/test/plugin/test_buf_file.rb +62 -23
- data/test/plugin/test_buf_file_single.rb +65 -0
- data/test/plugin/test_in_http.rb +2 -3
- data/test/plugin/test_in_monitor_agent.rb +2 -3
- data/test/plugin/test_in_tcp.rb +87 -2
- data/test/plugin/test_in_udp.rb +28 -0
- data/test/plugin/test_out_forward.rb +14 -18
- data/test/plugin/test_out_http.rb +1 -0
- data/test/plugin/test_output.rb +269 -0
- data/test/plugin/test_output_as_buffered_compress.rb +32 -18
- data/test/plugin/test_parser_regexp.rb +1 -6
- data/test/plugin_helper/test_http_server_helper.rb +1 -1
- data/test/plugin_helper/test_server.rb +59 -5
- data/test/test_config.rb +0 -21
- data/test/test_formatter.rb +23 -20
- data/test/test_log.rb +71 -36
- data/test/test_supervisor.rb +277 -282
- metadata +13 -19
- data/.drone.yml +0 -35
- data/.gitlab-ci.yml +0 -103
- data/test/test_logger_initializer.rb +0 -46
data/test/test_supervisor.rb
CHANGED
@@ -10,6 +10,7 @@ require 'uri'
|
|
10
10
|
require 'fileutils'
|
11
11
|
require 'tempfile'
|
12
12
|
require 'securerandom'
|
13
|
+
require 'pathname'
|
13
14
|
|
14
15
|
if Fluent.windows?
|
15
16
|
require 'win32/event'
|
@@ -29,12 +30,15 @@ class SupervisorTest < ::Test::Unit::TestCase
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def setup
|
33
|
+
@stored_global_logger = $log
|
32
34
|
@tmp_dir = tmp_dir
|
33
35
|
@tmp_root_dir = File.join(@tmp_dir, 'root')
|
34
36
|
FileUtils.mkdir_p(@tmp_dir)
|
37
|
+
@sigdump_path = "/tmp/sigdump-#{Process.pid}.log"
|
35
38
|
end
|
36
39
|
|
37
40
|
def teardown
|
41
|
+
$log = @stored_global_logger
|
38
42
|
begin
|
39
43
|
FileUtils.rm_rf(@tmp_dir)
|
40
44
|
rescue Errno::EACCES
|
@@ -51,12 +55,11 @@ class SupervisorTest < ::Test::Unit::TestCase
|
|
51
55
|
|
52
56
|
|
53
57
|
def test_system_config
|
54
|
-
|
55
|
-
sv = Fluent::Supervisor.new(opts)
|
58
|
+
sv = Fluent::Supervisor.new({})
|
56
59
|
conf_data = <<-EOC
|
57
60
|
<system>
|
58
61
|
rpc_endpoint 127.0.0.1:24445
|
59
|
-
suppress_repeated_stacktrace
|
62
|
+
suppress_repeated_stacktrace false
|
60
63
|
suppress_config_dump true
|
61
64
|
without_source true
|
62
65
|
enable_get_dump true
|
@@ -84,7 +87,7 @@ class SupervisorTest < ::Test::Unit::TestCase
|
|
84
87
|
sys_conf = sv.__send__(:build_system_config, conf)
|
85
88
|
|
86
89
|
assert_equal '127.0.0.1:24445', sys_conf.rpc_endpoint
|
87
|
-
assert_equal
|
90
|
+
assert_equal false, sys_conf.suppress_repeated_stacktrace
|
88
91
|
assert_equal true, sys_conf.suppress_config_dump
|
89
92
|
assert_equal true, sys_conf.without_source
|
90
93
|
assert_equal true, sys_conf.enable_get_dump
|
@@ -119,8 +122,7 @@ class SupervisorTest < ::Test::Unit::TestCase
|
|
119
122
|
end
|
120
123
|
|
121
124
|
def test_system_config
|
122
|
-
|
123
|
-
sv = Fluent::Supervisor.new(opts)
|
125
|
+
sv = Fluent::Supervisor.new({})
|
124
126
|
conf_data = <<-EOC
|
125
127
|
system:
|
126
128
|
rpc_endpoint: 127.0.0.1:24445
|
@@ -191,26 +193,60 @@ class SupervisorTest < ::Test::Unit::TestCase
|
|
191
193
|
end
|
192
194
|
end
|
193
195
|
|
194
|
-
def
|
196
|
+
def test_usr1_in_main_process_signal_handlers
|
195
197
|
omit "Windows cannot handle signals" if Fluent.windows?
|
196
198
|
|
197
199
|
create_info_dummy_logger
|
198
200
|
|
199
|
-
|
200
|
-
sv = Fluent::Supervisor.new(opts)
|
201
|
+
sv = Fluent::Supervisor.new({})
|
201
202
|
sv.send(:install_main_process_signal_handlers)
|
202
203
|
|
203
|
-
|
204
|
-
Process.kill :USR1, $$
|
205
|
-
rescue
|
206
|
-
end
|
204
|
+
Process.kill :USR1, Process.pid
|
207
205
|
|
208
206
|
sleep 1
|
209
207
|
|
210
|
-
info_msg =
|
208
|
+
info_msg = "[info]: force flushing buffered events\n"
|
211
209
|
assert{ $log.out.logs.first.end_with?(info_msg) }
|
212
210
|
ensure
|
213
|
-
$log.out.reset if $log
|
211
|
+
$log.out.reset if $log&.out&.respond_to?(:reset)
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_cont_in_main_process_signal_handlers
|
215
|
+
omit "Windows cannot handle signals" if Fluent.windows?
|
216
|
+
|
217
|
+
sv = Fluent::Supervisor.new({})
|
218
|
+
sv.send(:install_main_process_signal_handlers)
|
219
|
+
|
220
|
+
Process.kill :CONT, Process.pid
|
221
|
+
|
222
|
+
sleep 1
|
223
|
+
|
224
|
+
assert{ File.exist?(@sigdump_path) }
|
225
|
+
ensure
|
226
|
+
File.delete(@sigdump_path) if File.exist?(@sigdump_path)
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_term_cont_in_main_process_signal_handlers
|
230
|
+
omit "Windows cannot handle signals" if Fluent.windows?
|
231
|
+
|
232
|
+
create_debug_dummy_logger
|
233
|
+
|
234
|
+
sv = Fluent::Supervisor.new({})
|
235
|
+
sv.send(:install_main_process_signal_handlers)
|
236
|
+
|
237
|
+
Process.kill :TERM, Process.pid
|
238
|
+
Process.kill :CONT, Process.pid
|
239
|
+
|
240
|
+
sleep 1
|
241
|
+
|
242
|
+
debug_msg = "[debug]: fluentd main process get SIGTERM\n"
|
243
|
+
logs = $log.out.logs
|
244
|
+
assert{ logs.any?{|log| log.include?(debug_msg) } }
|
245
|
+
|
246
|
+
assert{ not File.exist?(@sigdump_path) }
|
247
|
+
ensure
|
248
|
+
$log.out.reset if $log&.out&.respond_to?(:reset)
|
249
|
+
File.delete(@sigdump_path) if File.exist?(@sigdump_path)
|
214
250
|
end
|
215
251
|
|
216
252
|
def test_main_process_command_handlers
|
@@ -218,8 +254,7 @@ class SupervisorTest < ::Test::Unit::TestCase
|
|
218
254
|
|
219
255
|
create_info_dummy_logger
|
220
256
|
|
221
|
-
|
222
|
-
sv = Fluent::Supervisor.new(opts)
|
257
|
+
sv = Fluent::Supervisor.new({})
|
223
258
|
r, w = IO.pipe
|
224
259
|
$stdin = r
|
225
260
|
sv.send(:install_main_process_signal_handlers)
|
@@ -233,23 +268,21 @@ class SupervisorTest < ::Test::Unit::TestCase
|
|
233
268
|
|
234
269
|
sleep 1
|
235
270
|
|
236
|
-
info_msg =
|
271
|
+
info_msg = "[info]: force flushing buffered events\n"
|
237
272
|
assert{ $log.out.logs.first.end_with?(info_msg) }
|
238
273
|
ensure
|
239
|
-
$log.out.reset if $log
|
274
|
+
$log.out.reset if $log&.out&.respond_to?(:reset)
|
240
275
|
end
|
241
276
|
|
242
|
-
def
|
277
|
+
def test_usr1_in_supervisor_signal_handler
|
243
278
|
omit "Windows cannot handle signals" if Fluent.windows?
|
244
279
|
|
245
280
|
create_debug_dummy_logger
|
246
281
|
|
247
282
|
server = DummyServer.new
|
248
283
|
server.install_supervisor_signal_handlers
|
249
|
-
|
250
|
-
|
251
|
-
rescue
|
252
|
-
end
|
284
|
+
|
285
|
+
Process.kill :USR1, Process.pid
|
253
286
|
|
254
287
|
sleep 1
|
255
288
|
|
@@ -257,12 +290,43 @@ class SupervisorTest < ::Test::Unit::TestCase
|
|
257
290
|
logs = $log.out.logs
|
258
291
|
assert{ logs.any?{|log| log.include?(debug_msg) } }
|
259
292
|
ensure
|
260
|
-
$log.out.reset if $log
|
293
|
+
$log.out.reset if $log&.out&.respond_to?(:reset)
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_cont_in_supervisor_signal_handler
|
297
|
+
omit "Windows cannot handle signals" if Fluent.windows?
|
298
|
+
|
299
|
+
server = DummyServer.new
|
300
|
+
server.install_supervisor_signal_handlers
|
301
|
+
|
302
|
+
Process.kill :CONT, Process.pid
|
303
|
+
|
304
|
+
sleep 1
|
305
|
+
|
306
|
+
assert{ File.exist?(@sigdump_path) }
|
307
|
+
ensure
|
308
|
+
File.delete(@sigdump_path) if File.exist?(@sigdump_path)
|
309
|
+
end
|
310
|
+
|
311
|
+
def test_term_cont_in_supervisor_signal_handler
|
312
|
+
omit "Windows cannot handle signals" if Fluent.windows?
|
313
|
+
|
314
|
+
server = DummyServer.new
|
315
|
+
server.install_supervisor_signal_handlers
|
316
|
+
|
317
|
+
Process.kill :TERM, Process.pid
|
318
|
+
Process.kill :CONT, Process.pid
|
319
|
+
|
320
|
+
assert{ not File.exist?(@sigdump_path) }
|
321
|
+
ensure
|
322
|
+
File.delete(@sigdump_path) if File.exist?(@sigdump_path)
|
261
323
|
end
|
262
324
|
|
263
325
|
def test_windows_shutdown_event
|
264
326
|
omit "Only for Windows platform" unless Fluent.windows?
|
265
327
|
|
328
|
+
create_debug_dummy_logger
|
329
|
+
|
266
330
|
server = DummyServer.new
|
267
331
|
def server.config
|
268
332
|
{:signame => "TestFluentdEvent"}
|
@@ -285,7 +349,7 @@ class SupervisorTest < ::Test::Unit::TestCase
|
|
285
349
|
logs = $log.out.logs
|
286
350
|
assert{ logs.any?{|log| log.include?(debug_msg) } }
|
287
351
|
ensure
|
288
|
-
$log.out.reset if $log
|
352
|
+
$log.out.reset if $log&.out&.respond_to?(:reset)
|
289
353
|
end
|
290
354
|
|
291
355
|
def test_supervisor_event_handler
|
@@ -311,15 +375,14 @@ class SupervisorTest < ::Test::Unit::TestCase
|
|
311
375
|
logs = $log.out.logs
|
312
376
|
assert{ logs.any?{|log| log.include?(debug_msg) } }
|
313
377
|
ensure
|
314
|
-
$log.out.reset if $log
|
378
|
+
$log.out.reset if $log&.out&.respond_to?(:reset)
|
315
379
|
end
|
316
380
|
|
317
|
-
data("Normal", {raw_path: "C:\\Windows\\Temp\\sigdump.log", expected: "C:\\Windows\\Temp\\sigdump-#{
|
318
|
-
data("UNIX style", {raw_path: "/Windows/Temp/sigdump.log", expected: "/Windows/Temp/sigdump-#{
|
319
|
-
data("No extension", {raw_path: "C:\\Windows\\Temp\\sigdump", expected: "C:\\Windows\\Temp\\sigdump-#{
|
320
|
-
data("Multi-extension", {raw_path: "C:\\Windows\\Temp\\sig.dump.bk", expected: "C:\\Windows\\Temp\\sig.dump-#{
|
381
|
+
data("Normal", {raw_path: "C:\\Windows\\Temp\\sigdump.log", expected: "C:\\Windows\\Temp\\sigdump-#{Process.pid}.log"})
|
382
|
+
data("UNIX style", {raw_path: "/Windows/Temp/sigdump.log", expected: "/Windows/Temp/sigdump-#{Process.pid}.log"})
|
383
|
+
data("No extension", {raw_path: "C:\\Windows\\Temp\\sigdump", expected: "C:\\Windows\\Temp\\sigdump-#{Process.pid}"})
|
384
|
+
data("Multi-extension", {raw_path: "C:\\Windows\\Temp\\sig.dump.bk", expected: "C:\\Windows\\Temp\\sig.dump-#{Process.pid}.bk"})
|
321
385
|
def test_fluentsigdump_get_path_with_pid(data)
|
322
|
-
p data
|
323
386
|
path = Fluent::FluentSigdump.get_path_with_pid(data[:raw_path])
|
324
387
|
assert_equal(data[:expected], path)
|
325
388
|
end
|
@@ -368,8 +431,7 @@ class SupervisorTest < ::Test::Unit::TestCase
|
|
368
431
|
|
369
432
|
create_info_dummy_logger
|
370
433
|
|
371
|
-
|
372
|
-
sv = Fluent::Supervisor.new(opts)
|
434
|
+
sv = Fluent::Supervisor.new({})
|
373
435
|
conf_data = <<-EOC
|
374
436
|
<system>
|
375
437
|
rpc_endpoint "#{bindaddr}:24447"
|
@@ -386,7 +448,7 @@ class SupervisorTest < ::Test::Unit::TestCase
|
|
386
448
|
|
387
449
|
sv.send(:install_main_process_signal_handlers)
|
388
450
|
response = Net::HTTP.get(URI.parse("http://#{localhost}:24447/api/plugins.flushBuffers"))
|
389
|
-
info_msg =
|
451
|
+
info_msg = "[info]: force flushing buffered events\n"
|
390
452
|
|
391
453
|
server.stop_rpc_server
|
392
454
|
|
@@ -405,8 +467,7 @@ class SupervisorTest < ::Test::Unit::TestCase
|
|
405
467
|
def test_invalid_rpc_endpoint(data)
|
406
468
|
endpoint = data[0]
|
407
469
|
|
408
|
-
|
409
|
-
sv = Fluent::Supervisor.new(opts)
|
470
|
+
sv = Fluent::Supervisor.new({})
|
410
471
|
conf_data = <<-EOC
|
411
472
|
<system>
|
412
473
|
rpc_endpoint "#{endpoint}"
|
@@ -434,8 +495,7 @@ class SupervisorTest < ::Test::Unit::TestCase
|
|
434
495
|
|
435
496
|
create_info_dummy_logger
|
436
497
|
|
437
|
-
|
438
|
-
sv = Fluent::Supervisor.new(opts)
|
498
|
+
sv = Fluent::Supervisor.new({})
|
439
499
|
conf_data = <<-EOC
|
440
500
|
<system>
|
441
501
|
rpc_endpoint "#{bindaddr}:24447"
|
@@ -462,36 +522,17 @@ class SupervisorTest < ::Test::Unit::TestCase
|
|
462
522
|
assert_equal('{"ok":true}', response)
|
463
523
|
end
|
464
524
|
|
465
|
-
def
|
466
|
-
tmp_dir = "#{@tmp_dir}/dir/test_load_config.conf"
|
467
|
-
conf_info_str = %[
|
468
|
-
<system>
|
469
|
-
log_level info
|
470
|
-
</system>
|
471
|
-
]
|
472
|
-
conf_debug_str = %[
|
473
|
-
<system>
|
474
|
-
log_level debug
|
475
|
-
</system>
|
476
|
-
]
|
477
|
-
now = Time.now
|
478
|
-
Timecop.freeze(now)
|
479
|
-
|
480
|
-
write_config tmp_dir, conf_info_str
|
481
|
-
|
525
|
+
def test_serverengine_config
|
482
526
|
params = {}
|
483
527
|
params['workers'] = 1
|
528
|
+
params['fluentd_conf_path'] = "fluentd.conf"
|
484
529
|
params['use_v1_config'] = true
|
485
|
-
params['log_path'] = 'test/tmp/supervisor/log'
|
486
|
-
params['suppress_repeated_stacktrace'] = true
|
487
|
-
params['log_level'] = Fluent::Log::LEVEL_INFO
|
488
530
|
params['conf_encoding'] = 'utf-8'
|
489
|
-
|
531
|
+
params['log_level'] = Fluent::Log::LEVEL_INFO
|
532
|
+
load_config_proc = Proc.new { Fluent::Supervisor.serverengine_config(params) }
|
490
533
|
|
491
|
-
# first call
|
492
534
|
se_config = load_config_proc.call
|
493
535
|
assert_equal Fluent::Log::LEVEL_INFO, se_config[:log_level]
|
494
|
-
assert_equal true, se_config[:suppress_repeated_stacktrace]
|
495
536
|
assert_equal 'spawn', se_config[:worker_type]
|
496
537
|
assert_equal 1, se_config[:workers]
|
497
538
|
assert_equal false, se_config[:log_stdin]
|
@@ -499,99 +540,23 @@ class SupervisorTest < ::Test::Unit::TestCase
|
|
499
540
|
assert_equal false, se_config[:log_stderr]
|
500
541
|
assert_equal true, se_config[:enable_heartbeat]
|
501
542
|
assert_equal false, se_config[:auto_heartbeat]
|
543
|
+
assert_equal "fluentd.conf", se_config[:config_path]
|
502
544
|
assert_equal false, se_config[:daemonize]
|
503
545
|
assert_nil se_config[:pid_path]
|
504
|
-
|
505
|
-
# second call immediately(reuse config)
|
506
|
-
se_config = load_config_proc.call
|
507
|
-
pre_config_mtime = se_config[:windows_daemon_cmdline][5]['pre_config_mtime']
|
508
|
-
pre_loadtime = se_config[:windows_daemon_cmdline][5]['pre_loadtime']
|
509
|
-
assert_nil pre_config_mtime
|
510
|
-
assert_nil pre_loadtime
|
511
|
-
|
512
|
-
Timecop.freeze(now + 5)
|
513
|
-
|
514
|
-
# third call after 5 seconds(don't reuse config)
|
515
|
-
se_config = load_config_proc.call
|
516
|
-
pre_config_mtime = se_config[:windows_daemon_cmdline][5]['pre_config_mtime']
|
517
|
-
pre_loadtime = se_config[:windows_daemon_cmdline][5]['pre_loadtime']
|
518
|
-
assert_not_nil pre_config_mtime
|
519
|
-
assert_not_nil pre_loadtime
|
520
|
-
|
521
|
-
# forth call immediately(reuse config)
|
522
|
-
se_config = load_config_proc.call
|
523
|
-
# test that pre_config_mtime and pre_loadtime are not changed from previous one because reused pre_config
|
524
|
-
assert_equal pre_config_mtime, se_config[:windows_daemon_cmdline][5]['pre_config_mtime']
|
525
|
-
assert_equal pre_loadtime, se_config[:windows_daemon_cmdline][5]['pre_loadtime']
|
526
|
-
|
527
|
-
write_config tmp_dir, conf_debug_str
|
528
|
-
|
529
|
-
# fifth call after changed conf file(don't reuse config)
|
530
|
-
se_config = load_config_proc.call
|
531
|
-
assert_equal Fluent::Log::LEVEL_INFO, se_config[:log_level]
|
532
|
-
ensure
|
533
|
-
Timecop.return
|
534
546
|
end
|
535
547
|
|
536
|
-
def
|
537
|
-
tmp_dir = "#{@tmp_dir}/dir/test_load_config_log.conf"
|
538
|
-
conf_info_str = %[
|
539
|
-
<system>
|
540
|
-
<log>
|
541
|
-
format json
|
542
|
-
time_format %FT%T.%L%z
|
543
|
-
</log>
|
544
|
-
</system>
|
545
|
-
]
|
546
|
-
write_config tmp_dir, conf_info_str
|
547
|
-
params = {
|
548
|
-
'use_v1_config' => true,
|
549
|
-
'conf_encoding' => 'utf8',
|
550
|
-
'log_level' => Fluent::Log::LEVEL_INFO,
|
551
|
-
'log_path' => 'test/tmp/supervisor/log',
|
552
|
-
|
553
|
-
'workers' => 1,
|
554
|
-
'log_format' => :json,
|
555
|
-
'log_time_format' => '%FT%T.%L%z',
|
556
|
-
}
|
557
|
-
|
558
|
-
r = Fluent::Supervisor.load_config(tmp_dir, params)
|
559
|
-
assert_equal :json, r[:logger].format
|
560
|
-
assert_equal '%FT%T.%L%z', r[:logger].time_format
|
561
|
-
end
|
562
|
-
|
563
|
-
def test_load_config_for_daemonize
|
564
|
-
tmp_dir = "#{@tmp_dir}/dir/test_load_config.conf"
|
565
|
-
conf_info_str = %[
|
566
|
-
<system>
|
567
|
-
log_level info
|
568
|
-
</system>
|
569
|
-
]
|
570
|
-
conf_debug_str = %[
|
571
|
-
<system>
|
572
|
-
log_level debug
|
573
|
-
</system>
|
574
|
-
]
|
575
|
-
|
576
|
-
now = Time.now
|
577
|
-
Timecop.freeze(now)
|
578
|
-
|
579
|
-
write_config tmp_dir, conf_info_str
|
580
|
-
|
548
|
+
def test_serverengine_config_for_daemonize
|
581
549
|
params = {}
|
582
550
|
params['workers'] = 1
|
551
|
+
params['fluentd_conf_path'] = "fluentd.conf"
|
583
552
|
params['use_v1_config'] = true
|
584
|
-
params['
|
585
|
-
params['suppress_repeated_stacktrace'] = true
|
553
|
+
params['conf_encoding'] = 'utf-8'
|
586
554
|
params['log_level'] = Fluent::Log::LEVEL_INFO
|
587
555
|
params['daemonize'] = './fluentd.pid'
|
588
|
-
|
589
|
-
load_config_proc = Proc.new { Fluent::Supervisor.load_config(tmp_dir, params) }
|
556
|
+
load_config_proc = Proc.new { Fluent::Supervisor.serverengine_config(params) }
|
590
557
|
|
591
|
-
# first call
|
592
558
|
se_config = load_config_proc.call
|
593
559
|
assert_equal Fluent::Log::LEVEL_INFO, se_config[:log_level]
|
594
|
-
assert_equal true, se_config[:suppress_repeated_stacktrace]
|
595
560
|
assert_equal 'spawn', se_config[:worker_type]
|
596
561
|
assert_equal 1, se_config[:workers]
|
597
562
|
assert_equal false, se_config[:log_stdin]
|
@@ -599,161 +564,199 @@ class SupervisorTest < ::Test::Unit::TestCase
|
|
599
564
|
assert_equal false, se_config[:log_stderr]
|
600
565
|
assert_equal true, se_config[:enable_heartbeat]
|
601
566
|
assert_equal false, se_config[:auto_heartbeat]
|
567
|
+
assert_equal "fluentd.conf", se_config[:config_path]
|
602
568
|
assert_equal true, se_config[:daemonize]
|
603
569
|
assert_equal './fluentd.pid', se_config[:pid_path]
|
570
|
+
end
|
604
571
|
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
# test that pre_config_mtime and pre_loadtime are not changed from previous one because reused pre_config
|
624
|
-
assert_equal pre_config_mtime, se_config[:windows_daemon_cmdline][5]['pre_config_mtime']
|
625
|
-
assert_equal pre_loadtime, se_config[:windows_daemon_cmdline][5]['pre_loadtime']
|
572
|
+
sub_test_case "init logger" do
|
573
|
+
data(supervisor: true)
|
574
|
+
data(worker: false)
|
575
|
+
def test_init_for_logger(supervisor)
|
576
|
+
tmp_conf_path = "#{@tmp_dir}/dir/test_init_for_logger.conf"
|
577
|
+
conf_info_str = <<~EOC
|
578
|
+
<system>
|
579
|
+
log_level warn # To suppress logs
|
580
|
+
suppress_repeated_stacktrace false
|
581
|
+
ignore_repeated_log_interval 10s
|
582
|
+
ignore_same_log_interval 20s
|
583
|
+
<log>
|
584
|
+
format json
|
585
|
+
time_format %FT%T.%L%z
|
586
|
+
</log>
|
587
|
+
</system>
|
588
|
+
EOC
|
589
|
+
write_config tmp_conf_path, conf_info_str
|
626
590
|
|
627
|
-
|
591
|
+
s = Fluent::Supervisor.new({config_path: tmp_conf_path})
|
592
|
+
s.configure(supervisor: supervisor)
|
628
593
|
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
594
|
+
assert_equal :json, $log.format
|
595
|
+
assert_equal '%FT%T.%L%z', $log.time_format
|
596
|
+
assert_equal false, $log.suppress_repeated_stacktrace
|
597
|
+
assert_equal 10, $log.ignore_repeated_log_interval
|
598
|
+
assert_equal 20, $log.ignore_same_log_interval
|
599
|
+
end
|
635
600
|
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
601
|
+
data(
|
602
|
+
daily_age: 'daily',
|
603
|
+
weekly_age: 'weekly',
|
604
|
+
monthly_age: 'monthly',
|
605
|
+
integer_age: 2,
|
606
|
+
)
|
607
|
+
def test_logger_with_rotate_age_and_rotate_size(rotate_age)
|
608
|
+
config_path = "#{@tmp_dir}/empty.conf"
|
609
|
+
write_config config_path, ""
|
610
|
+
|
611
|
+
sv = Fluent::Supervisor.new(
|
612
|
+
config_path: config_path,
|
613
|
+
log_path: "#{@tmp_dir}/test",
|
614
|
+
log_rotate_age: rotate_age,
|
615
|
+
log_rotate_size: 10,
|
616
|
+
)
|
617
|
+
sv.__send__(:setup_global_logger)
|
618
|
+
|
619
|
+
assert_equal Fluent::LogDeviceIO, $log.out.class
|
620
|
+
assert_equal rotate_age, $log.out.instance_variable_get(:@shift_age)
|
621
|
+
assert_equal 10, $log.out.instance_variable_get(:@shift_size)
|
622
|
+
end
|
642
623
|
|
643
|
-
|
624
|
+
sub_test_case "system log rotation" do
|
625
|
+
def parse_text(text)
|
626
|
+
basepath = File.expand_path(File.dirname(__FILE__) + '/../../')
|
627
|
+
Fluent::Config.parse(text, '(test)', basepath, true).elements.find { |e| e.name == 'system' }
|
628
|
+
end
|
644
629
|
|
645
|
-
|
646
|
-
|
647
|
-
|
630
|
+
def test_override_default_log_rotate
|
631
|
+
Tempfile.open do |file|
|
632
|
+
config = parse_text(<<-EOS)
|
633
|
+
<system>
|
634
|
+
<log>
|
635
|
+
rotate_age 3
|
636
|
+
rotate_size 300
|
637
|
+
</log>
|
638
|
+
</system>
|
639
|
+
EOS
|
640
|
+
file.puts(config)
|
641
|
+
file.flush
|
642
|
+
sv = Fluent::Supervisor.new({log_path: "#{@tmp_dir}/test.log", config_path: file.path})
|
643
|
+
|
644
|
+
sv.__send__(:setup_global_logger)
|
645
|
+
logger = $log.instance_variable_get(:@logger)
|
646
|
+
|
647
|
+
assert_equal Fluent::LogDeviceIO, $log.out.class
|
648
|
+
assert_equal 3, $log.out.instance_variable_get(:@shift_age)
|
649
|
+
assert_equal 300, $log.out.instance_variable_get(:@shift_size)
|
650
|
+
end
|
651
|
+
end
|
648
652
|
|
649
|
-
|
650
|
-
|
651
|
-
|
653
|
+
def test_override_default_log_rotate_with_yaml_config
|
654
|
+
Tempfile.open do |file|
|
655
|
+
config = <<-EOS
|
656
|
+
system:
|
657
|
+
log:
|
658
|
+
rotate_age: 3
|
659
|
+
rotate_size: 300
|
660
|
+
EOS
|
661
|
+
file.puts(config)
|
662
|
+
file.flush
|
663
|
+
sv = Fluent::Supervisor.new({log_path: "#{@tmp_dir}/test.log", config_path: file.path, config_file_type: :yaml})
|
664
|
+
|
665
|
+
sv.__send__(:setup_global_logger)
|
666
|
+
logger = $log.instance_variable_get(:@logger)
|
667
|
+
|
668
|
+
assert_equal Fluent::LogDeviceIO, $log.out.class
|
669
|
+
assert_equal 3, $log.out.instance_variable_get(:@shift_age)
|
670
|
+
assert_equal 300, $log.out.instance_variable_get(:@shift_size)
|
671
|
+
end
|
672
|
+
end
|
673
|
+
end
|
652
674
|
|
653
|
-
|
654
|
-
|
655
|
-
weekly_age: 'weekly',
|
656
|
-
monthly_age: 'monthly',
|
657
|
-
integer_age: 2,
|
658
|
-
)
|
659
|
-
def test_logger_with_rotate_age_and_rotate_size(rotate_age)
|
660
|
-
opts = Fluent::Supervisor.default_options.merge(
|
661
|
-
log_path: "#{@tmp_dir}/test", log_rotate_age: rotate_age, log_rotate_size: 10
|
662
|
-
)
|
663
|
-
sv = Fluent::Supervisor.new(opts)
|
664
|
-
log = sv.instance_variable_get(:@log)
|
665
|
-
log.init(:standalone, 0)
|
675
|
+
def test_log_level_affects
|
676
|
+
sv = Fluent::Supervisor.new({})
|
666
677
|
|
667
|
-
|
668
|
-
|
669
|
-
assert_equal 10, $log.out.instance_variable_get(:@shift_size)
|
670
|
-
end
|
678
|
+
c = Fluent::Config::Element.new('system', '', { 'log_level' => 'error' }, [])
|
679
|
+
stub(Fluent::Config).build { config_element('ROOT', '', {}, [c]) }
|
671
680
|
|
672
|
-
|
673
|
-
|
674
|
-
basepath = File.expand_path(File.dirname(__FILE__) + '/../../')
|
675
|
-
Fluent::Config.parse(text, '(test)', basepath, true).elements.find { |e| e.name == 'system' }
|
681
|
+
sv.configure
|
682
|
+
assert_equal Fluent::Log::LEVEL_ERROR, $log.level
|
676
683
|
end
|
677
684
|
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
file.flush
|
690
|
-
opts = Fluent::Supervisor.default_options.merge(
|
691
|
-
log_path: "#{@tmp_dir}/test.log", config_path: file.path
|
692
|
-
)
|
693
|
-
sv = Fluent::Supervisor.new(opts)
|
694
|
-
|
695
|
-
log = sv.instance_variable_get(:@log)
|
696
|
-
log.init(:standalone, 0)
|
697
|
-
logger = $log.instance_variable_get(:@logger)
|
698
|
-
|
699
|
-
assert_equal([3, 300],
|
700
|
-
[logger.instance_variable_get(:@rotate_age),
|
701
|
-
logger.instance_variable_get(:@rotate_size)])
|
685
|
+
data(supervisor: true)
|
686
|
+
data(worker: false)
|
687
|
+
def test_log_path(supervisor)
|
688
|
+
log_path = Pathname(@tmp_dir) + "fluentd.log"
|
689
|
+
config_path = Pathname(@tmp_dir) + "fluentd.conf"
|
690
|
+
write_config config_path.to_s, ""
|
691
|
+
|
692
|
+
s = Fluent::Supervisor.new(config_path: config_path.to_s, log_path: log_path.to_s)
|
693
|
+
assert_rr do
|
694
|
+
mock.proxy(File).chmod(0o777, log_path.parent.to_s).never
|
695
|
+
s.__send__(:setup_global_logger, supervisor: supervisor)
|
702
696
|
end
|
703
|
-
end
|
704
697
|
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
system:
|
709
|
-
log:
|
710
|
-
rotate_age: 3
|
711
|
-
rotate_size: 300
|
712
|
-
EOS
|
713
|
-
file.puts(config)
|
714
|
-
file.flush
|
715
|
-
opts = Fluent::Supervisor.default_options.merge(
|
716
|
-
log_path: "#{@tmp_dir}/test.log", config_path: file.path, config_file_type: :yaml,
|
717
|
-
)
|
718
|
-
sv = Fluent::Supervisor.new(opts)
|
719
|
-
|
720
|
-
log = sv.instance_variable_get(:@log)
|
721
|
-
log.init(:standalone, 0)
|
722
|
-
logger = $log.instance_variable_get(:@logger)
|
723
|
-
|
724
|
-
assert_equal([3, 300],
|
725
|
-
[logger.instance_variable_get(:@rotate_age),
|
726
|
-
logger.instance_variable_get(:@rotate_size)])
|
727
|
-
end
|
698
|
+
assert { log_path.parent.exist? }
|
699
|
+
ensure
|
700
|
+
$log.out.close
|
728
701
|
end
|
729
|
-
end
|
730
702
|
|
731
|
-
|
732
|
-
|
703
|
+
data(supervisor: true)
|
704
|
+
data(worker: false)
|
705
|
+
def test_dir_permission(supervisor)
|
706
|
+
omit "NTFS doesn't support UNIX like permissions" if Fluent.windows?
|
707
|
+
|
708
|
+
log_path = Pathname(@tmp_dir) + "fluentd.log"
|
709
|
+
config_path = Pathname(@tmp_dir) + "fluentd.conf"
|
710
|
+
conf = <<~EOC
|
711
|
+
<system>
|
712
|
+
dir_permission 0o777
|
713
|
+
</system>
|
714
|
+
EOC
|
715
|
+
write_config config_path.to_s, conf
|
716
|
+
|
717
|
+
s = Fluent::Supervisor.new(config_path: config_path.to_s, log_path: log_path.to_s)
|
718
|
+
assert_rr do
|
719
|
+
mock.proxy(File).chmod(0o777, log_path.parent.to_s).once
|
720
|
+
s.__send__(:setup_global_logger, supervisor: supervisor)
|
721
|
+
end
|
733
722
|
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
723
|
+
assert { log_path.parent.exist? }
|
724
|
+
assert { (File.stat(log_path.parent).mode & 0xFFF) == 0o777 }
|
725
|
+
ensure
|
726
|
+
$log.out.close
|
727
|
+
end
|
738
728
|
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
729
|
+
def test_files_for_each_process_with_rotate_on_windows
|
730
|
+
omit "Only for Windows." unless Fluent.windows?
|
731
|
+
|
732
|
+
log_path = Pathname(@tmp_dir) + "log" + "fluentd.log"
|
733
|
+
config_path = Pathname(@tmp_dir) + "fluentd.conf"
|
734
|
+
conf = <<~EOC
|
735
|
+
<system>
|
736
|
+
<log>
|
737
|
+
rotate_age 5
|
738
|
+
</log>
|
739
|
+
</system>
|
740
|
+
EOC
|
741
|
+
write_config config_path.to_s, conf
|
743
742
|
|
744
|
-
|
745
|
-
|
746
|
-
|
743
|
+
s = Fluent::Supervisor.new(config_path: config_path.to_s, log_path: log_path.to_s)
|
744
|
+
s.__send__(:setup_global_logger, supervisor: true)
|
745
|
+
$log.out.close
|
747
746
|
|
748
|
-
|
749
|
-
|
750
|
-
|
747
|
+
s = Fluent::Supervisor.new(config_path: config_path.to_s, log_path: log_path.to_s)
|
748
|
+
s.__send__(:setup_global_logger, supervisor: false)
|
749
|
+
$log.out.close
|
751
750
|
|
752
|
-
|
753
|
-
|
751
|
+
ENV["SERVERENGINE_WORKER_ID"] = "1"
|
752
|
+
s = Fluent::Supervisor.new(config_path: config_path.to_s, log_path: log_path.to_s)
|
753
|
+
s.__send__(:setup_global_logger, supervisor: false)
|
754
|
+
$log.out.close
|
754
755
|
|
755
|
-
|
756
|
-
|
756
|
+
assert { log_path.parent.entries.size == 5 } # [".", "..", "logfile.log", ...]
|
757
|
+
ensure
|
758
|
+
ENV.delete("SERVERENGINE_WORKER_ID")
|
759
|
+
end
|
757
760
|
end
|
758
761
|
|
759
762
|
def test_enable_shared_socket
|
@@ -787,14 +790,6 @@ class SupervisorTest < ::Test::Unit::TestCase
|
|
787
790
|
end
|
788
791
|
end
|
789
792
|
|
790
|
-
def test_per_process_path
|
791
|
-
path = Fluent::Supervisor::LoggerInitializer.per_process_path("C:/tmp/test.log", :supervisor, 0)
|
792
|
-
assert_equal(path, "C:/tmp/test-supervisor-0.log")
|
793
|
-
|
794
|
-
path = Fluent::Supervisor::LoggerInitializer.per_process_path("C:/tmp/test.log", :worker, 1)
|
795
|
-
assert_equal(path, "C:/tmp/test-1.log")
|
796
|
-
end
|
797
|
-
|
798
793
|
def create_debug_dummy_logger
|
799
794
|
dl_opts = {}
|
800
795
|
dl_opts[:log_level] = ServerEngine::DaemonLogger::DEBUG
|