Module: LogProcessor

Included in:
LogStash::Inputs::S3SNSSQS
Defined in:
lib/logstash/inputs/s3snssqs/log_processor.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



9
10
11
# File 'lib/logstash/inputs/s3snssqs/log_processor.rb', line 9

def self.included(base)
  base.extend(self)
end

Instance Method Details

#process(record, logstash_event_queue) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/logstash/inputs/s3snssqs/log_processor.rb', line 13

def process(record, logstash_event_queue)
  file = record[:local_file]
  codec = @codec_factory.get_codec(record)
  folder = record[:folder]
  type = @type_by_folder.fetch(record[:bucket],{})[folder]
   = {}
  line_count = 0
  event_count = 0
  #start_time = Time.now
  file_t0 = Process.clock_gettime(Process::CLOCK_MONOTONIC) #PROFILING
  read_file(file) do |line|
    line_count += 1
    if stop?
      @logger.warn("[#{Thread.current[:name]}] Abort reading in the middle of the file, we will read it again when logstash is started")
      throw :skip_delete
    end
    begin
      codec.decode(line) do |event|
        event_count += 1
        decorate_event(event, , type, record[:key], record[:bucket], record[:s3_data])
        #event_time = Time.now #PROFILING
        #event.set("[@metadata][progress][begin]", start_time)
        #event.set("[@metadata][progress][index_time]", event_time)
        #event.set("[@metadata][progress][line]", line_count)
        logstash_event_queue << event
      end
    rescue Exception => e
      @logger.error("[#{Thread.current[:name]}] Unable to decode line", :line => line, :error => e)
    end
  end
  file_t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC) #PROFILING
  processing_time = (file_t1 - file_t0)
  #@logger.warn("[#{Thread.current[:name]}] Completed long running File ( took #{processing_time} ) s", file: record[:key], events: event_count, processing_time: processing_time  ) if processing_time > 600.0 #PROFILING
  # ensure any stateful codecs (such as multi-line ) are flushed to the queue
  codec.flush do |event|
    event_count += 1
    decorate_event(event, , type, record[:key], record[:bucket], record[:s3_data])
    @logger.debug("[#{Thread.current[:name]}] Flushing an incomplete event", :event => event.to_s)
    logstash_event_queue << event
  end
  # signal completion:
  return true
end