logstash-core 5.0.0.alpha3.snapshot2-java → 5.0.0.alpha3.snapshot4-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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/lib/logstash-core/version.rb +1 -1
  3. data/lib/logstash/agent.rb +49 -31
  4. data/lib/logstash/api/init.ru +3 -3
  5. data/lib/logstash/api/lib/app/service.rb +1 -1
  6. data/lib/logstash/config/config_ast.rb +23 -18
  7. data/lib/logstash/config/loader.rb +4 -4
  8. data/lib/logstash/config/mixin.rb +10 -21
  9. data/lib/logstash/environment.rb +30 -0
  10. data/lib/logstash/filters/base.rb +2 -2
  11. data/lib/logstash/inputs/base.rb +2 -2
  12. data/lib/logstash/instrument/collector.rb +1 -1
  13. data/lib/logstash/logging/json.rb +21 -0
  14. data/lib/logstash/output_delegator.rb +2 -2
  15. data/lib/logstash/patches/clamp.rb +69 -0
  16. data/lib/logstash/pipeline.rb +37 -62
  17. data/lib/logstash/plugin.rb +1 -1
  18. data/lib/logstash/runner.rb +155 -146
  19. data/lib/logstash/settings.rb +267 -0
  20. data/lib/logstash/util/decorators.rb +6 -6
  21. data/lib/logstash/util/java_version.rb +1 -10
  22. data/lib/logstash/util/worker_threads_default_printer.rb +2 -2
  23. data/lib/logstash/version.rb +1 -1
  24. data/locales/en.yml +17 -20
  25. data/logstash-core.gemspec +1 -1
  26. data/spec/api/spec_helper.rb +15 -16
  27. data/spec/conditionals_spec.rb +113 -113
  28. data/spec/logstash/agent_spec.rb +77 -68
  29. data/spec/logstash/config/config_ast_spec.rb +4 -2
  30. data/spec/logstash/config/mixin_spec.rb +33 -7
  31. data/spec/logstash/filters/base_spec.rb +16 -16
  32. data/spec/logstash/inputs/base_spec.rb +8 -8
  33. data/spec/logstash/output_delegator_spec.rb +2 -0
  34. data/spec/logstash/pipeline_spec.rb +60 -26
  35. data/spec/logstash/plugin_spec.rb +2 -2
  36. data/spec/logstash/runner_spec.rb +112 -25
  37. data/spec/logstash/setting_spec.rb +130 -0
  38. data/spec/logstash/settings_spec.rb +62 -0
  39. metadata +11 -9
  40. data/lib/logstash/util/defaults_printer.rb +0 -31
  41. data/spec/logstash/util/defaults_printer_spec.rb +0 -50
  42. data/spec/logstash/util/worker_threads_default_printer_spec.rb +0 -45
@@ -64,24 +64,24 @@ describe "conditionals in filter" do
64
64
  CONFIG
65
65
 
66
66
  sample({"foo" => "bar"}) do
67
- expect(subject["always"]).to eq("awesome")
68
- expect(subject["hello"]).to eq("world")
69
- expect(subject["fancy"]).to be_nil
70
- expect(subject["free"]).to be_nil
67
+ expect(subject.get("always")).to eq("awesome")
68
+ expect(subject.get("hello")).to eq("world")
69
+ expect(subject.get("fancy")).to be_nil
70
+ expect(subject.get("free")).to be_nil
71
71
  end
72
72
 
73
73
  sample({"notfoo" => "bar"}) do
74
- expect(subject["always"]).to eq("awesome")
75
- expect(subject["hello"]).to be_nil
76
- expect(subject["fancy"]).to be_nil
77
- expect(subject["free"]).to eq("hugs")
74
+ expect(subject.get("always")).to eq("awesome")
75
+ expect(subject.get("hello")).to be_nil
76
+ expect(subject.get("fancy")).to be_nil
77
+ expect(subject.get("free")).to eq("hugs")
78
78
  end
79
79
 
80
80
  sample({"bar" => "baz"}) do
81
- expect(subject["always"]).to eq("awesome")
82
- expect(subject["hello"]).to be_nil
83
- expect(subject["fancy"]).to eq("pants")
84
- expect(subject["free"]).to be_nil
81
+ expect(subject.get("always")).to eq("awesome")
82
+ expect(subject.get("hello")).to be_nil
83
+ expect(subject.get("fancy")).to eq("pants")
84
+ expect(subject.get("free")).to be_nil
85
85
  end
