logstash-plugins / logstash-input-couchdb_changes

This plugin captures the _changes stream from a CouchDB instance
Apache License 2.0
27 stars 22 forks source link

Error: undefined method `[]' for nil:NilClass {:level=>:error} #19

Closed OrangeDog closed 8 years ago

OrangeDog commented 9 years ago

This is using Debian packages from Ubuntu 12.04.

$ ruby --version
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]
$ bin/logstash --version
logstash 1.5.4
$ couchdb -V
couchdb - Apache CouchDB 1.2.0
$ curl http://localhost:5984/my_db
{"db_name":"my_db","doc_count":5919,"doc_del_count":1158442,"update_seq":1739236,"purge_seq":0,"compact_running":false,"disk_size":1404829819,"data_size":1279400465,"instance_start_time":"1441701661856532","disk_format_version":6,"committed_update_seq":1739236}
$ cat test.conf
input { couchdb_changes { db => "my_db" } }
$ bin/logstash -f test.conf
Logstash startup completed
A plugin had an unrecoverable error. Will restart this plugin.
  Plugin: <LogStash::Inputs::CouchDBChanges db=>"my_db", debug=>false, codec=><LogStash::Codecs::Plain charset=>"UTF-8">, host=>"localhost", port=>5984, secure=>false, password=><password>, heartbeat=>1000, keep_revision=>false, ignore_attachments=>true, always_reconnect=>true, reconnect_delay=>10>
  Error: undefined method `[]' for nil:NilClass {:level=>:error}
OrangeDog commented 9 years ago

Seems to work fine though on a CentOS 5 box though.

$ ruby --version
ruby 1.8.7 (2011-12-28 patchlevel 357) [x86_64-linux]
$ bin/logstash --version
logstash 1.5.4
$ couchdb -V
couchdb - Apache CouchDB 1.2.1
OrangeDog commented 9 years ago

Downgrading ruby on the Ubuntu machine didn't change anything.

$ ruby --version
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
untergeek commented 9 years ago

Logstash does not use the system ruby. It uses a bundled JRuby.

untergeek commented 9 years ago

If you'd like to see more, launch Logstash with the --verbose flag, or even with the --debug flag

OrangeDog commented 9 years ago

Noted. Here's the verbose output.

$ bin/logstash --verbose --debug -f ~/test.conf 
No sequence_path set, generating one... {:sequence_path=>"/home/me/.couchdb_seq", :level=>:info}
Pipeline started {:level=>:info}
Logstash startup completed
Connecting to CouchDB _changes stream at: {:host=>"localhost", :port=>"5984", :db=>"my_db", :level=>:info}
A plugin had an unrecoverable error. Will restart this plugin.
  Plugin: <LogStash::Inputs::CouchDBChanges db=>"my_db", debug=>false, codec=><LogStash::Codecs::Plain charset=>"UTF-8">, host=>"localhost", port=>5984, secure=>false, password=><password>, heartbeat=>1000, keep_revision=>false, ignore_attachments=>true, always_reconnect=>true, reconnect_delay=>10>
  Error: undefined method `[]' for nil:NilClass {:level=>:error}
Plugin is finished {:plugin=><LogStash::Inputs::CouchDBChanges db=>"my_db", debug=>false, codec=><LogStash::Codecs::Plain charset=>"UTF-8">, host=>"localhost", port=>5984, secure=>false, password=><password>, heartbeat=>1000, keep_revision=>false, ignore_attachments=>true, always_reconnect=>true, reconnect_delay=>10>, :level=>:info}
untergeek commented 9 years ago

Remove --verbose and use just the --debug, please. Also, what does the input block look like?

OrangeDog commented 9 years ago

Debug output is here: https://gist.github.com/OrangeDog/451d4cbe38af13105501

Input block is given in the first comment:

$ cat test.conf
input { couchdb_changes { db => "my_db" } }
untergeek commented 9 years ago

I can't find an error here. And it does work on other machines? I tested with a fresh install and it's working for me.

What version of Java is on the box in question? That could have an effect.

OrangeDog commented 9 years ago
$ java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

Yes, it works on a centos5 box (java 1.8.0_45). I don't have another ubuntu 12.04 box around to test. I plan to test a centos7 box too.

untergeek commented 9 years ago

I can't explain why it's not working for you on 12.04. I can spin up a version of that in vagrant or docker, but that will take me a while. Something else may be at work, app_armor, SELinux, or the like. I don't know.

OrangeDog commented 9 years ago

Could it be due to the content of couchdb's response, or has it not gotten that far?

untergeek commented 9 years ago

I can't tell from the debug output. It makes no sense that it should work fine on one platform but not on another, though.

OrangeDog commented 9 years ago

After further testing, it's only this install that fails, regardless of which couchdb server or database it's looking at. Installs on other ubuntu machines looking at the same database work fine.

untergeek commented 9 years ago

Sorry to hear you're having a hard time with that one box. I have no idea what you've tried, but wonder if there isn't a network/firewall issue going on.

usebee commented 9 years ago

Hi all, I also got this problem on my Window environment.

This is my conf : input { couchdb_changes { db => "db_name" host => "localhost"
} } output { elasticsearch { host => localhost protocol => http } }

And logs from Logstash was :+1:

A plugin had an unrecoverable error. Will restart this plugin. Plugin: <LogStash::Inputs::CouchDBChanges db=>"db_name", host=> "localhost", debug=>false, codec=><LogStash::Codecs::Plain charset=>"UTF-8">, po rt=>5984, secure=>false, password=>, heartbeat=>1000, keep_revision=>f alse, ignore_attachments=>true, always_reconnect=>true, reconnect_delay=>10> Error: undefined method `[]' for nil:NilClass {:level=>:error}

