Is it possible to launch a Ruby debugger from within the Logstash Ruby filter plugin? It would be very handy for debugging.
To add inline ruby in your filter, place all code in the code option. This code will be executed for every event the filter receives. You can also place ruby code in the init option. It will be executed only once during the plugin's register phase.
Logstash has a rich set of filters, and you can even write your own, but often this is not necessary since there is a out-of-the-box filter that allows you to embed Ruby code directly in the configuration file.
The filters of Logstash measures manipulate and create events like Apache-Access. Many filter plugins used to manage the events in Logstash. Here, in an example of the Logstash Aggregate Filter, we are filtering the duration every SQL transaction in a database and computing the total time.
Ruby Filter is a filter that is extremely useful in differentiating red stones such as Ruby, Spinel, Tourmaline, and Garnets from others that might look similar in comparison.
The good Logstash folks have thought of this already as they included pry
into Logstash core. So all you have to do is to require pry in your ruby
filter code as shown in the sample config below:
input {
file {
path => "/tmp/myfile.csv"
sincedb_path => "/dev/null"
start_position => "beginning"
}
}
filter {
ruby {
code => "require 'pry'
... your code ...
# start a REPL session
binding.pry
... your code ...
"
}
}
When Logstash runs, you'll get a REPL session in your terminal which looks like this and you'll be able to do whatever pry allows you to do.
[1] pry(#<LogStash::Filters::Ruby>)>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With