logstash-plugins / logstash-input-gelf

Apache License 2.0
20 stars 39 forks source link

Tests hangs on Windows #22

Closed gmoskovicz closed 6 years ago

gmoskovicz commented 8 years ago

Setting the environment variable to debug:

env:TEST_DEBUG = "true"

Shows that the UDP connection is not working as expected. Here is the information from the output:

[33mgelf listener died 
{
    : exception=>#<SocketError: bind: nameorservicenotknown>,
    : backtrace=>[
        "org/jruby/ext/socket
/RubyUDPSocket.java:160:in `bind'",
        "C:/jruby/lib/ruby/gems/shared/gems/logstash-input-gelf-2.0.2/lib/logstash/inputs/ge
lf.rb:84:in `udp_listener'",
        "C:/jruby/lib/ruby/gems/shared/gems/logstash-input-gelf-2.0.2/lib/logstash/inputs/gelf.rb:6
3:in `run'",
        "C:/jruby/lib/ruby/gems/shared/gems/logstash-core-2.0.0.beta3-java/lib/logstash/pipeline.rb:180:in `inputwo
rker'",
        "C:/jruby/lib/ruby/gems/shared/gems/logstash-core-2.0.0.beta3-java/lib/logstash/pipeline.rb:174:in `start_input'
"
    ],
    : level=>: warn,
    : file=>"/jruby/lib/ruby/gems/shared/gems/logstash-input-gelf-2.0.2/lib/logstash/inputs/gelf.rb",
    : line=>"66",
    : method=>"run"
}
←[0m
gmoskovicz commented 8 years ago

Prior to this, we can see a message for the Listener starting:

←[32mStarting gelf listener
{
    : address=>"127.0.0.1:12201",
    : level=>: info,
    : file=>"/jruby/lib/ruby/gems/shared/gems/logsta
sh-input-gelf-2.0.2/lib/logstash/inputs/gelf.rb",
    : line=>"81",
    : method=>"udp_listener"
}
←[0m
gmoskovicz commented 8 years ago

This is the main reason why the Plugins tests are hanging. There is a socket error binding 127.0.0.1:12201.

gmoskovicz commented 8 years ago

CC @ph @suyograo

gmoskovicz commented 8 years ago

The very first message looks related:

←[33mgelf listener died 
{
    : exception=>#<RuntimeError: expectedUTF-8encodingforvalue=127.0.0.1,
    encoding=#<Encoding: Windows-1252>>,
    : backtrace=>[
        "C:/jruby/lib/ruby/gems/shared/gems/logstash-core-2.0.0.beta3-java/lib/logstash/event.rb:264:
in `validate_value'",
        "C:/jruby/lib/ruby/gems/shared/gems/logstash-devutils-0.0.18-java/lib/logstash/devutils/rspec/spec
_helper.rb:43:in `[]='",
        "C:/jruby/lib/ruby/gems/shared/gems/logstash-input-gelf-2.0.2/lib/logstash/inputs/gelf.rb:101:i
n `udp_listener'",
        "C:/jruby/lib/ruby/gems/shared/gems/logstash-input-gelf-2.0.2/lib/logstash/inputs/gelf.rb:63:in `run'
",
        "C:/jruby/lib/ruby/gems/shared/gems/logstash-core-2.0.0.beta3-java/lib/logstash/pipeline.rb:180:in `inputworker'",
        "C
:/jruby/lib/ruby/gems/shared/gems/logstash-core-2.0.0.beta3-java/lib/logstash/pipeline.rb:174:in `start_input'"
    ],
    : level=>: warn,
    : file=>"/jruby/lib/ruby/gems/shared/gems/logstash-input-gelf-2.0.2/lib/logstash/inputs/gelf.rb",
    : line=>"66",
    : method=>"run"
}
←[0m
gmoskovicz commented 8 years ago

Find what is causing this, we need to force encoding to UTF-8 here:

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

      event["source_host"] = client[3].force_encoding("UTF-8")

Which succeeds!

gmoskovicz commented 8 years ago

23 fixes this issue:

PS C:\jruby\lib\ruby\gems\shared\gems\logstash-input-gelf-2.0.2\spec\inputs> rspec .\gelf_spec.rb
io/console not supported; tty will not be manipulated
Using Accessor#strict_set for specs
Run options: exclude {:redis=>true, :socket=>true, :performance=>true, :couchdb=>true, :elasticsearch=>true, :elasticsea
rch_secure=>true, :export_cypher=>true, :integration=>true, :unix=>true}
reads chunked gelf messages #<GELF::Notifier:0x1221c139 @enabled=true, @max_chunk_size=1420, @level_mapping={0=>7, 1=>6,
 2=>5, 3=>4, 4=>3, 5=>1}, @rescue_network_errors=false, @default_options={"version"=>"1.0", "host"=>"OWNEROR-H4J1HH2", "
level"=>5, "facility"=>"gelf-rb"}, @sender=#<GELF::RubyUdpSender:0xcbb2984 @socket=#<UDPSocket:fd 114>, @addresses=[["12
7.0.0.1", 12201]], @i=0>, @collect_file_and_line=true, @level=0>
      input {
        gelf {
          port => "12201"
          host => "127.0.0.1"
        }
      }
pass
..

Finished in 5.89 seconds (files took 4.84 seconds to load)
2 examples, 0 failures

Randomized with seed 43262
jsvd commented 6 years ago

closed by #23