logstash-output-elasticsearch 3.0.2-java → 4.1.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -3
- data/Gemfile +1 -1
- data/lib/logstash/outputs/elasticsearch/common.rb +90 -58
- data/lib/logstash/outputs/elasticsearch/common_configs.rb +12 -32
- data/lib/logstash/outputs/elasticsearch/http_client/manticore_adapter.rb +63 -0
- data/lib/logstash/outputs/elasticsearch/http_client/pool.rb +378 -0
- data/lib/logstash/outputs/elasticsearch/http_client.rb +70 -64
- data/lib/logstash/outputs/elasticsearch/http_client_builder.rb +15 -4
- data/lib/logstash/outputs/elasticsearch/template_manager.rb +1 -1
- data/lib/logstash/outputs/elasticsearch.rb +27 -4
- data/logstash-output-elasticsearch.gemspec +3 -5
- data/spec/es_spec_helper.rb +1 -0
- data/spec/fixtures/5x_node_resp.json +2 -0
- data/spec/integration/outputs/create_spec.rb +2 -5
- data/spec/integration/outputs/index_spec.rb +1 -1
- data/spec/integration/outputs/parent_spec.rb +1 -3
- data/spec/integration/outputs/pipeline_spec.rb +1 -2
- data/spec/integration/outputs/retry_spec.rb +51 -49
- data/spec/integration/outputs/routing_spec.rb +1 -1
- data/spec/integration/outputs/secure_spec.rb +4 -8
- data/spec/integration/outputs/templates_spec.rb +12 -8
- data/spec/integration/outputs/update_spec.rb +13 -27
- data/spec/unit/outputs/elasticsearch/http_client/manticore_adapter_spec.rb +25 -0
- data/spec/unit/outputs/elasticsearch/http_client/pool_spec.rb +142 -0
- data/spec/unit/outputs/elasticsearch/http_client_spec.rb +8 -22
- data/spec/unit/outputs/elasticsearch_proxy_spec.rb +5 -6
- data/spec/unit/outputs/elasticsearch_spec.rb +33 -30
- data/spec/unit/outputs/elasticsearch_ssl_spec.rb +10 -6
- metadata +72 -87
- data/lib/logstash/outputs/elasticsearch/buffer.rb +0 -124
- data/spec/unit/buffer_spec.rb +0 -118
@@ -12,7 +12,7 @@ shared_examples "a routing indexer" do
|
|
12
12
|
before do
|
13
13
|
subject.register
|
14
14
|
event_count.times do
|
15
|
-
subject.
|
15
|
+
subject.multi_receive([LogStash::Event.new("message" => "Hello World!", "type" => type)])
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -24,8 +24,7 @@ describe "send messages to ElasticSearch using HTTPS", :elasticsearch_secure =>
|
|
24
24
|
|
25
25
|
it "sends events to ES" do
|
26
26
|
expect {
|
27
|
-
subject.
|
28
|
-
subject.flush
|
27
|
+
subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
|
29
28
|
}.to_not raise_error
|
30
29
|
end
|
31
30
|
end
|
@@ -48,8 +47,7 @@ describe "connect using HTTP Authentication", :elasticsearch_secure => true do
|
|
48
47
|
|
49
48
|
it "sends events to ES" do
|
50
49
|
expect {
|
51
|
-
subject.
|
52
|
-
subject.flush
|
50
|
+
subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
|
53
51
|
}.to_not raise_error
|
54
52
|
end
|
55
53
|
end
|
@@ -78,8 +76,7 @@ describe "send messages to ElasticSearch using HTTPS", :elasticsearch_secure =>
|
|
78
76
|
|
79
77
|
it "sends events to ES" do
|
80
78
|
expect {
|
81
|
-
subject.
|
82
|
-
subject.flush
|
79
|
+
subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
|
83
80
|
}.to_not raise_error
|
84
81
|
end
|
85
82
|
end
|
@@ -101,8 +98,7 @@ describe "connect using HTTP Authentication", :elasticsearch_secure => true do
|
|
101
98
|
|
102
99
|
it "sends events to ES" do
|
103
100
|
expect {
|
104
|
-
subject.
|
105
|
-
subject.flush
|
101
|
+
subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
|
106
102
|
}.to_not raise_error
|
107
103
|
end
|
108
104
|
end
|
@@ -24,14 +24,16 @@ describe "index template expected behavior", :integration => true do
|
|
24
24
|
|
25
25
|
subject.register
|
26
26
|
|
27
|
-
subject.
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
27
|
+
subject.multi_receive([
|
28
|
+
LogStash::Event.new("message" => "sample message here"),
|
29
|
+
LogStash::Event.new("somevalue" => 100),
|
30
|
+
LogStash::Event.new("somevalue" => 10),
|
31
|
+
LogStash::Event.new("somevalue" => 1),
|
32
|
+
LogStash::Event.new("country" => "us"),
|
33
|
+
LogStash::Event.new("country" => "at"),
|
34
|
+
LogStash::Event.new("geoip" => { "location" => [ 0.0, 0.0 ] })
|
35
|
+
])
|
36
|
+
|
35
37
|
@es.indices.refresh
|
36
38
|
|
37
39
|
# Wait or fail until everything's indexed.
|
@@ -88,3 +90,5 @@ describe "index template expected behavior", :integration => true do
|
|
88
90
|
insist { terms }.include?("at")
|
89
91
|
end
|
90
92
|
end
|
93
|
+
|
94
|
+
|
@@ -2,7 +2,6 @@ require_relative "../../../spec/es_spec_helper"
|
|
2
2
|
|
3
3
|
describe "Update actions", :integration => true do
|
4
4
|
require "logstash/outputs/elasticsearch"
|
5
|
-
require "elasticsearch"
|
6
5
|
|
7
6
|
def get_es_output( options={} )
|
8
7
|
settings = {
|
@@ -40,16 +39,14 @@ describe "Update actions", :integration => true do
|
|
40
39
|
it "should not create new document" do
|
41
40
|
subject = get_es_output({ 'document_id' => "456" } )
|
42
41
|
subject.register
|
43
|
-
subject.
|
44
|
-
subject.flush
|
42
|
+
subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
|
45
43
|
expect {@es.get(:index => 'logstash-update', :type => 'logs', :id => "456", :refresh => true)}.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
|
46
44
|
end
|
47
45
|
|
48
46
|
it "should update existing document" do
|
49
47
|
subject = get_es_output({ 'document_id' => "123" })
|
50
48
|
subject.register
|
51
|
-
subject.
|
52
|
-
subject.flush
|
49
|
+
subject.multi_receive([LogStash::Event.new("message" => "updated message here")])
|
53
50
|
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "123", :refresh => true)
|
54
51
|
insist { r["_source"]["message"] } == 'updated message here'
|
55
52
|
end
|
@@ -59,8 +56,7 @@ describe "Update actions", :integration => true do
|
|
59
56
|
it "should update an existing document that has a 'data' field" do
|
60
57
|
subject = get_es_output({ 'document_id' => "123" })
|
61
58
|
subject.register
|
62
|
-
subject.
|
63
|
-
subject.flush
|
59
|
+
subject.multi_receive([LogStash::Event.new("data" => "updated message here", "message" => "foo")])
|
64
60
|
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "123", :refresh => true)
|
65
61
|
insist { r["_source"]["data"] } == 'updated message here'
|
66
62
|
insist { r["_source"]["message"] } == 'foo'
|
@@ -71,8 +67,7 @@ describe "Update actions", :integration => true do
|
|
71
67
|
it "should increment a counter with event/doc 'count' variable" do
|
72
68
|
subject = get_es_output({ 'document_id' => "123", 'script' => 'scripted_update', 'script_type' => 'file' })
|
73
69
|
subject.register
|
74
|
-
subject.
|
75
|
-
subject.flush
|
70
|
+
subject.multi_receive([LogStash::Event.new("count" => 2)])
|
76
71
|
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "123", :refresh => true)
|
77
72
|
insist { r["_source"]["counter"] } == 3
|
78
73
|
end
|
@@ -80,8 +75,7 @@ describe "Update actions", :integration => true do
|
|
80
75
|
it "should increment a counter with event/doc '[data][count]' nested variable" do
|
81
76
|
subject = get_es_output({ 'document_id' => "123", 'script' => 'scripted_update_nested', 'script_type' => 'file' })
|
82
77
|
subject.register
|
83
|
-
subject.
|
84
|
-
subject.flush
|
78
|
+
subject.multi_receive([LogStash::Event.new("data" => { "count" => 3 })])
|
85
79
|
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "123", :refresh => true)
|
86
80
|
insist { r["_source"]["counter"] } == 4
|
87
81
|
end
|
@@ -94,8 +88,7 @@ describe "Update actions", :integration => true do
|
|
94
88
|
'script_type' => 'inline'
|
95
89
|
})
|
96
90
|
subject.register
|
97
|
-
subject.
|
98
|
-
subject.flush
|
91
|
+
subject.multi_receive([LogStash::Event.new("counter" => 3 )])
|
99
92
|
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "123", :refresh => true)
|
100
93
|
insist { r["_source"]["counter"] } == 4
|
101
94
|
end
|
@@ -109,8 +102,7 @@ describe "Update actions", :integration => true do
|
|
109
102
|
'script_type' => 'inline'
|
110
103
|
})
|
111
104
|
subject.register
|
112
|
-
subject.
|
113
|
-
subject.flush
|
105
|
+
subject.multi_receive([LogStash::Event.new("count" => 3 )])
|
114
106
|
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "123", :refresh => true)
|
115
107
|
insist { r["_source"]["counter"] } == 4
|
116
108
|
end
|
@@ -124,8 +116,7 @@ describe "Update actions", :integration => true do
|
|
124
116
|
'script_type' => 'inline'
|
125
117
|
})
|
126
118
|
subject.register
|
127
|
-
subject.
|
128
|
-
subject.flush
|
119
|
+
subject.multi_receive([LogStash::Event.new("counter" => 3 )])
|
129
120
|
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "456", :refresh => true)
|
130
121
|
insist { r["_source"]["counter"] } == 3
|
131
122
|
end
|
@@ -139,8 +130,7 @@ describe "Update actions", :integration => true do
|
|
139
130
|
'script_type' => 'indexed'
|
140
131
|
})
|
141
132
|
subject.register
|
142
|
-
subject.
|
143
|
-
subject.flush
|
133
|
+
subject.multi_receive([LogStash::Event.new("count" => 4 )])
|
144
134
|
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "123", :refresh => true)
|
145
135
|
insist { r["_source"]["counter"] } == 5
|
146
136
|
end
|
@@ -150,8 +140,7 @@ describe "Update actions", :integration => true do
|
|
150
140
|
it "should create new documents with provided upsert" do
|
151
141
|
subject = get_es_output({ 'document_id' => "456", 'upsert' => '{"message": "upsert message"}' })
|
152
142
|
subject.register
|
153
|
-
subject.
|
154
|
-
subject.flush
|
143
|
+
subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
|
155
144
|
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "456", :refresh => true)
|
156
145
|
insist { r["_source"]["message"] } == 'upsert message'
|
157
146
|
end
|
@@ -159,8 +148,7 @@ describe "Update actions", :integration => true do
|
|
159
148
|
it "should create new documents with event/doc as upsert" do
|
160
149
|
subject = get_es_output({ 'document_id' => "456", 'doc_as_upsert' => true })
|
161
150
|
subject.register
|
162
|
-
subject.
|
163
|
-
subject.flush
|
151
|
+
subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
|
164
152
|
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "456", :refresh => true)
|
165
153
|
insist { r["_source"]["message"] } == 'sample message here'
|
166
154
|
end
|
@@ -169,8 +157,7 @@ describe "Update actions", :integration => true do
|
|
169
157
|
it "should create new documents with upsert content" do
|
170
158
|
subject = get_es_output({ 'document_id' => "456", 'script' => 'scripted_update', 'upsert' => '{"message": "upsert message"}', 'script_type' => 'file' })
|
171
159
|
subject.register
|
172
|
-
subject.
|
173
|
-
subject.flush
|
160
|
+
subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
|
174
161
|
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "456", :refresh => true)
|
175
162
|
insist { r["_source"]["message"] } == 'upsert message'
|
176
163
|
end
|
@@ -178,8 +165,7 @@ describe "Update actions", :integration => true do
|
|
178
165
|
it "should create new documents with event/doc as script params" do
|
179
166
|
subject = get_es_output({ 'document_id' => "456", 'script' => 'scripted_upsert', 'scripted_upsert' => true, 'script_type' => 'file' })
|
180
167
|
subject.register
|
181
|
-
subject.
|
182
|
-
subject.flush
|
168
|
+
subject.multi_receive([LogStash::Event.new("counter" => 1)])
|
183
169
|
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "456", :refresh => true)
|
184
170
|
insist { r["_source"]["counter"] } == 1
|
185
171
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "logstash/devutils/rspec/spec_helper"
|
2
|
+
require "logstash/outputs/elasticsearch/http_client"
|
3
|
+
|
4
|
+
describe LogStash::Outputs::ElasticSearch::HttpClient::ManticoreAdapter do
|
5
|
+
let(:logger) { Cabin::Channel.get }
|
6
|
+
let(:options) { {} }
|
7
|
+
|
8
|
+
subject { described_class.new(logger, options) }
|
9
|
+
|
10
|
+
it "should raise an exception if requests are issued after close" do
|
11
|
+
subject.close
|
12
|
+
expect { subject.perform_request("http://localhost:9200", :get, '/') }.to raise_error(::Manticore::ClientStoppedException)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should implement host unreachable exceptions" do
|
16
|
+
expect(subject.host_unreachable_exceptions).to be_a(Array)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "integration specs", :integration => true do
|
20
|
+
it "should perform correct tests without error" do
|
21
|
+
resp = subject.perform_request("http://localhost:9200", :get, "/")
|
22
|
+
expect(resp.code).to eql(200)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require "logstash/devutils/rspec/spec_helper"
|
2
|
+
require "logstash/outputs/elasticsearch/http_client"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
describe LogStash::Outputs::ElasticSearch::HttpClient::Pool do
|
6
|
+
let(:logger) { Cabin::Channel.get }
|
7
|
+
let(:adapter) { LogStash::Outputs::ElasticSearch::HttpClient::ManticoreAdapter.new(logger) }
|
8
|
+
let(:initial_urls) { [URI.parse("http://localhost:9200")] }
|
9
|
+
let(:options) { {:resurrect_delay => 2} } # Shorten the delay a bit to speed up tests
|
10
|
+
|
11
|
+
subject { described_class.new(logger, adapter, initial_urls, options) }
|
12
|
+
|
13
|
+
describe "initialization" do
|
14
|
+
it "should be successful" do
|
15
|
+
expect { subject }.not_to raise_error
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "the resurrectionist" do
|
20
|
+
it "should start the resurrectionist when created" do
|
21
|
+
expect(subject.resurrectionist_alive?).to eql(true)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should attempt to resurrect connections after the ressurrect delay" do
|
25
|
+
expect(subject).to receive(:resurrect_dead!).once
|
26
|
+
sleep(subject.resurrect_delay + 1)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "the sniffer" do
|
31
|
+
it "should not start the sniffer by default" do
|
32
|
+
expect(subject.sniffer_alive?).to eql(nil)
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when enabled" do
|
36
|
+
let(:options) { super.merge(:sniffing => true)}
|
37
|
+
|
38
|
+
it "should start the sniffer" do
|
39
|
+
expect(subject.sniffer_alive?).to eql(true)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "check sniff" do
|
44
|
+
context "with a good sniff result" do
|
45
|
+
let(:sniff_resp_path) { File.dirname(__FILE__) + '/../../../../fixtures/5x_node_resp.json' }
|
46
|
+
let(:sniff_resp) { double("resp") }
|
47
|
+
let(:sniff_resp_body) { File.open(sniff_resp_path).read }
|
48
|
+
|
49
|
+
before do
|
50
|
+
allow(subject).to receive(:perform_request).
|
51
|
+
with(:get, '_nodes').
|
52
|
+
and_return([double('url'), sniff_resp])
|
53
|
+
allow(sniff_resp).to receive(:body).and_return(sniff_resp_body)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should execute a sniff without error" do
|
57
|
+
expect { subject.check_sniff }.not_to raise_error
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should return the correct sniff URL list" do
|
61
|
+
url_strs = subject.check_sniff.map(&:to_s)
|
62
|
+
expect(url_strs).to include("http://127.0.0.1:9200")
|
63
|
+
expect(url_strs).to include("http://127.0.0.1:9201")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "closing" do
|
70
|
+
before do
|
71
|
+
# Simulate a single in use connection on the first check of this
|
72
|
+
allow(adapter).to receive(:close).and_call_original
|
73
|
+
allow(subject).to receive(:wait_for_in_use_connections).and_call_original
|
74
|
+
allow(subject).to receive(:in_use_connections).and_return([subject.empty_url_meta()],[])
|
75
|
+
subject.close
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should close the adapter" do
|
79
|
+
expect(adapter).to have_received(:close)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should stop the resurrectionist" do
|
83
|
+
expect(subject.resurrectionist_alive?).to eql(false)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should stop the sniffer" do
|
87
|
+
# If no sniffer (the default) returns nil
|
88
|
+
expect(subject.sniffer_alive?).to be_falsey
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should wait for in use connections to terminate" do
|
92
|
+
expect(subject).to have_received(:wait_for_in_use_connections).once
|
93
|
+
expect(subject).to have_received(:in_use_connections).twice
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "connection management" do
|
98
|
+
context "with only one URL in the list" do
|
99
|
+
it "should use the only URL in 'with_connection'" do
|
100
|
+
subject.with_connection do |c|
|
101
|
+
expect(c).to eql(initial_urls.first)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "with multiple URLs in the list" do
|
107
|
+
let(:initial_urls) { [ URI.parse("http://localhost:9200"), URI.parse("http://localhost:9201"), URI.parse("http://localhost:9202") ] }
|
108
|
+
|
109
|
+
it "should minimize the number of connections to a single URL" do
|
110
|
+
connected_urls = []
|
111
|
+
|
112
|
+
# If we make 2x the number requests as we have URLs we should
|
113
|
+
# connect to each URL exactly 2 times
|
114
|
+
(initial_urls.size*2).times do
|
115
|
+
u, meta = subject.get_connection
|
116
|
+
connected_urls << u
|
117
|
+
end
|
118
|
+
|
119
|
+
connected_urls.each {|u| subject.return_connection(u) }
|
120
|
+
initial_urls.each do |url|
|
121
|
+
conn_count = connected_urls.select {|u| u == url}.size
|
122
|
+
expect(conn_count).to eql(2)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should correctly resurrect the dead" do
|
127
|
+
u,m = subject.get_connection
|
128
|
+
|
129
|
+
# The resurrectionist will call this to check on the backend
|
130
|
+
response = double("response")
|
131
|
+
expect(adapter).to receive(:perform_request).with(u, 'HEAD', subject.healthcheck_path, {}, nil).and_return(response)
|
132
|
+
|
133
|
+
subject.return_connection(u)
|
134
|
+
subject.mark_dead(u, Exception.new)
|
135
|
+
|
136
|
+
expect(subject.url_meta(u)[:dead]).to eql(true)
|
137
|
+
sleep subject.resurrect_delay + 1
|
138
|
+
expect(subject.url_meta(u)[:dead]).to eql(false)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -19,7 +19,7 @@ describe LogStash::Outputs::ElasticSearch::HttpClient do
|
|
19
19
|
|
20
20
|
shared_examples("proper host handling") do
|
21
21
|
it "should properly transform a host:port string to a URL" do
|
22
|
-
expect(subject.send(:host_to_url, hostname_port)).to eql(http_hostname_port)
|
22
|
+
expect(subject.send(:host_to_url, hostname_port).to_s).to eql(http_hostname_port)
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should raise an error when a partial URL is an invalid format" do
|
@@ -29,11 +29,11 @@ describe LogStash::Outputs::ElasticSearch::HttpClient do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should not raise an error with a / for a path" do
|
32
|
-
expect(subject.send(:host_to_url, "#{http_hostname_port}/")).to eql("#{http_hostname_port}/")
|
32
|
+
expect(subject.send(:host_to_url, "#{http_hostname_port}/").to_s).to eql("#{http_hostname_port}/")
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should parse full URLs correctly" do
|
36
|
-
expect(subject.send(:host_to_url, http_hostname_port)).to eql(http_hostname_port)
|
36
|
+
expect(subject.send(:host_to_url, http_hostname_port).to_s).to eql(http_hostname_port)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should reject full URLs with usernames and passwords" do
|
@@ -56,7 +56,7 @@ describe LogStash::Outputs::ElasticSearch::HttpClient do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should handle an ssl url correctly when SSL is nil" do
|
59
|
-
expect(subject.send(:host_to_url, https_hostname_port, nil)).to eql(https_hostname_port)
|
59
|
+
expect(subject.send(:host_to_url, https_hostname_port, nil).to_s).to eql(https_hostname_port)
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should raise an exception if an unexpected value is passed in" do
|
@@ -66,7 +66,7 @@ describe LogStash::Outputs::ElasticSearch::HttpClient do
|
|
66
66
|
|
67
67
|
describe "path" do
|
68
68
|
it "should allow paths in a url" do
|
69
|
-
expect(subject.send(:host_to_url, http_hostname_port_path, nil)).to eql(http_hostname_port_path)
|
69
|
+
expect(subject.send(:host_to_url, http_hostname_port_path, nil).to_s).to eql(http_hostname_port_path)
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should not allow paths in two places" do
|
@@ -76,7 +76,7 @@ describe LogStash::Outputs::ElasticSearch::HttpClient do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should automatically insert a / in front of path overlays if needed" do
|
79
|
-
expect(subject.send(:host_to_url, http_hostname_port, false, "otherpath")).to eql(http_hostname_port + "/otherpath")
|
79
|
+
expect(subject.send(:host_to_url, http_hostname_port, false, "otherpath")).to eql(URI.parse(http_hostname_port + "/otherpath"))
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
@@ -99,26 +99,12 @@ describe LogStash::Outputs::ElasticSearch::HttpClient do
|
|
99
99
|
|
100
100
|
describe "sniffing" do
|
101
101
|
let(:client) { LogStash::Outputs::ElasticSearch::HttpClient.new(base_options.merge(client_opts)) }
|
102
|
-
let(:transport) { client.client.transport }
|
103
|
-
|
104
|
-
before do
|
105
|
-
allow(transport).to receive(:reload_connections!)
|
106
|
-
end
|
107
102
|
|
108
103
|
context "with sniffing enabled" do
|
109
104
|
let(:client_opts) { {:sniffing => true, :sniffing_delay => 1 } }
|
110
105
|
|
111
|
-
after do
|
112
|
-
client.stop_sniffing!
|
113
|
-
end
|
114
|
-
|
115
106
|
it "should start the sniffer" do
|
116
|
-
expect(client.
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should periodically sniff the client" do
|
120
|
-
sleep 2
|
121
|
-
expect(transport).to have_received(:reload_connections!).at_least(:once)
|
107
|
+
expect(client.pool.sniffing).to be_truthy
|
122
108
|
end
|
123
109
|
end
|
124
110
|
|
@@ -126,7 +112,7 @@ describe LogStash::Outputs::ElasticSearch::HttpClient do
|
|
126
112
|
let(:client_opts) { {:sniffing => false} }
|
127
113
|
|
128
114
|
it "should not start the sniffer" do
|
129
|
-
expect(client.
|
115
|
+
expect(client.pool.sniffing).to be_falsey
|
130
116
|
end
|
131
117
|
end
|
132
118
|
end
|