86
86
  end
87
87
 
@@ -102,31 +102,31 @@ describe "conditionals in filter" do
102
102
  CONFIG
103
103
 
104
104
  sample("foo" => "bar", "nest" => 124) do
105
- expect(subject["always"]).to be_nil
106
- expect(subject["hello"]).to be_nil
107
- expect(subject["fancy"]).to be_nil
108
- expect(subject["free"]).to be_nil
105
+ expect(subject.get("always")).to be_nil
106
+ expect(subject.get("hello")).to be_nil
107
+ expect(subject.get("fancy")).to be_nil
108
+ expect(subject.get("free")).to be_nil
109
109
  end
110
110
 
111
111
  sample("foo" => "bar", "nest" => 123) do
112
- expect(subject["always"]).to eq("awesome")
113
- expect(subject["hello"]).to eq("world")
114
- expect(subject["fancy"]).to be_nil
115
- expect(subject["free"]).to be_nil
112
+ expect(subject.get("always")).to eq("awesome")
113
+ expect(subject.get("hello")).to eq("world")
114
+ expect(subject.get("fancy")).to be_nil
115
+ expect(subject.get("free")).to be_nil
116
116
  end
117
117
 
118
118
  sample("notfoo" => "bar", "nest" => 123) do
119
- expect(subject["always"]).to eq("awesome")
120
- expect(subject["hello"]).to be_nil
121
- expect(subject["fancy"]).to be_nil
122
- expect(subject["free"]).to eq("hugs")
119
+ expect(subject.get("always")).to eq("awesome")
120
+ expect(subject.get("hello")).to be_nil
121
+ expect(subject.get("fancy")).to be_nil
122
+ expect(subject.get("free")).to eq("hugs")
123
123
  end
124
124
 
125
125
  sample("bar" => "baz", "nest" => 123) do
126
- expect(subject["always"]).to eq("awesome")
127
- expect(subject["hello"]).to be_nil
128
- expect(subject["fancy"]).to eq("pants")
129
- expect(subject["free"]).to be_nil
126
+ expect(subject.get("always")).to eq("awesome")
127
+ expect(subject.get("hello")).to be_nil
128
+ expect(subject.get("fancy")).to eq("pants")
129
+ expect(subject.get("free")).to be_nil
130
130
  end
131
131
  end
132
132
 
@@ -140,7 +140,7 @@ describe "conditionals in filter" do
140
140
  CONFIG
141
141
 
142
142
  sample("foo" => 123, "bar" => 123) do
143
- expect(subject["tags"] ).to include("woot")
143
+ expect(subject.get("tags") ).to include("woot")
144
144
  end
145
145
  end
146
146
 
@@ -169,12 +169,12 @@ describe "conditionals in filter" do
169
169
  CONFIG
170
170
 
171
171
  sample("foo" => "foo", "foobar" => "foobar", "greeting" => "hello world") do
172
- expect(subject["tags"]).to include("field in field")
173
- expect(subject["tags"]).to include("field in string")
174
- expect(subject["tags"]).to include("string in field")
175
- expect(subject["tags"]).to include("field in list")
176
- expect(subject["tags"]).not_to include("shouldnotexist")
177
- expect(subject["tags"]).to include("shouldexist")
172
+ expect(subject.get("tags")).to include("field in field")
173
+ expect(subject.get("tags")).to include("field in string")
174
+ expect(subject.get("tags")).to include("string in field")
175
+ expect(subject.get("tags")).to include("field in list")
176
+ expect(subject.get("tags")).not_to include("shouldnotexist")
177
+ expect(subject.get("tags")).to include("shouldexist")
178
178
  end
179
179
  end
180
180
 
@@ -192,107 +192,107 @@ describe "conditionals in filter" do
192
192
 
193
193
  sample("foo" => "foo", "somelist" => [ "one", "two" ], "foobar" => "foobar", "greeting" => "hello world", "tags" => [ "fancypantsy" ]) do
194
194
  # verify the original exists
195
- expect(subject["tags"]).to include("fancypantsy")
195
+ expect(subject.get("tags")).to include("fancypantsy")
196
196
 
