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.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -3
  3. data/Gemfile +1 -1
  4. data/lib/logstash/outputs/elasticsearch/common.rb +90 -58
  5. data/lib/logstash/outputs/elasticsearch/common_configs.rb +12 -32
  6. data/lib/logstash/outputs/elasticsearch/http_client/manticore_adapter.rb +63 -0
  7. data/lib/logstash/outputs/elasticsearch/http_client/pool.rb +378 -0
  8. data/lib/logstash/outputs/elasticsearch/http_client.rb +70 -64
  9. data/lib/logstash/outputs/elasticsearch/http_client_builder.rb +15 -4
  10. data/lib/logstash/outputs/elasticsearch/template_manager.rb +1 -1
  11. data/lib/logstash/outputs/elasticsearch.rb +27 -4
  12. data/logstash-output-elasticsearch.gemspec +3 -5
  13. data/spec/es_spec_helper.rb +1 -0
  14. data/spec/fixtures/5x_node_resp.json +2 -0
  15. data/spec/integration/outputs/create_spec.rb +2 -5
  16. data/spec/integration/outputs/index_spec.rb +1 -1
  17. data/spec/integration/outputs/parent_spec.rb +1 -3
  18. data/spec/integration/outputs/pipeline_spec.rb +1 -2
  19. data/spec/integration/outputs/retry_spec.rb +51 -49
  20. data/spec/integration/outputs/routing_spec.rb +1 -1
  21. data/spec/integration/outputs/secure_spec.rb +4 -8
  22. data/spec/integration/outputs/templates_spec.rb +12 -8
  23. data/spec/integration/outputs/update_spec.rb +13 -27
  24. data/spec/unit/outputs/elasticsearch/http_client/manticore_adapter_spec.rb +25 -0
  25. data/spec/unit/outputs/elasticsearch/http_client/pool_spec.rb +142 -0
  26. data/spec/unit/outputs/elasticsearch/http_client_spec.rb +8 -22
  27. data/spec/unit/outputs/elasticsearch_proxy_spec.rb +5 -6
  28. data/spec/unit/outputs/elasticsearch_spec.rb +33 -30
  29. data/spec/unit/outputs/elasticsearch_ssl_spec.rb +10 -6
  30. metadata +72 -87
  31. data/lib/logstash/outputs/elasticsearch/buffer.rb +0 -124
  32. data/spec/unit/buffer_spec.rb +0 -118
@@ -1,6 +1,5 @@
1
1
  require_relative "../../../spec/es_spec_helper"
2
2
  require 'stud/temporary'
3
- require 'elasticsearch'
4
3
  require "logstash/outputs/elasticsearch"
5
4
 
6
5
  describe "Proxy option" do
@@ -15,7 +14,7 @@ describe "Proxy option" do
15
14
  }
16
15
 
17
16
  before do
18
- allow(::Elasticsearch::Client).to receive(:new).with(any_args)
17
+ allow(::Manticore::Client).to receive(:new).with(any_args)
19
18
  end
20
19
 
21
20
  describe "valid configs" do
@@ -27,8 +26,8 @@ describe "Proxy option" do
27
26
  let(:proxy) { "http://127.0.0.1:1234" }
28
27
 
29
28
  it "should set the proxy to the exact value" do
30
- expect(::Elasticsearch::Client).to have_received(:new) do |options|
31
- expect(options[:transport_options][:proxy]).to eql(proxy)
29
+ expect(::Manticore::Client).to have_received(:new) do |options|
30
+ expect(options[:proxy]).to eql(proxy)
32
31
  end
33
32
  end
34
33
  end
@@ -38,8 +37,8 @@ describe "Proxy option" do
38
37
 
39
38
  it "should pass through the proxy values as symbols" do
40
39
  expected = {:hosts => proxy["hosts"], :protocol => proxy["protocol"]}
41
- expect(::Elasticsearch::Client).to have_received(:new) do |options|
42
- expect(options[:transport_options][:proxy]).to eql(expected)
40
+ expect(::Manticore::Client).to have_received(:new) do |options|
41
+ expect(options[:proxy]).to eql(expected)
43
42
  end
