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
@@ -3,7 +3,10 @@ require "spec_helper"
3
3
  require "logstash/runner"
4
4
  require "stud/task"
5
5
  require "stud/trap"
6
+ require "stud/temporary"
6
7
  require "logstash/util/java_version"
8
+ require "logstash/logging/json"
9
+ require "json"
7
10
 
8
11
  class NullRunner
9
12
  def run(args); end
@@ -17,15 +20,49 @@ describe LogStash::Runner do
17
20
  before :each do
18
21
  allow(Cabin::Channel).to receive(:get).with(LogStash).and_return(channel)
19
22
  allow(channel).to receive(:subscribe).with(any_args)
23
+ allow(channel).to receive(:log) {}
24
+ allow(LogStash::ShutdownWatcher).to receive(:logger).and_return(channel)
25
+ end
26
+
27
+ after :each do
28
+ LogStash::SETTINGS.reset
29
+ end
30
+
31
+ after :all do
32
+ LogStash::ShutdownWatcher.logger = nil
33
+ end
34
+
35
+ describe "argument precedence" do
36
+ let(:config) { "input {} output {}" }
37
+ let(:cli_args) { ["-e", config, "-w", "20"] }
38
+ let(:settings_yml_hash) { { "pipeline.workers" => 2 } }
39
+
40
+ before :each do
41
+ allow(LogStash::SETTINGS).to receive(:read_yaml).and_return(settings_yml_hash)
42
+ end
43
+
44
+ after :each do
45
+ LogStash::SETTINGS.reset
46
+ end
47
+
48
+ it "favors the last occurence of an option" do
49
+ expect(LogStash::Agent).to receive(:new) do |settings|
50
+ expect(settings.get("config.string")).to eq(config)
51
+ expect(settings.get("pipeline.workers")).to eq(20)
52
+ end
53
+ subject.run("bin/logstash", cli_args)
54
+ end
20
55
  end
21
56
 
22
57
  describe "argument parsing" do
23
58
  subject { LogStash::Runner.new("") }
59
+ before :each do
60
+ allow(Cabin::Channel.get(LogStash)).to receive(:terminal)
61
+ end
24
62
  context "when -e is given" do
25
63
 
26
64
  let(:args) { ["-e", "input {} output {}"] }
27
65
  let(:agent) { double("agent") }
28
- let(:agent_logger) { double("agent logger") }
29
66
 
30
67
  before do
31
68
  allow(agent).to receive(:logger=).with(anything)
@@ -42,10 +79,8 @@ describe LogStash::Runner do
42
79
 
43
80
  context "with no arguments" do
44
81
  let(:args) { [] }
45
- let(:agent) { double("agent") }
46
82
 
47
83
  before(:each) do
48
- allow(LogStash::Agent).to receive(:new).and_return(agent)
49
84
  allow(LogStash::Util::JavaVersion).to receive(:warn_on_bad_java_version)
50
85
  end
51
86
 
@@ -96,7 +131,33 @@ describe LogStash::Runner do
96
131
  end
97
132
  end
98
133
 
99
- describe "--config-test" do
134
+ describe "--log.format=json" do
135
+ subject { LogStash::Runner.new("") }
136
+ let(:logfile) { Stud::Temporary.file }
137
+ let(:args) { [ "--log.format", "json", "-l", logfile.path, "-e", "input {} output{}" ] }
138
+
139
+ after do
140
+ logfile.close
141
+ File.unlink(logfile.path)
142
+ end
143
+
144
+ before do
145
+ expect(channel).to receive(:subscribe).with(kind_of(LogStash::Logging::JSON)).and_call_original
146
+ subject.run(args)
147
+
148
+ # Log file should have stuff in it.
149
+ expect(logfile.stat.size).to be > 0
150
+ end
151
+
152
+ it "should log in valid json. One object per line." do
153
+ logfile.each_line do |line|
154
+ expect(line).not_to be_empty
155
+ expect { JSON.parse(line) }.not_to raise_error
156
+ end
157
+ end
158
+ end
159
+
160
+ describe "--config.test_and_exit" do
100
161
  subject { LogStash::Runner.new("") }