197
- expect(subject["tags"]).to include("baz")
198
- expect(subject["tags"]).not_to include("foo")
199
- expect(subject["tags"]).to include("notfoo")
200
- expect(subject["tags"]).to include("notsomelist")
201
- expect(subject["tags"]).not_to include("somelist")
202
- expect(subject["tags"]).to include("no string in missing field")
197
+ expect(subject.get("tags")).to include("baz")
198
+ expect(subject.get("tags")).not_to include("foo")
199
+ expect(subject.get("tags")).to include("notfoo")
200
+ expect(subject.get("tags")).to include("notsomelist")
201
+ expect(subject.get("tags")).not_to include("somelist")
202
+ expect(subject.get("tags")).to include("no string in missing field")
203
203
  end
204
204
  end
205
205
 
206
206
  describe "operators" do
207
207
  conditional "[message] == 'sample'" do
208
- sample("sample") { expect(subject["tags"] ).to include("success") }
209
- sample("different") { expect(subject["tags"] ).to include("failure") }
208
+ sample("sample") { expect(subject.get("tags") ).to include("success") }
209
+ sample("different") { expect(subject.get("tags") ).to include("failure") }
210
210
  end
211
211
 
212
212
  conditional "[message] != 'sample'" do
213
- sample("sample") { expect(subject["tags"] ).to include("failure") }
214
- sample("different") { expect(subject["tags"] ).to include("success") }
213
+ sample("sample") { expect(subject.get("tags") ).to include("failure") }
214
+ sample("different") { expect(subject.get("tags") ).to include("success") }
215
215
  end
216
216
 
217
217
  conditional "[message] < 'sample'" do
218
- sample("apple") { expect(subject["tags"] ).to include("success") }
219
- sample("zebra") { expect(subject["tags"] ).to include("failure") }
218
+ sample("apple") { expect(subject.get("tags") ).to include("success") }
219
+ sample("zebra") { expect(subject.get("tags") ).to include("failure") }
220
220
  end
221
221
 
222
222
  conditional "[message] > 'sample'" do
223
- sample("zebra") { expect(subject["tags"] ).to include("success") }
224
- sample("apple") { expect(subject["tags"] ).to include("failure") }
223
+ sample("zebra") { expect(subject.get("tags") ).to include("success") }
224
+ sample("apple") { expect(subject.get("tags") ).to include("failure") }
225
225
  end
226
226
 
227
227
  conditional "[message] <= 'sample'" do
228
- sample("apple") { expect(subject["tags"] ).to include("success") }
229
- sample("zebra") { expect(subject["tags"] ).to include("failure") }
230
- sample("sample") { expect(subject["tags"] ).to include("success") }
228
+ sample("apple") { expect(subject.get("tags") ).to include("success") }
229
+ sample("zebra") { expect(subject.get("tags") ).to include("failure") }
230
+ sample("sample") { expect(subject.get("tags") ).to include("success") }
231
231
  end
232
232
 
233
233
  conditional "[message] >= 'sample'" do
234
- sample("zebra") { expect(subject["tags"] ).to include("success") }
235
- sample("sample") { expect(subject["tags"] ).to include("success") }
236
- sample("apple") { expect(subject["tags"] ).to include("failure") }
234
+ sample("zebra") { expect(subject.get("tags") ).to include("success") }
235
+ sample("sample") { expect(subject.get("tags") ).to include("success") }
236
+ sample("apple") { expect(subject.get("tags") ).to include("failure") }
237
237
  end
238
238
 
239
239
  conditional "[message] =~ /sample/" do
240
- sample("apple") { expect(subject["tags"] ).to include("failure") }
241
- sample("sample") { expect(subject["tags"] ).to include("success") }
242
- sample("some sample") { expect(subject["tags"] ).to include("success") }
240
+ sample("apple") { expect(subject.get("tags") ).to include("failure") }
241
+ sample("sample") { expect(subject.get("tags") ).to include("success") }
242
+ sample("some sample") { expect(subject.get("tags") ).to include("success") }
243
243
  end
244
244
 
245
245
  conditional "[message] !~ /sample/" do
