Class: Fluent::Plugin::ConcatFilter
- Inherits:
-
Filter
- Object
- Filter
- Fluent::Plugin::ConcatFilter
- Defined in:
- lib/fluent/plugin/filter_concat.rb
Defined Under Namespace
Classes: TimeoutError
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #filter_stream(tag, es) ⇒ Object
-
#initialize ⇒ ConcatFilter
constructor
A new instance of ConcatFilter.
- #shutdown ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ ConcatFilter
Returns a new instance of ConcatFilter.
43 44 45 46 47 48 49 50 51 |
# File 'lib/fluent/plugin/filter_concat.rb', line 43 def initialize super @buffer = Hash.new {|h, k| h[k] = [] } @timeout_map_mutex = Thread::Mutex.new @timeout_map_mutex.synchronize do @timeout_map = Hash.new {|h, k| h[k] = Fluent::Engine.now } end end |
Instance Method Details
#configure(conf) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/fluent/plugin/filter_concat.rb', line 53 def configure(conf) super if @n_lines.nil? && @multiline_start_regexp.nil? && @multiline_end_regexp.nil? && @partial_key.nil? && !@use_partial_metadata raise Fluent::ConfigError, "Either n_lines, multiline_start_regexp, multiline_end_regexp, partial_key or use_partial_metadata is required" end if @n_lines && (@multiline_start_regexp || @multiline_end_regexp) raise Fluent::ConfigError, "n_lines and multiline_start_regexp/multiline_end_regexp are exclusive" end if @partial_key && @n_lines raise Fluent::ConfigError, "partial_key and n_lines are exclusive" end if @partial_key && (@multiline_start_regexp || @multiline_end_regexp) raise Fluent::ConfigError, "partial_key and multiline_start_regexp/multiline_end_regexp are exclusive" end if @partial_key && @partial_value.nil? raise Fluent::ConfigError, "partial_value is required when partial_key is specified" end if @use_partial_metadata && @n_lines raise Fluent::ConfigError, "user_partial_metadata and n_lines are exclusive" end if @use_partial_metadata && (@multiline_start_regexp || @multiline_end_regexp) raise Fluent::ConfigError, "user_partial_metadata and multiline_start_regexp/multiline_end_regexp are exclusive" end if @use_partial_metadata && @partial_key raise Fluent::ConfigError, "user_partial_metadata and partial_key are exclusive" end @mode = nil case when @n_lines @mode = :line when @partial_key @mode = :partial when @use_partial_metadata @mode = :partial_metadata when @multiline_start_regexp || @multiline_end_regexp @mode = :regexp if @multiline_start_regexp @multiline_start_regexp = Regexp.compile(@multiline_start_regexp[1..-2]) end if @multiline_end_regexp @multiline_end_regexp = Regexp.compile(@multiline_end_regexp[1..-2]) end if @continuous_line_regexp @continuous_line_regexp = Regexp.compile(@continuous_line_regexp[1..-2]) end end end |
#filter_stream(tag, es) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/fluent/plugin/filter_concat.rb', line 115 def filter_stream(tag, es) new_es = Fluent::MultiEventStream.new es.each do |time, record| if /\Afluent\.(?:trace|debug|info|warn|error|fatal)\z/ =~ tag new_es.add(time, record) next end unless record.key?(@key) new_es.add(time, record) next end if @mode == :partial unless record.key?(@partial_key) new_es.add(time, record) next end end if @mode == :partial_metadata unless record.key?("partial_message") new_es.add(time, record) next end end begin flushed_es = process(tag, time, record) unless flushed_es.empty? flushed_es.each do |_time, new_record| time = _time if @use_first_timestamp merged_record = record.merge(new_record) case @mode when :partial merged_record.delete(@partial_key) unless @keep_partial_key when :partial_metadata unless @keep_partial_metadata merged_record.delete("partial_message") merged_record.delete("partial_id") merged_record.delete("partial_ordinal") merged_record.delete("partial_last") end end new_es.add(time, merged_record) end end rescue => e router.emit_error_event(tag, time, record, e) end end new_es end |
#shutdown ⇒ Object
109 110 111 112 113 |
# File 'lib/fluent/plugin/filter_concat.rb', line 109 def shutdown @finished = true flush_remaining_buffer super end |
#start ⇒ Object
103 104 105 106 107 |
# File 'lib/fluent/plugin/filter_concat.rb', line 103 def start super @finished = false timer_execute(:filter_concat_timer, 1, &method(:on_timer)) end |