logstash-core 5.0.0.alpha2.snapshot2-java → 5.0.0.alpha3-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.

Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/lib/logstash-core/version.rb +1 -1
  3. data/lib/logstash/agent.rb +48 -31
  4. data/lib/logstash/api/{lib/helpers/app_helpers.rb → app_helpers.rb} +0 -0
  5. data/lib/logstash/api/command_factory.rb +34 -0
  6. data/lib/logstash/api/commands/base.rb +25 -0
  7. data/lib/logstash/api/commands/stats.rb +105 -0
  8. data/lib/logstash/api/commands/system/basicinfo_command.rb +23 -0
  9. data/lib/logstash/api/commands/system/plugins_command.rb +35 -0
  10. data/lib/logstash/api/modules/base.rb +43 -0
  11. data/lib/logstash/api/modules/node.rb +24 -0
  12. data/lib/logstash/api/modules/node_stats.rb +59 -0
  13. data/lib/logstash/api/modules/plugins.rb +15 -0
  14. data/lib/logstash/api/modules/root.rb +15 -0
  15. data/lib/logstash/api/modules/stats.rb +63 -0
  16. data/lib/logstash/api/rack_app.rb +33 -0
  17. data/lib/logstash/api/service.rb +73 -0
  18. data/lib/logstash/config/config_ast.rb +23 -18
  19. data/lib/logstash/config/loader.rb +4 -4
  20. data/lib/logstash/config/mixin.rb +10 -21
  21. data/lib/logstash/environment.rb +29 -0
  22. data/lib/logstash/filters/base.rb +2 -2
  23. data/lib/logstash/inputs/base.rb +2 -2
  24. data/lib/logstash/instrument/collector.rb +1 -1
  25. data/lib/logstash/instrument/metric_store.rb +11 -1
  26. data/lib/logstash/instrument/periodic_poller/base.rb +2 -0
  27. data/lib/logstash/instrument/periodic_poller/jvm.rb +47 -2
  28. data/lib/logstash/logging/json.rb +21 -0
  29. data/lib/logstash/output_delegator.rb +2 -2
  30. data/lib/logstash/patches/clamp.rb +69 -0
  31. data/lib/logstash/pipeline.rb +36 -69
  32. data/lib/logstash/plugin.rb +1 -1
  33. data/lib/logstash/runner.rb +171 -146
  34. data/lib/logstash/settings.rb +267 -0
  35. data/lib/logstash/util/decorators.rb +6 -6
  36. data/lib/logstash/util/java_version.rb +1 -10
  37. data/lib/logstash/util/thread_dump.rb +55 -0
  38. data/lib/logstash/util/worker_threads_default_printer.rb +2 -2
  39. data/lib/logstash/version.rb +1 -1
  40. data/lib/logstash/webserver.rb +15 -49
  41. data/locales/en.yml +22 -25
  42. data/logstash-core.gemspec +3 -3
  43. data/spec/api/lib/api/node_spec.rb +2 -2
  44. data/spec/api/lib/api/node_stats_spec.rb +32 -57
  45. data/spec/api/lib/api/plugins_spec.rb +3 -3
  46. data/spec/api/lib/api/root_spec.rb +2 -2
  47. data/spec/api/lib/api/support/resource_dsl_methods.rb +47 -0
  48. data/spec/api/lib/commands/stats.rb +47 -0
  49. data/spec/api/spec_helper.rb +21 -21
  50. data/spec/conditionals_spec.rb +113 -113
  51. data/spec/logstash/agent_spec.rb +85 -68
  52. data/spec/logstash/config/config_ast_spec.rb +4 -2
  53. data/spec/logstash/config/mixin_spec.rb +33 -7
  54. data/spec/logstash/filters/base_spec.rb +16 -16
  55. data/spec/logstash/inputs/base_spec.rb +8 -8
  56. data/spec/logstash/instrument/periodic_poller/jvm_spec.rb +45 -0
  57. data/spec/logstash/output_delegator_spec.rb +2 -0
  58. data/spec/logstash/pipeline_reporter_spec.rb +5 -1
  59. data/spec/logstash/pipeline_spec.rb +75 -30
  60. data/spec/logstash/plugin_spec.rb +2 -2
  61. data/spec/logstash/runner_spec.rb +112 -25
  62. data/spec/logstash/setting_spec.rb +130 -0
  63. data/spec/logstash/settings_spec.rb +62 -0
  64. metadata +37 -43
  65. data/lib/logstash/api/init.ru +0 -31
  66. data/lib/logstash/api/lib/app.rb +0 -40
  67. data/lib/logstash/api/lib/app/command.rb +0 -29
  68. data/lib/logstash/api/lib/app/command_factory.rb +0 -29
  69. data/lib/logstash/api/lib/app/commands/stats/events_command.rb +0 -13
  70. data/lib/logstash/api/lib/app/commands/stats/hotthreads_command.rb +0 -120
  71. data/lib/logstash/api/lib/app/commands/stats/memory_command.rb +0 -25
  72. data/lib/logstash/api/lib/app/commands/system/basicinfo_command.rb +0 -15
  73. data/lib/logstash/api/lib/app/commands/system/plugins_command.rb +0 -28
  74. data/lib/logstash/api/lib/app/modules/node.rb +0 -25
  75. data/lib/logstash/api/lib/app/modules/node_stats.rb +0 -51
  76. data/lib/logstash/api/lib/app/modules/plugins.rb +0 -15
  77. data/lib/logstash/api/lib/app/modules/stats.rb +0 -21
  78. data/lib/logstash/api/lib/app/root.rb +0 -13
  79. data/lib/logstash/api/lib/app/service.rb +0 -61
  80. data/lib/logstash/api/lib/app/stats.rb +0 -56
  81. data/lib/logstash/util/defaults_printer.rb +0 -31
  82. data/spec/api/lib/api/stats_spec.rb +0 -19
  83. data/spec/api/lib/commands/events_spec.rb +0 -17
  84. data/spec/api/lib/commands/jvm_spec.rb +0 -45
  85. data/spec/logstash/util/defaults_printer_spec.rb +0 -50
  86. data/spec/logstash/util/worker_threads_default_printer_spec.rb +0 -45