246
- sample("apple") { expect(subject["tags"]).to include("success") }
247
- sample("sample") { expect(subject["tags"]).to include("failure") }
248
- sample("some sample") { expect(subject["tags"]).to include("failure") }
246
+ sample("apple") { expect(subject.get("tags")).to include("success") }
247
+ sample("sample") { expect(subject.get("tags")).to include("failure") }
248
+ sample("some sample") { expect(subject.get("tags")).to include("failure") }
249
249
  end
250
250
 
251
251
  end
252
252
 
253
253
  describe "negated expressions" do
254
254
  conditional "!([message] == 'sample')" do
255
- sample("sample") { expect(subject["tags"]).not_to include("success") }
256
- sample("different") { expect(subject["tags"]).not_to include("failure") }
255
+ sample("sample") { expect(subject.get("tags")).not_to include("success") }
256
+ sample("different") { expect(subject.get("tags")).not_to include("failure") }
257
257
  end
258
258
 
259
259
  conditional "!([message] != 'sample')" do
260
- sample("sample") { expect(subject["tags"]).not_to include("failure") }
261
- sample("different") { expect(subject["tags"]).not_to include("success") }
260
+ sample("sample") { expect(subject.get("tags")).not_to include("failure") }
261
+ sample("different") { expect(subject.get("tags")).not_to include("success") }
262
262
  end
263
263
 
264
264
  conditional "!([message] < 'sample')" do
265
- sample("apple") { expect(subject["tags"]).not_to include("success") }
266
- sample("zebra") { expect(subject["tags"]).not_to include("failure") }
265
+ sample("apple") { expect(subject.get("tags")).not_to include("success") }
266
+ sample("zebra") { expect(subject.get("tags")).not_to include("failure") }
267
267
  end
268
268
 
269
269
  conditional "!([message] > 'sample')" do
270
- sample("zebra") { expect(subject["tags"]).not_to include("success") }
271
- sample("apple") { expect(subject["tags"]).not_to include("failure") }
270
+ sample("zebra") { expect(subject.get("tags")).not_to include("success") }
271
+ sample("apple") { expect(subject.get("tags")).not_to include("failure") }
272
272
  end
273
273
 
274
274
  conditional "!([message] <= 'sample')" do
275
- sample("apple") { expect(subject["tags"]).not_to include("success") }
276
- sample("zebra") { expect(subject["tags"]).not_to include("failure") }
277
- sample("sample") { expect(subject["tags"]).not_to include("success") }
275
+ sample("apple") { expect(subject.get("tags")).not_to include("success") }
276
+ sample("zebra") { expect(subject.get("tags")).not_to include("failure") }
277
+ sample("sample") { expect(subject.get("tags")).not_to include("success") }
278
278
  end
279
279
 
280
280
  conditional "!([message] >= 'sample')" do
281
- sample("zebra") { expect(subject["tags"]).not_to include("success") }
282
- sample("sample") { expect(subject["tags"]).not_to include("success") }
283
- sample("apple") { expect(subject["tags"]).not_to include("failure") }
281
+ sample("zebra") { expect(subject.get("tags")).not_to include("success") }
282
+ sample("sample") { expect(subject.get("tags")).not_to include("success") }
283
+ sample("apple") { expect(subject.get("tags")).not_to include("failure") }
284
284
  end
285
285
 
286
286
  conditional "!([message] =~ /sample/)" do
287
- sample("apple") { expect(subject["tags"]).not_to include("failure") }
288
- sample("sample") { expect(subject["tags"]).not_to include("success") }
289
- sample("some sample") { expect(subject["tags"]).not_to include("success") }
287
+ sample("apple") { expect(subject.get("tags")).not_to include("failure") }
288
+ sample("sample") { expect(subject.get("tags")).not_to include("success") }
289
+ sample("some sample") { expect(subject.get("tags")).not_to include("success") }
290
290
  end
291
291
 
292
292
  conditional "!([message] !~ /sample/)" do
293
- sample("apple") { expect(subject["tags"]).not_to include("success") }
294
- sample("sample") { expect(subject["tags"]).not_to include("failure") }
295
- sample("some sample") { expect(subject["tags"]).not_to include("failure") }
293
+ sample("apple") { expect(subject.get("tags")).not_to include("success") }
294
+ sample("sample") { expect(subject.get("tags")).not_to include("failure") }
295
+ sample("some sample") { expect(subject.get("tags")).not_to include("failure") }
296
296
  end