101
162
  let(:args) { ["-t", "-e", pipeline_string] }
102
163
 
@@ -130,8 +191,9 @@ describe LogStash::Runner do
130
191
 
131
192
  context "when :pipeline_workers is not defined by the user" do
132
193
  it "should not pass the value to the pipeline" do
133
- expect(LogStash::Pipeline).to receive(:new).once.with(pipeline_string, hash_excluding(:pipeline_workers)).and_return(pipeline)
134
-
194
+ expect(LogStash::Agent).to receive(:new) do |settings|
195
+ expect(settings.set?("pipeline.workers")).to be(false)
196
+ end
135
197
  args = ["-e", pipeline_string]
136
198
  subject.run("bin/logstash", args)
137
199
  end
@@ -139,42 +201,67 @@ describe LogStash::Runner do
139
201
 
140
202
  context "when :pipeline_workers is defined by the user" do
141
203
  it "should pass the value to the pipeline" do
142
- main_pipeline_settings[:pipeline_workers] = 2
143
- expect(LogStash::Pipeline).to receive(:new).with(pipeline_string, hash_including(main_pipeline_settings)).and_return(pipeline)
204
+ expect(LogStash::Agent).to receive(:new) do |settings|
205
+ expect(settings.set?("pipeline.workers")).to be(true)
206
+ expect(settings.get("pipeline.workers")).to be(2)
207
+ end
144
208
 
145
209
  args = ["-w", "2", "-e", pipeline_string]
146
210
  subject.run("bin/logstash", args)
147
211
  end
148
212
  end
149
213
 
150
- describe "debug_config" do
151
- it "should set 'debug_config' to false by default" do
152
- expect(LogStash::Config::Loader).to receive(:new).with(anything, false).and_call_original
153
- expect(LogStash::Pipeline).to receive(:new).with(pipeline_string, hash_including(:debug_config => false)).and_return(pipeline)
154
- args = ["--debug", "-e", pipeline_string]
214
+ describe "config.debug" do
215
+ it "should set 'config.debug' to false by default" do
216
+ expect(LogStash::Agent).to receive(:new) do |settings|
217
+ expect(settings.get("config.debug")).to eq(false)
218
+ end
219
+ args = ["--log.level", "debug", "-e", pipeline_string]
155
220
  subject.run("bin/logstash", args)
156
221
  end
157
222
 
158
- it "should allow overriding debug_config" do
159
- expect(LogStash::Config::Loader).to receive(:new).with(anything, true).and_call_original
160
- expect(LogStash::Pipeline).to receive(:new).with(pipeline_string, hash_including(:debug_config => true)).and_return(pipeline)
161
- args = ["--debug", "--debug-config", "-e", pipeline_string]
223
+ it "should allow overriding config.debug" do
224
+ expect(LogStash::Agent).to receive(:new) do |settings|
225
+ expect(settings.get("config.debug")).to eq(true)
226
+ end
227
+ args = ["--log.level", "debug", "--config.debug", "-e", pipeline_string]
162
228
  subject.run("bin/logstash", args)
163
229
  end
164
230
  end
231
+ end
165
232
 
166
- context "when configuring environment variable support" do
167
- it "should set 'allow_env' to false by default" do
168
- args = ["-e", pipeline_string]
169
- expect(LogStash::Pipeline).to receive(:new).with(pipeline_string, hash_including(:allow_env => false)).and_return(pipeline)
233
+ describe "--log.level" do
234
+ before :each do
235
+ allow_any_instance_of(subject).to receive(:show_version)
236
+ end
237
+ context "when not set" do
238
+ it "should set log level to warn" do
239
+ args = ["--version"]
170
240
  subject.run("bin/logstash", args)
241
+ expect(channel.level).to eq(:warn)
171
242
  end