44
43
  end
45
44
  end
@@ -14,9 +14,8 @@ describe "outputs/elasticsearch" do
14
14
 
15
15
  let(:eso) {LogStash::Outputs::ElasticSearch.new(options)}
16
16
 
17
- let(:manticore_host) {
18
- eso.client.send(:client).transport.options[:hosts].first
19
- }
17
+ let(:manticore_urls) { eso.client.pool.urls }
18
+ let(:manticore_url) { manticore_urls.first }
20
19
 
21
20
  let(:do_register) { true }
22
21
 
@@ -67,17 +66,15 @@ describe "outputs/elasticsearch" do
67
66
  end
68
67
 
69
68
  it "should properly set the path on the HTTP client adding slashes" do
70
- expect(manticore_host).to include("/" + options["path"] + "/")
69
+ expect(manticore_url.path).to eql("/" + options["path"] + "/")
71
70
  end
72
71
 
73
72
  context "with extra slashes" do
74
73
  let(:path) { "/slashed-path/ "}
75
- let(:eso) {
76
- LogStash::Outputs::ElasticSearch.new(options.merge("path" => "/some-path/"))
77
- }
74
+ let(:options) { super.merge("path" => "/some-path/") }
78
75
 
79
76
  it "should properly set the path on the HTTP client without adding slashes" do
80
- expect(manticore_host).to include(options["path"])
77
+ expect(manticore_url.path).to eql(options["path"])
81
78
  end
82
79
  end
83
80
 
@@ -88,7 +85,7 @@ describe "outputs/elasticsearch" do
88
85
  o["hosts"] = ["http://localhost:9200/mypath/"]
89
86
  o
90
87
  end
91
- let(:client_host_path) { URI.parse(eso.client.client_options[:hosts].first).path }
88
+ let(:client_host_path) { manticore_url.path }
92
89
 
93
90
  it "should initialize without error" do
94
91
  expect { eso }.not_to raise_error
@@ -133,15 +130,12 @@ describe "outputs/elasticsearch" do
133
130
  end
134
131
  describe "without a port specified" do
135
132
  it "should properly set the default port (9200) on the HTTP client" do
136
- expect(manticore_host).to include("9200")
133
+ expect(manticore_url.port).to eql(9200)
137
134
  end
138
135
  end
139
136
  describe "with a port other than 9200 specified" do
140
- let(:manticore_host) {
141
- eso.client.send(:client).transport.options[:hosts].last
142
- }
143
137
  it "should properly set the specified port on the HTTP client" do
144
- expect(manticore_host).to include("9202")
138
+ expect(manticore_urls.any? {|u| u.port == 9202}).to eql(true)
145
139
  end
146
140
  end
147
141
 
@@ -168,9 +162,6 @@ describe "outputs/elasticsearch" do
168
162
 
169
163
  end
170
164
 
171
- # TODO(sissel): Improve this. I'm not a fan of using message expectations (expect().to receive...)
172
- # especially with respect to logging to verify a failure/retry has occurred. For now, this
173
- # should suffice, though.
174
165
  context "with timeout set" do
175
166
  let(:listener) { Flores::Random.tcp_listener }
176
167
  let(:port) { listener[2] }
@@ -188,21 +179,15 @@ describe "outputs/elasticsearch" do
188
179
  eso.register
189
180
 
190
181
  # Expect a timeout to be logged.
191
- expect(eso.logger).to receive(:error).with(/Attempted to send a bulk request/, anything)
192
- end
193
-
194
- after do
195
- listener[0].close
196
- # Stop the receive buffer, but don't flush because that would hang forever in this case since ES never returns a result
197
- eso.instance_variable_get(:@buffer).stop(false,false)
198
- eso.close
182
+ expect(eso.logger).to receive(:error).with(/Attempted to send a bulk request to Elasticsearch/i, anything).at_least(:once)
183
+ expect(eso.client).to receive(:bulk).at_least(:twice).and_call_original
199
184
  end
