Module: LogStashHelper
- Defined in:
- lib/logstash/devutils/rspec/logstash_helpers.rb
Instance Method Summary collapse
-
#agent(&block) ⇒ Object
def input.
- #config(configstr) ⇒ Object
-
#input(config, &block) ⇒ Object
def sample.
- #sample(sample_event, &block) ⇒ Object
- #tags(*tags) ⇒ Object
-
#type(default_type) ⇒ Object
def config.
Instance Method Details
#agent(&block) ⇒ Object
def input
81 82 83 84 85 86 87 88 |
# File 'lib/logstash/devutils/rspec/logstash_helpers.rb', line 81 def agent(&block) it("agent(#{caller[0].gsub(/ .*/, "")}) runs") do pipeline = LogStash::Pipeline.new(config) pipeline.run block.call end end |
#config(configstr) ⇒ Object
8 9 10 |
# File 'lib/logstash/devutils/rspec/logstash_helpers.rb', line 8 def config(configstr) let(:config) { configstr } end |
#input(config, &block) ⇒ Object
def sample
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/logstash/devutils/rspec/logstash_helpers.rb', line 56 def input(config, &block) pipeline = LogStash::Pipeline.new(config) queue = Queue.new pipeline.instance_eval do # create closure to capture queue @output_func = lambda { |event| queue << event } # output_func is now a method, call closure def output_func(event) @output_func.call(event) end end pipeline_thread = Thread.new { pipeline.run } sleep 0.1 while !pipeline.ready? result = block.call(pipeline, queue) pipeline.shutdown pipeline_thread.join result end |
#sample(sample_event, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/logstash/devutils/rspec/logstash_helpers.rb', line 21 def sample(sample_event, &block) name = sample_event.is_a?(String) ? sample_event : LogStash::Json.dump(sample_event) name = name[0..50] + "..." if name.length > 50 describe "\"#{name}\"" do let(:pipeline) { LogStash::Pipeline.new(config) } let(:event) do sample_event = [sample_event] unless sample_event.is_a?(Array) next sample_event.collect do |e| e = { "message" => e } if e.is_a?(String) next LogStash::Event.new(e) end end let(:results) do results = [] pipeline.instance_eval { @filters.each(&:register) } event.each do |e| # filter call the block on all filtered events, included new events added by the filter pipeline.filter(e) { |filtered_event| results << filtered_event } end # flush makes sure to empty any buffered events in the filter pipeline.flush_filters(:final => true) { |flushed_event| results << flushed_event } results.select { |e| !e.cancelled? } end subject { results.length > 1 ? results : results.first } it("when processed", &block) end end |
#tags(*tags) ⇒ Object
16 17 18 19 |
# File 'lib/logstash/devutils/rspec/logstash_helpers.rb', line 16 def (*) let(:default_tags) { } puts "Setting default tags: #{tags}" end |
#type(default_type) ⇒ Object
def config
12 13 14 |
# File 'lib/logstash/devutils/rspec/logstash_helpers.rb', line 12 def type(default_type) let(:default_type) { default_type } end |