172
-
173
- it "should support templating environment variables" do
174
- args = ["-e", pipeline_string, "--allow-env"]
175
- expect(LogStash::Pipeline).to receive(:new).with(pipeline_string, hash_including(:allow_env => true)).and_return(pipeline)
243
+ end
244
+ context "when setting to debug" do
245
+ it "should set log level to debug" do
246
+ args = ["--log.level", "debug", "--version"]
247
+ subject.run("bin/logstash", args)
248
+ expect(channel.level).to eq(:debug)
249
+ end
250
+ end
251
+ context "when setting to verbose" do
252
+ it "should set log level to info" do
253
+ args = ["--log.level", "verbose", "--version"]
176
254
  subject.run("bin/logstash", args)
255
+ expect(channel.level).to eq(:info)
256
+ end
257
+ end
258
+ context "when setting to quiet" do
259
+ it "should set log level to error" do
260
+ args = ["--log.level", "quiet", "--version"]
261
+ subject.run("bin/logstash", args)
262
+ expect(channel.level).to eq(:error)
177
263
  end
178
264
  end
179
265
  end
266
+
180
267
  end
@@ -0,0 +1,130 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+ require "logstash/settings"
4
+
5
+ describe LogStash::Setting do
6
+ let(:logger) { double("logger") }
7
+ describe "#value" do
8
+ context "when using a default value" do
9
+ context "when no value is set" do
10
+ subject { described_class.new("number", Numeric, 1) }
11
+ it "should return the default value" do
12
+ expect(subject.value).to eq(1)
13
+ end
14
+ end
15
+
16
+ context "when a value is set" do
17
+ subject { described_class.new("number", Numeric, 1) }
18
+ let(:new_value) { 2 }
19
+ before :each do
20
+ subject.set(new_value)
21
+ end
22
+ it "should return the set value" do
23
+ expect(subject.value).to eq(new_value)
24
+ end
25
+ end
26
+ end
27
+
28
+ context "when not using a default value" do
29
+ context "when no value is set" do
30
+ subject { described_class.new("number", Numeric, nil, false) }
31
+ it "should return the default value" do
32
+ expect(subject.value).to eq(nil)
33
+ end
34
+ end
35
+
36
+ context "when a value is set" do
37
+ subject { described_class.new("number", Numeric, nil, false) }
38
+ let(:new_value) { 2 }
39
+ before :each do
40
+ subject.set(new_value)
41
+ end
42
+ it "should return the set value" do
43
+ expect(subject.value).to eq(new_value)
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ describe "#set?" do
50
+ context "when there is not value set" do
51
+ subject { described_class.new("number", Numeric, 1) }
52
+ it "should return false" do
53
+ expect(subject.set?).to be(false)
54
+ end
55
+ end
56
+ context "when there is a value set" do
57
+ subject { described_class.new("number", Numeric, 1) }
58
+ before :each do
59
+ subject.set(2)
60
+ end
61
+ it "should return false" do
62
+ expect(subject.set?).to be(true)
63
+ end
64
+ end
65
+ end
66
+ describe "#set" do
67
+ subject { described_class.new("number", Numeric, 1) }
68
+ it "should change the value of a setting" do
69
+ expect(subject.value).to eq(1)
70
+ subject.set(4)
71
+ expect(subject.value).to eq(4)
72
+ end
73
+ context "when executed for the first time" do
74
+ it "should change the result of set?" do
75
+ expect(subject.set?).to eq(false)
76
+ subject.set(4)
77
+ expect(subject.set?).to eq(true)
78
+ end
79
+ end
80
+
81
+ context "when the argument's class does not match @klass" do
82
+ it "should throw an exception" do
83
+ expect { subject.set("not a number") }.to raise_error
84
+ end
85
+ end
86
+ end
87
+
88
+ describe "#reset" do
89
+ subject { described_class.new("number", Numeric, 1) }
90
+ context "if value is already set" do
91
+ before :each do
92
+ subject.set(2)
93
+ end
94
+ it "should reset value to default" do
95
+ subject.reset
96
+ expect(subject.value).to eq(1)
97
+ end
98
+ it "should reset set? to false" do
99
+ expect(subject.set?).to eq(true)
100
+ subject.reset
101
+ expect(subject.set?).to eq(false)
102
+ end
103
+ end
104
+ end
105
+
106
+ describe "validator_proc" do
107
+ let(:default_value) { "small text" }
108
+ subject { described_class.new("mytext", String, default_value) {|v| v.size < 20 } }
109
+ context "when validation fails" do
110
+ let(:new_value) { "very very very very very big text" }
111
+ it "should raise an exception" do
112
+ expect { subject.set(new_value) }.to raise_error
113
+ end
114
+ it "should not change the value" do
115
+ subject.set(new_value) rescue nil
116
+ expect(subject.value).to eq(default_value)
117
+ end
118
+ end
119
+ context "when validation is successful" do
120
+ let(:new_value) { "smaller text" }
121
+ it "should not raise an exception" do
122
+ expect { subject.set(new_value) }.to_not raise_error
123
+ end
124
+ it "should change the value" do
125
+ subject.set(new_value)
126
+ expect(subject.value).to eq(new_value)
127
+ end
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+ require "logstash/settings"
4
+
5
+ describe LogStash::Settings do
6
+ let(:numeric_setting_name) { "number" }
7
+ let(:numeric_setting) { LogStash::Setting.new(numeric_setting_name, Numeric, 1) }
8
+ describe "#register" do
9
+ context "if setting has already been registered" do
10
+ before :each do
11
+ subject.register(numeric_setting)
12
+ end
13
+ it "should raise an exception" do
14
+ expect { subject.register(numeric_setting) }.to raise_error
15
+ end
16
+ end
17
+ context "if setting hasn't been registered" do
18
+ it "should not raise an exception" do
19
+ expect { subject.register(numeric_setting) }.to_not raise_error
20
+ end
21
+ end
22
+ end
23
+ describe "#get_setting" do
24
+ context "if setting has been registered" do
25
+ before :each do
26
+ subject.register(numeric_setting)
27
+ end
28
+ it "should return the setting" do
29
+ expect(subject.get_setting(numeric_setting_name)).to eq(numeric_setting)
30
+ end
31
+ end
32
+ context "if setting hasn't been registered" do
33
+ it "should raise an exception" do
34
+ expect { subject.get_setting(numeric_setting_name) }.to raise_error
35
+ end
36
+ end
37
+ end
38
+ describe "#get_subset" do
39
+ let(:numeric_setting_1) { LogStash::Setting.new("num.1", Numeric, 1) }
40
+ let(:numeric_setting_2) { LogStash::Setting.new("num.2", Numeric, 2) }
41
+ let(:numeric_setting_3) { LogStash::Setting.new("num.3", Numeric, 3) }
42
+ let(:string_setting_1) { LogStash::Setting.new("string.1", String, "hello") }
43
+ before :each do
44
+ subject.register(numeric_setting_1)
45
+ subject.register(numeric_setting_2)
46
+ subject.register(numeric_setting_3)
47
+ subject.register(string_setting_1)
48
+ end
49
+
50
+ it "supports regex" do
51
+ expect(subject.get_subset(/num/).get_setting("num.3")).to eq(numeric_setting_3)
52
+ expect { subject.get_subset(/num/).get_setting("string.1") }.to raise_error
53
+ end
54
+
55
+ it "returns a copy of settings" do
56
+ subset = subject.get_subset(/num/)
57
+ subset.set("num.2", 1000)
58
+ expect(subject.get("num.2")).to eq(2)
59
+ expect(subset.get("num.2")).to eq(1000)
60
+ end
61
+ end
62
+ end
metadata CHANGED
@@ -1,21 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.alpha3.snapshot2
4
+ version: 5.0.0.alpha3.snapshot4
5
5
  platform: java
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-11 00:00:00.000000000 Z
11
+ date: 2016-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
16
  - - '='