200
185
 
201
186
  it "should fail after the timeout" do
202
- Thread.new { eso.receive(LogStash::Event.new) }
187
+ Thread.new { eso.multi_receive([LogStash::Event.new]) }
203
188
 
204
- # Allow the timeout to occur.
205
- sleep(options["timeout"] + 0.5)
189
+ # Allow the timeout to occur
190
+ sleep 6
206
191
  end
207
192
  end
208
193
 
@@ -230,12 +215,12 @@ describe "outputs/elasticsearch" do
230
215
  describe "SSL end to end" do
231
216
  shared_examples("an encrypted client connection") do
232
217
  it "should enable SSL in manticore" do
233
- expect(eso.client.client_options[:hosts].map {|h| URI.parse(h).scheme}.uniq).to eql(['https'])
218
+ expect(eso.client.pool.urls.map(&:scheme).uniq).to eql(['https'])
234
219
  end
235
220
  end
236
221
 
237
222
  let(:eso) {LogStash::Outputs::ElasticSearch.new(options)}
238
- subject(:manticore) { eso.client.client}
223
+ subject(:manticore) { eso.client.pool.adapter.client}
239
224
 
240
225
  before do
241
226
  eso.register
@@ -276,4 +261,22 @@ describe "outputs/elasticsearch" do
276
261
  end
277
262
  end
278
263
  end
264
+
265
+ describe "sleep interval calculation" do
266
+ let(:retry_max_interval) { 64 }
267
+ subject(:eso) { LogStash::Outputs::ElasticSearch.new("retry_max_interval" => retry_max_interval) }
268
+
269
+ it "should double the given value" do
270
+ expect(eso.next_sleep_interval(2)).to eql(4)
271
+ expect(eso.next_sleep_interval(32)).to eql(64)
272
+ end
273
+
274
+ it "should not increase the value past the max retry interval" do
275
+ sleep_interval = 2
276
+ 100.times do
277
+ sleep_interval = eso.next_sleep_interval(sleep_interval)
278
+ expect(sleep_interval).to be <= retry_max_interval
279
+ end
280
+ end
281
+ end
279
282
  end
@@ -6,22 +6,26 @@ describe "SSL option" do
6
6
  subject do
7
7
  require "logstash/outputs/elasticsearch"
8
8
  settings = {
9
- "hosts" => "node01",
9
+ "hosts" => "localhost",
10
10
  "ssl" => true,
11
- "ssl_certificate_verification" => false
11
+ "ssl_certificate_verification" => false,
12
+ "pool_max" => 1,
13
+ "pool_max_per_route" => 1
12
14
  }
13
15
  next LogStash::Outputs::ElasticSearch.new(settings)
14
16
  end
15
17
 
16
18
  it "should pass the flag to the ES client" do
17
- expect(::Elasticsearch::Client).to receive(:new) do |args|
19
+ expect(::Manticore::Client).to receive(:new) do |args|
18
20
  expect(args[:ssl]).to eq(:enabled => true, :verify => false)
19
21
  end
20
22
  subject.register
21
23
  end
22
24
 
23
- it "print a warning" do
24
- expect(subject.logger).to receive(:warn)
25
+ it "should print a warning" do
26
+ disabled_matcher = /You have enabled encryption but DISABLED certificate verification/
27
+ expect(subject.logger).to receive(:warn).with(disabled_matcher).at_least(:once)
28
+ allow(subject.logger).to receive(:warn).with(any_args)
25
29
  subject.register
26
30
  end
27
31
  end
@@ -45,7 +49,7 @@ describe "SSL option" do
45
49
  end
46
50
 
47
51
  it "should pass the keystore parameters to the ES client" do
48
- expect(::Elasticsearch::Client).to receive(:new) do |args|
52
+ expect(::Manticore::Client).to receive(:new) do |args|
49
53
  expect(args[:ssl]).to include(:keystore => keystore_path, :keystore_password => "test")
