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
@@ -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)
@@ -75,6 +98,7 @@ describe LogStash::Agent do
75
98
  sleep 0.1
76
99
  Stud.stop!(t)
77
100
  t.join
101
+ subject.shutdown
78
102
  end
79
103
  end
80
104
 
@@ -91,6 +115,7 @@ describe LogStash::Agent do
91
115
  sleep 0.1
92
116
  Stud.stop!(t)
93
117
  t.join
118
+ subject.shutdown
94
119
  end
95
120
  end
96
121
 
@@ -106,15 +131,22 @@ describe LogStash::Agent do
106
131
  sleep 0.1
107
132
  Stud.stop!(t)
108
133
  t.join
134
+
135
+ subject.shutdown
109
136
  end
110
137
  end
111
138
  end
112
139
  end
113
140
 
114
141
  context "when auto_reload is true" do
115
- let(:agent_args) { { :logger => logger, :auto_reload => true, :reload_interval => 0.01 } }
142
+ let(:agent_args) do
143
+ {
144
+ "config.reload.automatic" => true,
145
+ "config.reload.interval" => 0.01,
146
+ "path.config" => config_file,
147
+ }
148
+ end
116
149
  let(:pipeline_id) { "main" }
117
- let(:pipeline_settings) { { :config_path => config_file } }
118
150
 
119
151
  before(:each) do
120
152
  subject.register_pipeline(pipeline_id, pipeline_settings)
@@ -129,6 +161,7 @@ describe LogStash::Agent do
129
161
  sleep 0.1
130
162
  Stud.stop!(t)
131
163
  t.join
164
+ subject.shutdown
132
165
  end
133
166
  end
134
167
 
@@ -144,6 +177,7 @@ describe LogStash::Agent do
144
177
  sleep 0.1
145
178
  Stud.stop!(t)
146
179
  t.join
180
+ subject.shutdown
147
181
  end
148
182
  end
149
183
 
@@ -158,6 +192,7 @@ describe LogStash::Agent do
158
192
  sleep 0.1
159
193
  Stud.stop!(t)
160
194
  t.join
195
+ subject.shutdown
161
196
  end
162
197
  end
163
198
  end
@@ -168,9 +203,9 @@ describe LogStash::Agent do
168
203
  let(:pipeline_id) { "main" }
169
204
  let(:first_pipeline_config) { "input { } filter { } output { }" }
170
205
  let(:second_pipeline_config) { "input { generator {} } filter { } output { }" }
171
- let(:pipeline_settings) { {
172
- :config_string => first_pipeline_config,
173
- :pipeline_workers => 4
206
+ let(:pipeline_args) { {
207
+ "config.string" => first_pipeline_config,
208
+ "pipeline.workers" => 4
174
209
  } }
175
210
 
176
211
  before(:each) do
@@ -194,30 +229,18 @@ describe LogStash::Agent do
194
229
  end
195
230
 
196
231
  describe "Environment Variables In Configs" do
232
+ let(:pipeline_config) { "input { generator { message => '${FOO}-bar' } } filter { } output { }" }
197
233
  let(:agent_args) { {
198
- :logger => logger,
199
- :auto_reload => false,
200
- :reload_interval => 0.01
234
+ "config.reload.automatic" => false,
235
+ "config.reload.interval" => 0.01,
236
+ "config.string" => pipeline_config
201
237
  } }
202
238
  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
239
 
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
-
216
- context "when allow_env is true" do
240
+ context "environment variable templating" do
217
241
  before :each do
218
242
  @foo_content = ENV["FOO"]
219
243
  ENV["FOO"] = "foo"
220
- pipeline_settings.merge!(:allow_env => true)
221
244
  end
222
245
 
223
246
  after :each do
@@ -225,7 +248,7 @@ describe LogStash::Agent do
225
248
  end
226
249
 
227
250
  it "doesn't upgrade the state" do
228
- expect(subject).to receive(:fetch_config).and_return(pipeline_config)
251
+ allow(subject).to receive(:fetch_config).and_return(pipeline_config)
229
252
  subject.register_pipeline(pipeline_id, pipeline_settings)
230
253
  expect(subject.pipelines[pipeline_id].inputs.first.message).to eq("foo-bar")
231
254
  end
@@ -235,9 +258,9 @@ describe LogStash::Agent do
235
258
  describe "#upgrade_pipeline" do
236
259
  let(:pipeline_id) { "main" }
237
260
  let(:pipeline_config) { "input { } filter { } output { }" }
238
- let(:pipeline_settings) { {
239
- :config_string => pipeline_config,
240
- :pipeline_workers => 4
261
+ let(:pipeline_args) { {
262
+ "config.string" => pipeline_config,
263
+ "pipeline.workers" => 4
241
264
  } }
242
265
  let(:new_pipeline_config) { "input { generator {} } output { }" }
243
266
 
@@ -284,23 +307,12 @@ describe LogStash::Agent do
284
307
  end
285
308
 
286
309
  describe "#fetch_config" do
287
- let(:file_config) { "input { generator { count => 100 } } output { }" }
288
310
  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
311
+ let(:agent_args) { { "config.string" => cli_config, "path.config" => config_file } }
299
312
 
300
313
  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))
314
+ fetched_config = subject.send(:fetch_config, agent_settings)
315
+ expect(fetched_config.strip).to eq(cli_config + IO.read(config_file).strip)
304
316
  end
305
317
  end
306
318
 
@@ -328,13 +340,17 @@ describe LogStash::Agent do
328
340
  f.path
329
341
  end
330
342
  let(:interval) { 0.2 }
331
- let(:pipeline_settings) { { :pipeline_workers => 4,
332
- :config_path => config_path } }
343
+ let(:pipeline_args) do
344
+ {
345
+ "pipeline.workers" => 4,
346
+ "path.config" => config_path
347
+ }
348
+ end
333
349
 
334
350
  let(:agent_args) do
335
- super.merge({ :auto_reload => true,
336
- :reload_interval => interval,
337
- :collect_metric => true })
351
+ super.merge({ "config.reload.automatic" => true,
352
+ "config.reload.interval" => interval,
353
+ "metric.collect" => true })
338
354
  end
339
355
 
340
356
  before :each do
@@ -352,6 +368,7 @@ describe LogStash::Agent do
352
368
  end
353
369
 
354
370
  after :each do
371
+ subject.shutdown
355
372
  Stud.stop!(@t)
356
373
  @t.join
357
374
  end