lib/logstash/inputs/couchdb_changes.rb in logstash-input-couchdb_changes-3.0.2 vs lib/logstash/inputs/couchdb_changes.rb in logstash-input-couchdb_changes-3.1.0

- old
+ new

@@ -62,10 +62,14 @@ # If you specify this value, it is anticipated that you will # only be doing so for an initial read under special circumstances # and that you will unset this value afterwards. config :initial_sequence, :validate => :number + # Preserve the CouchDB document id "_id" value in the + # output. + config :keep_id, :validate => :boolean, :default => false + # Preserve the CouchDB document revision "_rev" value in the # output. config :keep_revision, :validate => :boolean, :default => false # Future feature! Until implemented, changing this from the default @@ -110,11 +114,20 @@ @sequencedb = SequenceDB::File.new(@sequence_path) @path = '/' + @db + '/_changes' @scheme = @secure ? 'https' : 'http' - @sequence = @initial_sequence ? @initial_sequence : @sequencedb.read + if !@initial_sequence.nil? + @logger.info("initial_sequence is set, writing to filesystem ...", + :initial_sequence => @initial_sequence, :sequence_path => @sequence_path) + @sequencedb.write(@initial_sequence) + @sequence = @initial_sequence + else + @logger.info("No initial_sequence set, reading from filesystem ...", + :sequence_path => @sequence_path) + @sequence = @sequencedb.read + end end module SequenceDB class File @@ -170,12 +183,12 @@ end end end end rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, - Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e - @logger.error("Connection problem encountered: Retrying connection in 10 seconds...", :error => e.to_s) + Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, SocketError => e + @logger.error("Connection problem encountered: Retrying connection in " + @reconnect_delay.to_s + " seconds...", :error => e.to_s, :host => @host.to_s, :port => @port.to_s, :db => @db) retry if reconnect? rescue Errno::EBADF => e @logger.error("Unable to connect: Bad file descriptor: ", :error => e.to_s) retry if reconnect? rescue ArgumentError => e @@ -212,10 +225,10 @@ if data['doc']['_deleted'] hash['@metadata']['action'] = 'delete' else hash['doc'] = data['doc'] hash['@metadata']['action'] = 'update' - hash['doc'].delete('_id') + hash['doc'].delete('_id') unless @keep_id hash['doc_as_upsert'] = true hash['doc'].delete('_rev') unless @keep_revision end hash['@metadata']['seq'] = data['seq'] event = LogStash::Event.new(hash)