50
54
  end
51
55
  subject.register
metadata CHANGED
@@ -1,187 +1,167 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 4.1.0
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-10 00:00:00.000000000 Z
11
+ date: 2016-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: concurrent-ruby
15
- version_requirements: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
14
  requirement: !ruby/object:Gem::Requirement
21
15
  requirements:
22
- - - '>='
16
+ - - ">="
23
17
  - !ruby/object:Gem::Version
24
- version: '0'
25
- prerelease: false
26
- type: :runtime
27
- - !ruby/object:Gem::Dependency
28
- name: elasticsearch
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '>='
32
- - !ruby/object:Gem::Version
33
- version: 1.0.13
34
- - - ~>
35
- - !ruby/object:Gem::Version
36
- version: '1.0'
37
- requirement: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - '>='
40
- - !ruby/object:Gem::Version
41
- version: 1.0.13
42
- - - ~>
18
+ version: 0.0.17
19
+ - - "~>"
43
20
  - !ruby/object:Gem::Version
44
- version: '1.0'
21
+ version: '0.0'
22
+ name: stud
45
23
  prerelease: false
46
24
  type: :runtime
47
- - !ruby/object:Gem::Dependency
48
- name: stud
49
25
  version_requirements: !ruby/object:Gem::Requirement
50
26
  requirements:
51
- - - '>='
27
+ - - ">="
52
28
  - !ruby/object:Gem::Version
53
29
  version: 0.0.17
54
- - - ~>
30
+ - - "~>"
55
31
  - !ruby/object:Gem::Version
56
32
  version: '0.0'
33
+ - !ruby/object:Gem::Dependency
57
34
  requirement: !ruby/object:Gem::Requirement
58
35
  requirements:
59
- - - '>='
60
- - !ruby/object:Gem::Version
61
- version: 0.0.17
62
- - - ~>
36
+ - - "~>"
63
37
  - !ruby/object:Gem::Version
64
- version: '0.0'
38
+ version: '0.6'
39
+ name: cabin
65
40
  prerelease: false
66
41
  type: :runtime
67
- - !ruby/object:Gem::Dependency
68
- name: cabin
69
42
  version_requirements: !ruby/object:Gem::Requirement
70
43
  requirements:
71
- - - ~>
44
+ - - "~>"
72
45
  - !ruby/object:Gem::Version
73
46
  version: '0.6'
47
+ - !ruby/object:Gem::Dependency
74
48
  requirement: !ruby/object:Gem::Requirement
75
49
  requirements:
76
- - - ~>
50
+ - - "~>"
77
51
  - !ruby/object:Gem::Version
78
- version: '0.6'
52
+ version: '2.0'
53
+ name: logstash-core-plugin-api
79
54
  prerelease: false
80
55
  type: :runtime
81
- - !ruby/object:Gem::Dependency
82
- name: logstash-core-plugin-api
83
56
  version_requirements: !ruby/object:Gem::Requirement
84
57
  requirements:
85
- - - ~>
58
+ - - "~>"
86
59
  - !ruby/object:Gem::Version
87
60
  version: '2.0'
61
+ - !ruby/object:Gem::Dependency
88
62
  requirement: !ruby/object:Gem::Requirement
89
63
  requirements:
90
- - - ~>
64
+ - - "~>"
91
65
  - !ruby/object:Gem::Version
92
- version: '2.0'
93
- prerelease: false
94
- type: :runtime
95
- - !ruby/object:Gem::Dependency
66
+ version: 0.0.42
96
67
  name: ftw
68
+ prerelease: false
69
+ type: :development
97
70
  version_requirements: !ruby/object:Gem::Requirement
98
71
  requirements:
99
- - - ~>
72
+ - - "~>"
100
73
  - !ruby/object:Gem::Version
101
74
  version: 0.0.42
75
+ - !ruby/object:Gem::Dependency
102
76
  requirement: !ruby/object:Gem::Requirement
103
77
  requirements:
