logstash-core 2.1.3-java → 2.2.0-java
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of logstash-core might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/logstash-core.rb +1 -3
- data/lib/logstash-core/logstash-core.rb +3 -0
- data/lib/logstash-core/version.rb +8 -0
- data/lib/logstash/agent.rb +48 -20
- data/lib/logstash/codecs/base.rb +2 -2
- data/lib/logstash/config/config_ast.rb +8 -3
- data/lib/logstash/environment.rb +0 -16
- data/lib/logstash/filters/base.rb +9 -5
- data/lib/logstash/inputs/base.rb +1 -1
- data/lib/logstash/output_delegator.rb +150 -0
- data/lib/logstash/outputs/base.rb +37 -40
- data/lib/logstash/pipeline.rb +259 -178
- data/lib/logstash/pipeline_reporter.rb +114 -0
- data/lib/logstash/plugin.rb +1 -1
- data/lib/logstash/{shutdown_controller.rb → shutdown_watcher.rb} +10 -37
- data/lib/logstash/util.rb +17 -0
- data/lib/logstash/util/decorators.rb +14 -7
- data/lib/logstash/util/worker_threads_default_printer.rb +4 -4
- data/lib/logstash/util/wrapped_synchronous_queue.rb +41 -0
- data/lib/logstash/version.rb +10 -2
- data/locales/en.yml +8 -3
- data/logstash-core.gemspec +5 -3
- data/spec/{core/conditionals_spec.rb → conditionals_spec.rb} +0 -0
- data/spec/{core/config_spec.rb → logstash/config/config_ast_spec.rb} +0 -0
- data/spec/{core/config_cpu_core_strategy_spec.rb → logstash/config/cpu_core_strategy_spec.rb} +0 -0
- data/spec/{core/config_defaults_spec.rb → logstash/config/defaults_spec.rb} +0 -0
- data/spec/{core/config_mixin_spec.rb → logstash/config/mixin_spec.rb} +0 -0
- data/spec/{core → logstash}/environment_spec.rb +0 -0
- data/spec/{filters → logstash/filters}/base_spec.rb +0 -0
- data/spec/{inputs → logstash/inputs}/base_spec.rb +0 -0
- data/spec/{lib/logstash → logstash}/java_integration_spec.rb +0 -0
- data/spec/{util → logstash}/json_spec.rb +0 -0
- data/spec/logstash/output_delegator_spec.rb +126 -0
- data/spec/logstash/outputs/base_spec.rb +40 -0
- data/spec/logstash/pipeline_reporter_spec.rb +85 -0
- data/spec/{core → logstash}/pipeline_spec.rb +128 -16
- data/spec/{core → logstash}/plugin_spec.rb +47 -1
- data/spec/logstash/runner_spec.rb +68 -0
- data/spec/{core/shutdown_controller_spec.rb → logstash/shutdown_watcher_spec.rb} +17 -11
- data/spec/{util → logstash/util}/buftok_spec.rb +0 -0
- data/spec/{util → logstash/util}/charset_spec.rb +0 -0
- data/spec/{util → logstash/util}/defaults_printer_spec.rb +4 -4
- data/spec/{util → logstash/util}/java_version_spec.rb +0 -0
- data/spec/{util → logstash/util}/plugin_version_spec.rb +0 -0
- data/spec/{util → logstash/util}/unicode_trimmer_spec.rb +0 -0
- data/spec/{util → logstash/util}/worker_threads_default_printer_spec.rb +8 -8
- data/spec/logstash/util/wrapped_synchronous_queue_spec.rb +28 -0
- data/spec/{util_spec.rb → logstash/util_spec.rb} +0 -0
- metadata +74 -81
- data/lib/logstash/event.rb +0 -275
- data/lib/logstash/patches/bundler.rb +0 -36
- data/lib/logstash/sized_queue.rb +0 -8
- data/lib/logstash/string_interpolation.rb +0 -140
- data/lib/logstash/timestamp.rb +0 -97
- data/lib/logstash/util/accessors.rb +0 -123
- data/spec/core/event_spec.rb +0 -518
- data/spec/core/runner_spec.rb +0 -40
- data/spec/core/timestamp_spec.rb +0 -84
- data/spec/coverage_helper.rb +0 -24
- data/spec/lib/logstash/bundler_spec.rb +0 -121
- data/spec/license_spec.rb +0 -67
- data/spec/outputs/base_spec.rb +0 -26
- data/spec/plugin_manager/install_spec.rb +0 -28
- data/spec/plugin_manager/update_spec.rb +0 -39
- data/spec/plugin_manager/util_spec.rb +0 -71
- data/spec/spec_helper.rb +0 -11
- data/spec/util/accessors_spec.rb +0 -170
- data/spec/util/compress_spec.rb +0 -121
- data/spec/util/gemfile_spec.rb +0 -212
- data/spec/util/retryable_spec.rb +0 -139
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
# use a dummy NOOP output to test Outputs::Base
|
5
|
+
class LogStash::Outputs::NOOP < LogStash::Outputs::Base
|
6
|
+
config_name "noop"
|
7
|
+
milestone 2
|
8
|
+
|
9
|
+
config :dummy_option, :validate => :string
|
10
|
+
|
11
|
+
def register; end
|
12
|
+
|
13
|
+
def receive(event)
|
14
|
+
return output?(event)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class LogStash::Outputs::NOOPLegacyNoWorkers < ::LogStash::Outputs::Base
|
19
|
+
LEGACY_WORKERS_NOT_SUPPORTED_REASON = "legacy reason"
|
20
|
+
|
21
|
+
def register
|
22
|
+
workers_not_supported(LEGACY_WORKERS_NOT_SUPPORTED_REASON)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "LogStash::Outputs::Base#new" do
|
27
|
+
it "should instantiate cleanly" do
|
28
|
+
params = { "dummy_option" => "potatoes", "codec" => "json", "workers" => 2 }
|
29
|
+
worker_params = params.dup; worker_params["workers"] = 1
|
30
|
+
|
31
|
+
expect do
|
32
|
+
LogStash::Outputs::NOOP.new(params.dup)
|
33
|
+
end.not_to raise_error
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should move workers_not_supported declarations up to the class level" do
|
37
|
+
LogStash::Outputs::NOOPLegacyNoWorkers.new.register
|
38
|
+
expect(LogStash::Outputs::NOOPLegacyNoWorkers.workers_not_supported?).to eql(true)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
require "logstash/pipeline"
|
4
|
+
require "logstash/pipeline_reporter"
|
5
|
+
|
6
|
+
class DummyOutput < LogStash::Outputs::Base
|
7
|
+
config_name "dummyoutput"
|
8
|
+
milestone 2
|
9
|
+
|
10
|
+
attr_reader :num_closes, :events
|
11
|
+
|
12
|
+
def initialize(params={})
|
13
|
+
super
|
14
|
+
@num_closes = 0
|
15
|
+
@events = []
|
16
|
+
end
|
17
|
+
|
18
|
+
def register
|
19
|
+
end
|
20
|
+
|
21
|
+
def receive(event)
|
22
|
+
@events << event
|
23
|
+
end
|
24
|
+
|
25
|
+
def close
|
26
|
+
@num_closes += 1
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
#TODO: Figure out how to add more tests that actually cover inflight events
|
31
|
+
#This will require some janky multithreading stuff
|
32
|
+
describe LogStash::PipelineReporter do
|
33
|
+
let(:generator_count) { 5 }
|
34
|
+
let(:config) do
|
35
|
+
"input { generator { count => #{generator_count} } } output { dummyoutput {} } "
|
36
|
+
end
|
37
|
+
let(:pipeline) { LogStash::Pipeline.new(config)}
|
38
|
+
let(:reporter) { pipeline.reporter }
|
39
|
+
|
40
|
+
before do
|
41
|
+
allow(LogStash::Plugin).to receive(:lookup).with("output", "dummyoutput").and_return(DummyOutput)
|
42
|
+
allow(LogStash::Plugin).to receive(:lookup).with("input", "generator").and_call_original
|
43
|
+
allow(LogStash::Plugin).to receive(:lookup).with("codec", "plain").and_call_original
|
44
|
+
|
45
|
+
@pre_snapshot = reporter.snapshot
|
46
|
+
pipeline.run
|
47
|
+
@post_snapshot = reporter.snapshot
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "events filtered" do
|
51
|
+
it "should start at zero" do
|
52
|
+
expect(@pre_snapshot.events_filtered).to eql(0)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should end at the number of generated events" do
|
56
|
+
expect(@post_snapshot.events_filtered).to eql(generator_count)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "events consumed" do
|
61
|
+
it "should start at zero" do
|
62
|
+
expect(@pre_snapshot.events_consumed).to eql(0)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should end at the number of generated events" do
|
66
|
+
expect(@post_snapshot.events_consumed).to eql(generator_count)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "inflight count" do
|
71
|
+
it "should be zero before running" do
|
72
|
+
expect(@pre_snapshot.inflight_count).to eql(0)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should be zero after running" do
|
76
|
+
expect(@post_snapshot.inflight_count).to eql(0)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "output states" do
|
81
|
+
it "should include the count of received events" do
|
82
|
+
expect(@post_snapshot.output_info.first[:events_received]).to eql(generator_count)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "spec_helper"
|
3
|
+
require "logstash/inputs/generator"
|
4
|
+
require "logstash/filters/multiline"
|
3
5
|
|
4
6
|
class DummyInput < LogStash::Inputs::Base
|
5
7
|
config_name "dummyinput"
|
@@ -35,17 +37,19 @@ class DummyOutput < LogStash::Outputs::Base
|
|
35
37
|
config_name "dummyoutput"
|
36
38
|
milestone 2
|
37
39
|
|
38
|
-
attr_reader :num_closes
|
40
|
+
attr_reader :num_closes, :events
|
39
41
|
|
40
42
|
def initialize(params={})
|
41
43
|
super
|
42
44
|
@num_closes = 0
|
45
|
+
@events = []
|
43
46
|
end
|
44
47
|
|
45
48
|
def register
|
46
49
|
end
|
47
|
-
|
50
|
+
|
48
51
|
def receive(event)
|
52
|
+
@events << event
|
49
53
|
end
|
50
54
|
|
51
55
|
def close
|
@@ -80,22 +84,21 @@ class DummySafeFilter < LogStash::Filters::Base
|
|
80
84
|
end
|
81
85
|
|
82
86
|
class TestPipeline < LogStash::Pipeline
|
83
|
-
attr_reader :outputs, :
|
87
|
+
attr_reader :outputs, :settings, :logger
|
84
88
|
end
|
85
89
|
|
86
90
|
describe LogStash::Pipeline do
|
87
|
-
let(:worker_thread_count) {
|
91
|
+
let(:worker_thread_count) { LogStash::Pipeline::DEFAULT_SETTINGS[:default_pipeline_workers] }
|
88
92
|
let(:safe_thread_count) { 1 }
|
89
93
|
let(:override_thread_count) { 42 }
|
90
94
|
|
91
|
-
describe "defaulting the
|
95
|
+
describe "defaulting the pipeline workers based on thread safety" do
|
92
96
|
before(:each) do
|
93
97
|
allow(LogStash::Plugin).to receive(:lookup).with("input", "dummyinput").and_return(DummyInput)
|
94
98
|
allow(LogStash::Plugin).to receive(:lookup).with("codec", "plain").and_return(DummyCodec)
|
95
99
|
allow(LogStash::Plugin).to receive(:lookup).with("output", "dummyoutput").and_return(DummyOutput)
|
96
100
|
allow(LogStash::Plugin).to receive(:lookup).with("filter", "dummyfilter").and_return(DummyFilter)
|
97
101
|
allow(LogStash::Plugin).to receive(:lookup).with("filter", "dummysafefilter").and_return(DummySafeFilter)
|
98
|
-
allow(LogStash::Config::CpuCoreStrategy).to receive(:fifty_percent).and_return(worker_thread_count)
|
99
102
|
end
|
100
103
|
|
101
104
|
context "when there are some not threadsafe filters" do
|
@@ -117,13 +120,13 @@ describe LogStash::Pipeline do
|
|
117
120
|
|
118
121
|
context "when there is no command line -w N set" do
|
119
122
|
it "starts one filter thread" do
|
120
|
-
msg = "Defaulting
|
123
|
+
msg = "Defaulting pipeline worker threads to 1 because there are some" +
|
121
124
|
" filters that might not work with multiple worker threads"
|
122
125
|
pipeline = TestPipeline.new(test_config_with_filters)
|
123
126
|
expect(pipeline.logger).to receive(:warn).with(msg,
|
124
127
|
{:count_was=>worker_thread_count, :filters=>["dummyfilter"]})
|
125
128
|
pipeline.run
|
126
|
-
expect(pipeline.
|
129
|
+
expect(pipeline.worker_threads.size).to eq(safe_thread_count)
|
127
130
|
end
|
128
131
|
end
|
129
132
|
|
@@ -134,9 +137,9 @@ describe LogStash::Pipeline do
|
|
134
137
|
pipeline = TestPipeline.new(test_config_with_filters)
|
135
138
|
expect(pipeline.logger).to receive(:warn).with(msg,
|
136
139
|
{:worker_threads=> override_thread_count, :filters=>["dummyfilter"]})
|
137
|
-
pipeline.configure(
|
140
|
+
pipeline.configure(:pipeline_workers, override_thread_count)
|
138
141
|
pipeline.run
|
139
|
-
expect(pipeline.
|
142
|
+
expect(pipeline.worker_threads.size).to eq(override_thread_count)
|
140
143
|
end
|
141
144
|
end
|
142
145
|
end
|
@@ -161,7 +164,7 @@ describe LogStash::Pipeline do
|
|
161
164
|
it "starts multiple filter threads" do
|
162
165
|
pipeline = TestPipeline.new(test_config_with_filters)
|
163
166
|
pipeline.run
|
164
|
-
expect(pipeline.
|
167
|
+
expect(pipeline.worker_threads.size).to eq(worker_thread_count)
|
165
168
|
end
|
166
169
|
end
|
167
170
|
end
|
@@ -206,8 +209,8 @@ describe LogStash::Pipeline do
|
|
206
209
|
pipeline.run
|
207
210
|
|
208
211
|
expect(pipeline.outputs.size ).to eq(1)
|
209
|
-
expect(pipeline.outputs.first.
|
210
|
-
expect(pipeline.outputs.first.
|
212
|
+
expect(pipeline.outputs.first.workers.size ).to eq(pipeline.default_output_workers)
|
213
|
+
expect(pipeline.outputs.first.workers.first.num_closes ).to eq(1)
|
211
214
|
end
|
212
215
|
|
213
216
|
it "should call output close correctly with output workers" do
|
@@ -215,8 +218,13 @@ describe LogStash::Pipeline do
|
|
215
218
|
pipeline.run
|
216
219
|
|
217
220
|
expect(pipeline.outputs.size ).to eq(1)
|
218
|
-
|
219
|
-
|
221
|
+
# We even close the parent output worker, even though it doesn't receive messages
|
222
|
+
|
223
|
+
output_delegator = pipeline.outputs.first
|
224
|
+
output = output_delegator.workers.first
|
225
|
+
|
226
|
+
expect(output.num_closes).to eq(1)
|
227
|
+
output_delegator.workers.each do |plugin|
|
220
228
|
expect(plugin.num_closes ).to eq(1)
|
221
229
|
end
|
222
230
|
end
|
@@ -268,6 +276,36 @@ describe LogStash::Pipeline do
|
|
268
276
|
end
|
269
277
|
end
|
270
278
|
|
279
|
+
describe "max inflight warning" do
|
280
|
+
let(:config) { "input { dummyinput {} } output { dummyoutput {} }" }
|
281
|
+
let(:batch_size) { 1 }
|
282
|
+
let(:pipeline) { LogStash::Pipeline.new(config, :pipeline_batch_size => batch_size, :pipeline_workers => 1) }
|
283
|
+
let(:logger) { pipeline.logger }
|
284
|
+
let(:warning_prefix) { /CAUTION: Recommended inflight events max exceeded!/ }
|
285
|
+
|
286
|
+
before(:each) do
|
287
|
+
allow(LogStash::Plugin).to receive(:lookup).with("input", "dummyinput").and_return(DummyInput)
|
288
|
+
allow(LogStash::Plugin).to receive(:lookup).with("codec", "plain").and_return(DummyCodec)
|
289
|
+
allow(LogStash::Plugin).to receive(:lookup).with("output", "dummyoutput").and_return(DummyOutput)
|
290
|
+
allow(logger).to receive(:warn)
|
291
|
+
thread = Thread.new { pipeline.run }
|
292
|
+
pipeline.shutdown
|
293
|
+
thread.join
|
294
|
+
end
|
295
|
+
|
296
|
+
it "should not raise a max inflight warning if the max_inflight count isn't exceeded" do
|
297
|
+
expect(logger).not_to have_received(:warn).with(warning_prefix)
|
298
|
+
end
|
299
|
+
|
300
|
+
context "with a too large inflight count" do
|
301
|
+
let(:batch_size) { LogStash::Pipeline::MAX_INFLIGHT_WARN_THRESHOLD + 1 }
|
302
|
+
|
303
|
+
it "should raise a max inflight warning if the max_inflight count is exceeded" do
|
304
|
+
expect(logger).to have_received(:warn).with(warning_prefix)
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
271
309
|
context "compiled filter funtions" do
|
272
310
|
|
273
311
|
context "new events should propagate down the filters" do
|
@@ -318,8 +356,82 @@ describe LogStash::Pipeline do
|
|
318
356
|
it "doesn't raise an error" do
|
319
357
|
pipeline = TestPipeline.new(pipeline_with_no_filters)
|
320
358
|
pipeline.run
|
321
|
-
expect { pipeline.
|
359
|
+
expect { pipeline.stalling_threads_info }.to_not raise_error
|
322
360
|
end
|
323
361
|
end
|
324
362
|
end
|
363
|
+
|
364
|
+
context "Periodic Flush" do
|
365
|
+
let(:number_of_events) { 100 }
|
366
|
+
let(:config) do
|
367
|
+
<<-EOS
|
368
|
+
input {
|
369
|
+
generator {
|
370
|
+
count => #{number_of_events}
|
371
|
+
}
|
372
|
+
}
|
373
|
+
filter {
|
374
|
+
multiline {
|
375
|
+
pattern => "^NeverMatch"
|
376
|
+
negate => true
|
377
|
+
what => "previous"
|
378
|
+
}
|
379
|
+
}
|
380
|
+
output {
|
381
|
+
dummyoutput {}
|
382
|
+
}
|
383
|
+
EOS
|
384
|
+
end
|
385
|
+
let(:output) { DummyOutput.new }
|
386
|
+
|
387
|
+
before do
|
388
|
+
allow(DummyOutput).to receive(:new).with(any_args).and_return(output)
|
389
|
+
allow(LogStash::Plugin).to receive(:lookup).with("input", "generator").and_return(LogStash::Inputs::Generator)
|
390
|
+
allow(LogStash::Plugin).to receive(:lookup).with("codec", "plain").and_return(LogStash::Codecs::Plain)
|
391
|
+
allow(LogStash::Plugin).to receive(:lookup).with("filter", "multiline").and_return(LogStash::Filters::Multiline)
|
392
|
+
allow(LogStash::Plugin).to receive(:lookup).with("output", "dummyoutput").and_return(DummyOutput)
|
393
|
+
end
|
394
|
+
|
395
|
+
it "flushes the buffered contents of the filter" do
|
396
|
+
Thread.abort_on_exception = true
|
397
|
+
pipeline = LogStash::Pipeline.new(config, { :flush_interval => 1 })
|
398
|
+
Thread.new { pipeline.run }
|
399
|
+
sleep 0.1 while !pipeline.ready?
|
400
|
+
# give us a bit of time to flush the events
|
401
|
+
wait(5).for do
|
402
|
+
next unless output && output.events && output.events.first
|
403
|
+
output.events.first["message"].split("\n").count
|
404
|
+
end.to eq(number_of_events)
|
405
|
+
pipeline.shutdown
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
context "Multiple pipelines" do
|
410
|
+
before do
|
411
|
+
allow(LogStash::Plugin).to receive(:lookup).with("input", "generator").and_return(LogStash::Inputs::Generator)
|
412
|
+
allow(LogStash::Plugin).to receive(:lookup).with("codec", "plain").and_return(DummyCodec)
|
413
|
+
allow(LogStash::Plugin).to receive(:lookup).with("filter", "dummyfilter").and_return(DummyFilter)
|
414
|
+
allow(LogStash::Plugin).to receive(:lookup).with("output", "dummyoutput").and_return(DummyOutput)
|
415
|
+
end
|
416
|
+
|
417
|
+
let(:pipeline1) { LogStash::Pipeline.new("input { generator {} } filter { dummyfilter {} } output { dummyoutput {}}") }
|
418
|
+
let(:pipeline2) { LogStash::Pipeline.new("input { generator {} } filter { dummyfilter {} } output { dummyoutput {}}") }
|
419
|
+
|
420
|
+
it "should handle evaluating different config" do
|
421
|
+
# When the functions are compiled from the AST it will generate instance
|
422
|
+
# variables that are unique to the actual config, the intance are pointing
|
423
|
+
# to conditionals/plugins.
|
424
|
+
#
|
425
|
+
# Before the `defined_singleton_method`, the definition of the method was
|
426
|
+
# not unique per class, but the `instance variables` were unique per class.
|
427
|
+
#
|
428
|
+
# So the methods were trying to access instance variables that did not exist
|
429
|
+
# in the current instance and was returning an array containing nil values for
|
430
|
+
# the match.
|
431
|
+
expect(pipeline1.output_func(LogStash::Event.new)).not_to include(nil)
|
432
|
+
expect(pipeline1.filter_func(LogStash::Event.new)).not_to include(nil)
|
433
|
+
expect(pipeline2.output_func(LogStash::Event.new)).not_to include(nil)
|
434
|
+
expect(pipeline1.filter_func(LogStash::Event.new)).not_to include(nil)
|
435
|
+
end
|
436
|
+
end
|
325
437
|
end
|
@@ -108,7 +108,7 @@ describe LogStash::Plugin do
|
|
108
108
|
|
109
109
|
subject.validate({})
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
|
113
113
|
it 'logs a warning if the plugin use the milestone option' do
|
114
114
|
expect_any_instance_of(Cabin::Channel).to receive(:warn)
|
@@ -120,4 +120,50 @@ describe LogStash::Plugin do
|
|
120
120
|
end
|
121
121
|
end
|
122
122
|
end
|
123
|
+
|
124
|
+
describe "subclass initialize" do
|
125
|
+
let(:args) { Hash.new }
|
126
|
+
|
127
|
+
[
|
128
|
+
StromaeCodec = Class.new(LogStash::Codecs::Base) do
|
129
|
+
config_name "stromae"
|
130
|
+
config :foo_tag, :validate => :string, :default => "bar"
|
131
|
+
end,
|
132
|
+
StromaeFilter = Class.new(LogStash::Filters::Base) do
|
133
|
+
config_name "stromae"
|
134
|
+
config :foo_tag, :validate => :string, :default => "bar"
|
135
|
+
end,
|
136
|
+
StromaeInput = Class.new(LogStash::Inputs::Base) do
|
137
|
+
config_name "stromae"
|
138
|
+
config :foo_tag, :validate => :string, :default => "bar"
|
139
|
+
end,
|
140
|
+
StromaeOutput = Class.new(LogStash::Outputs::Base) do
|
141
|
+
config_name "stromae"
|
142
|
+
config :foo_tag, :validate => :string, :default => "bar"
|
143
|
+
end
|
144
|
+
].each do |klass|
|
145
|
+
|
146
|
+
it "subclass #{klass.name} does not modify params" do
|
147
|
+
klass.new(args)
|
148
|
+
expect(args).to be_empty
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context "codec initialization" do
|
153
|
+
|
154
|
+
class LogStash::Codecs::Noop < LogStash::Codecs::Base
|
155
|
+
config_name "noop"
|
156
|
+
|
157
|
+
config :format, :validate => :string
|
158
|
+
def register; end
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should only register once" do
|
162
|
+
args = { "codec" => LogStash::Codecs::Noop.new("format" => ".") }
|
163
|
+
expect_any_instance_of(LogStash::Codecs::Noop).to receive(:register).once
|
164
|
+
LogStash::Plugin.new(args)
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
end
|
123
169
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
require "logstash/runner"
|
4
|
+
require "stud/task"
|
5
|
+
require "stud/trap"
|
6
|
+
|
7
|
+
class NullRunner
|
8
|
+
def run(args); end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe LogStash::Runner do
|
12
|
+
|
13
|
+
context "argument parsing" do
|
14
|
+
it "should run agent" do
|
15
|
+
expect(Stud::Task).to receive(:new).once.and_return(nil)
|
16
|
+
args = ["agent", "-e", ""]
|
17
|
+
expect(subject.run(args)).to eq(nil)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should run agent help" do
|
21
|
+
expect(subject).to receive(:show_help).once.and_return(nil)
|
22
|
+
args = ["agent", "-h"]
|
23
|
+
expect(subject.run(args).wait).to eq(0)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should show help with no arguments" do
|
27
|
+
expect($stderr).to receive(:puts).once.and_return("No command given")
|
28
|
+
expect($stderr).to receive(:puts).once
|
29
|
+
args = []
|
30
|
+
expect(subject.run(args).wait).to eq(1)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should show help for unknown commands" do
|
34
|
+
expect($stderr).to receive(:puts).once.and_return("No such command welp")
|
35
|
+
expect($stderr).to receive(:puts).once
|
36
|
+
args = ["welp"]
|
37
|
+
expect(subject.run(args).wait).to eq(1)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "pipeline settings" do
|
42
|
+
let(:pipeline_string) { "input { stdin {} } output { stdout {} }" }
|
43
|
+
let(:base_pipeline_settings) { { :pipeline_id => "base" } }
|
44
|
+
let(:pipeline) { double("pipeline") }
|
45
|
+
|
46
|
+
before(:each) do
|
47
|
+
task = Stud::Task.new { 1 }
|
48
|
+
allow(pipeline).to receive(:run).and_return(task)
|
49
|
+
end
|
50
|
+
|
51
|
+
context "when pipeline workers is not defined by the user" do
|
52
|
+
it "should not pass the value to the pipeline" do
|
53
|
+
expect(LogStash::Pipeline).to receive(:new).with(pipeline_string, base_pipeline_settings).and_return(pipeline)
|
54
|
+
args = ["agent", "-e", pipeline_string]
|
55
|
+
subject.run(args).wait
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when pipeline workers is defined by the user" do
|
60
|
+
it "should pass the value to the pipeline" do
|
61
|
+
base_pipeline_settings[:pipeline_workers] = 2
|
62
|
+
expect(LogStash::Pipeline).to receive(:new).with(pipeline_string, base_pipeline_settings).and_return(pipeline)
|
63
|
+
args = ["agent", "-w", "2", "-e", pipeline_string]
|
64
|
+
subject.run(args).wait
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|