logstash-core 2.4.1-java → 5.0.0.alpha1-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/version.rb +1 -1
- data/lib/logstash/agent.rb +124 -411
- data/lib/logstash/api/init.ru +31 -0
- data/lib/logstash/api/lib/app.rb +40 -0
- data/lib/logstash/api/lib/app/command.rb +29 -0
- data/lib/logstash/api/lib/app/command_factory.rb +29 -0
- data/lib/logstash/api/lib/app/commands/stats/events_command.rb +13 -0
- data/lib/logstash/api/lib/app/commands/stats/hotthreads_command.rb +120 -0
- data/lib/logstash/api/lib/app/commands/stats/memory_command.rb +25 -0
- data/lib/logstash/api/lib/app/commands/system/basicinfo_command.rb +15 -0
- data/lib/logstash/api/lib/app/commands/system/plugins_command.rb +28 -0
- data/lib/logstash/api/lib/app/modules/node.rb +25 -0
- data/lib/logstash/api/lib/app/modules/node_stats.rb +51 -0
- data/lib/logstash/api/lib/app/modules/plugins.rb +15 -0
- data/lib/logstash/api/lib/app/modules/stats.rb +21 -0
- data/lib/logstash/api/lib/app/root.rb +13 -0
- data/lib/logstash/api/lib/app/service.rb +61 -0
- data/lib/logstash/api/lib/app/stats.rb +56 -0
- data/lib/logstash/api/lib/helpers/app_helpers.rb +23 -0
- data/lib/logstash/codecs/base.rb +1 -29
- data/lib/logstash/config/config_ast.rb +18 -31
- data/lib/logstash/config/loader.rb +3 -5
- data/lib/logstash/config/mixin.rb +25 -64
- data/lib/logstash/filter_delegator.rb +65 -0
- data/lib/logstash/inputs/base.rb +1 -1
- data/lib/logstash/inputs/metrics.rb +47 -0
- data/lib/logstash/instrument/collector.rb +109 -0
- data/lib/logstash/instrument/metric.rb +102 -0
- data/lib/logstash/instrument/metric_store.rb +228 -0
- data/lib/logstash/instrument/metric_type.rb +24 -0
- data/lib/logstash/instrument/metric_type/base.rb +35 -0
- data/lib/logstash/instrument/metric_type/counter.rb +29 -0
- data/lib/logstash/instrument/metric_type/gauge.rb +22 -0
- data/lib/logstash/instrument/metric_type/mean.rb +33 -0
- data/lib/logstash/instrument/namespaced_metric.rb +54 -0
- data/lib/logstash/instrument/null_metric.rb +4 -3
- data/lib/logstash/instrument/periodic_poller/base.rb +57 -0
- data/lib/logstash/instrument/periodic_poller/jvm.rb +92 -0
- data/lib/logstash/instrument/periodic_poller/os.rb +13 -0
- data/lib/logstash/instrument/periodic_poller/periodic_poller_observer.rb +19 -0
- data/lib/logstash/instrument/periodic_pollers.rb +26 -0
- data/lib/logstash/instrument/snapshot.rb +16 -0
- data/lib/logstash/json.rb +2 -3
- data/lib/logstash/namespace.rb +1 -0
- data/lib/logstash/output_delegator.rb +16 -3
- data/lib/logstash/outputs/base.rb +1 -32
- data/lib/logstash/pipeline.rb +67 -8
- data/lib/logstash/plugin.rb +57 -19
- data/lib/logstash/runner.rb +348 -84
- data/lib/logstash/util.rb +9 -0
- data/lib/logstash/util/duration_formatter.rb +15 -0
- data/lib/logstash/util/java_version.rb +2 -4
- data/lib/logstash/util/loggable.rb +29 -0
- data/lib/logstash/version.rb +1 -1
- data/lib/logstash/webserver.rb +98 -0
- data/locales/en.yml +42 -24
- data/logstash-core.gemspec +9 -6
- data/spec/api/lib/api/node_spec.rb +64 -0
- data/spec/api/lib/api/node_stats_spec.rb +68 -0
- data/spec/api/lib/api/plugins_spec.rb +57 -0
- data/spec/api/lib/api/root_spec.rb +20 -0
- data/spec/api/lib/api/stats_spec.rb +19 -0
- data/spec/api/lib/commands/events_spec.rb +17 -0
- data/spec/api/lib/commands/jvm_spec.rb +45 -0
- data/spec/api/spec_helper.rb +128 -0
- data/spec/logstash/agent_spec.rb +62 -169
- data/spec/logstash/config/config_ast_spec.rb +2 -47
- data/spec/logstash/config/mixin_spec.rb +0 -157
- data/spec/logstash/filter_delegator_spec.rb +143 -0
- data/spec/logstash/inputs/metrics_spec.rb +52 -0
- data/spec/logstash/instrument/collector_spec.rb +49 -0
- data/spec/logstash/instrument/metric_spec.rb +110 -0
- data/spec/logstash/instrument/metric_store_spec.rb +163 -0
- data/spec/logstash/instrument/metric_type/counter_spec.rb +40 -0
- data/spec/logstash/instrument/metric_type/gauge_spec.rb +40 -0
- data/spec/logstash/instrument/namespaced_metric_spec.rb +25 -0
- data/spec/logstash/instrument/null_metric_spec.rb +9 -51
- data/spec/logstash/json_spec.rb +14 -0
- data/spec/logstash/output_delegator_spec.rb +6 -3
- data/spec/logstash/outputs/base_spec.rb +0 -107
- data/spec/logstash/pipeline_spec.rb +204 -33
- data/spec/logstash/plugin_spec.rb +80 -15
- data/spec/logstash/runner_spec.rb +134 -38
- data/spec/logstash/shutdown_watcher_spec.rb +0 -1
- data/spec/logstash/util/duration_formatter_spec.rb +11 -0
- data/spec/logstash/util/java_version_spec.rb +10 -2
- data/spec/logstash/util_spec.rb +28 -0
- data/spec/support/matchers.rb +30 -0
- metadata +154 -20
- data/lib/logstash/logging/json.rb +0 -21
- data/lib/logstash/special_agent.rb +0 -8
- data/lib/logstash/util/safe_uri.rb +0 -50
- data/spec/logstash/codecs/base_spec.rb +0 -74
- data/spec/static/i18n_spec.rb +0 -25
data/spec/logstash/json_spec.rb
CHANGED
@@ -59,6 +59,20 @@ describe "LogStash::Json" do
|
|
59
59
|
expect(LogStash::Json.dump(array)).to eql(json_array)
|
60
60
|
end
|
61
61
|
|
62
|
+
context "pretty print" do
|
63
|
+
|
64
|
+
let(:hash) { { "foo" => "bar", :zoo => 2 } }
|
65
|
+
|
66
|
+
it "should serialize with pretty print" do
|
67
|
+
pprint_json = LogStash::Json.dump(hash, :pretty => true)
|
68
|
+
expect(pprint_json).to include("\n")
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should by default do no pretty print" do
|
72
|
+
pprint_json = LogStash::Json.dump(hash)
|
73
|
+
expect(pprint_json).not_to include("\n")
|
74
|
+
end
|
75
|
+
end
|
62
76
|
end
|
63
77
|
|
64
78
|
else
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
require "logstash/output_delegator"
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
describe LogStash::OutputDelegator do
|
@@ -6,19 +7,21 @@ describe LogStash::OutputDelegator do
|
|
6
7
|
let(:events) { 7.times.map { LogStash::Event.new }}
|
7
8
|
let(:default_worker_count) { 1 }
|
8
9
|
|
9
|
-
subject { described_class.new(logger, out_klass, default_worker_count) }
|
10
|
+
subject { described_class.new(logger, out_klass, default_worker_count, LogStash::Instrument::NullMetric.new) }
|
10
11
|
|
11
12
|
context "with a plain output plugin" do
|
12
13
|
let(:out_klass) { double("output klass") }
|
13
14
|
let(:out_inst) { double("output instance") }
|
14
15
|
|
15
|
-
before do
|
16
|
+
before(:each) do
|
16
17
|
allow(out_klass).to receive(:new).with(any_args).and_return(out_inst)
|
17
18
|
allow(out_klass).to receive(:threadsafe?).and_return(false)
|
18
19
|
allow(out_klass).to receive(:workers_not_supported?).and_return(false)
|
19
|
-
allow(out_klass).to receive(:name).and_return("example")
|
20
20
|
allow(out_inst).to receive(:register)
|
21
21
|
allow(out_inst).to receive(:multi_receive)
|
22
|
+
allow(out_inst).to receive(:metric=).with(any_args)
|
23
|
+
allow(out_inst).to receive(:id).and_return("a-simple-plugin")
|
24
|
+
allow(out_inst).to receive(:plugin_unique_name).and_return("hello-123")
|
22
25
|
allow(logger).to receive(:debug).with(any_args)
|
23
26
|
end
|
24
27
|
|
@@ -15,31 +15,6 @@ class LogStash::Outputs::NOOP < LogStash::Outputs::Base
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
# use a dummy NOOP output to test Outputs::Base
|
20
|
-
class LogStash::Outputs::NOOPSingle < LogStash::Outputs::Base
|
21
|
-
config_name "noop single"
|
22
|
-
concurrency :single
|
23
|
-
|
24
|
-
config :dummy_option, :validate => :string
|
25
|
-
|
26
|
-
def register; end
|
27
|
-
|
28
|
-
def receive(event)
|
29
|
-
return output?(event)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
class LogStash::Outputs::NOOPShared < ::LogStash::Outputs::Base
|
34
|
-
concurrency :shared
|
35
|
-
|
36
|
-
def register; end
|
37
|
-
end
|
38
|
-
|
39
|
-
class LogStash::Outputs::NOOPLegacy < ::LogStash::Outputs::Base
|
40
|
-
def register; end
|
41
|
-
end
|
42
|
-
|
43
18
|
class LogStash::Outputs::NOOPLegacyNoWorkers < ::LogStash::Outputs::Base
|
44
19
|
LEGACY_WORKERS_NOT_SUPPORTED_REASON = "legacy reason"
|
45
20
|
|
@@ -48,52 +23,7 @@ class LogStash::Outputs::NOOPLegacyNoWorkers < ::LogStash::Outputs::Base
|
|
48
23
|
end
|
49
24
|
end
|
50
25
|
|
51
|
-
class LogStash::Outputs::NOOPMultiReceiveEncoded < ::LogStash::Outputs::Base
|
52
|
-
concurrency :single
|
53
|
-
|
54
|
-
def register; end
|
55
|
-
|
56
|
-
def multi_receive_encoded(events_and_encoded)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
26
|
describe "LogStash::Outputs::Base#new" do
|
61
|
-
describe "concurrency" do
|
62
|
-
subject { klass.new({}) }
|
63
|
-
|
64
|
-
context "single" do
|
65
|
-
let(:klass) { LogStash::Outputs::NOOPSingle }
|
66
|
-
|
67
|
-
it "should set concurrency correctly" do
|
68
|
-
expect(subject.concurrency).to eq(:single)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context "shared" do
|
73
|
-
let(:klass) { LogStash::Outputs::NOOPShared }
|
74
|
-
|
75
|
-
it "should set concurrency correctly" do
|
76
|
-
expect(subject.concurrency).to eq(:shared)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context "legacy" do
|
81
|
-
let(:klass) { LogStash::Outputs::NOOPLegacy }
|
82
|
-
|
83
|
-
it "should set concurrency correctly" do
|
84
|
-
expect(subject.concurrency).to eq(:legacy)
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should default the # of workers to 1" do
|
88
|
-
expect(subject.workers).to eq(1)
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should default concurrency to :legacy" do
|
92
|
-
expect(subject.concurrency).to eq(:legacy)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
27
|
it "should instantiate cleanly" do
|
98
28
|
params = { "dummy_option" => "potatoes", "codec" => "json", "workers" => 2 }
|
99
29
|
worker_params = params.dup; worker_params["workers"] = 1
|
@@ -107,41 +37,4 @@ describe "LogStash::Outputs::Base#new" do
|
|
107
37
|
LogStash::Outputs::NOOPLegacyNoWorkers.new.register
|
108
38
|
expect(LogStash::Outputs::NOOPLegacyNoWorkers.workers_not_supported?).to eql(true)
|
109
39
|
end
|
110
|
-
|
111
|
-
describe "dispatching multi_receive" do
|
112
|
-
let(:event) { double("event") }
|
113
|
-
let(:events) { [event] }
|
114
|
-
subject { klass.new({}) }
|
115
|
-
|
116
|
-
context "with multi_receive_encoded" do
|
117
|
-
let(:klass) { LogStash::Outputs::NOOPMultiReceiveEncoded }
|
118
|
-
let(:codec) { double("codec") }
|
119
|
-
let(:encoded) { double("encoded") }
|
120
|
-
|
121
|
-
before do
|
122
|
-
allow(codec).to receive(:multi_encode).with(events).and_return(encoded)
|
123
|
-
allow(subject).to receive(:codec).and_return(codec)
|
124
|
-
allow(subject).to receive(:multi_receive_encoded)
|
125
|
-
subject.multi_receive(events)
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should invoke multi_receive_encoded if it exists" do
|
129
|
-
expect(subject).to have_received(:multi_receive_encoded).with(encoded)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
context "with plain #receive" do
|
134
|
-
let(:klass) { LogStash::Outputs::NOOPSingle }
|
135
|
-
|
136
|
-
before do
|
137
|
-
allow(subject).to receive(:multi_receive).and_call_original
|
138
|
-
allow(subject).to receive(:receive).with(event)
|
139
|
-
subject.multi_receive(events)
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should receive the event by itself" do
|
143
|
-
expect(subject).to have_received(:receive).with(event)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
40
|
end
|
@@ -17,6 +17,21 @@ class DummyInput < LogStash::Inputs::Base
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
class DummyInputGenerator < LogStash::Inputs::Base
|
21
|
+
config_name "dummyinputgenerator"
|
22
|
+
milestone 2
|
23
|
+
|
24
|
+
def register
|
25
|
+
end
|
26
|
+
|
27
|
+
def run(queue)
|
28
|
+
queue << Logstash::Event.new while !stop?
|
29
|
+
end
|
30
|
+
|
31
|
+
def close
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
20
35
|
class DummyCodec < LogStash::Codecs::Base
|
21
36
|
config_name "dummycodec"
|
22
37
|
milestone 2
|
@@ -47,16 +62,20 @@ class DummyOutput < LogStash::Outputs::Base
|
|
47
62
|
|
48
63
|
def register
|
49
64
|
end
|
50
|
-
|
65
|
+
|
51
66
|
def receive(event)
|
52
67
|
@events << event
|
53
68
|
end
|
54
69
|
|
55
70
|
def close
|
56
|
-
@num_closes
|
71
|
+
@num_closes = 1
|
57
72
|
end
|
58
73
|
end
|
59
74
|
|
75
|
+
class DummyOutputMore < DummyOutput
|
76
|
+
config_name "dummyoutputmore"
|
77
|
+
end
|
78
|
+
|
60
79
|
class DummyFilter < LogStash::Filters::Base
|
61
80
|
config_name "dummyfilter"
|
62
81
|
milestone 2
|
@@ -118,10 +137,28 @@ describe LogStash::Pipeline do
|
|
118
137
|
eos
|
119
138
|
}
|
120
139
|
|
140
|
+
describe "debug compiled" do
|
141
|
+
let(:logger) { double("pipeline logger").as_null_object }
|
142
|
+
|
143
|
+
before do
|
144
|
+
expect(Cabin::Channel).to receive(:get).with(LogStash).and_return(logger).at_least(:once)
|
145
|
+
allow(logger).to receive(:debug?).and_return(true)
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should not receive a debug message with the compiled code" do
|
149
|
+
expect(logger).not_to receive(:debug).with(/Compiled pipeline/, anything)
|
150
|
+
pipeline = TestPipeline.new(test_config_with_filters)
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should print the compiled code if debug_config is set to true" do
|
154
|
+
expect(logger).to receive(:debug).with(/Compiled pipeline/, anything)
|
155
|
+
pipeline = TestPipeline.new(test_config_with_filters, :debug_config => true)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
121
159
|
context "when there is no command line -w N set" do
|
122
160
|
it "starts one filter thread" do
|
123
|
-
msg = "Defaulting pipeline worker threads to 1 because there are some"
|
124
|
-
" filters that might not work with multiple worker threads"
|
161
|
+
msg = "Defaulting pipeline worker threads to 1 because there are some filters that might not work with multiple worker threads"
|
125
162
|
pipeline = TestPipeline.new(test_config_with_filters)
|
126
163
|
expect(pipeline.logger).to receive(:warn).with(msg,
|
127
164
|
{:count_was=>worker_thread_count, :filters=>["dummyfilter"]})
|
@@ -132,8 +169,7 @@ describe LogStash::Pipeline do
|
|
132
169
|
|
133
170
|
context "when there is command line -w N set" do
|
134
171
|
it "starts multiple filter thread" do
|
135
|
-
msg = "Warning: Manual override - there are filters that might"
|
136
|
-
" not work with multiple worker threads"
|
172
|
+
msg = "Warning: Manual override - there are filters that might not work with multiple worker threads"
|
137
173
|
pipeline = TestPipeline.new(test_config_with_filters)
|
138
174
|
expect(pipeline.logger).to receive(:warn).with(msg,
|
139
175
|
{:worker_threads=> override_thread_count, :filters=>["dummyfilter"]})
|
@@ -356,26 +392,36 @@ describe LogStash::Pipeline do
|
|
356
392
|
end
|
357
393
|
end
|
358
394
|
|
359
|
-
|
360
|
-
|
361
|
-
|
395
|
+
context "metrics" do
|
396
|
+
config <<-CONFIG
|
397
|
+
input { }
|
398
|
+
filter { }
|
399
|
+
output { }
|
400
|
+
CONFIG
|
401
|
+
|
402
|
+
it "uses a `NullMetric` object if no metric is given" do
|
403
|
+
pipeline = LogStash::Pipeline.new(config)
|
404
|
+
expect(pipeline.metric).to be_kind_of(LogStash::Instrument::NullMetric)
|
405
|
+
end
|
406
|
+
end
|
407
|
+
|
408
|
+
context "Multiples pipelines" do
|
409
|
+
before do
|
410
|
+
allow(LogStash::Plugin).to receive(:lookup).with("input", "dummyinputgenerator").and_return(DummyInputGenerator)
|
362
411
|
allow(LogStash::Plugin).to receive(:lookup).with("codec", "plain").and_return(DummyCodec)
|
412
|
+
allow(LogStash::Plugin).to receive(:lookup).with("filter", "dummyfilter").and_return(DummyFilter)
|
363
413
|
allow(LogStash::Plugin).to receive(:lookup).with("output", "dummyoutput").and_return(DummyOutput)
|
414
|
+
allow(LogStash::Plugin).to receive(:lookup).with("output", "dummyoutputmore").and_return(DummyOutputMore)
|
364
415
|
end
|
365
416
|
|
366
|
-
|
367
|
-
|
368
|
-
<<-eos
|
369
|
-
input { dummyinput {} }
|
370
|
-
output { dummyoutput {} }
|
371
|
-
eos
|
372
|
-
end
|
417
|
+
let(:pipeline1) { LogStash::Pipeline.new("input { dummyinputgenerator {} } filter { dummyfilter {} } output { dummyoutput {}}") }
|
418
|
+
let(:pipeline2) { LogStash::Pipeline.new("input { dummyinputgenerator {} } filter { dummyfilter {} } output { dummyoutputmore {}}") }
|
373
419
|
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
420
|
+
it "should handle evaluating different config" do
|
421
|
+
expect(pipeline1.output_func(LogStash::Event.new)).not_to include(nil)
|
422
|
+
expect(pipeline1.filter_func(LogStash::Event.new)).not_to include(nil)
|
423
|
+
expect(pipeline2.output_func(LogStash::Event.new)).not_to include(nil)
|
424
|
+
expect(pipeline1.filter_func(LogStash::Event.new)).not_to include(nil)
|
379
425
|
end
|
380
426
|
end
|
381
427
|
|
@@ -389,7 +435,7 @@ describe LogStash::Pipeline do
|
|
389
435
|
}
|
390
436
|
}
|
391
437
|
filter {
|
392
|
-
multiline {
|
438
|
+
multiline {
|
393
439
|
pattern => "^NeverMatch"
|
394
440
|
negate => true
|
395
441
|
what => "previous"
|
@@ -401,7 +447,7 @@ describe LogStash::Pipeline do
|
|
401
447
|
EOS
|
402
448
|
end
|
403
449
|
let(:output) { DummyOutput.new }
|
404
|
-
|
450
|
+
|
405
451
|
before do
|
406
452
|
allow(DummyOutput).to receive(:new).with(any_args).and_return(output)
|
407
453
|
allow(LogStash::Plugin).to receive(:lookup).with("input", "generator").and_return(LogStash::Inputs::Generator)
|
@@ -437,8 +483,8 @@ describe LogStash::Pipeline do
|
|
437
483
|
|
438
484
|
it "should handle evaluating different config" do
|
439
485
|
# When the functions are compiled from the AST it will generate instance
|
440
|
-
# variables that are unique to the actual config, the
|
441
|
-
# to conditionals/plugins.
|
486
|
+
# variables that are unique to the actual config, the intances are pointing
|
487
|
+
# to conditionals and/or plugins.
|
442
488
|
#
|
443
489
|
# Before the `defined_singleton_method`, the definition of the method was
|
444
490
|
# not unique per class, but the `instance variables` were unique per class.
|
@@ -453,19 +499,144 @@ describe LogStash::Pipeline do
|
|
453
499
|
end
|
454
500
|
end
|
455
501
|
|
456
|
-
context "
|
457
|
-
|
502
|
+
context "#started_at" do
|
503
|
+
let(:config) do
|
504
|
+
<<-EOS
|
505
|
+
input {
|
506
|
+
generator {}
|
507
|
+
}
|
508
|
+
EOS
|
509
|
+
end
|
510
|
+
|
511
|
+
subject { described_class.new(config) }
|
512
|
+
|
513
|
+
it "returns nil when the pipeline isnt started" do
|
514
|
+
expect(subject.started_at).to be_nil
|
515
|
+
end
|
516
|
+
|
517
|
+
it "return when the pipeline started working" do
|
518
|
+
t = Thread.new { subject.run }
|
519
|
+
sleep(0.1)
|
520
|
+
expect(subject.started_at).to be < Time.now
|
521
|
+
t.kill rescue nil
|
522
|
+
end
|
523
|
+
end
|
524
|
+
|
525
|
+
context "#uptime" do
|
526
|
+
let(:config) do
|
527
|
+
<<-EOS
|
528
|
+
input {
|
529
|
+
generator {}
|
530
|
+
}
|
531
|
+
EOS
|
532
|
+
end
|
533
|
+
subject { described_class.new(config) }
|
534
|
+
|
535
|
+
context "when the pipeline is not started" do
|
536
|
+
it "returns 0" do
|
537
|
+
expect(subject.uptime).to eq(0)
|
538
|
+
end
|
539
|
+
end
|
540
|
+
|
541
|
+
context "when the pipeline is started" do
|
542
|
+
it "return the duration in milliseconds" do
|
543
|
+
t = Thread.new { subject.run }
|
544
|
+
sleep(0.1)
|
545
|
+
expect(subject.uptime).to be > 0
|
546
|
+
t.kill rescue nil
|
547
|
+
end
|
548
|
+
end
|
549
|
+
end
|
550
|
+
|
551
|
+
context "when collecting metrics in the pipeline" do
|
552
|
+
subject { described_class.new(config, { :metric => metric, :pipeline_id => pipeline_id }) }
|
553
|
+
let(:pipeline_id) { :main }
|
554
|
+
let(:metric) { LogStash::Instrument::Metric.new }
|
555
|
+
let(:number_of_events) { 1000 }
|
556
|
+
let(:multiline_id) { "my-multiline" }
|
557
|
+
let(:multiline_id_other) { "my-multiline_other" }
|
558
|
+
let(:dummy_output_id) { "my-dummyoutput" }
|
559
|
+
let(:generator_id) { "my-generator" }
|
560
|
+
let(:config) do
|
561
|
+
<<-EOS
|
562
|
+
input {
|
563
|
+
generator {
|
564
|
+
count => #{number_of_events}
|
565
|
+
id => "#{generator_id}"
|
566
|
+
}
|
567
|
+
}
|
568
|
+
filter {
|
569
|
+
multiline {
|
570
|
+
id => "#{multiline_id}"
|
571
|
+
pattern => "hello"
|
572
|
+
what => next
|
573
|
+
}
|
574
|
+
multiline {
|
575
|
+
id => "#{multiline_id_other}"
|
576
|
+
pattern => "hello"
|
577
|
+
what => next
|
578
|
+
}
|
579
|
+
}
|
580
|
+
output {
|
581
|
+
dummyoutput {
|
582
|
+
id => "#{dummy_output_id}"
|
583
|
+
}
|
584
|
+
}
|
585
|
+
EOS
|
586
|
+
end
|
587
|
+
let(:dummyoutput) { DummyOutput.new({ "id" => dummy_output_id }) }
|
588
|
+
|
589
|
+
before :each do
|
590
|
+
allow(DummyOutput).to receive(:new).with(any_args).and_return(dummyoutput)
|
458
591
|
allow(LogStash::Plugin).to receive(:lookup).with("input", "generator").and_return(LogStash::Inputs::Generator)
|
459
|
-
allow(LogStash::Plugin).to receive(:lookup).with("codec", "plain").and_return(
|
460
|
-
allow(LogStash::Plugin).to receive(:lookup).with("filter", "
|
592
|
+
allow(LogStash::Plugin).to receive(:lookup).with("codec", "plain").and_return(LogStash::Codecs::Plain)
|
593
|
+
allow(LogStash::Plugin).to receive(:lookup).with("filter", "multiline").and_return(LogStash::Filters::Multiline)
|
461
594
|
allow(LogStash::Plugin).to receive(:lookup).with("output", "dummyoutput").and_return(DummyOutput)
|
595
|
+
|
596
|
+
# Reset the metric store
|
597
|
+
LogStash::Instrument::Collector.instance.clear
|
598
|
+
|
599
|
+
Thread.new { subject.run }
|
600
|
+
# make sure we have received all the generated events
|
601
|
+
sleep 1 while dummyoutput.events.size < number_of_events
|
462
602
|
end
|
463
603
|
|
464
|
-
|
465
|
-
|
604
|
+
after :each do
|
605
|
+
subject.shutdown
|
606
|
+
end
|
607
|
+
|
608
|
+
context "global metric" do
|
609
|
+
let(:collected_metric) { LogStash::Instrument::Collector.instance.snapshot_metric.metric_store.get_with_path("stats/events") }
|
610
|
+
|
611
|
+
it "populates the differents" do
|
612
|
+
expect(collected_metric[:stats][:events][:in].value).to eq(number_of_events)
|
613
|
+
expect(collected_metric[:stats][:events][:filtered].value).to eq(number_of_events)
|
614
|
+
expect(collected_metric[:stats][:events][:out].value).to eq(number_of_events)
|
615
|
+
end
|
616
|
+
end
|
617
|
+
|
618
|
+
context "pipelines" do
|
619
|
+
let(:collected_metric) { LogStash::Instrument::Collector.instance.snapshot_metric.metric_store.get_with_path("stats/pipelines/") }
|
466
620
|
|
467
|
-
|
468
|
-
|
621
|
+
it "populates the pipelines core metrics" do
|
622
|
+
expect(collected_metric[:stats][:pipelines][:main][:events][:in].value).to eq(number_of_events)
|
623
|
+
expect(collected_metric[:stats][:pipelines][:main][:events][:filtered].value).to eq(number_of_events)
|
624
|
+
expect(collected_metric[:stats][:pipelines][:main][:events][:out].value).to eq(number_of_events)
|
625
|
+
end
|
626
|
+
|
627
|
+
it "populates the filter metrics" do
|
628
|
+
[multiline_id, multiline_id_other].map(&:to_sym).each do |id|
|
629
|
+
[:in, :out].each do |metric_key|
|
630
|
+
plugin_name = "multiline_#{id}".to_sym
|
631
|
+
expect(collected_metric[:stats][:pipelines][:main][:plugins][:filters][plugin_name][:events][metric_key].value).to eq(number_of_events)
|
632
|
+
end
|
633
|
+
end
|
634
|
+
end
|
635
|
+
|
636
|
+
it "populates the output metrics" do
|
637
|
+
plugin_name = "dummyoutput_#{dummy_output_id}".to_sym
|
638
|
+
expect(collected_metric[:stats][:pipelines][:main][:plugins][:outputs][plugin_name][:events][:out].value).to eq(number_of_events)
|
639
|
+
end
|
469
640
|
end
|
470
641
|
end
|
471
642
|
end
|