17
17
  - !ruby/object:Gem::Version
18
- version: 5.0.0.pre.alpha3.snapshot2
18
+ version: 5.0.0.alpha3.snapshot4
19
19
  name: logstash-core-event-java
20
20
  prerelease: false
21
21
  type: :runtime
@@ -23,7 +23,7 @@ dependencies:
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 5.0.0.pre.alpha3.snapshot2
26
+ version: 5.0.0.alpha3.snapshot4
27
27
  - !ruby/object:Gem::Dependency
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
@@ -351,12 +351,14 @@ files:
351
351
  - lib/logstash/java_integration.rb
352
352
  - lib/logstash/json.rb
353
353
  - lib/logstash/logging.rb
354
+ - lib/logstash/logging/json.rb
354
355
  - lib/logstash/namespace.rb
355
356
  - lib/logstash/output_delegator.rb
356
357
  - lib/logstash/outputs/base.rb
357
358
  - lib/logstash/patches.rb
358
359
  - lib/logstash/patches/bugfix_jruby_2558.rb
359
360
  - lib/logstash/patches/cabin.rb
361
+ - lib/logstash/patches/clamp.rb
360
362
  - lib/logstash/patches/profile_require_calls.rb
361
363
  - lib/logstash/patches/rubygems.rb
362
364
  - lib/logstash/patches/stronger_openssl_defaults.rb