297
297
 
298
298
  end
@@ -300,47 +300,47 @@ describe "conditionals in filter" do
300
300
  describe "value as an expression" do
301
301
  # testing that a field has a value should be true.
302
302
  conditional "[message]" do
303
- sample("apple") { expect(subject["tags"]).to include("success") }
304
- sample("sample") { expect(subject["tags"]).to include("success") }
305
- sample("some sample") { expect(subject["tags"]).to include("success") }
303
+ sample("apple") { expect(subject.get("tags")).to include("success") }
304
+ sample("sample") { expect(subject.get("tags")).to include("success") }
305
+ sample("some sample") { expect(subject.get("tags")).to include("success") }
306
306
  end
307
307
 
308
308
  # testing that a missing field has a value should be false.
309
309
  conditional "[missing]" do
310
- sample("apple") { expect(subject["tags"]).to include("failure") }
311
- sample("sample") { expect(subject["tags"]).to include("failure") }
312
- sample("some sample") { expect(subject["tags"]).to include("failure") }
310
+ sample("apple") { expect(subject.get("tags")).to include("failure") }
311
+ sample("sample") { expect(subject.get("tags")).to include("failure") }
312
+ sample("some sample") { expect(subject.get("tags")).to include("failure") }
313
313
  end
314
314
  end
315
315
 
316
316
  describe "logic operators" do
317
317
  describe "and" do
318
318
  conditional "[message] and [message]" do
319
- sample("whatever") { expect(subject["tags"]).to include("success") }
319
+ sample("whatever") { expect(subject.get("tags")).to include("success") }
320
320
  end
321
321
  conditional "[message] and ![message]" do
322
- sample("whatever") { expect(subject["tags"]).to include("failure") }
322
+ sample("whatever") { expect(subject.get("tags")).to include("failure") }
323
323
  end
324
324
  conditional "![message] and [message]" do
325
- sample("whatever") { expect(subject["tags"]).to include("failure") }
325
+ sample("whatever") { expect(subject.get("tags")).to include("failure") }
326
326
  end
327
327
  conditional "![message] and ![message]" do
328
- sample("whatever") { expect(subject["tags"]).to include("failure") }
328
+ sample("whatever") { expect(subject.get("tags")).to include("failure") }
329
329
  end
330
330
  end
331
331
 
332
332
  describe "or" do
333
333
  conditional "[message] or [message]" do
334
- sample("whatever") { expect(subject["tags"]).to include("success") }
334
+ sample("whatever") { expect(subject.get("tags")).to include("success") }
335
335
  end
336
336
  conditional "[message] or ![message]" do
337
- sample("whatever") { expect(subject["tags"]).to include("success") }
337
+ sample("whatever") { expect(subject.get("tags")).to include("success") }
338
338
  end
339
339
  conditional "![message] or [message]" do
340
- sample("whatever") { expect(subject["tags"]).to include("success") }
340
+ sample("whatever") { expect(subject.get("tags")).to include("success") }
341
341
  end
342
342
  conditional "![message] or ![message]" do
343
- sample("whatever") { expect(subject["tags"]).to include("failure") }
343
+ sample("whatever") { expect(subject.get("tags")).to include("failure") }
344
344
  end
345
345
  end
346
346
  end
@@ -348,19 +348,19 @@ describe "conditionals in filter" do
348
348
  describe "field references" do
349
349
  conditional "[field with space]" do
350
350
  sample("field with space" => "hurray") do
351
- expect(subject["tags"]).to include("success")
351
+ expect(subject.get("tags")).to include("success")
352
352
  end
353
353
  end
354
354
 
355
355
  conditional "[field with space] == 'hurray'" do
356
356
  sample("field with space" => "hurray") do
357
- expect(subject["tags"]).to include("success")
357
+ expect(subject.get("tags")).to include("success")
358
358
  end
359
359
  end
360
360
 
361
361
  conditional "[nested field][reference with][some spaces] == 'hurray'" do
362
362
  sample({"nested field" => { "reference with" => { "some spaces" => "hurray" } } }) do
363
- expect(subject["tags"]).to include("success")
363
+ expect(subject.get("tags")).to include("success")
364
364
  end