@@ -169,10 +169,12 @@ describe LogStashConfigParser do
169
169
  end
170
170
 
171
171
  describe "generated conditional functionals" do
172
- it "should be defined at instance level" do
172
+ it "should be created per instance" do
173
173
  instance_1 = pipeline_klass.new(config_string)
174
174
  instance_2 = pipeline_klass.new(config_string)
175
- expect(instance_1.method(:cond_func_1).owner).to_not be(instance_2.method(:cond_func_1).owner)
175
+ generated_method_1 = instance_1.instance_variable_get("@generated_objects")[:cond_func_1]
176
+ generated_method_2 = instance_2.instance_variable_get("@generated_objects")[:cond_func_1]
177
+ expect(generated_method_1).to_not be(generated_method_2)
176
178
  end
177
179
  end
178
180
  end
@@ -160,14 +160,14 @@ describe LogStash::Config::Mixin do
160
160
  let(:plugin_class) do
161
161
  Class.new(LogStash::Filters::Base) do
162
162
  config_name "one_plugin"
163
- config :oneString, :validate => :string
164
- config :oneBoolean, :validate => :boolean
165
- config :oneNumber, :validate => :number
166
- config :oneArray, :validate => :array
167
- config :oneHash, :validate => :hash
163
+ config :oneString, :validate => :string, :required => false
164
+ config :oneBoolean, :validate => :boolean, :required => false
165
+ config :oneNumber, :validate => :number, :required => false
166
+ config :oneArray, :validate => :array, :required => false
167
+ config :oneHash, :validate => :hash, :required => false
168
168
 
169
169
  def initialize(params)
170
- super(params.merge(LogStash::Config::Mixin::ALLOW_ENV_FLAG => true))
170
+ super(params)
171
171
  end
172
172
  end
173
173
  end
@@ -231,8 +231,34 @@ describe LogStash::Config::Mixin do
231
231
  expect(subject.oneArray).to(be == [ "first array value", "fancy" ])
232
232
  expect(subject.oneHash).to(be == { "key1" => "fancy", "key2" => "fancy is true", "key3" => "true or false" })
233
233
  end
