Class: Fluent::Plugin::TailInput
- Inherits:
-
Input
show all
- Includes:
- Compatibility, DirWatcher, GroupWatch
- Defined in:
- lib/fluent/plugin/in_tail.rb,
lib/fluent/plugin/in_tail.rb,
lib/fluent/plugin/in_tail/io_handler.rb,
lib/fluent/plugin/in_tail/dir_watcher.rb,
lib/fluent/plugin/in_tail/group_watch.rb,
lib/fluent/plugin/in_tail/line_feeder.rb,
lib/fluent/plugin/in_tail/worker_pool.rb,
lib/fluent/plugin/in_tail/stat_watcher.rb,
lib/fluent/plugin/in_tail/tail_watcher.rb,
lib/fluent/plugin/in_tail/compatibility.rb,
lib/fluent/plugin/in_tail/position_file.rb
Overview
Reopen TailInput to keep worker-mode setup and lifecycle helpers grouped
separately from the synchronous file-watching implementation above.
Defined Under Namespace
Modules: Compatibility, DirWatcher, GroupWatch, GroupWatchParams
Classes: Entry, FilePositionEntry, GroupWatcher, LineFeeder, MemoryPositionEntry, MetricsInfo, PositionFile, StatWatcher, TailWatcher, TargetInfo, TimerTrigger, WatcherSetupError, WorkerBatch, WorkerCompatibility, WorkerCompletionWatcher, WorkerPool
Constant Summary
collapse
- RESERVED_CHARS =
['/', '*', '%'].freeze
- WORKER_COMPATIBILITY =
WorkerCompatibility.new(self)
- WORKER_PARSER_TYPES =
%w[
none regexp json csv tsv ltsv msgpack apache apache2 apache_error nginx syslog
].freeze
- WORKER_QUEUE_BYTES =
64 * 1024 * 1024
Constants included
from DirWatcher
DirWatcher::DIR_WATCH_DEBOUNCE_INTERVAL, DirWatcher::GLOB_STAR, DirWatcher::MAX_DIR_PATTERNS, DirWatcher::WILDCARD_CHARS
Constants inherited
from Base
Base::LOCK_FILE_BUCKETS
Configurable::CONFIG_TYPE_REGISTRY
Instance Attribute Summary collapse
Attributes included from GroupWatch
#default_group_key, #group_watchers
#log
Attributes inherited from Base
#under_plugin_development
Instance Method Summary
collapse
-
#build_line_feeder ⇒ Object
TailInput builds its LineFeeder in start, after the configure of a plugin which inherits TailInput is done, so that the parameters set by that plugin are used.
-
#check_dir_permission ⇒ Object
-
#close ⇒ Object
-
#close_watcher_handles ⇒ Object
-
#configure(conf) ⇒ Object
-
#configure_encoding ⇒ Object
-
#configure_tag ⇒ Object
-
#construct_watcher(target_info) ⇒ Object
-
#detach_watcher(tw, ino, close_io = true) ⇒ Object
-
#detach_watcher_after_rotate_wait(tw, ino) ⇒ Object
-
#have_read_capability? ⇒ Boolean
-
#initialize ⇒ TailInput
constructor
A new instance of TailInput.
-
#parse_encoding_param(encoding_name) ⇒ Object
-
#setup_watcher(target_info, pe) ⇒ Object
-
#shutdown ⇒ Object
-
#start ⇒ Object
-
#start_watchers(targets_info) ⇒ Object
-
#statistics ⇒ Object
-
#stop ⇒ Object
-
#stop_watchers(targets_info, immediate: false, unwatched: false, remove_watcher: true) ⇒ Object
-
#throttling_is_enabled?(tw) ⇒ Boolean
-
#update_watcher(tail_watcher, pe, new_inode) ⇒ Object
-
#update_watcher_raw(tail_watcher, pe, new_inode) ⇒ Object
refresh_watchers calls @tails.keys so we don't use stop_watcher -> start_watcher sequence for safety.
Methods included from DirWatcher
#attach_dir_watcher, #brace_group, #detach_dir_watcher, #detach_dir_watchers, #detach_refresh_timer, #dir_path_parts, #existence_path, #existing_dirs, #expand_brace_patterns, #expand_brace_patterns_into, #expand_paths, #expand_paths_raw, #expand_watch_dirs, #expand_watch_dirs_of_pattern, #extended_glob_pattern, #initialize_dir_watchers, #interleave_watch_dirs, #limit_dir_watchers, #literal_glob_pattern, #on_dir_changed, #path_components, #real_path, #refresh_watchers, #refresh_watchers_on_timer, #refresh_watchers_raw, #request_refresh_watchers, #split_brace_alternatives, #take_dir_watcher_rotation_request, #time_dependent_component_index, #trigger_refresh_watchers, #unwatch_removed_inodes, #update_dir_watchers, #use_glob?, #watch_dirs_of_path
#convert_line_to_event, #flush_buffer, #parse_multilines, #parse_singleline, #receive_lines
Methods included from GroupWatch
#add_path_to_group_watcher, #construct_group_key, #construct_groupwatchers, #find_group, #find_group_from_metadata, included
Methods inherited from Input
#metric_callback, #multi_workers_ready?, #zero_downtime_restart_ready?
included
included, #terminate
#plugin_id, #plugin_id_configured?, #plugin_id_for_test?, #plugin_root_dir
Methods inherited from Base
#acquire_worker_lock, #after_shutdown, #after_shutdown?, #after_start, #after_started?, #before_shutdown, #before_shutdown?, #called_in_test?, #closed?, #configured?, #context_router, #context_router=, #fluentd_worker_id, #get_lock_path, #has_router?, #inspect, #multi_workers_ready?, #plugin_root_dir, #reloadable_plugin?, #shutdown?, #started?, #stopped?, #string_safe_encoding, #terminate, #terminated?
#system_config, #system_config_override
#config, #configure_proxy_generate, #configured_section_create, included, lookup_type, register_type
Constructor Details
Returns a new instance of TailInput.
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/fluent/plugin/in_tail.rb', line 61
def initialize
super
@paths = []
@tails = {}
@tails_rotate_wait = {}
@pf_file = nil
@watcher_refresh_monitor = Monitor.new
@pf = nil
@ignore_list = []
@shutdown_start_time = nil
@metrics = nil
@startup = true
@capability = Fluent::Capability.new(:current_process)
initialize_dir_watchers
end
|
Instance Attribute Details
#paths ⇒ Object
Returns the value of attribute paths.
143
144
145
|
# File 'lib/fluent/plugin/in_tail.rb', line 143
def paths
@paths
end
|
Instance Method Details
#build_line_feeder ⇒ Object
TailInput builds its LineFeeder in start, after the configure of a plugin
which inherits TailInput is done, so that the parameters set by that
plugin are used.
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
|
# File 'lib/fluent/plugin/in_tail.rb', line 372
def build_line_feeder
LineFeeder.new(
parser: @parser,
router_provider: method(:router),
log: log,
tag: @tag,
tag_prefix: @tag_prefix,
tag_suffix: @tag_suffix,
path_key: @path_key,
emit_unmatched_lines: @emit_unmatched_lines,
multiline_mode: @multiline_mode,
parse_handler: method(@multiline_mode ? :parse_multilines : :parse_singleline),
convert_handler: method(:convert_line_to_event),
flush_handler: method(:flush_buffer),
)
end
|
#check_dir_permission ⇒ Object
246
247
248
249
250
251
252
253
254
255
256
257
258
|
# File 'lib/fluent/plugin/in_tail.rb', line 246
def check_dir_permission
expand_paths_raw.select { |path|
not File.exist?(path)
}.each { |path|
inaccessible_dir = Pathname.new(File.expand_path(path))
.ascend
.reverse_each
.find { |p| p.directory? && !p.executable? }
if inaccessible_dir
log.warn "Skip #{path} because '#{inaccessible_dir}' lacks execute permission."
end
}
end
|
#close ⇒ Object
355
356
357
358
359
360
361
362
|
# File 'lib/fluent/plugin/in_tail.rb', line 355
def close
super
@worker_completion_watcher&.close
close_watcher_handles
@pf_file.close if @pf_file && !@pf_file.closed?
end
|
#close_watcher_handles ⇒ Object
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
|
# File 'lib/fluent/plugin/in_tail.rb', line 482
def close_watcher_handles
if @worker_pool
close_worker_watcher_handles
return
end
@tails.keys.each do |path|
tw = @tails.delete(path)
if tw
tw.close
end
end
@tails_rotate_wait.keys.each do |tw|
tw.close
end
end
|
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
# File 'lib/fluent/plugin/in_tail.rb', line 145
def configure(conf)
@variable_store = Fluent::VariableStore.fetch_or_build(:in_tail)
compat_parameters_convert(conf, :parser)
parser_config = conf.elements('parse').first
unless parser_config
raise Fluent::ConfigError, "<parse> section is required."
end
(1..Fluent::Plugin::MultilineParser::FORMAT_MAX_NUM).each do |n|
parser_config["format#{n}"] = conf["format#{n}"] if conf["format#{n}"]
end
parser_config['unmatched_lines'] = conf['emit_unmatched_lines']
super
if @dir_watcher_limit <= 0
raise Fluent::ConfigError, "dir_watcher_limit must be greater than zero"
end
if !@enable_watch_timer && !@enable_stat_watcher
raise Fluent::ConfigError, "either of enable_watch_timer or enable_stat_watcher must be true"
end
raise Fluent::ConfigError, "'num_threads' must be greater than 0" unless @num_threads.positive?
if @enable_dir_watcher && !@enable_stat_watcher
log.info(
'enable_stat_watcher is disabled for files,' +
' but enable_dir_watcher still uses directory stat watchers' +
' and may use inotify'
)
end
if @glob_policy == :always && @path_delimiter == ','
raise Fluent::ConfigError, "cannot use glob_policy as always with the default path_delimiter: `,\""
end
if @glob_policy == :extended && /\{.*,.*\}/.match?(@path) && extended_glob_pattern(@path)
raise Fluent::ConfigError, "cannot include curly braces with glob patterns in `#{@path}\". Use glob_policy always instead."
end
if RESERVED_CHARS.include?(@path_delimiter)
rc = RESERVED_CHARS.join(', ')
raise Fluent::ConfigError, "#{rc} are reserved words: #{@path_delimiter}"
end
@paths = @path.split(@path_delimiter).map(&:strip).uniq
if @paths.empty?
raise Fluent::ConfigError, "tail: 'path' parameter is required on tail input"
end
if @path_timezone
Fluent::Timezone.validate!(@path_timezone)
@path_formatters = @paths.map{|path| [path, Fluent::Timezone.formatter(@path_timezone, path)]}.to_h
@exclude_path_formatters = @exclude_path.map{|path| [path, Fluent::Timezone.formatter(@path_timezone, path)]}.to_h
end
check_dir_permission unless Fluent.windows?
if @pos_file
if @variable_store.key?(@pos_file) && !called_in_test?
plugin_id_using_this_path = @variable_store[@pos_file]
raise Fluent::ConfigError, "Other 'in_tail' plugin already use same pos_file path: plugin_id = #{plugin_id_using_this_path}, pos_file path = #{@pos_file}"
end
@variable_store[@pos_file] = self.plugin_id
else
if @follow_inodes
raise Fluent::ConfigError, "Can't follow inodes without pos_file configuration parameter"
end
log.warn "'pos_file PATH' parameter is not set to a 'tail' source."
log.warn "this parameter is highly recommended to save the position to resume tailing."
end
configure_tag
configure_encoding
@multiline_mode = parser_config["@type"].include?("multiline")
@file_perm = system_config.file_permission || Fluent::DEFAULT_FILE_PERMISSION
@dir_perm = system_config.dir_permission || Fluent::DEFAULT_DIR_PERMISSION
@parser = parser_create(usage: parser_config['usage'] || @parser_configs.first.usage)
if @read_bytes_limit_per_second > 0
if !@enable_watch_timer
raise Fluent::ConfigError, "Need to enable watch timer when using log throttling feature"
end
min_bytes = TailWatcher::IOHandler::BYTES_TO_READ
if @read_bytes_limit_per_second < min_bytes
log.warn "Should specify greater equal than #{min_bytes}. Use #{min_bytes} for read_bytes_limit_per_second"
@read_bytes_limit_per_second = min_bytes
end
end
opened_file_metrics = metrics_create(namespace: "fluentd", subsystem: "input", name: "files_opened_total", help_text: "Total number of opened files")
closed_file_metrics = metrics_create(namespace: "fluentd", subsystem: "input", name: "files_closed_total", help_text: "Total number of closed files")
rotated_file_metrics = metrics_create(namespace: "fluentd", subsystem: "input", name: "files_rotated_total", help_text: "Total number of rotated files")
throttling_metrics = metrics_create(namespace: "fluentd", subsystem: "input", name: "files_throttled_total", help_text: "Total number of times throttling occurs per file when throttling enabled")
tracked_file_metrics = metrics_create(namespace: "fluentd", subsystem: "input", name: "files_tracked_count", help_text: "Number of tracked files", prefer_gauge: true)
@metrics = MetricsInfo.new(opened_file_metrics, closed_file_metrics, rotated_file_metrics, throttling_metrics, tracked_file_metrics)
end
|
271
272
273
274
275
276
277
278
279
280
281
282
283
|
# File 'lib/fluent/plugin/in_tail.rb', line 271
def configure_encoding
unless @encoding
if @from_encoding
raise Fluent::ConfigError, "tail: 'from_encoding' parameter must be specified with 'encoding' parameter."
end
end
@encoding = parse_encoding_param(@encoding) if @encoding
@from_encoding = parse_encoding_param(@from_encoding) if @from_encoding
if @encoding && (@encoding == @from_encoding)
log.warn "'encoding' and 'from_encoding' are same encoding. No effect"
end
end
|
260
261
262
263
264
265
266
267
268
269
|
# File 'lib/fluent/plugin/in_tail.rb', line 260
def configure_tag
if @tag.index('*')
@tag_prefix, @tag_suffix = @tag.split('*')
@tag_prefix ||= ''
@tag_suffix ||= ''
else
@tag_prefix = nil
@tag_suffix = nil
end
end
|
#construct_watcher(target_info) ⇒ Object
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
|
# File 'lib/fluent/plugin/in_tail.rb', line 428
def construct_watcher(target_info)
path = target_info.path
begin
target_info.ino = Fluent::FileWrapper.stat(path).ino
rescue Errno::ENOENT, Errno::EACCES
log.warn "stat() for #{path} failed. Continuing without tailing it."
return
end
pe = nil
if @pf
pe = @pf[target_info]
pe.update(target_info.ino, 0) if @read_from_head && pe.read_inode.zero?
end
begin
tw = setup_watcher(target_info, pe)
rescue WatcherSetupError => e
log.warn "Skip #{path} because unexpected setup error happens: #{e}"
return
end
@tails[path] = tw
tw.ready_to_shutdown(@shutdown_start_time) if @shutdown_start_time
tw.on_notify
end
|
#detach_watcher(tw, ino, close_io = true) ⇒ Object
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
|
# File 'lib/fluent/plugin/in_tail.rb', line 553
def detach_watcher(tw, ino, close_io = true)
if @follow_inodes && tw.ino != ino
log.warn("detach_watcher could be detaching an unexpected tail_watcher with a different ino.",
path: tw.path, actual_ino_in_tw: tw.ino, expect_ino_to_close: ino)
end
tw.watchers.each do |watcher|
event_loop_detach(watcher)
end
tw.detach(@shutdown_start_time)
defer_worker_completion = tw.pending? || @worker_waiting_watchers&.include?(tw)
if close_io && defer_worker_completion
tw.defer_close
@worker_detached_watchers << tw unless @worker_detached_watchers.include?(tw)
end
tw.close if close_io
tw.group_watcher&.delete(tw.path, tw)
if @pf && tw.unwatched && (@follow_inodes || !@tails[tw.path])
target_info = TargetInfo.new(tw.path, ino)
if defer_worker_completion
@worker_deferred_unwatch[tw] = target_info
else
@pf.unwatch(target_info)
end
end
end
|
#detach_watcher_after_rotate_wait(tw, ino) ⇒ Object
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
|
# File 'lib/fluent/plugin/in_tail.rb', line 590
def detach_watcher_after_rotate_wait(tw, ino)
if @open_on_every_update
detach_watcher(tw, ino)
return
end
return if @tails_rotate_wait[tw]
if throttling_is_enabled?(tw)
start_time_to_wait = Fluent::Clock.now
timer = timer_execute(:in_tail_close_watcher, 1, repeat: true) do
unless @enable_watch_timer
begin
tw.read_more
rescue => e
log.error e.to_s
log.error_backtrace
end
end
elapsed = Fluent::Clock.now - start_time_to_wait
if tw.eof? && elapsed >= @rotate_wait
timer.detach
@tails_rotate_wait.delete(tw)
detach_watcher(tw, ino)
end
end
@tails_rotate_wait[tw] = { ino: ino, timer: timer }
else
timer = timer_execute(:in_tail_close_watcher, @rotate_wait, repeat: false) do
@tails_rotate_wait.delete(tw)
detach_watcher(tw, ino)
end
@tails_rotate_wait[tw] = { ino: ino, timer: timer }
end
end
|
#have_read_capability? ⇒ Boolean
364
365
366
367
|
# File 'lib/fluent/plugin/in_tail.rb', line 364
def have_read_capability?
@capability.have_capability?(:effective, :dac_read_search) ||
@capability.have_capability?(:effective, :dac_override)
end
|
#parse_encoding_param(encoding_name) ⇒ Object
285
286
287
288
289
290
291
|
# File 'lib/fluent/plugin/in_tail.rb', line 285
def parse_encoding_param(encoding_name)
begin
Encoding.find(encoding_name) if encoding_name
rescue ArgumentError => e
raise Fluent::ConfigError, e.message
end
end
|
#setup_watcher(target_info, pe) ⇒ Object
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
|
# File 'lib/fluent/plugin/in_tail.rb', line 389
def setup_watcher(target_info, pe)
@line_feeder ||= build_line_feeder
file_feed = @line_feeder.new_file_feed(flush_interval: @multiline_flush_interval)
read_from_head = !@startup || @read_from_head
tw = TailWatcher.new(target_info, pe, log, read_from_head, @follow_inodes, method(:update_watcher), file_feed, method(:io_handler), @metrics)
tw.ready_to_shutdown(@shutdown_start_time) if @shutdown_start_time
if @enable_watch_timer
tt = TimerTrigger.new(1, log) { tw.on_notify }
tw.register_watcher(tt)
end
if @enable_stat_watcher
tt = StatWatcher.new(target_info.path, log) { tw.on_notify }
tw.register_watcher(tt)
end
tw.watchers.each do |watcher|
event_loop_attach(watcher)
end
tw.group_watcher = add_path_to_group_watcher(target_info.path, tw)
tw
rescue => e
if tw
tw.watchers.each do |watcher|
event_loop_detach(watcher)
end
tw.detach(@shutdown_start_time)
tw.close
end
raise e
end
|
#shutdown ⇒ Object
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
# File 'lib/fluent/plugin/in_tail.rb', line 327
def shutdown
@shutdown_start_time = Fluent::Clock.now
(@tails.values + @tails_rotate_wait.keys).uniq.each do |tw|
tw.ready_to_shutdown(@shutdown_start_time)
end
@watcher_refresh_monitor.synchronize {}
detach_dir_watchers
detach_refresh_timer
stop_watchers(existence_path, immediate: true, remove_watcher: false)
@tails_rotate_wait.dup.each do |tw, rotation|
event_loop_detach(rotation[:timer]) if @worker_pool
detach_watcher(tw, rotation[:ino], false)
end
shutdown_worker_pool
@pf_file.close if @pf_file && !@worker_pool
super
end
|
#start ⇒ Object
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
# File 'lib/fluent/plugin/in_tail.rb', line 293
def start
super
@line_feeder = build_line_feeder
configure_worker_mode if @num_threads > 1
if @pos_file
pos_file_dir = File.dirname(@pos_file)
FileUtils.mkdir_p(pos_file_dir, mode: @dir_perm) unless Dir.exist?(pos_file_dir)
@pf_file = File.open(@pos_file, File::RDWR|File::CREAT|File::BINARY, @file_perm)
@pf_file.sync = true
@pf = PositionFile.load(@pf_file, @follow_inodes, expand_paths, logger: log)
if @pos_file_compaction_interval
timer_execute(:in_tail_refresh_compact_pos_file, @pos_file_compaction_interval) do
log.info('Clean up the pos file')
@pf.try_compact
end
end
end
refresh_watchers unless @skip_refresh_on_startup
update_dir_watchers
timer_execute(:in_tail_refresh_watchers, @refresh_interval, &method(:refresh_watchers_on_timer))
end
|
#start_watchers(targets_info) ⇒ Object
457
458
459
460
461
462
|
# File 'lib/fluent/plugin/in_tail.rb', line 457
def start_watchers(targets_info)
targets_info.each_value {|target_info|
construct_watcher(target_info)
break if before_shutdown?
}
end
|
#statistics ⇒ Object
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
|
# File 'lib/fluent/plugin/in_tail.rb', line 633
def statistics
stats = super
stats = {
'input' => stats["input"].merge({
'opened_file_count' => @metrics.opened.get,
'closed_file_count' => @metrics.closed.get,
'rotated_file_count' => @metrics.rotated.get,
'throttled_log_count' => @metrics.throttled.get,
'tracked_file_count' => @metrics.tracked.get,
})
}
if @worker_pool
stats['input'].merge!(
'worker_pending_batch_count' => @worker_metrics[:pending_batches].get,
'worker_pending_bytes' => @worker_metrics[:pending_bytes].get,
'worker_parse_error_count' => @worker_metrics[:parse_errors].get,
)
end
stats
end
|
#stop ⇒ Object
319
320
321
322
323
324
325
|
# File 'lib/fluent/plugin/in_tail.rb', line 319
def stop
if @variable_store
@variable_store.delete(@pos_file)
end
super
end
|
#stop_watchers(targets_info, immediate: false, unwatched: false, remove_watcher: true) ⇒ Object
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
|
# File 'lib/fluent/plugin/in_tail.rb', line 464
def stop_watchers(targets_info, immediate: false, unwatched: false, remove_watcher: true)
targets_info.each_value { |target_info|
if remove_watcher
tw = @tails.delete(target_info.path)
else
tw = @tails[target_info.path]
end
if tw
tw.unwatched = unwatched
if immediate
detach_watcher(tw, target_info.ino, false)
else
detach_watcher_after_rotate_wait(tw, target_info.ino)
end
end
}
end
|
#throttling_is_enabled?(tw) ⇒ Boolean
584
585
586
587
588
|
# File 'lib/fluent/plugin/in_tail.rb', line 584
def throttling_is_enabled?(tw)
return true if @read_bytes_limit_per_second > 0
return true if tw.group_watcher && tw.group_watcher.limit >= 0
false
end
|
#update_watcher(tail_watcher, pe, new_inode) ⇒ Object
499
500
501
502
503
504
505
|
# File 'lib/fluent/plugin/in_tail.rb', line 499
def update_watcher(tail_watcher, pe, new_inode)
@watcher_refresh_monitor.synchronize do
return if @shutdown_start_time
update_watcher_raw(tail_watcher, pe, new_inode)
end
end
|
#update_watcher_raw(tail_watcher, pe, new_inode) ⇒ Object
refresh_watchers calls @tails.keys so we don't use stop_watcher -> start_watcher sequence for safety.
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
|
# File 'lib/fluent/plugin/in_tail.rb', line 508
def update_watcher_raw(tail_watcher, pe, new_inode)
if @follow_inodes && new_inode.nil?
@tails.delete(tail_watcher.path)
detach_watcher_after_rotate_wait(tail_watcher, pe.read_inode)
return
end
path = tail_watcher.path
log.info("detected rotation of #{path}; waiting #{@rotate_wait} seconds")
if @pf
pe_inode = pe.read_inode
target_info_from_position_entry = TargetInfo.new(path, pe_inode)
unless pe_inode == @pf[target_info_from_position_entry].read_inode
log.warn "Skip update_watcher because watcher has been already updated by other inotify event",
path: path, inode: pe.read_inode, inode_in_pos_file: @pf[target_info_from_position_entry].read_inode
return
end
end
new_target_info = TargetInfo.new(path, new_inode)
if @follow_inodes
new_position_entry = @pf[new_target_info]
if new_position_entry.read_inode == 0
@tails[path] = setup_watcher(new_target_info, new_position_entry)
@tails[path].ready_to_shutdown(@shutdown_start_time) if @shutdown_start_time
@tails[path].on_notify
end
else
@tails[path] = setup_watcher(new_target_info, pe)
@tails[path].ready_to_shutdown(@shutdown_start_time) if @shutdown_start_time
@tails[path].on_notify
end
detach_watcher_after_rotate_wait(tail_watcher, pe.read_inode)
end
|