365
365
  end
366
366
  end
@@ -385,13 +385,13 @@ describe "conditionals in filter" do
385
385
  expect(subject).to be_an(Array)
386
386
  expect(subject.length).to eq(2)
387
387
 
388
- expect(subject[0]["type"]).to eq("original")
389
- expect(subject[0]["cond1"]).to eq("true")
390
- expect(subject[0]["cond2"]).to eq(nil)
388
+ expect(subject[0].get("type")).to eq("original")
389
+ expect(subject[0].get("cond1")).to eq("true")
390
+ expect(subject[0].get("cond2")).to eq(nil)
391
391
 
392
- expect(subject[1]["type"]).to eq("clone")
393
- # expect(subject[1]["cond1"]).to eq(nil)
394
- # expect(subject[1]["cond2"]).to eq("true")
392
+ expect(subject[1].get("type")).to eq("clone")
393
+ # expect(subject[1].get("cond1")).to eq(nil)
394
+ # expect(subject[1].get("cond2")).to eq("true")
395
395
  end
396
396
  end
397
397
 
@@ -413,16 +413,16 @@ describe "conditionals in filter" do
413
413
 
414
414
  sample({"type" => "original"}) do
415
415
  # puts subject.inspect
416
- expect(subject[0]["cond1"]).to eq(nil)
417
- expect(subject[0]["cond2"]).to eq(nil)
416
+ expect(subject[0].get("cond1")).to eq(nil)
417
+ expect(subject[0].get("cond2")).to eq(nil)
418
418
 
419
- expect(subject[1]["type"]).to eq("clone1")
420
- expect(subject[1]["cond1"]).to eq("true")
421
- expect(subject[1]["cond2"]).to eq(nil)
419
+ expect(subject[1].get("type")).to eq("clone1")
420
+ expect(subject[1].get("cond1")).to eq("true")
421
+ expect(subject[1].get("cond2")).to eq(nil)
422
422
 
423
- expect(subject[2]["type"]).to eq("clone2")
424
- expect(subject[2]["cond1"]).to eq(nil)
425
- expect(subject[2]["cond2"]).to eq("true")
423
+ expect(subject[2].get("type")).to eq("clone2")
424
+ expect(subject[2].get("cond1")).to eq(nil)
425
+ expect(subject[2].get("cond2")).to eq("true")
426
426
  end
427
427
  end
428
428
 
@@ -7,8 +7,14 @@ require_relative "../support/mocks_classes"
7
7
  describe LogStash::Agent do
8
8
 
9
9
  let(:logger) { double("logger") }
10
- let(:agent_args) { { :logger => logger } }
11
- subject { LogStash::Agent.new(agent_args) }
10
+ let(:agent_settings) { LogStash::SETTINGS }
11
+ let(:agent_args) { {} }
12
+ let(:pipeline_settings) { agent_settings.clone }
13
+ let(:pipeline_args) { {} }
14
+ let(:config_file) { Stud::Temporary.pathname }
15
+ let(:config_file_txt) { "input { generator { count => 100000 } } output { }" }
16
+
17
+ subject { LogStash::Agent.new(agent_settings) }
12
18
 
13
19
  before :each do
14
20
  [:info, :warn, :error, :fatal, :debug].each do |level|
@@ -17,46 +23,63 @@ describe LogStash::Agent do
17
23
  [:info?, :warn?, :error?, :fatal?, :debug?].each do |level|
18
24
  allow(logger).to receive(level)
19
25
  end
26
+ File.open(config_file, "w") { |f| f.puts config_file_txt }
27
+ agent_args.each do |key, value|
28
+ agent_settings.set(key, value)
29
+ pipeline_settings.set(key, value)
30
+ end
31
+ pipeline_args.each do |key, value|
32
+ pipeline_settings.set(key, value)
33
+ end
34
+ #subject.logger = logger
35
+ end
36
+
37
+ after :each do
38
+ LogStash::SETTINGS.reset
39
+ File.unlink(config_file)
40
+ end
41
+
42
+ it "fallback to hostname when no name is provided" do
43
+ expect(LogStash::Agent.new.node_name).to eq(Socket.gethostname)
20
44
  end
21
45
 
22
46
  describe "register_pipeline" do