234
+ end
235
+
236
+ context "should support $ in values" do
237
+ before do
238
+ ENV["bar"] = "foo"
239
+ ENV["f$$"] = "bar"
240
+ end
241
+
242
+ after do
243
+ ENV.delete("bar")
244
+ ENV.delete("f$$")
245
+ end
246
+
247
+ subject do
248
+ plugin_class.new(
249
+ "oneString" => "${f$$:val}",
250
+ "oneArray" => ["foo$bar", "${bar:my$val}"]
251
+ # "dollar_in_env" => "${f$$:final}"
252
+ )
253
+ end
234
254
 
255
+ it "should support $ in values" do
256
+ expect(subject.oneArray).to(be == ["foo$bar", "foo"])
257
+ end
258
+
259
+ it "should not support $ in environment variable name" do
260
+ expect(subject.oneString).to(be == "${f$$:val}")
261
+ end
235
262
  end
236
263
  end
237
-
238
264
  end
@@ -62,7 +62,7 @@ describe LogStash::Filters::NOOP do
62
62
  CONFIG
63
63
 
64
64
  sample "example" do
65
- insist { subject["new_field"] } == ["new_value", "new_value_2"]
65
+ insist { subject.get("new_field") } == ["new_value", "new_value_2"]
66
66
  end
67
67
  end
68
68
 
@@ -76,7 +76,7 @@ describe LogStash::Filters::NOOP do
76
76
  CONFIG
77
77
 
78
78
  sample("type" => "noop") do
79
- insist { subject["tags"] } == ["test"]
79
+ insist { subject.get("tags") } == ["test"]
80
80
  end
81
81
  end
82
82
 
@@ -90,11 +90,11 @@ describe LogStash::Filters::NOOP do
90
90
  CONFIG
91
91
 
92
92
  sample("type" => "noop") do
93
- insist { subject["tags"] } == ["test"]
93
+ insist { subject.get("tags") } == ["test"]
94
94
  end
95
95
 
96
96
  sample("type" => "noop", "tags" => ["t1", "t2"]) do
97
- insist { subject["tags"] } == ["t1", "t2", "test"]
97
+ insist { subject.get("tags") } == ["t1", "t2", "test"]
98
98
  end
99
99
  end
100
100
 
@@ -108,19 +108,19 @@ describe LogStash::Filters::NOOP do
108
108
  CONFIG
109
109
 
110
110
  sample("type" => "noop") do
111
- insist { subject["tags"] } == ["test"]
111
+ insist { subject.get("tags") } == ["test"]
112
112
  end
113
113
 
114
114
  sample("type" => "noop", "tags" => ["t1"]) do
115
- insist { subject["tags"] } == ["t1", "test"]
115
+ insist { subject.get("tags") } == ["t1", "test"]
116
116
  end
117
117
 
118
118
  sample("type" => "noop", "tags" => ["t1", "t2"]) do
119
- insist { subject["tags"] } == ["t1", "t2", "test"]
119
+ insist { subject.get("tags") } == ["t1", "t2", "test"]
120
120
  end
121
121
 
122
122
  sample("type" => "noop", "tags" => ["t1", "t2", "t3"]) do
123
- insist { subject["tags"] } == ["t1", "t2", "t3", "test"]
123
+ insist { subject.get("tags") } == ["t1", "t2", "t3", "test"]
124
124
  end
125
125
  end
126
126
 
@@ -134,27 +134,27 @@ describe LogStash::Filters::NOOP do
134
134
  CONFIG
135
135
 
136
136
  sample("type" => "noop", "tags" => ["t4"]) do
137
- insist { subject["tags"] } == ["t4"]
137
+ insist { subject.get("tags") } == ["t4"]
138
138
  end
139
139
 
140
140
  sample("type" => "noop", "tags" => ["t1", "t2", "t3"]) do
141
- insist { subject["tags"] } == ["t1"]
141
+ insist { subject.get("tags") } == ["t1"]
142
142
  end
143
143
 
144
144
  # also test from Json deserialized data to test the handling of native Java collections by JrJackson
145
145
  # see https://github.com/elastic/logstash/issues/2261
146
146
  sample(LogStash::Json.load("{\"type\":\"noop\", \"tags\":[\"t1\", \"t2\", \"t3\"]}")) do