I tried both LogStash : 1.5.4 and 2.0 within same error.

Any advice ?

Regards

untergeek commented 9 years ago

@usebee I cannot replicate this problem. Please try using the --debug flag and see if more information than https://gist.github.com/OrangeDog/451d4cbe38af13105501 provides is evident.

usebee commented 9 years ago

@untergeek , this is my logs with debug. Could you take a look at it here :+1:

https://drive.google.com/file/d/0B9O4JOQIbX9IQ29ZNzFUR21GVVU/view?usp=sharing

Many thanks

Regards

usebee commented 9 years ago

@untergeek ,

After debug I found it come from CouchDB itself, because CouchDB alway return HTTP 500 error instead of _changes JSON. Then we got that problem.

Seem there're bug with CouchDB or I missing some configuration in CouchDB Server !

Problem is : when url_build without setting from initial_sequence config "since" param will be nil, then CouchDB will return HTTP 500 error.

URI error such as : http://localhost:5984/db_name/_changes?feed=continuous&include_docs=true&since=&heartbeat=1000$limit=10

So in config file we have to set :

couchdb_changes {
    db => "db_name"
    initial_sequence => 0     
} 

Or please set default config when this param not set in your plugin, them problem will be gone.

Hope it could help if anybody got same problem like me !

Regards

untergeek commented 9 years ago

@usebee If the plugin is unable to get a value from the file at sequence_path it should automatically assign an initial_sequence of 0:

https://github.com/logstash-plugins/logstash-input-couchdb_changes/blob/master/lib/logstash/inputs/couchdb_changes.rb#L126

So the question is, why is "since" not getting a value in your situation? You should never have to set initial_sequence except in special situations. Is there a problem with your sequence_path getting set and populated? Perhaps you should manually specify a sequence_path and ensure it's getting written to.

untergeek commented 9 years ago

It seems that a check to see if the file is writable may be in order. I worry about doing this, though, as I'd hate to ruin a sequence number in a file.

usebee commented 9 years ago

@untergeek : In fact, I found in debug log sequence_path not set, and it using default : $HOME/.couchdb_seq and this file had been created as well, but maybe it's not writable with my case.

I'll try to check it more ! But seem we have to check to ensure that file writable or not will be great !

Thanks

untergeek commented 9 years ago

@usebee it may be an environment variable fail in Windows (which may or may not be possible to overcome). I may have to document the need to manually specify a writable sequence_path for Windows environments.

raphaelmerx commented 7 years ago

This is the error you get when your CouchDB requires authentication. After setting the username and password configuration options, the plugin reads successfully from the _changes endpoint.