104
- - - ~>
78
+ - - ">="
105
79
  - !ruby/object:Gem::Version
106
- version: 0.0.42
80
+ version: '0'
81
+ name: logstash-codec-plain
107
82
  prerelease: false
108
83
  type: :development
109
- - !ruby/object:Gem::Dependency
110
- name: logstash-codec-plain
111
84
  version_requirements: !ruby/object:Gem::Requirement
112
85
  requirements:
113
- - - '>='
86
+ - - ">="
114
87
  - !ruby/object:Gem::Version
115
88
  version: '0'
89
+ - !ruby/object:Gem::Dependency
116
90
  requirement: !ruby/object:Gem::Requirement
117
91
  requirements:
118
- - - '>='
92
+ - - ">="
119
93
  - !ruby/object:Gem::Version
120
- version: '0'
121
- prerelease: false
122
- type: :development
123
- - !ruby/object:Gem::Dependency
94
+ version: 0.5.4
95
+ - - "<"
96
+ - !ruby/object:Gem::Version
97
+ version: 1.0.0
124
98
  name: manticore
99
+ prerelease: false
100
+ type: :runtime
125
101
  version_requirements: !ruby/object:Gem::Requirement
126
102
  requirements:
127
- - - '>='
103
+ - - ">="
128
104
  - !ruby/object:Gem::Version
129
105
  version: 0.5.4
130
- - - <
106
+ - - "<"
131
107
  - !ruby/object:Gem::Version
132
108
  version: 1.0.0
109
+ - !ruby/object:Gem::Dependency
133
110
  requirement: !ruby/object:Gem::Requirement
134
111
  requirements:
135
- - - '>='
112
+ - - ">="
136
113
  - !ruby/object:Gem::Version
137
- version: 0.5.4
138
- - - <
139
- - !ruby/object:Gem::Version
140
- version: 1.0.0
141
- prerelease: false
142
- type: :runtime
143
- - !ruby/object:Gem::Dependency
114
+ version: '0'
144
115
  name: logstash-devutils
116
+ prerelease: false
117
+ type: :development
145
118
  version_requirements: !ruby/object:Gem::Requirement
146
119
  requirements:
147
- - - '>='
120
+ - - ">="
148
121
  - !ruby/object:Gem::Version
149
122
  version: '0'
123
+ - !ruby/object:Gem::Dependency
150
124
  requirement: !ruby/object:Gem::Requirement
151
125
  requirements:
152
- - - '>='
126
+ - - ">="
153
127
  - !ruby/object:Gem::Version
154
128
  version: '0'
129
+ name: longshoreman
155
130
  prerelease: false
156
131
  type: :development
157
- - !ruby/object:Gem::Dependency
158
- name: longshoreman
159
132
  version_requirements: !ruby/object:Gem::Requirement
160
133
  requirements:
161
- - - '>='
134
+ - - ">="
162
135
  - !ruby/object:Gem::Version
163
136
  version: '0'
137
+ - !ruby/object:Gem::Dependency
164
138
  requirement: !ruby/object:Gem::Requirement
165
139
  requirements:
166
- - - '>='
140
+ - - ">="
167
141
  - !ruby/object:Gem::Version
168
142
  version: '0'
143
+ name: flores
169
144
  prerelease: false
170
145
  type: :development
171
- - !ruby/object:Gem::Dependency
172
- name: flores
173
146
  version_requirements: !ruby/object:Gem::Requirement
174
147
  requirements:
175
- - - '>='
148
+ - - ">="
176
149
  - !ruby/object:Gem::Version
177
150
  version: '0'
151
+ - !ruby/object:Gem::Dependency
178
152
  requirement: !ruby/object:Gem::Requirement
179
153
  requirements:
180
- - - '>='
154
+ - - ">="
181
155
  - !ruby/object:Gem::Version
182
156
  version: '0'
157
+ name: elasticsearch
183
158
  prerelease: false
184
159
  type: :development
160
+ version_requirements: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
185
165
  description: This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program