147
- insist { subject["tags"] } == ["t1"]
147
+ insist { subject.get("tags") } == ["t1"]
148
148
  end
149
149
 
150
150
  sample("type" => "noop", "tags" => ["t1", "t2"]) do
151
- insist { subject["tags"] } == ["t1"]
151
+ insist { subject.get("tags") } == ["t1"]
152
152
  end
153
153
 
154
154
  # also test from Json deserialized data to test the handling of native Java collections by JrJackson
155
155
  # see https://github.com/elastic/logstash/issues/2261
156
156
  sample(LogStash::Json.load("{\"type\":\"noop\", \"tags\":[\"t1\", \"t2\"]}")) do
157
- insist { subject["tags"] } == ["t1"]
157
+ insist { subject.get("tags") } == ["t1"]
158
158
  end
159
159
  end
160
160
 
@@ -168,13 +168,13 @@ describe LogStash::Filters::NOOP do
168
168
  CONFIG
169
169
 
170
170
  sample("type" => "noop", "tags" => ["t1", "goaway", "t3"], "blackhole" => "goaway") do
171
- insist { subject["tags"] } == ["t1", "t3"]
171
+ insist { subject.get("tags") } == ["t1", "t3"]
172
172
  end
173
173
 
174
174
  # also test from Json deserialized data to test the handling of native Java collections by JrJackson
175
175
  # see https://github.com/elastic/logstash/issues/2261
176
176
  sample(LogStash::Json.load("{\"type\":\"noop\", \"tags\":[\"t1\", \"goaway\", \"t3\"], \"blackhole\":\"goaway\"}")) do
177
- insist { subject["tags"] } == ["t1", "t3"]
177
+ insist { subject.get("tags") } == ["t1", "t3"]
178
178
  end
179
179
  end
180
180
 
@@ -230,7 +230,7 @@ describe LogStash::Filters::NOOP do
230
230
 
231
231
  sample("type" => "noop", "t1" => ["t2", "t3"]) do
232
232
  insist { subject }.include?("t1")
233
- insist { subject["[t1][0]"] } == "t3"
233
+ insist { subject.get("[t1][0]") } == "t3"
234
234
  end
235
235
  end
236
236
 
@@ -15,50 +15,50 @@ describe "LogStash::Inputs::Base#decorate" do
15
15
  input = LogStash::Inputs::NOOP.new("tags" => "value")
16
16
  evt = LogStash::Event.new({"type" => "noop"})
17
17
  input.instance_eval {decorate(evt)}
18
- expect(evt["tags"]).to eq(["value"])
18
+ expect(evt.get("tags")).to eq(["value"])
19
19
  end
20
20
 
21
21
  it "should add multiple tag" do
22
22
  input = LogStash::Inputs::NOOP.new("tags" => ["value1","value2"])
23
23
  evt = LogStash::Event.new({"type" => "noop"})
24
24
  input.instance_eval {decorate(evt)}
25
- expect(evt["tags"]).to eq(["value1","value2"])
25
+ expect(evt.get("tags")).to eq(["value1","value2"])
26
26
  end
27
27
 
28
28
  it "should allow duplicates tag" do
29
29
  input = LogStash::Inputs::NOOP.new("tags" => ["value","value"])
30
30
  evt = LogStash::Event.new({"type" => "noop"})
31
31
  input.instance_eval {decorate(evt)}
32
- expect(evt["tags"]).to eq(["value","value"])
32
+ expect(evt.get("tags")).to eq(["value","value"])
33
33
  end
34
34
 
35
35
  it "should add tag with sprintf" do
36
36
  input = LogStash::Inputs::NOOP.new("tags" => "%{type}")
37
37
  evt = LogStash::Event.new({"type" => "noop"})
38
38
  input.instance_eval {decorate(evt)}
39
- expect(evt["tags"]).to eq(["noop"])
39
+ expect(evt.get("tags")).to eq(["noop"])
40
40
  end
41
41
 
42
42
  it "should add single field" do
43
43
  input = LogStash::Inputs::NOOP.new("add_field" => {"field" => "value"})
44
44
  evt = LogStash::Event.new({"type" => "noop"})
