Hello,
in order to debug/test ruby filters I wrote some tests with test/unit. I have my test-data in json files and would like it to load it into an event (something like LogStash::Event.new(data = json)).
This is the test file, and the filter is in map_wildfly_data.rb
load "map_wildfly_data.rb"
require "json"
require "test/unit"
require "logstash/event"
class TestFilter < Test::Unit::TestCase
def test_xa
file = File.read("wf_data_xa.json")
json = JSON.parse(file)
event = LogStash::Event.new(data = json)
filter(event)
assert_equal(event.get("wf_data.datasource.type"), "xa")
end
end
I tested it so far with gem install logstash-event, but it found an old version logstash-event-1.2.02.gem, from before the Event-API changed, so is no good, I get:
Error: test_xa(TestFilter):
NoMethodError: undefined method `set' for #<LogStash::Event:0x00000000a253f0>
Is there a gem that includes the new Event-API?
I am learning ruby as I go, so I have no real idea (other than installing gems) of how to make libraries accessible from the test class (quasi jars in CP-like), but I guess with some pointers I can do that too.
Well, that didn't help much. After some hours of rubying and rvming I got the library installed, but it does not provide logstash/event
➜ ✗ gem list |grep logstash-core
logstash-core (6.2.5 java)
➜ ✗ ruby map_wildfly_data.test.rb
/usr/share/rvm/rubies/jruby-9.1.13.0/lib/ruby/stdlib/power_assert.rb:7: warning: tracing (e.g. set_trace_func) will not capture all events without --debug flag
LoadError: no such file to load -- logstash/event
require at org/jruby/RubyKernel.java:955
require at /usr/share/rvm/rubies/jruby-9.1.13.0/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:59
<main> at map_wildfly_data.test.rb:4
Is it somewhere else? Or are my gems not working like they should?
So, finally solved it. It was a long journey. I wish the documentation would be more specific on how to use the libraries for development (or provide a working dev-utils gem for that matter). For many ruby-newbies (i found in forums) it is not really clear how this stuff works at all. I understand teaching ruby from scratch is not your mission, but since you provide this all-to-powerful filter, making it easier to use should be.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.