logstash-core 7.0.0.alpha2-java → 7.0.0.beta1-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/lib/logstash/agent.rb +62 -57
  3. data/lib/logstash/compiler/lscl.rb +2 -3
  4. data/lib/logstash/config/config_ast.rb +59 -17
  5. data/lib/logstash/environment.rb +1 -1
  6. data/lib/logstash/instrument/metric_store.rb +1 -1
  7. data/lib/logstash/instrument/periodic_poller/dlq.rb +5 -7
  8. data/lib/logstash/instrument/periodic_poller/pq.rb +6 -8
  9. data/lib/logstash/instrument/periodic_pollers.rb +3 -3
  10. data/lib/logstash/java_pipeline.rb +36 -15
  11. data/lib/logstash/patches/resolv.rb +0 -21
  12. data/lib/logstash/pipeline.rb +27 -10
  13. data/lib/logstash/pipeline_action/base.rb +1 -1
  14. data/lib/logstash/pipeline_action/create.rb +7 -13
  15. data/lib/logstash/pipeline_action/reload.rb +35 -12
  16. data/lib/logstash/pipeline_action/stop.rb +4 -6
  17. data/lib/logstash/pipeline_settings.rb +1 -1
  18. data/lib/logstash/pipelines_registry.rb +166 -0
  19. data/lib/logstash/settings.rb +5 -5
  20. data/lib/logstash/state_resolver.rb +5 -5
  21. data/lib/logstash/util/duration_formatter.rb +1 -1
  22. data/lib/logstash/util/safe_uri.rb +1 -0
  23. data/lib/logstash/util.rb +11 -1
  24. data/locales/en.yml +1 -1
  25. data/logstash-core.gemspec +17 -20
  26. data/spec/logstash/acked_queue_concurrent_stress_spec.rb +1 -1
  27. data/spec/logstash/agent/converge_spec.rb +25 -31
  28. data/spec/logstash/agent_spec.rb +5 -5
  29. data/spec/logstash/event_spec.rb +2 -2
  30. data/spec/logstash/instrument/wrapped_write_client_spec.rb +1 -1
  31. data/spec/logstash/legacy_ruby_event_spec.rb +6 -5
  32. data/spec/logstash/pipeline_action/create_spec.rb +9 -8
  33. data/spec/logstash/pipeline_action/reload_spec.rb +10 -9
  34. data/spec/logstash/pipeline_action/stop_spec.rb +4 -3
  35. data/spec/logstash/pipelines_registry_spec.rb +220 -0
  36. data/spec/logstash/queue_factory_spec.rb +2 -1
  37. data/spec/logstash/runner_spec.rb +2 -0
  38. data/spec/logstash/settings/array_coercible_spec.rb +1 -1
  39. data/spec/logstash/settings/bytes_spec.rb +2 -2
  40. data/spec/logstash/settings/port_range_spec.rb +1 -1
  41. data/spec/logstash/state_resolver_spec.rb +26 -22
  42. data/spec/logstash/util/safe_uri_spec.rb +40 -0
  43. data/spec/logstash/util/time_value_spec.rb +1 -1
  44. data/spec/logstash/util/wrapped_acked_queue_spec.rb +1 -1
  45. data/spec/support/matchers.rb +25 -19
  46. data/spec/support/shared_contexts.rb +3 -3
  47. data/versions-gem-copy.yml +6 -6
  48. metadata +73 -88
@@ -22,6 +22,8 @@ describe LogStash::Runner do
22
22
  before :each do
23
23
  clear_data_dir
24
24
 
25
+ WebMock.disable_net_connect!(allow_localhost: true)
26
+
25
27
  allow(LogStash::Runner).to receive(:logger).and_return(logger)
26
28
  allow(logger).to receive(:debug?).and_return(true)
27
29
  allow(logger).to receive(:subscribe).with(any_args)
@@ -27,7 +27,7 @@ describe LogStash::Setting::ArrayCoercible do
27
27
 
28
28
  describe "initialization" do
29
29
  subject { described_class }
30
- let(:element_class) { Fixnum }
30
+ let(:element_class) { Integer }
31
31
  context "when given values of incorrect element class" do
32
32
  let(:value) { "test" }
33
33
 
@@ -35,8 +35,8 @@ describe LogStash::Setting::Bytes do
35
35
 