45
45
  input.instance_eval {decorate(evt)}
46
- expect(evt["field"]).to eq("value")
46
+ expect(evt.get("field")).to eq("value")
47
47
  end
48
48
 
49
49
  it "should add single field with sprintf" do
50
50
  input = LogStash::Inputs::NOOP.new("add_field" => {"%{type}" => "%{type}"})
51
51
  evt = LogStash::Event.new({"type" => "noop"})
52
52
  input.instance_eval {decorate(evt)}
53
- expect(evt["noop"]).to eq("noop")
53
+ expect(evt.get("noop")).to eq("noop")
54
54
  end
55
55
 
56
56
  it "should add multiple field" do
57
57
  input = LogStash::Inputs::NOOP.new("add_field" => {"field" => ["value1", "value2"], "field2" => "value"})
58
58
  evt = LogStash::Event.new({"type" => "noop"})
59
59
  input.instance_eval {decorate(evt)}
60
- expect(evt["field"]).to eq(["value1","value2"])
61
- expect(evt["field2"]).to eq("value")
60
+ expect(evt.get("field")).to eq(["value1","value2"])
61
+ expect(evt.get("field2")).to eq("value")
62
62
  end
63
63
  end
64
64
 
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ require 'logstash/instrument/periodic_poller/jvm'
3
+
4
+ describe LogStash::Instrument::PeriodicPoller::JVM do
5
+ let(:metric) { LogStash::Instrument::Metric.new }
6
+ let(:options) { {} }
7
+ subject(:jvm) { described_class.new(metric, options) }
8
+
9
+ it "should initialize cleanly" do
10
+ expect { jvm }.not_to raise_error
11
+ end
12
+
13
+ describe "collections" do
14
+ subject(:collection) { jvm.collect }
15
+
16
+ it "should run cleanly" do
17
+ expect { collection }.not_to raise_error
18
+ end
19
+
20
+ describe "metrics" do
21
+ let(:snapshot_store) { metric.collector.snapshot_metric.metric_store }
22
+ subject(:jvm_metrics) { snapshot_store.get_shallow(:jvm, :process) }
23
+
24
+ # Make looking up metric paths easy when given varargs of keys
25
+ # e.g. mval(:parent, :child)
26
+ def mval(*metric_path)
27
+ metric_path.reduce(jvm_metrics) {|acc,k| acc[k]}.value
28
+ end
29
+
30
+ [
31
+ :max_file_descriptors,
32
+ :open_file_descriptors,
33
+ :peak_open_file_descriptors,
34
+ [:mem, :total_virtual_in_bytes],
35
+ [:cpu, :total_in_millis],
36
+ [:cpu, :percent]
37
+ ].each do |path|
38
+ path = Array(path)
39
+ it "should have a value for #{path} that is Numeric" do
40
+ expect(mval(*path)).to be_a(Numeric)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -13,10 +13,12 @@ describe LogStash::OutputDelegator do
13
13
  let(:out_klass) { double("output klass") }
14
14
  let(:out_inst) { double("output instance") }
15
15
 
16
+
16
17
  before(:each) do
17
18
  allow(out_klass).to receive(:new).with(any_args).and_return(out_inst)
18
19
  allow(out_klass).to receive(:threadsafe?).and_return(false)
19
20
  allow(out_klass).to receive(:workers_not_supported?).and_return(false)
21
+ allow(out_klass).to receive(:name).and_return("example")
20
22
  allow(out_inst).to receive(:register)
21
23
  allow(out_inst).to receive(:multi_receive)
22
24
  allow(out_inst).to receive(:metric=).with(any_args)
@@ -47,6 +47,10 @@ describe LogStash::PipelineReporter do
47
47
  @post_snapshot = reporter.snapshot
48
48
  end
49
49
 
50
+ after do
51
+ pipeline.shutdown
52
+ end
53
+
50
54
  describe "events filtered" do
51
55
  it "should start at zero" do
52
56
  expect(@pre_snapshot.events_filtered).to eql(0)
@@ -82,4 +86,4 @@ describe LogStash::PipelineReporter do
82
86
  expect(@post_snapshot.output_info.first[:events_received]).to eql(generator_count)
83
87
  end
84
88
  end