23
47
  let(:pipeline_id) { "main" }
24
48
  let(:config_string) { "input { } filter { } output { }" }
25
- let(:settings) { {
26
- :config_string => config_string,
27
- :pipeline_workers => 4
28
- } }
29
-
30
- let(:agent_args) { {
31
- :logger => logger,
32
- :auto_reload => false,
33
- :reload_interval => 0.01
34
- } }
49
+ let(:agent_args) do
50
+ {
51
+ "config.string" => config_string,
52
+ "config.reload.automatic" => true,
53
+ "config.reload.interval" => 0.01,
54
+ "pipeline.workers" => 4,
55
+ }
56
+ end
35
57
 
36
58
  it "should delegate settings to new pipeline" do
37
- expect(LogStash::Pipeline).to receive(:new).with(settings[:config_string], hash_including(settings))
38
- subject.register_pipeline(pipeline_id, settings)
59
+ expect(LogStash::Pipeline).to receive(:new) do |arg1, arg2|
60
+ expect(arg1).to eq(config_string)
61
+ expect(arg2.to_hash).to include(agent_args)
62
+ end
63
+ subject.register_pipeline(pipeline_id, agent_settings)
39
64
  end
40
65
  end
41
66
 
42
67
  describe "#execute" do
43
- let(:sample_config) { "input { generator { count => 100000 } } output { }" }
44
- let(:config_file) { Stud::Temporary.pathname }
68
+ let(:config_file_txt) { "input { generator { count => 100000 } } output { }" }
45
69
 
46
70
  before :each do
47
71
  allow(subject).to receive(:start_webserver).and_return(false)
48
72
  allow(subject).to receive(:stop_webserver).and_return(false)
49
- File.open(config_file, "w") { |f| f.puts sample_config }
50
- end
51
-
52
- after :each do
53
- File.unlink(config_file)
54
73
  end
55
74
 
56
75
  context "when auto_reload is false" do
57
- let(:agent_args) { { :logger => logger, :auto_reload => false } }
76
+ let(:agent_args) do
77
+ {
78
+ "config.reload.automatic" => false,
79
+ "path.config" => config_file
80
+ }
81
+ end
58
82
  let(:pipeline_id) { "main" }
59
- let(:pipeline_settings) { { :config_path => config_file } }
60
83
 
61
84
  before(:each) do
62
85
  subject.register_pipeline(pipeline_id, pipeline_settings)
@@ -112,9 +135,14 @@ describe LogStash::Agent do
112
135
  end
113
136
 
114
137
  context "when auto_reload is true" do
115
- let(:agent_args) { { :logger => logger, :auto_reload => true, :reload_interval => 0.01 } }
138
+ let(:agent_args) do
139
+ {
140
+ "config.reload.automatic" => true,
141
+ "config.reload.interval" => 0.01,
142
+ "path.config" => config_file,
143
+ }
144
+ end
116
145
  let(:pipeline_id) { "main" }
117
- let(:pipeline_settings) { { :config_path => config_file } }
118
146
 
119
147
  before(:each) do
120
148
  subject.register_pipeline(pipeline_id, pipeline_settings)
@@ -168,9 +196,9 @@ describe LogStash::Agent do
168
196
  let(:pipeline_id) { "main" }
169
197
  let(:first_pipeline_config) { "input { } filter { } output { }" }
170
198
  let(:second_pipeline_config) { "input { generator {} } filter { } output { }" }
