logstash-core 5.6.16-java → 6.0.0.alpha1-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/gemspec_jars.rb +4 -7
- data/lib/logstash-core/logstash-core.jar +0 -0
- data/lib/logstash-core/version.rb +4 -8
- data/lib/logstash-core_jars.rb +12 -26
- data/lib/logstash/agent.rb +261 -246
- data/lib/logstash/api/commands/default_metadata.rb +1 -1
- data/lib/logstash/api/commands/hot_threads_reporter.rb +5 -11
- data/lib/logstash/api/commands/node.rb +3 -2
- data/lib/logstash/api/commands/stats.rb +3 -2
- data/lib/logstash/bootstrap_check/bad_java.rb +16 -0
- data/lib/logstash/bootstrap_check/bad_ruby.rb +12 -0
- data/lib/logstash/bootstrap_check/default_config.rb +17 -0
- data/lib/logstash/compiler.rb +38 -0
- data/lib/logstash/compiler/lscl.rb +566 -0
- data/lib/logstash/compiler/lscl/lscl_grammar.rb +3503 -0
- data/lib/logstash/compiler/treetop_monkeypatches.rb +92 -0
- data/lib/logstash/config/config_ast.rb +4 -82
- data/lib/logstash/config/mixin.rb +73 -41
- data/lib/logstash/config/pipeline_config.rb +48 -0
- data/lib/logstash/config/source/base.rb +16 -0
- data/lib/logstash/config/source/local.rb +215 -0
- data/lib/logstash/config/source_loader.rb +125 -0
- data/lib/logstash/converge_result.rb +103 -0
- data/lib/logstash/environment.rb +6 -19
- data/lib/logstash/errors.rb +2 -0
- data/lib/logstash/execution_context.rb +4 -7
- data/lib/logstash/filter_delegator.rb +6 -9
- data/lib/logstash/inputs/base.rb +0 -2
- data/lib/logstash/instrument/collector.rb +5 -7
- data/lib/logstash/instrument/metric_store.rb +12 -12
- data/lib/logstash/instrument/metric_type/mean.rb +0 -5
- data/lib/logstash/instrument/namespaced_metric.rb +0 -4
- data/lib/logstash/instrument/namespaced_null_metric.rb +0 -4
- data/lib/logstash/instrument/null_metric.rb +0 -10
- data/lib/logstash/instrument/periodic_poller/cgroup.rb +85 -168
- data/lib/logstash/instrument/periodic_poller/jvm.rb +5 -5
- data/lib/logstash/instrument/periodic_poller/pq.rb +3 -7
- data/lib/logstash/instrument/periodic_pollers.rb +1 -3
- data/lib/logstash/instrument/wrapped_write_client.rb +24 -33
- data/lib/logstash/logging/logger.rb +15 -47
- data/lib/logstash/namespace.rb +0 -1
- data/lib/logstash/output_delegator.rb +5 -7
- data/lib/logstash/outputs/base.rb +0 -2
- data/lib/logstash/pipeline.rb +159 -87
- data/lib/logstash/pipeline_action.rb +13 -0
- data/lib/logstash/pipeline_action/base.rb +29 -0
- data/lib/logstash/pipeline_action/create.rb +47 -0
- data/lib/logstash/pipeline_action/reload.rb +48 -0
- data/lib/logstash/pipeline_action/stop.rb +23 -0
- data/lib/logstash/plugin.rb +0 -1
- data/lib/logstash/plugins/hooks_registry.rb +6 -0
- data/lib/logstash/plugins/registry.rb +0 -1
- data/lib/logstash/program.rb +14 -0
- data/lib/logstash/queue_factory.rb +5 -1
- data/lib/logstash/runner.rb +58 -80
- data/lib/logstash/settings.rb +3 -27
- data/lib/logstash/state_resolver.rb +41 -0
- data/lib/logstash/util/java_version.rb +6 -0
- data/lib/logstash/util/safe_uri.rb +12 -148
- data/lib/logstash/util/thread_dump.rb +4 -7
- data/lib/logstash/util/wrapped_acked_queue.rb +36 -39
- data/lib/logstash/util/wrapped_synchronous_queue.rb +29 -39
- data/lib/logstash/version.rb +10 -8
- data/locales/en.yml +3 -54
- data/logstash-core.gemspec +8 -35
- data/spec/{logstash/api/modules → api/lib/api}/logging_spec.rb +10 -1
- data/spec/{logstash/api/modules → api/lib/api}/node_plugins_spec.rb +2 -1
- data/spec/{logstash/api/modules → api/lib/api}/node_spec.rb +3 -3
- data/spec/{logstash/api/modules → api/lib/api}/node_stats_spec.rb +3 -7
- data/spec/{logstash/api/modules → api/lib/api}/plugins_spec.rb +3 -4
- data/spec/{logstash/api/modules → api/lib/api}/root_spec.rb +2 -2
- data/spec/api/lib/api/support/resource_dsl_methods.rb +87 -0
- data/spec/{logstash/api/commands/stats_spec.rb → api/lib/commands/stats.rb} +2 -7
- data/spec/{logstash/api → api/lib}/errors_spec.rb +1 -1
- data/spec/{logstash/api → api/lib}/rack_app_spec.rb +0 -0
- data/spec/api/spec_helper.rb +106 -0
- data/spec/logstash/agent/converge_spec.rb +286 -0
- data/spec/logstash/agent/metrics_spec.rb +244 -0
- data/spec/logstash/agent_spec.rb +213 -225
- data/spec/logstash/compiler/compiler_spec.rb +584 -0
- data/spec/logstash/config/config_ast_spec.rb +8 -47
- data/spec/logstash/config/mixin_spec.rb +2 -42
- data/spec/logstash/config/pipeline_config_spec.rb +75 -0
- data/spec/logstash/config/source/local_spec.rb +395 -0
- data/spec/logstash/config/source_loader_spec.rb +122 -0
- data/spec/logstash/converge_result_spec.rb +179 -0
- data/spec/logstash/event_spec.rb +0 -66
- data/spec/logstash/execution_context_spec.rb +8 -12
- data/spec/logstash/filter_delegator_spec.rb +12 -24
- data/spec/logstash/inputs/base_spec.rb +7 -5
- data/spec/logstash/instrument/periodic_poller/cgroup_spec.rb +92 -225
- data/spec/logstash/instrument/periodic_poller/jvm_spec.rb +1 -1
- data/spec/logstash/instrument/periodic_poller/os_spec.rb +32 -29
- data/spec/logstash/instrument/wrapped_write_client_spec.rb +33 -33
- data/spec/logstash/legacy_ruby_event_spec.rb +13 -4
- data/spec/logstash/output_delegator_spec.rb +11 -20
- data/spec/logstash/outputs/base_spec.rb +7 -5
- data/spec/logstash/pipeline_action/create_spec.rb +83 -0
- data/spec/logstash/pipeline_action/reload_spec.rb +83 -0
- data/spec/logstash/pipeline_action/stop_spec.rb +37 -0
- data/spec/logstash/pipeline_pq_file_spec.rb +1 -1
- data/spec/logstash/pipeline_spec.rb +81 -137
- data/spec/logstash/plugin_spec.rb +2 -1
- data/spec/logstash/plugins/hooks_registry_spec.rb +6 -0
- data/spec/logstash/queue_factory_spec.rb +13 -1
- data/spec/logstash/runner_spec.rb +29 -140
- data/spec/logstash/settings/writable_directory_spec.rb +10 -13
- data/spec/logstash/settings_spec.rb +0 -91
- data/spec/logstash/state_resolver_spec.rb +156 -0
- data/spec/logstash/timestamp_spec.rb +2 -6
- data/spec/logstash/util/java_version_spec.rb +22 -0
- data/spec/logstash/util/safe_uri_spec.rb +0 -56
- data/spec/logstash/util/wrapped_synchronous_queue_spec.rb +22 -0
- data/spec/support/helpers.rb +9 -11
- data/spec/support/matchers.rb +96 -6
- data/spec/support/mocks_classes.rb +80 -0
- data/spec/support/shared_contexts.rb +2 -27
- metadata +100 -149
- data/lib/logstash/config/loader.rb +0 -107
- data/lib/logstash/config/modules_common.rb +0 -103
- data/lib/logstash/config/source/modules.rb +0 -55
- data/lib/logstash/config/string_escape.rb +0 -27
- data/lib/logstash/dependency_report.rb +0 -131
- data/lib/logstash/dependency_report_runner.rb +0 -17
- data/lib/logstash/elasticsearch_client.rb +0 -142
- data/lib/logstash/instrument/global_metrics.rb +0 -13
- data/lib/logstash/instrument/periodic_poller/dlq.rb +0 -24
- data/lib/logstash/modules/cli_parser.rb +0 -74
- data/lib/logstash/modules/elasticsearch_config.rb +0 -22
- data/lib/logstash/modules/elasticsearch_importer.rb +0 -37
- data/lib/logstash/modules/elasticsearch_resource.rb +0 -10
- data/lib/logstash/modules/file_reader.rb +0 -36
- data/lib/logstash/modules/kibana_base.rb +0 -24
- data/lib/logstash/modules/kibana_client.rb +0 -124
- data/lib/logstash/modules/kibana_config.rb +0 -105
- data/lib/logstash/modules/kibana_dashboards.rb +0 -36
- data/lib/logstash/modules/kibana_importer.rb +0 -17
- data/lib/logstash/modules/kibana_resource.rb +0 -10
- data/lib/logstash/modules/kibana_settings.rb +0 -40
- data/lib/logstash/modules/logstash_config.rb +0 -120
- data/lib/logstash/modules/resource_base.rb +0 -38
- data/lib/logstash/modules/scaffold.rb +0 -52
- data/lib/logstash/modules/settings_merger.rb +0 -23
- data/lib/logstash/modules/util.rb +0 -17
- data/lib/logstash/util/dead_letter_queue_manager.rb +0 -61
- data/lib/logstash/util/environment_variables.rb +0 -43
- data/spec/logstash/config/loader_spec.rb +0 -38
- data/spec/logstash/config/string_escape_spec.rb +0 -24
- data/spec/logstash/instrument/periodic_poller/dlq_spec.rb +0 -17
- data/spec/logstash/modules/logstash_config_spec.rb +0 -56
- data/spec/logstash/modules/scaffold_spec.rb +0 -234
- data/spec/logstash/pipeline_dlq_commit_spec.rb +0 -109
- data/spec/logstash/settings/splittable_string_array_spec.rb +0 -51
- data/spec/logstash/util/wrapped_acked_queue_spec.rb +0 -49
- data/versions-gem-copy.yml +0 -12
@@ -7,8 +7,8 @@ require_relative "../../support/mocks_classes"
|
|
7
7
|
require "spec_helper"
|
8
8
|
|
9
9
|
describe LogStash::Instrument::WrappedWriteClient do
|
10
|
-
let
|
11
|
-
let
|
10
|
+
let(:write_client) { queue.write_client }
|
11
|
+
let(:read_client) { queue.read_client }
|
12
12
|
let(:pipeline) { double("pipeline", :pipeline_id => :main) }
|
13
13
|
let(:collector) { LogStash::Instrument::Collector.new }
|
14
14
|
let(:metric) { LogStash::Instrument::Metric.new(collector) }
|
@@ -18,54 +18,39 @@ describe LogStash::Instrument::WrappedWriteClient do
|
|
18
18
|
|
19
19
|
subject { described_class.new(write_client, pipeline, metric, plugin) }
|
20
20
|
|
21
|
-
def threaded_read_client
|
22
|
-
Thread.new do
|
23
|
-
started_at = Time.now
|
24
|
-
|
25
|
-
batch_size = 0
|
26
|
-
loop {
|
27
|
-
if Time.now - started_at > 60
|
28
|
-
raise "Took too much time to read from the queue"
|
29
|
-
end
|
30
|
-
batch_size = read_client.read_batch.size
|
31
|
-
|
32
|
-
break if batch_size > 0
|
33
|
-
}
|
34
|
-
expect(batch_size).to eq(1)
|
35
|
-
end
|
36
|
-
end
|
37
21
|
|
38
22
|
shared_examples "queue tests" do
|
39
23
|
it "pushes single event to the `WriteClient`" do
|
40
|
-
|
41
|
-
|
24
|
+
t = Thread.new do
|
25
|
+
subject.push(event)
|
42
26
|
end
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
[pusher_thread, reader_thread].collect(&:join)
|
27
|
+
sleep(0.01) while !t.status
|
28
|
+
expect(read_client.read_batch.size).to eq(1)
|
29
|
+
t.kill rescue nil
|
47
30
|
end
|
48
31
|
|
49
32
|
it "pushes batch to the `WriteClient`" do
|
50
33
|
batch = write_client.get_new_batch
|
51
34
|
batch << event
|
52
35
|
|
53
|
-
|
54
|
-
|
36
|
+
t = Thread.new do
|
37
|
+
subject.push_batch(batch)
|
55
38
|
end
|
56
39
|
|
57
|
-
|
58
|
-
|
40
|
+
sleep(0.01) while !t.status
|
41
|
+
expect(read_client.read_batch.size).to eq(1)
|
42
|
+
t.kill rescue nil
|
59
43
|
end
|
60
44
|
|
61
45
|
context "recorded metrics" do
|
62
46
|
before do
|
63
|
-
|
64
|
-
|
47
|
+
t = Thread.new do
|
48
|
+
subject.push(event)
|
65
49
|
end
|
66
|
-
|
67
|
-
|
68
|
-
|
50
|
+
sleep(0.01) while !t.status
|
51
|
+
sleep(0.250) # make it block for some time, so duration isn't 0
|
52
|
+
read_client.read_batch.size
|
53
|
+
t.kill rescue nil
|
69
54
|
end
|
70
55
|
|
71
56
|
let(:snapshot_store) { collector.snapshot_metric.metric_store }
|
@@ -110,4 +95,19 @@ describe LogStash::Instrument::WrappedWriteClient do
|
|
110
95
|
|
111
96
|
include_examples "queue tests"
|
112
97
|
end
|
98
|
+
|
99
|
+
context "AckedMemoryQueue" do
|
100
|
+
let(:queue) { LogStash::Util::WrappedAckedQueue.create_memory_based("", 1024, 10, 1024) }
|
101
|
+
|
102
|
+
before do
|
103
|
+
read_client.set_events_metric(metric.namespace([:stats, :events]))
|
104
|
+
read_client.set_pipeline_metric(metric.namespace([:stats, :pipelines, :main, :events]))
|
105
|
+
end
|
106
|
+
|
107
|
+
after do
|
108
|
+
queue.close
|
109
|
+
end
|
110
|
+
|
111
|
+
include_examples "queue tests"
|
112
|
+
end
|
113
113
|
end
|
@@ -399,17 +399,17 @@ describe LogStash::Event do
|
|
399
399
|
end
|
400
400
|
|
401
401
|
it "should assign current time when no timestamp" do
|
402
|
-
expect(LogStash::Event.new({}).timestamp.to_i).to be_within(
|
402
|
+
expect(LogStash::Event.new({}).timestamp.to_i).to be_within(1).of (Time.now.to_i)
|
403
403
|
end
|
404
404
|
|
405
405
|
it "should tag for invalid value" do
|
406
406
|
event = LogStash::Event.new("@timestamp" => "foo")
|
407
|
-
expect(event.timestamp.to_i).to be_within(
|
407
|
+
expect(event.timestamp.to_i).to be_within(1).of Time.now.to_i
|
408
408
|
expect(event.get("tags")).to eq([LogStash::Event::TIMESTAMP_FAILURE_TAG])
|
409
409
|
expect(event.get(LogStash::Event::TIMESTAMP_FAILURE_FIELD)).to eq("foo")
|
410
410
|
|
411
411
|
event = LogStash::Event.new("@timestamp" => 666)
|
412
|
-
expect(event.timestamp.to_i).to be_within(
|
412
|
+
expect(event.timestamp.to_i).to be_within(1).of Time.now.to_i
|
413
413
|
expect(event.get("tags")).to eq([LogStash::Event::TIMESTAMP_FAILURE_TAG])
|
414
414
|
expect(event.get(LogStash::Event::TIMESTAMP_FAILURE_FIELD)).to eq(666)
|
415
415
|
end
|
@@ -421,7 +421,7 @@ describe LogStash::Event do
|
|
421
421
|
|
422
422
|
it "should tag for invalid string format" do
|
423
423
|
event = LogStash::Event.new("@timestamp" => "foo")
|
424
|
-
expect(event.timestamp.to_i).to be_within(
|
424
|
+
expect(event.timestamp.to_i).to be_within(1).of Time.now.to_i
|
425
425
|
expect(event.get("tags")).to eq([LogStash::Event::TIMESTAMP_FAILURE_TAG])
|
426
426
|
expect(event.get(LogStash::Event::TIMESTAMP_FAILURE_FIELD)).to eq("foo")
|
427
427
|
end
|
@@ -590,6 +590,15 @@ describe LogStash::Event do
|
|
590
590
|
describe "#to_s" do
|
591
591
|
let(:timestamp) { LogStash::Timestamp.new }
|
592
592
|
let(:event1) { LogStash::Event.new({ "@timestamp" => timestamp, "host" => "foo", "message" => "bar"}) }
|
593
|
+
let(:event2) { LogStash::Event.new({ "host" => "bar", "message" => "foo"}) }
|
594
|
+
|
595
|
+
it "should cache only one template" do
|
596
|
+
LogStash::StringInterpolation.clear_cache
|
597
|
+
expect {
|
598
|
+
event1.to_s
|
599
|
+
event2.to_s
|
600
|
+
}.to change { LogStash::StringInterpolation.cache_size }.by(1)
|
601
|
+
end
|
593
602
|
|
594
603
|
it "return the string containing the timestamp, the host and the message" do
|
595
604
|
expect(event1.to_s).to eq("#{timestamp.to_iso8601} #{event1.get("host")} #{event1.get("message")}")
|
@@ -2,26 +2,18 @@
|
|
2
2
|
require "logstash/output_delegator"
|
3
3
|
require "logstash/execution_context"
|
4
4
|
require "spec_helper"
|
5
|
+
require "support/shared_contexts"
|
5
6
|
|
6
7
|
describe LogStash::OutputDelegator do
|
7
|
-
|
8
|
-
class MockGauge
|
9
|
-
def increment(_)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
8
|
let(:logger) { double("logger") }
|
14
9
|
let(:events) { 7.times.map { LogStash::Event.new }}
|
15
10
|
let(:plugin_args) { {"id" => "foo", "arg1" => "val1"} }
|
16
11
|
let(:collector) { [] }
|
17
|
-
let(:counter_in) { MockGauge.new }
|
18
|
-
let(:counter_out) { MockGauge.new }
|
19
|
-
let(:counter_time) { MockGauge.new }
|
20
12
|
let(:metric) { LogStash::Instrument::NamespacedNullMetric.new(collector, :null) }
|
21
|
-
|
22
|
-
|
13
|
+
|
14
|
+
include_context "execution_context"
|
23
15
|
|
24
|
-
subject { described_class.new(logger, out_klass, metric,
|
16
|
+
subject { described_class.new(logger, out_klass, metric, execution_context, ::LogStash::OutputDelegatorStrategyRegistry.instance, plugin_args) }
|
25
17
|
|
26
18
|
context "with a plain output plugin" do
|
27
19
|
let(:out_klass) { double("output klass") }
|
@@ -31,9 +23,6 @@ describe LogStash::OutputDelegator do
|
|
31
23
|
before(:each) do
|
32
24
|
# use the same metric instance
|
33
25
|
allow(metric).to receive(:namespace).with(any_args).and_return(metric)
|
34
|
-
allow(metric).to receive(:counter).with(:in).and_return(counter_in)
|
35
|
-
allow(metric).to receive(:counter).with(:out).and_return(counter_out)
|
36
|
-
allow(metric).to receive(:counter).with(:duration_in_millis).and_return(counter_time)
|
37
26
|
|
38
27
|
allow(out_klass).to receive(:new).with(any_args).and_return(out_inst)
|
39
28
|
allow(out_klass).to receive(:name).and_return("example")
|
@@ -42,7 +31,7 @@ describe LogStash::OutputDelegator do
|
|
42
31
|
allow(out_inst).to receive(:register)
|
43
32
|
allow(out_inst).to receive(:multi_receive)
|
44
33
|
allow(out_inst).to receive(:metric=).with(any_args)
|
45
|
-
allow(out_inst).to receive(:execution_context=).with(
|
34
|
+
allow(out_inst).to receive(:execution_context=).with(execution_context)
|
46
35
|
allow(out_inst).to receive(:id).and_return("a-simple-plugin")
|
47
36
|
|
48
37
|
allow(subject.metric_events).to receive(:increment).with(any_args)
|
@@ -55,7 +44,7 @@ describe LogStash::OutputDelegator do
|
|
55
44
|
|
56
45
|
it "should push the name of the plugin to the metric" do
|
57
46
|
expect(metric).to receive(:gauge).with(:name, out_klass.config_name)
|
58
|
-
described_class.new(logger, out_klass, metric,
|
47
|
+
described_class.new(logger, out_klass, metric, execution_context, ::LogStash::OutputDelegatorStrategyRegistry.instance, plugin_args)
|
59
48
|
end
|
60
49
|
|
61
50
|
context "after having received a batch of events" do
|
@@ -69,13 +58,15 @@ describe LogStash::OutputDelegator do
|
|
69
58
|
end
|
70
59
|
|
71
60
|
it "should increment the number of events received" do
|
72
|
-
expect(
|
73
|
-
expect(
|
61
|
+
expect(subject.metric_events).to receive(:increment).with(:in, events.length)
|
62
|
+
expect(subject.metric_events).to receive(:increment).with(:out, events.length)
|
74
63
|
subject.multi_receive(events)
|
75
64
|
end
|
76
65
|
|
77
66
|
it "should record the `duration_in_millis`" do
|
78
|
-
|
67
|
+
clock = spy("clock")
|
68
|
+
expect(subject.metric_events).to receive(:time).with(:duration_in_millis).and_return(clock)
|
69
|
+
expect(clock).to receive(:stop)
|
79
70
|
subject.multi_receive(events)
|
80
71
|
end
|
81
72
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
require "spec_helper"
|
3
3
|
require "logstash/outputs/base"
|
4
4
|
require "logstash/execution_context"
|
5
|
+
require "support/shared_contexts"
|
5
6
|
|
6
7
|
# use a dummy NOOP output to test Outputs::Base
|
7
8
|
class LogStash::Outputs::NOOPSingle < LogStash::Outputs::Base
|
@@ -80,23 +81,24 @@ describe "LogStash::Outputs::Base#new" do
|
|
80
81
|
end
|
81
82
|
|
82
83
|
context "execution context" do
|
83
|
-
|
84
|
+
include_context "execution_context"
|
85
|
+
|
84
86
|
let(:klass) { LogStash::Outputs::NOOPSingle }
|
85
87
|
|
86
88
|
subject(:instance) { klass.new(params.dup) }
|
87
89
|
|
88
90
|
it "allow to set the context" do
|
89
91
|
expect(instance.execution_context).to be_nil
|
90
|
-
instance.execution_context =
|
92
|
+
instance.execution_context = execution_context
|
91
93
|
|
92
|
-
expect(instance.execution_context).to eq(
|
94
|
+
expect(instance.execution_context).to eq(execution_context)
|
93
95
|
end
|
94
96
|
|
95
97
|
it "propagate the context to the codec" do
|
96
98
|
expect(instance.codec.execution_context).to be_nil
|
97
|
-
instance.execution_context =
|
99
|
+
instance.execution_context = execution_context
|
98
100
|
|
99
|
-
expect(instance.codec.execution_context).to eq(
|
101
|
+
expect(instance.codec.execution_context).to eq(execution_context)
|
100
102
|
end
|
101
103
|
end
|
102
104
|
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
require_relative "../../support/helpers"
|
4
|
+
require_relative "../../support/matchers"
|
5
|
+
require "logstash/pipeline_action/create"
|
6
|
+
require "logstash/instrument/null_metric"
|
7
|
+
require "logstash/inputs/generator"
|
8
|
+
|
9
|
+
describe LogStash::PipelineAction::Create do
|
10
|
+
let(:metric) { LogStash::Instrument::NullMetric.new(LogStash::Instrument::Collector.new) }
|
11
|
+
let(:pipeline_config) { mock_pipeline_config(:main, "input { generator { id => '123' } } output { null {} }") }
|
12
|
+
let(:pipelines) { Hash.new }
|
13
|
+
let(:agent) { double("agent") }
|
14
|
+
|
15
|
+
before do
|
16
|
+
clear_data_dir
|
17
|
+
end
|
18
|
+
|
19
|
+
subject { described_class.new(pipeline_config, metric) }
|
20
|
+
|
21
|
+
after do
|
22
|
+
pipelines.each { |_, pipeline| pipeline.shutdown }
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns the pipeline_id" do
|
26
|
+
expect(subject.pipeline_id).to eq(:main)
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
context "when we have really short lived pipeline" do
|
31
|
+
let(:pipeline_config) { mock_pipeline_config(:main, "input { generator { count => 1 } } output { null {} }") }
|
32
|
+
|
33
|
+
it "returns a successful execution status" do
|
34
|
+
expect(subject.execute(agent, pipelines)).to be_truthy
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when the pipeline successfully start" do
|
39
|
+
it "adds the pipeline to the current pipelines" do
|
40
|
+
expect { subject.execute(agent, pipelines) }.to change(pipelines, :size).by(1)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "starts the pipeline" do
|
44
|
+
subject.execute(agent, pipelines)
|
45
|
+
expect(pipelines[:main].running?).to be_truthy
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns a successful execution status" do
|
49
|
+
expect(subject.execute(agent, pipelines)).to be_truthy
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "when the pipeline doesn't start" do
|
54
|
+
context "with a syntax error" do
|
55
|
+
let(:pipeline_config) { mock_pipeline_config(:main, "input { generator { id => '123' } } output { stdout ") } # bad syntax
|
56
|
+
|
57
|
+
it "raises the exception upstream" do
|
58
|
+
expect { subject.execute(agent, pipelines) }.to raise_error
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "with an error raised during `#register`" do
|
63
|
+
let(:pipeline_config) { mock_pipeline_config(:main, "input { generator { id => '123' } } filter { ruby { init => '1/0' code => '1+2' } } output { null {} }") }
|
64
|
+
|
65
|
+
it "returns false" do
|
66
|
+
expect(subject.execute(agent, pipelines)).not_to be_a_successful_action
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "when sorting create action" do
|
72
|
+
let(:pipeline_config) { mock_pipeline_config(:main, "input { generator { id => '123' } } output { null {} }") }
|
73
|
+
let(:system_pipeline_config) { mock_pipeline_config(:main_2, "input { generator { id => '123' } } output { null {} }", { "pipeline.system" => true }) }
|
74
|
+
|
75
|
+
it "should give higher priority to system pipeline" do
|
76
|
+
action_user_pipeline = described_class.new(pipeline_config, metric)
|
77
|
+
action_system_pipeline = described_class.new(system_pipeline_config, metric)
|
78
|
+
|
79
|
+
sorted = [action_user_pipeline, action_system_pipeline].sort
|
80
|
+
expect(sorted).to eq([action_system_pipeline, action_user_pipeline])
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
require_relative "../../support/helpers"
|
4
|
+
require_relative "../../support/matchers"
|
5
|
+
require "logstash/pipeline_action/reload"
|
6
|
+
require "logstash/instrument/null_metric"
|
7
|
+
|
8
|
+
describe LogStash::PipelineAction::Reload do
|
9
|
+
let(:metric) { LogStash::Instrument::NullMetric.new(LogStash::Instrument::Collector.new) }
|
10
|
+
let(:pipeline_id) { :main }
|
11
|
+
let(:new_pipeline_config) { mock_pipeline_config(pipeline_id, "input { generator { id => 'new' } } output { null {} }", { "pipeline.reloadable" => true}) }
|
12
|
+
let(:pipeline_config) { "input { generator {} } output { null {} }" }
|
13
|
+
let(:pipeline) { LogStash::Pipeline.new(pipeline_config, mock_settings("pipeline.reloadable" => true)) }
|
14
|
+
let(:pipelines) { { pipeline_id => pipeline } }
|
15
|
+
let(:agent) { double("agent") }
|
16
|
+
|
17
|
+
subject { described_class.new(new_pipeline_config, metric) }
|
18
|
+
|
19
|
+
before do
|
20
|
+
clear_data_dir
|
21
|
+
pipeline.start
|
22
|
+
end
|
23
|
+
|
24
|
+
after do
|
25
|
+
pipelines.each { |_, pipeline| pipeline.shutdown }
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns the pipeline_id" do
|
29
|
+
expect(subject.pipeline_id).to eq(pipeline_id)
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when existing pipeline and new pipeline are both reloadable" do
|
33
|
+
it "stop the previous pipeline" do
|
34
|
+
expect { subject.execute(agent, pipelines) }.to change(pipeline, :running?).from(true).to(false)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "start the new pipeline" do
|
38
|
+
subject.execute(agent, pipelines)
|
39
|
+
expect(pipelines[pipeline_id].running?).to be_truthy
|
40
|
+
end
|
41
|
+
|
42
|
+
it "run the new pipeline code" do
|
43
|
+
subject.execute(agent, pipelines)
|
44
|
+
expect(pipelines[pipeline_id].config_hash).to eq(new_pipeline_config.config_hash)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when the existing pipeline is not reloadable" do
|
49
|
+
before do
|
50
|
+
allow(pipeline).to receive(:reloadable?).and_return(false)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "cannot successfully execute the action" do
|
54
|
+
expect(subject.execute(agent, pipelines)).not_to be_a_successful_action
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when the new pipeline is not reloadable" do
|
59
|
+
let(:new_pipeline_config) { mock_pipeline_config(pipeline_id, "input { generator { id => 'new' } } output { null {} }", { "pipeline.reloadable" => false}) }
|
60
|
+
|
61
|
+
it "cannot successfully execute the action" do
|
62
|
+
expect(subject.execute(agent, pipelines)).not_to be_a_successful_action
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "when the new pipeline has syntax errors" do
|
67
|
+
let(:new_pipeline_config) { mock_pipeline_config(pipeline_id, "input generator { id => 'new' } } output { null {} }", { "pipeline.reloadable" => false}) }
|
68
|
+
|
69
|
+
it "cannot successfully execute the action" do
|
70
|
+
expect(subject.execute(agent, pipelines)).not_to be_a_successful_action
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "when there is an error in the register" do
|
75
|
+
before do
|
76
|
+
allow_any_instance_of(LogStash::Inputs::Generator).to receive(:register).and_raise("Bad value")
|
77
|
+
end
|
78
|
+
|
79
|
+
it "cannot successfully execute the action" do
|
80
|
+
expect(subject.execute(agent, pipelines)).not_to be_a_successful_action
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
require_relative "../../support/helpers"
|
4
|
+
require "logstash/pipeline_action/stop"
|
5
|
+
require "logstash/pipeline"
|
6
|
+
require "logstash/instrument/null_metric"
|
7
|
+
|
8
|
+
describe LogStash::PipelineAction::Stop do
|
9
|
+
let(:pipeline_config) { "input { generator {} } output { null {} }" }
|
10
|
+
let(:pipeline_id) { :main }
|
11
|
+
let(:pipeline) { LogStash::Pipeline.new(pipeline_config) }
|
12
|
+
let(:pipelines) { { :main => pipeline } }
|
13
|
+
let(:agent) { double("agent") }
|
14
|
+
|
15
|
+
subject { described_class.new(pipeline_id) }
|
16
|
+
|
17
|
+
before do
|
18
|
+
clear_data_dir
|
19
|
+
pipeline.start
|
20
|
+
end
|
21
|
+
|
22
|
+
after do
|
23
|
+
pipeline.shutdown
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns the pipeline_id" do
|
27
|
+
expect(subject.pipeline_id).to eq(:main)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "shutdown the running pipeline" do
|
31
|
+
expect { subject.execute(agent, pipelines) }.to change(pipeline, :running?).from(true).to(false)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "removes the pipeline from the running pipelines" do
|
35
|
+
expect { subject.execute(agent, pipelines) }.to change { pipelines.include?(pipeline_id) }.from(true).to(false)
|
36
|
+
end
|
37
|
+
end
|