85
- end
89
+ end
@@ -84,9 +84,21 @@ class TestPipeline < LogStash::Pipeline
84
84
  end
85
85
 
86
86
  describe LogStash::Pipeline do
87
- let(:worker_thread_count) { LogStash::Pipeline::DEFAULT_SETTINGS[:default_pipeline_workers] }
87
+ let(:worker_thread_count) { 5 }
88
88
  let(:safe_thread_count) { 1 }
89
89
  let(:override_thread_count) { 42 }
90
+ let(:pipeline_settings_obj) { LogStash::SETTINGS }
91
+ let(:pipeline_settings) { {} }
92
+
93
+ before :each do
94
+ pipeline_workers_setting = LogStash::SETTINGS.get_setting("pipeline.workers")
95
+ allow(pipeline_workers_setting).to receive(:default).and_return(worker_thread_count)
96
+ pipeline_settings.each {|k, v| pipeline_settings_obj.set(k, v) }
97
+ end
98
+
99
+ after :each do
100
+ pipeline_settings_obj.reset
101
+ end
90
102
 
91
103
  describe "defaulting the pipeline workers based on thread safety" do
92
104
  before(:each) do
@@ -123,13 +135,15 @@ describe LogStash::Pipeline do
123
135
  end
124
136
 
125
137
  it "should not receive a debug message with the compiled code" do
138
+ pipeline_settings_obj.set("config.debug", false)
126
139
  expect(logger).not_to receive(:debug).with(/Compiled pipeline/, anything)
127
140
  pipeline = TestPipeline.new(test_config_with_filters)
128
141
  end
129
142
 
130
- it "should print the compiled code if debug_config is set to true" do
143
+ it "should print the compiled code if config.debug is set to true" do
144
+ pipeline_settings_obj.set("config.debug", true)
131
145
  expect(logger).to receive(:debug).with(/Compiled pipeline/, anything)
132
- pipeline = TestPipeline.new(test_config_with_filters, :debug_config => true)
146
+ pipeline = TestPipeline.new(test_config_with_filters, pipeline_settings_obj)
133
147
  end
134
148
  end
135
149
 
@@ -141,18 +155,21 @@ describe LogStash::Pipeline do
141
155
  {:count_was=>worker_thread_count, :filters=>["dummyfilter"]})
142
156
  pipeline.run
143
157
  expect(pipeline.worker_threads.size).to eq(safe_thread_count)
158
+ pipeline.shutdown
144
159
  end
145
160
  end
146
161
 
147
162
  context "when there is command line -w N set" do
163
+ let(:pipeline_settings) { {"pipeline.workers" => override_thread_count } }
148
164
  it "starts multiple filter thread" do
149
- msg = "Warning: Manual override - there are filters that might not work with multiple worker threads"
150
- pipeline = TestPipeline.new(test_config_with_filters)
165
+ msg = "Warning: Manual override - there are filters that might" +
166
+ " not work with multiple worker threads"
167
+ pipeline = TestPipeline.new(test_config_with_filters, pipeline_settings_obj)
151
168
  expect(pipeline.logger).to receive(:warn).with(msg,
152
169
  {:worker_threads=> override_thread_count, :filters=>["dummyfilter"]})
153
- pipeline.configure(:pipeline_workers, override_thread_count)
154
170
  pipeline.run
155
171
  expect(pipeline.worker_threads.size).to eq(override_thread_count)
172
+ pipeline.shutdown
156
173
  end
157
174
  end
158
175
  end
@@ -178,6 +195,7 @@ describe LogStash::Pipeline do
178
195
  pipeline = TestPipeline.new(test_config_with_filters)
179
196
  pipeline.run
180
197
  expect(pipeline.worker_threads.size).to eq(worker_thread_count)
198
+ pipeline.shutdown
181
199
  end
182
200
  end
183
201
  end
@@ -222,8 +240,9 @@ describe LogStash::Pipeline do
222
240
  pipeline.run
223
241
 
224
242
  expect(pipeline.outputs.size ).to eq(1)
