class LogStash::Outputs::Redisearch

An redisearch output will store data into Redisearch.

Public Instance Methods

close() click to toggle source

Method is for final bookkeeping and cleanup when plugin thread exit

# File lib/logstash/outputs/redisearch.rb, line 96
def close
    # Force full flush call to ensure that all accumulated messages are flushed.
    buffer_flush(:final => true)
end
flush(events, close=false) click to toggle source

Method is called from Stud::Buffer when max_items/max_interval is reached

# File lib/logstash/outputs/redisearch.rb, line 81
def flush(events, close=false)
  #buffer_flush should pass here the :final boolean value.
  @redisearch_client.add_docs(events)
  @logger.info("Buffer Inserted Successfully", :length => events.length)
end
on_flush_error(e) click to toggle source

Method is called from Stud::Buffer when an error occurs

# File lib/logstash/outputs/redisearch.rb, line 88
def on_flush_error(e)
  @logger.warn("Failed to send backlog of events to Redisearch",
    :exception => e,
    :backtrace => e.backtrace
  )
end
receive(event) click to toggle source

Method is to receive event and encode it in json format.

# File lib/logstash/outputs/redisearch.rb, line 69
def receive(event)
  begin
    @codec.encode(event)
  rescue StandardError => e
    @logger.warn("Error encoding event", :exception => e,
                 :event => event)
    sleep @reconnect_interval
    retry
  end
end
register() click to toggle source

Method is a constructor to this class. Used to intialize buffer, redisearch client and also to create a index if it is not present

# File lib/logstash/outputs/redisearch.rb, line 43
def register
  
  buffer_initialize(
    :max_items => @batch_events,
    :max_interval => @batch_timeout,
  )

  params = {
    "host"=>@host,
    "port"=>@port,
    "index"=>@index,
    "ssl"=>@ssl
  }

  if @password
    params["password"] = @password.value  
  end

  @idx = Index.new(params)
  @redisearch_client = @idx.connect()
  @codec.on_event(&method(:send_to_redisearch))

end
send_to_redisearch(event, payload) click to toggle source

Method to assign uuid to each event (formatting event as per document required by redisearch) and to append each event to buffer

# File lib/logstash/outputs/redisearch.rb, line 103
def send_to_redisearch(event, payload)
  begin
    doc_data = JSON.parse(payload)
    doc_id = @idx.get_id()
    document = [doc_id,doc_data]
    buffer_receive(document)

  rescue => e
    @logger.warn("Failed to send event to Redisearch", :event => event,
                 :exception => e,
                 :backtrace => e.backtrace)
    sleep @reconnect_interval
    retry
  end
end