36
36
  before { subject.set(text) }
37
37
 
38
- it "should coerce it to a Fixnum" do
39
- expect(subject.value).to be_a(Fixnum)
38
+ it "should coerce it to an Integer" do
39
+ expect(subject.value).to be_a(::Integer)
40
40
  end
41
41
  end
42
42
 
@@ -5,7 +5,7 @@ require "spec_helper"
5
5
 
6
6
  describe LogStash::Setting::PortRange do
7
7
 
8
- context "When the value is a Fixnum" do
8
+ context "When the value is an Integer" do
9
9
  subject { LogStash::Setting::PortRange.new("mynewtest", 9000) }
10
10
 
11
11
  it "coerces the value in a range" do
@@ -18,17 +18,17 @@ describe LogStash::StateResolver do
18
18
 
19
19
  after do
20
20
  # ensure that the the created pipeline are closed
21
- running_pipelines.each { |_, pipeline| pipeline.close }
21
+ pipelines.running_pipelines.each { |_, pipeline| pipeline.close }
22
22
  end
23
23
 
24
24
  context "when no pipeline is running" do
25
- let(:running_pipelines) { {} }
25
+ let(:pipelines) { LogStash::PipelinesRegistry.new }
26
26
 
27
27
  context "no pipeline configs is received" do
28
28
  let(:pipeline_configs) { [] }
29
29
 
30
30
  it "returns no action" do
31
- expect(subject.resolve(running_pipelines, pipeline_configs).size).to eq(0)
31
+ expect(subject.resolve(pipelines, pipeline_configs).size).to eq(0)
32
32
  end
33
33
  end
34
34
 
@@ -36,7 +36,7 @@ describe LogStash::StateResolver do
36
36
  let(:pipeline_configs) { [mock_pipeline_config(:hello_world)] }
37
37
 
38
38
  it "returns some actions" do