225
- expect(pipeline.outputs.first.workers.size ).to eq(::LogStash::Pipeline::DEFAULT_OUTPUT_WORKERS)
243
+ expect(pipeline.outputs.first.workers.size ).to eq(::LogStash::SETTINGS.get("pipeline.output.workers"))
226
244
  expect(pipeline.outputs.first.workers.first.num_closes ).to eq(1)
245
+ pipeline.shutdown
227
246
  end
228
247
 
229
248
  it "should call output close correctly with output workers" do
@@ -240,6 +259,7 @@ describe LogStash::Pipeline do
240
259
  output_delegator.workers.each do |plugin|
241
260
  expect(plugin.num_closes ).to eq(1)
242
261
  end
262
+ pipeline.shutdown
243
263
  end
244
264
  end
245
265
  end
@@ -261,6 +281,7 @@ describe LogStash::Pipeline do
261
281
  expect(pipeline).to receive(:start_flusher).ordered.and_call_original
262
282
 
263
283
  pipeline.run
284
+ pipeline.shutdown
264
285
  end
265
286
  end
266
287
 
@@ -279,7 +300,7 @@ describe LogStash::Pipeline do
279
300
  CONFIG
280
301
 
281
302
  sample("hello") do
282
- expect(subject["message"]).to eq("hello")
303
+ expect(subject.get("message")).to eq("hello")
283
304
  end
284
305
  end
285
306
 
@@ -299,10 +320,10 @@ describe LogStash::Pipeline do
299
320
  sample(["foo", "bar"]) do
300
321
  expect(subject.size).to eq(2)
301
322
 
302
- expect(subject[0]["message"]).to eq("foo\nbar")
303
- expect(subject[0]["type"]).to be_nil
304
- expect(subject[1]["message"]).to eq("foo\nbar")
305
- expect(subject[1]["type"]).to eq("clone1")
323
+ expect(subject[0].get("message")).to eq("foo\nbar")
324
+ expect(subject[0].get("type")).to be_nil
325
+ expect(subject[1].get("message")).to eq("foo\nbar")
326
+ expect(subject[1].get("type")).to eq("clone1")
306
327
  end
307
328
  end
308
329
  end
@@ -310,7 +331,8 @@ describe LogStash::Pipeline do
310
331
  describe "max inflight warning" do
311
332
  let(:config) { "input { dummyinput {} } output { dummyoutput {} }" }
312
333
  let(:batch_size) { 1 }
313
- let(:pipeline) { LogStash::Pipeline.new(config, :pipeline_batch_size => batch_size, :pipeline_workers => 1) }
334
+ let(:pipeline_settings) { { "pipeline.batch.size" => batch_size, "pipeline.workers" => 1 } }
335
+ let(:pipeline) { LogStash::Pipeline.new(config, pipeline_settings_obj) }
314
336
  let(:logger) { pipeline.logger }
315
337
  let(:warning_prefix) { /CAUTION: Recommended inflight events max exceeded!/ }
316
338
 
@@ -354,17 +376,17 @@ describe LogStash::Pipeline do
354
376
  sample("hello") do
355
377
  expect(subject.size).to eq(3)
356
378
 
357
- expect(subject[0]["message"]).to eq("hello")
358
- expect(subject[0]["type"]).to be_nil
359
- expect(subject[0]["foo"]).to eq("bar")
379
+ expect(subject[0].get("message")).to eq("hello")
380
+ expect(subject[0].get("type")).to be_nil
381
+ expect(subject[0].get("foo")).to eq("bar")
360
382
 
361
- expect(subject[1]["message"]).to eq("hello")
362
- expect(subject[1]["type"]).to eq("clone1")
363
- expect(subject[1]["foo"]).to eq("bar")
383
+ expect(subject[1].get("message")).to eq("hello")
384
+ expect(subject[1].get("type")).to eq("clone1")
385
+ expect(subject[1].get("foo")).to eq("bar")
364
386
 
365
- expect(subject[2]["message"]).to eq("hello")
366
- expect(subject[2]["type"]).to eq("clone2")
367
- expect(subject[2]["foo"]).to eq("bar")
387
+ expect(subject[2].get("message")).to eq("hello")
388
+ expect(subject[2].get("type")).to eq("clone2")
389
+ expect(subject[2].get("foo")).to eq("bar")
368
390
  end
369
391
  end
370
392
  end