171
- let(:pipeline_settings) { {
172
- :config_string => first_pipeline_config,
173
- :pipeline_workers => 4
199
+ let(:pipeline_args) { {
200
+ "config.string" => first_pipeline_config,
201
+ "pipeline.workers" => 4
174
202
  } }
175
203
 
176
204
  before(:each) do
@@ -194,30 +222,18 @@ describe LogStash::Agent do
194
222
  end
195
223
 
196
224
  describe "Environment Variables In Configs" do
225
+ let(:pipeline_config) { "input { generator { message => '${FOO}-bar' } } filter { } output { }" }
197
226
  let(:agent_args) { {
198
- :logger => logger,
199
- :auto_reload => false,
200
- :reload_interval => 0.01
227
+ "config.reload.automatic" => false,
228
+ "config.reload.interval" => 0.01,
229
+ "config.string" => pipeline_config
201
230
  } }
202
231
  let(:pipeline_id) { "main" }
203
- let(:pipeline_config) { "input { generator { message => '${FOO}-bar' } } filter { } output { }" }
204
- let(:pipeline_settings) { {
205
- :config_string => pipeline_config,
206
- } }
207
-
208
- context "when allow_env is false" do
209
- it "does not interpolate environment variables" do
210
- expect(subject).to receive(:fetch_config).and_return(pipeline_config)
211
- subject.register_pipeline(pipeline_id, pipeline_settings)
212
- expect(subject.pipelines[pipeline_id].inputs.first.message).to eq("${FOO}-bar")
213
- end
214
- end
215
232
 
216
- context "when allow_env is true" do
233
+ context "environment variable templating" do
217
234
  before :each do
218
235
  @foo_content = ENV["FOO"]
219
236
  ENV["FOO"] = "foo"
220
- pipeline_settings.merge!(:allow_env => true)
221
237
  end
222
238
 
223
239
  after :each do
@@ -225,7 +241,7 @@ describe LogStash::Agent do
225
241
  end
226
242
 
227
243
  it "doesn't upgrade the state" do
228
- expect(subject).to receive(:fetch_config).and_return(pipeline_config)
244
+ allow(subject).to receive(:fetch_config).and_return(pipeline_config)
229
245
  subject.register_pipeline(pipeline_id, pipeline_settings)
230
246
  expect(subject.pipelines[pipeline_id].inputs.first.message).to eq("foo-bar")
231
247
  end
@@ -235,9 +251,9 @@ describe LogStash::Agent do
235
251
  describe "#upgrade_pipeline" do
236
252
  let(:pipeline_id) { "main" }
237
253
  let(:pipeline_config) { "input { } filter { } output { }" }
238
- let(:pipeline_settings) { {
239
- :config_string => pipeline_config,
240
- :pipeline_workers => 4
254
+ let(:pipeline_args) { {
255
+ "config.string" => pipeline_config,
256
+ "pipeline.workers" => 4
241
257
  } }
242
258
  let(:new_pipeline_config) { "input { generator {} } output { }" }
243
259
 
@@ -284,23 +300,12 @@ describe LogStash::Agent do
284
300
  end
285
301
 
286
302
  describe "#fetch_config" do
287
- let(:file_config) { "input { generator { count => 100 } } output { }" }
288
303
  let(:cli_config) { "filter { drop { } } " }
289
- let(:tmp_config_path) { Stud::Temporary.pathname }
290
- let(:agent_args) { { :logger => logger, :config_string => "filter { drop { } } ", :config_path => tmp_config_path } }
291
-
292
- before :each do
293
- IO.write(tmp_config_path, file_config)
294
- end
295
-
296
- after :each do
297
- File.unlink(tmp_config_path)
298
- end
304
+ let(:agent_args) { { "config.string" => cli_config, "path.config" => config_file } }
299
305
 
300
306
  it "should join the config string and config path content" do
301
- settings = { :config_path => tmp_config_path, :config_string => cli_config }
302
- fetched_config = subject.send(:fetch_config, settings)
303
- expect(fetched_config.strip).to eq(cli_config + IO.read(tmp_config_path))
307
+ fetched_config = subject.send(:fetch_config, agent_settings)
308
+ expect(fetched_config.strip).to eq(cli_config + IO.read(config_file).strip)
304
309
  end
305
310
  end
306
311
 
@@ -328,13 +333,17 @@ describe LogStash::Agent do
328
333
  f.path
329
334
  end
330
335
  let(:interval) { 0.2 }
331
- let(:pipeline_settings) { { :pipeline_workers => 4,
332
- :config_path => config_path } }
336
+ let(:pipeline_args) do
337
+ {
338
+ "pipeline.workers" => 4,
339
+ "path.config" => config_path
340
+ }
341
+ end
333
342
 
334
343
  let(:agent_args) do
335
- super.merge({ :auto_reload => true,
336
- :reload_interval => interval,
337
- :collect_metric => true })
344
+ super.merge({ "config.reload.automatic" => true,
345
+ "config.reload.interval" => interval,
346
+ "metric.collect" => true })
338
347
  end
339
348
 
340
349
  before :each do