39
- expect(subject.resolve(running_pipelines, pipeline_configs)).to have_actions(
39
+ expect(subject.resolve(pipelines, pipeline_configs)).to have_actions(
40
40
  [:create, :hello_world],
41
41
  )
42
42
  end
@@ -47,13 +47,17 @@ describe LogStash::StateResolver do
47
47
  context "when a pipeline is running" do
48
48
  let(:main_pipeline) { mock_pipeline(:main) }
49
49
  let(:main_pipeline_config) { main_pipeline.pipeline_config }
50
- let(:running_pipelines) { { :main => main_pipeline } }
50
+ let(:pipelines) do
51
+ r = LogStash::PipelinesRegistry.new
52
+ r.create_pipeline(:main, main_pipeline) { true }
53
+ r
54
+ end
51
55
 
52
56
  context "when the pipeline config contains a new one and the existing" do
53
57
  let(:pipeline_configs) { [mock_pipeline_config(:hello_world), main_pipeline_config ] }
54
58
 
55
59
  it "creates the new one and keep the other one" do
56
- expect(subject.resolve(running_pipelines, pipeline_configs)).to have_actions(
60
+ expect(subject.resolve(pipelines, pipeline_configs)).to have_actions(
57
61
  [:create, :hello_world],
58
62
  )
59
63
  end
@@ -62,7 +66,7 @@ describe LogStash::StateResolver do
62
66
  let(:pipeline_configs) { [mock_pipeline_config(:hello_world)] }
63
67
 
64
68
  it "creates the new one and stop the old one one" do
65
- expect(subject.resolve(running_pipelines, pipeline_configs)).to have_actions(
69
+ expect(subject.resolve(pipelines, pipeline_configs)).to have_actions(
66
70
  [:create, :hello_world],
67
71
  [:stop, :main]
68
72
  )
@@ -73,7 +77,7 @@ describe LogStash::StateResolver do
73
77
  let(:pipeline_configs) { [] }
74
78
 
75
79
  it "stops the old one one" do
76
- expect(subject.resolve(running_pipelines, pipeline_configs)).to have_actions(
80
+ expect(subject.resolve(pipelines, pipeline_configs)).to have_actions(
77
81
  [:stop, :main]
78
82
  )
79
83
  end
@@ -83,7 +87,7 @@ describe LogStash::StateResolver do
83
87
  let(:pipeline_configs) { [mock_pipeline_config(:main, "input { generator {}}")] }
84
88
 
85
89
  it "reloads the old one one" do
86
- expect(subject.resolve(running_pipelines, pipeline_configs)).to have_actions(
90
+ expect(subject.resolve(pipelines, pipeline_configs)).to have_actions(
87
91
  [:reload, :main]
88
92
  )
89
93
  end
@@ -92,21 +96,21 @@ describe LogStash::StateResolver do
92
96
  end
93
97
 
94
98
  context "when we have a lot of pipeline running" do
95
- let(:running_pipelines) do
96
- {
97
- :main1 => mock_pipeline(:main1),
98
- :main2 => mock_pipeline(:main2),
99
- :main3 => mock_pipeline(:main3),
100
- :main4 => mock_pipeline(:main4),
101
- :main5 => mock_pipeline(:main5),
102
- :main6 => mock_pipeline(:main6),
103
- }
99
+ let(:pipelines) do
100
+ r = LogStash::PipelinesRegistry.new
101
+ r.create_pipeline(:main1, mock_pipeline(:main1)) { true }
102
+ r.create_pipeline(:main2, mock_pipeline(:main2)) { true }
103
+ r.create_pipeline(:main3, mock_pipeline(:main3)) { true }
104
+ r.create_pipeline(:main4, mock_pipeline(:main4)) { true }
105
+ r.create_pipeline(:main5, mock_pipeline(:main5)) { true }
106
+ r.create_pipeline(:main6, mock_pipeline(:main6)) { true }
107
+ r
104
108
  end
105
109
 
106
110
  context "without system pipeline" do
107
111
  let(:pipeline_configs) do
108
112
  [
109
- running_pipelines[:main1].pipeline_config,
113
+ pipelines.get_pipeline(:main1).pipeline_config,
110
114
  mock_pipeline_config(:main9),
111
115
  mock_pipeline_config(:main5, "input { generator {}}"),
112
116
  mock_pipeline_config(:main3, "input { generator {}}"),
@@ -115,7 +119,7 @@ describe LogStash::StateResolver do
115
119
  end
116
120
 
117
121
  it "generates actions required to converge" do
118
- expect(subject.resolve(running_pipelines, pipeline_configs)).to have_actions(
122
+ expect(subject.resolve(pipelines, pipeline_configs)).to have_actions(
119
123
  [:create, :main7],
120
124
  [:create, :main9],
121
125
  [:reload, :main3],
@@ -130,7 +134,7 @@ describe LogStash::StateResolver do
130
134
  context "with system pipeline" do
131
135
  let(:pipeline_configs) do
132
136
  [
133
- running_pipelines[:main1].pipeline_config,
137
+ pipelines.get_pipeline(:main1).pipeline_config,
134
138
  mock_pipeline_config(:main9),
135
139
  mock_pipeline_config(:main5, "input { generator {}}"),
136
140
  mock_pipeline_config(:main3, "input { generator {}}"),
@@ -140,7 +144,7 @@ describe LogStash::StateResolver do
140
144
  end
141
145
 
142
146
  it "creates the system pipeline before user defined pipelines" do
143
- expect(subject.resolve(running_pipelines, pipeline_configs)).to have_actions(
147
+ expect(subject.resolve(pipelines, pipeline_configs)).to have_actions(
144
148
  [:create, :monitoring],
145
149
  [:create, :main7],
146
150
  [:create, :main9],
@@ -32,5 +32,45 @@ module LogStash module Util
32
32
  end
33
33
  end
34
34
  end
35
+
36
+ describe "#initialize" do
37
+ context 'when host is required' do
38
+ MALFORMED_URIS = ['http:/user:pass@localhost:9600', 'http:/localhost', 'http:/localhost:9600', 'h;localhost', 'http:://localhost']
39
+
40
+ context 'malformed uris via string' do
41
+ MALFORMED_URIS.each do |arg|
42
+ it "#{arg}: should raise an error" do
43
+ expect{LogStash::Util::SafeURI.new(arg)}.to raise_error(ArgumentError)
44
+ end
45
+ end
46
+ end
47
+
48
+ context 'malformed uris via java.net.URI' do
49
+ MALFORMED_URIS.each do |arg|
50
+ it "#{arg}: should raise an error" do
51
+ java_uri = java.net.URI.new(arg)
52
+ expect{LogStash::Util::SafeURI.new(java_uri)}.to raise_error(ArgumentError)
53
+ end
54
+ end
55
+ end
56
+
57
+ context 'malformed uris via Ruby URI' do
58
+ MALFORMED_URIS.each do |arg|
59
+ it "#{arg}: should raise an error" do
60
+ ruby_uri = URI.parse(arg)
61
+ expect{LogStash::Util::SafeURI.new(ruby_uri)}.to raise_error(ArgumentError)
62
+ end
63
+ end
64
+ end
65
+
66
+ context 'uris with a valid host' do
67
+ ['http://user:pass@notlocalhost:9600', 'http://notlocalhost', 'https://notlocalhost:9600', '//notlocalhost', 'notlocalhost', 'notlocalhost:9200'].each do |arg|
68
+ it "#{arg}: should resolve host correctly" do
69
+ expect(LogStash::Util::SafeURI.new(arg).host).to eq('notlocalhost')
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
35
75
  end
36
76
  end end
@@ -51,7 +51,7 @@ describe TimeValue do
51
51
  a = TimeValue.from_value(32)
52
52
  fail "should not parse"
53
53
  rescue ArgumentError => e
54
- expect(e.message).to eq("value is not a string: 32 [Fixnum]")
54
+ expect(e.message).to eq("value is not a string: 32 [Integer]")
55
55
  end
56
56
  end
57
57
  end
@@ -38,7 +38,7 @@ describe LogStash::WrappedAckedQueue do
38
38
  let(:checkpoint_writes) { 1024 }
39
39
  let(:checkpoint_interval) { 0 }
40
40
  let(:path) { Stud::Temporary.directory }
41
- let(:queue) { LogStash::WrappedAckedQueue.new(path, page_capacity, max_events, checkpoint_acks, checkpoint_writes, checkpoint_interval, max_bytes) }
41
+ let(:queue) { LogStash::WrappedAckedQueue.new(path, page_capacity, max_events, checkpoint_acks, checkpoint_writes, checkpoint_interval, false, max_bytes) }
42
42
 
43
43
  after do
44
44
  queue.close
@@ -51,44 +51,50 @@ end
51
51
 
52
52
  RSpec::Matchers.define :have_pipeline? do |pipeline_config|
53
53
  match do |agent|
54
- pipeline = agent.get_pipeline(pipeline_config.pipeline_id)
55
- expect(pipeline).to_not be_nil
54
+ pipeline = nil
55
+ try(30) do
56
+ pipeline = agent.get_pipeline(pipeline_config.pipeline_id)
57
+ expect(pipeline).to_not be_nil
58
+ end
56
59
  expect(pipeline.config_str).to eq(pipeline_config.config_string)
60
+ expect(agent.running_pipelines.keys.map(&:to_s)).to include(pipeline_config.pipeline_id.to_s)
57
61
  end
58
62
 
59
63
  match_when_negated do |agent|
60
- pipeline = agent.get_pipeline(pipeline_config.pipeline_id)
61
- pipeline.nil? || pipeline.config_str != pipeline_config.config_string
64
+ pipeline = nil
65
+ try(30) do
66
+ pipeline = agent.get_pipeline(pipeline_config.pipeline_id)
67
+ expect(pipeline).to_not be_nil
68
+ end
69
+ # either the pipeline_id is not in the running pipelines OR it is but have different configurations
70
+ expect(!agent.running_pipelines.keys.map(&:to_s).include?(pipeline_config.pipeline_id.to_s) || pipeline.config_str != pipeline_config.config_string).to be_truthy
62
71
  end
63
72
  end
64
73
 
65
74
  RSpec::Matchers.define :have_running_pipeline? do |pipeline_config|
66
75
  match do |agent|
67
- Stud.try(10.times, [StandardError, RSpec::Expectations::ExpectationNotMetError]) do
76
+ pipeline = nil
77
+ try(30) do
68
78
  pipeline = agent.get_pipeline(pipeline_config.pipeline_id)
69
79
  expect(pipeline).to_not be_nil
70
- expect(pipeline.config_str).to eq(pipeline_config.config_string)
71
- expect(pipeline.running?).to be_truthy
72
80
  end
81
+ expect(pipeline.config_str).to eq(pipeline_config.config_string)
82
+ expect(pipeline.running?).to be_truthy
83
+ expect(agent.running_pipelines.keys.map(&:to_s)).to include(pipeline_config.pipeline_id.to_s)
73
84
  end
74
85
 
75
86
  failure_message do |agent|
76
87
  pipeline = agent.get_pipeline(pipeline_config.pipeline_id)
77
88
 
78
89
  if pipeline.nil?
79
- "Expected pipeline to exist and running, be we cannot find `#{pipeline_config.pipeline_id}` in the running pipelines `#{agent.pipelines.keys.join(",")}`"
80
- else
81
- if pipeline.running? == false
82
- "Found `#{pipeline_config.pipeline_id}` in the list of pipelines but its not running"
83
- elsif pipeline.config_str != pipeline_config.config_string
84
- "Found `#{pipeline_config.pipeline_id}` in the list of pipelines and running, but the config_string doesn't match,
85
- Expected:
86
- #{pipeline_config.config_string}
87
-
88
- got:
89
- #{pipeline.config_str}"
90
- end
90
+ "Expected pipeline to exist and running, be we cannot find '#{pipeline_config.pipeline_id.to_s}' in the running pipelines '#{agent.running_pipelines.keys.join(",")}'"
91
+ else
92
+ if !pipeline.running?
93
+ "Found '#{pipeline_config.pipeline_id.to_s}' in the list of pipelines but its not running"
94
+ elsif pipeline.config_str != pipeline_config.config_string
95
+ "Found '#{pipeline_config.pipeline_id.to_s}' in the list of pipelines and running, but the config_string doesn't match,\nExpected:\n#{pipeline_config.config_string}\n\ngot:\n#{pipeline.config_str}"
91
96
  end
97
+ end
92
98
  end
93
99
 
94
100
  match_when_negated do
@@ -26,12 +26,12 @@ shared_context "api setup" do
26
26
  @agent.execute
27
27
  pipeline_config = mock_pipeline_config(:main, "input { generator { id => '123' } } output { null {} }")
28
28
  pipeline_creator = LogStash::PipelineAction::Create.new(pipeline_config, @agent.metric)
29
- @pipelines = java.util.concurrent.ConcurrentHashMap.new
30
- expect(pipeline_creator.execute(@agent, @pipelines)).to be_truthy
29
+ @pipelines_registry = LogStash::PipelinesRegistry.new
30
+ expect(pipeline_creator.execute(@agent, @pipelines_registry)).to be_truthy
31
31
  end
32
32
 
33
33
  after :all do
34
- @pipelines.each do |_, pipeline|
34
+ @pipelines_registry.running_pipelines.each do |_, pipeline|
35
35
  pipeline.shutdown
36
36
  pipeline.thread.join
37
37
  end
@@ -7,21 +7,21 @@ logstash-core-plugin-api: 2.1.16
7
7
  # jruby must reference a *released* version of jruby which can be downloaded from the official download url
8
8
  # *and* for which jars artifacts are published for compile-time
9
9
  jruby:
10
- version: 9.1.13.0
11
- sha1: 815bac27d5daa1459a4477d6d80584f007ce6a68
10
+ version: 9.2.5.0
11
+ sha1: c78526ce98b1b4273d11989246cb9bf224ce9712
12
12
 
13
13
  # jruby-runtime-override, if specified, will override the jruby version installed in vendor/jruby for logstash runtime only,
14
14
  # not for the compile-time jars
15
15
  #
16
16
  #jruby-runtime-override:
17
- # url: http://ci.jruby.org/snapshots/previous/jruby-bin-9.1.13.0-SNAPSHOT.tar.gz
18
- # version: 9.1.13.0-SNAPSHOT
17
+ # url: http://ci.jruby.org/snapshots/previous/jruby-bin-9.2.0.0-SNAPSHOT.tar.gz
18
+ # version: 9.2.0.0-SNAPSHOT
19
19
  # sha1: IGNORE
20
20
 
21
21
  # Note: this file is copied to the root of logstash-core because its gemspec needs it when
22
22
  # bundler evaluates the gemspec via bin/logstash
23
23
  # Ensure Jackson version here is kept in sync with version used by jrjackson gem
24
- jrjackson: 0.4.6
25
- jackson: 2.9.5
24
+ jrjackson: 0.4.7
25
+ jackson: 2.9.8
26
26
 
27
27
  # This is a copy the project level versions.yml into this gem's root and it is created when the gemspec is evaluated.