module Fluent::Plugin::TailInput::GroupWatch
Attributes
default_group_key[R]
group_watchers[R]
Public Class Methods
included(mod)
click to toggle source
# File lib/fluent/plugin/in_tail/group_watch.rb, line 47 def self.included(mod) mod.include GroupWatchParams end
new()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_tail/group_watch.rb, line 53 def initialize super @group_watchers = {} @group_keys = nil @default_group_key = nil end
Public Instance Methods
add_path_to_group_watcher(path)
click to toggle source
# File lib/fluent/plugin/in_tail/group_watch.rb, line 81 def add_path_to_group_watcher(path) return nil if @group.nil? group_watcher = find_group_from_metadata(path) group_watcher.add(path) unless group_watcher.include?(path) group_watcher end
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_tail/group_watch.rb, line 60 def configure(conf) super unless @group.nil? ## Ensuring correct time period syntax @group.rule.each { |rule| raise "Metadata Group Limit >= DEFAULT_LIMIT" unless rule.limit >= GroupWatchParams::DEFAULT_LIMIT } @group_keys = Regexp.compile(@group.pattern).named_captures.keys @default_group_key = ([GroupWatchParams::DEFAULT_KEY] * @group_keys.length).join(GroupWatchParams::REGEXP_JOIN) ## Ensures that "specific" rules (with larger number of `rule.match` keys) ## have a higher priority against "generic" rules (with less number of `rule.match` keys). ## This will be helpful when a file satisfies more than one rule. @group.rule.sort_by! { |rule| -rule.match.length() } construct_groupwatchers @group_watchers[@default_group_key] ||= GroupWatcher.new(@group.rate_period, GroupWatchParams::DEFAULT_LIMIT) end end
construct_group_key(named_captures)
click to toggle source
# File lib/fluent/plugin/in_tail/group_watch.rb, line 94 def construct_group_key(named_captures) match_rule = [] @group_keys.each { |key| match_rule.append(named_captures.fetch(key, GroupWatchParams::DEFAULT_KEY)) } match_rule = match_rule.join(GroupWatchParams::REGEXP_JOIN) match_rule end
construct_groupwatchers()
click to toggle source
# File lib/fluent/plugin/in_tail/group_watch.rb, line 104 def construct_groupwatchers @group.rule.each { |rule| match_rule = construct_group_key(rule.match) @group_watchers[match_rule] ||= GroupWatcher.new(@group.rate_period, rule.limit) } end
find_group(metadata)
click to toggle source
# File lib/fluent/plugin/in_tail/group_watch.rb, line 111 def find_group(metadata) metadata_key = construct_group_key(metadata) gw_key = @group_watchers.keys.find { |regexp| metadata_key.match?(regexp) && regexp != @default_group_key } gw_key ||= @default_group_key @group_watchers[gw_key] end
find_group_from_metadata(path)
click to toggle source
# File lib/fluent/plugin/in_tail/group_watch.rb, line 119 def find_group_from_metadata(path) begin metadata = @group.pattern.match(path).named_captures group_watcher = find_group(metadata) rescue log.warn "Cannot find group from metadata, Adding file in the default group" group_watcher = @group_watchers[@default_group_key] end group_watcher end
remove_path_from_group_watcher(path)
click to toggle source
# File lib/fluent/plugin/in_tail/group_watch.rb, line 88 def remove_path_from_group_watcher(path) return if @group.nil? group_watcher = find_group_from_metadata(path) group_watcher.delete(path) end