@@ -366,12 +368,12 @@ files:
366
368
  - lib/logstash/plugins/registry.rb
367
369
  - lib/logstash/program.rb
368
370
  - lib/logstash/runner.rb
371
+ - lib/logstash/settings.rb
369
372
  - lib/logstash/shutdown_watcher.rb
370
373
  - lib/logstash/util.rb
371
374
  - lib/logstash/util/buftok.rb
372
375
  - lib/logstash/util/charset.rb
373
376
  - lib/logstash/util/decorators.rb
374
- - lib/logstash/util/defaults_printer.rb
375
377
  - lib/logstash/util/duration_formatter.rb
376
378
  - lib/logstash/util/filetools.rb
377
379
  - lib/logstash/util/java_version.rb
@@ -425,15 +427,15 @@ files:
425
427
  - spec/logstash/plugin_spec.rb
426
428
  - spec/logstash/plugins/registry_spec.rb
427
429
  - spec/logstash/runner_spec.rb
430
+ - spec/logstash/setting_spec.rb
431
+ - spec/logstash/settings_spec.rb
428
432
  - spec/logstash/shutdown_watcher_spec.rb
429
433
  - spec/logstash/util/buftok_spec.rb
430
434
  - spec/logstash/util/charset_spec.rb
431
- - spec/logstash/util/defaults_printer_spec.rb
432
435
  - spec/logstash/util/duration_formatter_spec.rb
433
436
  - spec/logstash/util/java_version_spec.rb
434
437
  - spec/logstash/util/plugin_version_spec.rb
435
438
  - spec/logstash/util/unicode_trimmer_spec.rb
436
- - spec/logstash/util/worker_threads_default_printer_spec.rb
437
439
  - spec/logstash/util/wrapped_synchronous_queue_spec.rb
438
440
  - spec/logstash/util_spec.rb
439
441
  - spec/static/i18n_spec.rb
@@ -501,15 +503,15 @@ test_files:
501
503
  - spec/logstash/plugin_spec.rb
502
504
  - spec/logstash/plugins/registry_spec.rb
503
505
  - spec/logstash/runner_spec.rb
506
+ - spec/logstash/setting_spec.rb
507
+ - spec/logstash/settings_spec.rb
504
508
  - spec/logstash/shutdown_watcher_spec.rb
505
509
  - spec/logstash/util/buftok_spec.rb
506
510
  - spec/logstash/util/charset_spec.rb
507
- - spec/logstash/util/defaults_printer_spec.rb
508
511
  - spec/logstash/util/duration_formatter_spec.rb
509
512
  - spec/logstash/util/java_version_spec.rb
510
513
  - spec/logstash/util/plugin_version_spec.rb
511
514
  - spec/logstash/util/unicode_trimmer_spec.rb
512
- - spec/logstash/util/worker_threads_default_printer_spec.rb
513
515
  - spec/logstash/util/wrapped_synchronous_queue_spec.rb
514
516
  - spec/logstash/util_spec.rb
515
517
  - spec/static/i18n_spec.rb