Module: Fluent::Plugin::TailInput::GroupWatch
- Included in:
- Fluent::Plugin::TailInput
- Defined in:
- lib/fluent/plugin/in_tail/group_watch.rb
Instance Attribute Summary collapse
-
#default_group_key ⇒ Object
readonly
Returns the value of attribute default_group_key.
-
#group_watchers ⇒ Object
readonly
Returns the value of attribute group_watchers.
Class Method Summary collapse
Instance Method Summary collapse
- #add_path_to_group_watcher(path) ⇒ Object
- #configure(conf) ⇒ Object
- #construct_group_key(named_captures) ⇒ Object
- #construct_groupwatchers ⇒ Object
- #find_group(metadata) ⇒ Object
- #find_group_from_metadata(path) ⇒ Object
- #initialize ⇒ Object
- #remove_path_from_group_watcher(path) ⇒ Object
Instance Attribute Details
#default_group_key ⇒ Object (readonly)
Returns the value of attribute default_group_key.
51 52 53 |
# File 'lib/fluent/plugin/in_tail/group_watch.rb', line 51 def default_group_key @default_group_key end |
#group_watchers ⇒ Object (readonly)
Returns the value of attribute group_watchers.
51 52 53 |
# File 'lib/fluent/plugin/in_tail/group_watch.rb', line 51 def group_watchers @group_watchers end |
Class Method Details
.included(mod) ⇒ Object
47 48 49 |
# File 'lib/fluent/plugin/in_tail/group_watch.rb', line 47 def self.included(mod) mod.include GroupWatchParams end |
Instance Method Details
#add_path_to_group_watcher(path) ⇒ Object
81 82 83 84 85 86 |
# 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 = (path) group_watcher.add(path) unless group_watcher.include?(path) group_watcher end |
#configure(conf) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# 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) ⇒ Object
94 95 96 97 98 99 100 101 102 |
# 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 ⇒ Object
104 105 106 107 108 109 |
# 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) ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/fluent/plugin/in_tail/group_watch.rb', line 111 def find_group() = construct_group_key() gw_key = @group_watchers.keys.find { |regexp| .match?(regexp) && regexp != @default_group_key } gw_key ||= @default_group_key @group_watchers[gw_key] end |
#find_group_from_metadata(path) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/fluent/plugin/in_tail/group_watch.rb', line 119 def (path) begin = @group.pattern.match(path).named_captures group_watcher = find_group() 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 |
#initialize ⇒ Object
53 54 55 56 57 58 |
# File 'lib/fluent/plugin/in_tail/group_watch.rb', line 53 def initialize super @group_watchers = {} @group_keys = nil @default_group_key = nil end |
#remove_path_from_group_watcher(path) ⇒ Object
88 89 90 91 92 |
# File 'lib/fluent/plugin/in_tail/group_watch.rb', line 88 def remove_path_from_group_watcher(path) return if @group.nil? group_watcher = (path) group_watcher.delete(path) end |