186
166
  email: info@elastic.co
187
167
  executables: []
@@ -195,15 +175,17 @@ files:
195
175
  - NOTICE.TXT
196
176
  - README.md
197
177
  - lib/logstash/outputs/elasticsearch.rb
198
- - lib/logstash/outputs/elasticsearch/buffer.rb
199
178
  - lib/logstash/outputs/elasticsearch/common.rb
200
179
  - lib/logstash/outputs/elasticsearch/common_configs.rb
201
180
  - lib/logstash/outputs/elasticsearch/elasticsearch-template.json
202
181
  - lib/logstash/outputs/elasticsearch/http_client.rb
182
+ - lib/logstash/outputs/elasticsearch/http_client/manticore_adapter.rb
183
+ - lib/logstash/outputs/elasticsearch/http_client/pool.rb
203
184
  - lib/logstash/outputs/elasticsearch/http_client_builder.rb
204
185
  - lib/logstash/outputs/elasticsearch/template_manager.rb
205
186
  - logstash-output-elasticsearch.gemspec
206
187
  - spec/es_spec_helper.rb
188
+ - spec/fixtures/5x_node_resp.json
207
189
  - spec/fixtures/scripts/scripted_update.groovy
208
190
  - spec/fixtures/scripts/scripted_update_nested.groovy
209
191
  - spec/fixtures/scripts/scripted_upsert.groovy
@@ -216,8 +198,9 @@ files:
216
198
  - spec/integration/outputs/secure_spec.rb
217
199
  - spec/integration/outputs/templates_spec.rb
218
200
  - spec/integration/outputs/update_spec.rb
219
- - spec/unit/buffer_spec.rb
220
201
  - spec/unit/http_client_builder_spec.rb
202
+ - spec/unit/outputs/elasticsearch/http_client/manticore_adapter_spec.rb
203
+ - spec/unit/outputs/elasticsearch/http_client/pool_spec.rb
221
204
  - spec/unit/outputs/elasticsearch/http_client_spec.rb
222
205
  - spec/unit/outputs/elasticsearch_proxy_spec.rb
223
206
  - spec/unit/outputs/elasticsearch_spec.rb
@@ -234,12 +217,12 @@ require_paths:
234
217
  - lib
235
218
  required_ruby_version: !ruby/object:Gem::Requirement
236
219
  requirements:
237
- - - '>='
220
+ - - ">="
238
221
  - !ruby/object:Gem::Version
239
222
  version: '0'
240
223
  required_rubygems_version: !ruby/object:Gem::Requirement
241
224
  requirements:
242
- - - '>='
225
+ - - ">="
243
226
  - !ruby/object:Gem::Version
244
227
  version: '0'
245
228
  requirements: []
@@ -250,6 +233,7 @@ specification_version: 4
250
233
  summary: Logstash Output to Elasticsearch
251
234
  test_files:
252
235
  - spec/es_spec_helper.rb
236
+ - spec/fixtures/5x_node_resp.json
253
237
  - spec/fixtures/scripts/scripted_update.groovy
254
238
  - spec/fixtures/scripts/scripted_update_nested.groovy
255
239
  - spec/fixtures/scripts/scripted_upsert.groovy
@@ -262,8 +246,9 @@ test_files:
262
246
  - spec/integration/outputs/secure_spec.rb
263
247
  - spec/integration/outputs/templates_spec.rb
264
248
  - spec/integration/outputs/update_spec.rb
265
- - spec/unit/buffer_spec.rb
266
249
  - spec/unit/http_client_builder_spec.rb
250
+ - spec/unit/outputs/elasticsearch/http_client/manticore_adapter_spec.rb
251
+ - spec/unit/outputs/elasticsearch/http_client/pool_spec.rb
267
252
  - spec/unit/outputs/elasticsearch/http_client_spec.rb
268
253
  - spec/unit/outputs/elasticsearch_proxy_spec.rb
269
254
  - spec/unit/outputs/elasticsearch_spec.rb