@@ -376,8 +398,14 @@ describe LogStash::Pipeline do
376
398
  output { }
377
399
  CONFIG
378
400
 
379
- it "uses a `NullMetric` object if no metric is given" do
380
- pipeline = LogStash::Pipeline.new(config)
401
+ it "uses a `NullMetric` object if `metric.collect` is set to false" do
402
+ settings = double("LogStash::SETTINGS")
403
+
404
+ allow(settings).to receive(:get_value).with("pipeline.id").and_return("main")
405
+ allow(settings).to receive(:get_value).with("metric.collect").and_return(false)
406
+ allow(settings).to receive(:get_value).with("config.debug").and_return(false)
407
+
408
+ pipeline = LogStash::Pipeline.new(config, settings)
381
409
  expect(pipeline.metric).to be_kind_of(LogStash::Instrument::NullMetric)
382
410
  end
383
411
  end
@@ -435,13 +463,13 @@ describe LogStash::Pipeline do
435
463
 
436
464
  it "flushes the buffered contents of the filter" do
437
465
  Thread.abort_on_exception = true
438
- pipeline = LogStash::Pipeline.new(config, { :flush_interval => 1 })
466
+ pipeline = LogStash::Pipeline.new(config, pipeline_settings_obj)
439
467
  Thread.new { pipeline.run }
440
468
  sleep 0.1 while !pipeline.ready?
441
469
  # give us a bit of time to flush the events
442
470
  wait(5).for do
443
471
  next unless output && output.events && output.events.first
444
- output.events.first["message"].split("\n").count
472
+ output.events.first.get("message").split("\n").count
445
473
  end.to eq(number_of_events)
446
474
  pipeline.shutdown
447
475
  end
@@ -495,7 +523,7 @@ describe LogStash::Pipeline do
495
523
  t = Thread.new { subject.run }
496
524
  sleep(0.1)
497
525
  expect(subject.started_at).to be < Time.now
498
- t.kill rescue nil
526
+ subject.shutdown
499
527
  end
500
528
  end
501
529
 
@@ -520,14 +548,15 @@ describe LogStash::Pipeline do
520
548
  t = Thread.new { subject.run }
521
549
  sleep(0.1)
522
550
  expect(subject.uptime).to be > 0
523
- t.kill rescue nil
551
+ subject.shutdown
524
552
  end
525
553
  end
526
554
  end
527
555
 
528
556
  context "when collecting metrics in the pipeline" do
529
- subject { described_class.new(config, { :metric => metric, :pipeline_id => pipeline_id }) }
530
- let(:pipeline_id) { :main }
557
+ let(:pipeline_settings) { { "pipeline.id" => pipeline_id } }
558
+ subject { described_class.new(config, pipeline_settings_obj) }
559
+ let(:pipeline_id) { "main" }
531
560
  let(:metric) { LogStash::Instrument::Metric.new }
532
561
  let(:number_of_events) { 1000 }
533
562
  let(:multiline_id) { "my-multiline" }
@@ -616,4 +645,20 @@ describe LogStash::Pipeline do
616
645
  end
617
646
  end
618
647
  end
648
+
649
+ context "Pipeline object" do
650
+ before do
651
+ allow(LogStash::Plugin).to receive(:lookup).with("input", "generator").and_return(LogStash::Inputs::Generator)
652
+ allow(LogStash::Plugin).to receive(:lookup).with("codec", "plain").and_return(DummyCodec)
653
+ allow(LogStash::Plugin).to receive(:lookup).with("filter", "dummyfilter").and_return(DummyFilter)
654
+ allow(LogStash::Plugin).to receive(:lookup).with("output", "dummyoutput").and_return(DummyOutput)
655
+ end
656
+
657
+ let(:pipeline1) { LogStash::Pipeline.new("input { generator {} } filter { dummyfilter {} } output { dummyoutput {}}") }
658
+ let(:pipeline2) { LogStash::Pipeline.new("input { generator {} } filter { dummyfilter {} } output { dummyoutput {}}") }
659
+
660
+ it "should not add ivars" do
661
+ expect(pipeline1.instance_variables).to eq(pipeline2.instance_variables)
662
+ end
663
+ end
619
664
  end