logstash-output-elasticsearch 11.0.2-java → 11.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/docs/index.asciidoc +11 -11
  4. data/lib/logstash/outputs/elasticsearch/http_client/pool.rb +2 -28
  5. data/lib/logstash/outputs/elasticsearch/http_client.rb +19 -0
  6. data/lib/logstash/outputs/elasticsearch/ilm.rb +2 -33
  7. data/lib/logstash/outputs/elasticsearch/template_manager.rb +1 -1
  8. data/lib/logstash/outputs/elasticsearch.rb +3 -14
  9. data/lib/logstash/plugin_mixins/elasticsearch/common.rb +5 -1
  10. data/logstash-output-elasticsearch.gemspec +3 -2
  11. data/spec/es_spec_helper.rb +14 -7
  12. data/spec/fixtures/_nodes/{5x_6x.json → 6x.json} +5 -5
  13. data/spec/integration/outputs/compressed_indexing_spec.rb +47 -46
  14. data/spec/integration/outputs/delete_spec.rb +49 -51
  15. data/spec/integration/outputs/ilm_spec.rb +230 -246
  16. data/spec/integration/outputs/index_spec.rb +5 -2
  17. data/spec/integration/outputs/index_version_spec.rb +78 -82
  18. data/spec/integration/outputs/ingest_pipeline_spec.rb +58 -60
  19. data/spec/integration/outputs/no_es_on_startup_spec.rb +14 -0
  20. data/spec/integration/outputs/painless_update_spec.rb +74 -164
  21. data/spec/integration/outputs/parent_spec.rb +67 -75
  22. data/spec/integration/outputs/retry_spec.rb +2 -2
  23. data/spec/integration/outputs/sniffer_spec.rb +15 -53
  24. data/spec/integration/outputs/templates_spec.rb +79 -81
  25. data/spec/integration/outputs/update_spec.rb +99 -101
  26. data/spec/spec_helper.rb +1 -5
  27. data/spec/unit/outputs/elasticsearch/data_stream_support_spec.rb +0 -14
  28. data/spec/unit/outputs/elasticsearch/http_client/pool_spec.rb +30 -37
  29. data/spec/unit/outputs/elasticsearch/http_client_spec.rb +69 -0
  30. data/spec/unit/outputs/elasticsearch/template_manager_spec.rb +9 -9
  31. data/spec/unit/outputs/elasticsearch_spec.rb +2 -8
  32. data/spec/unit/outputs/error_whitelist_spec.rb +1 -0
  33. metadata +21 -24
  34. data/lib/logstash/outputs/elasticsearch/templates/ecs-disabled/elasticsearch-2x.json +0 -95
  35. data/lib/logstash/outputs/elasticsearch/templates/ecs-disabled/elasticsearch-5x.json +0 -46
  36. data/lib/logstash/outputs/elasticsearch/templates/ecs-v1/elasticsearch-6x.json +0 -2950
  37. data/lib/logstash/outputs/elasticsearch/templates/ecs-v1/elasticsearch-7x.json +0 -2948
  38. data/spec/fixtures/_nodes/2x_1x.json +0 -27
  39. data/spec/fixtures/scripts/groovy/scripted_update.groovy +0 -2
  40. data/spec/fixtures/scripts/groovy/scripted_update_nested.groovy +0 -2
  41. data/spec/fixtures/scripts/groovy/scripted_upsert.groovy +0 -2
  42. data/spec/integration/outputs/groovy_update_spec.rb +0 -150
  43. data/spec/integration/outputs/templates_5x_spec.rb +0 -98
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4d12d1aba765125efba841af202081a30171914e9b5dc6aca66772c546c3bd6
4
- data.tar.gz: bbfe6f58cd3824fc67fd0c80a564f759a32863e0590a2749e772e1c05a9144aa
3
+ metadata.gz: a8d5dde6f4643a1482c56af7db786848d73759cac4728203ade488a8eec3ca76
4
+ data.tar.gz: 8c8e8b7b05589c7d86d92d3fc50c2d267c5650456c84806326c5bef488bfb819
5
5
  SHA512:
6
- metadata.gz: 9ce4b4ddb86e640a3fa56325557db23b0fa19a4ae3692997c4c45ac97562507fd86c3b3369df761339ee22ff62390f70a83d9caeb4b31310fef8b79a42cd0f49
7
- data.tar.gz: 9886cf6b18e0ed17aaa848376d979a31b4a3f90a55da17a2ffad997569d7847a08a137d3d62b62151a0012943715ded7572d718e41ce7d5227dbd025d117d44a
6
+ metadata.gz: aad121ec87c87db04fc35ce0bf28069eee3960b0bdca76c8297d5b1242e9e83a68b118b5f97e41ec34660073ba1f61f839e786ee2db306a56f5b2ad6c0e5dc06
7
+ data.tar.gz: 5201e002ae94e3acc00e44e79da5cd721fc80d39781e876c0d009d7c53f5ab90978a6126a691c5c07b159a30bc3e2bc38ef58801d0443094bcd3b810acbd7e98
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## 11.1.0
2
+ - Feat: add `user-agent` header passed to the Elasticsearch HTTP connection [#1038](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1038)
3
+
4
+ ## 11.0.5
5
+ - Fixed running post-register action when Elasticsearch status change from unhealthy to healthy [#1035](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1035)
6
+
7
+ ## 11.0.4
8
+ - [DOC] Clarify that `http_compression` applies to _requests_, and remove noise about _response_ decompression [#1000](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1000)
9
+
10
+ ## 11.0.3
11
+ - Fixed SSL handshake hang indefinitely with proxy setup [#1032](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1032)
12
+
1
13
  ## 11.0.2
2
14
  - Validate that required functionality in Elasticsearch is available upon initial connection [#1015](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1015)
3
15
 
data/docs/index.asciidoc CHANGED
@@ -278,16 +278,11 @@ not reevaluate its DNS value while the keepalive is in effect.
278
278
 
279
279
  ==== HTTP Compression
280
280
 
281
- This plugin supports request and response compression. Response compression is
282
- enabled by default for HTTP and for Elasticsearch versions 5.0 and later.
281
+ This plugin supports request compression, and handles compressed responses
282
+ from Elasticsearch.
283
283
 
284
- You don't have to set any configs in Elasticsearch for it to send back a
285
- compressed response. For versions before 5.0, or if HTTPS is enabled,
286
- `http.compression` must be set to `true` {ref}/modules-http.html#modules-http[in
287
- Elasticsearch] to take advantage of response compression when using this plugin.
288
-
289
- For requests compression, regardless of the Elasticsearch version, enable the
290
- `http_compression` setting in the Logstash config file.
284
+ To enable request compression, use the <<plugins-{type}s-{plugin}-http_compression>>
285
+ setting on this plugin.
291
286
 
292
287
  ==== Authentication
293
288
 
@@ -640,8 +635,13 @@ Any special characters present in the URLs here MUST be URL escaped! This means
640
635
  * Value type is <<boolean,boolean>>
641
636
  * Default value is `false`
642
637
 
643
- Enable gzip compression on requests. Note that response compression is on by
644
- default for Elasticsearch v5.0 and beyond
638
+ Enable gzip compression on requests.
639
+
640
+ This setting allows you to reduce this plugin's outbound network traffic by
641
+ compressing each bulk _request_ to {es}.
642
+
643
+ NOTE: This output plugin reads compressed _responses_ from {es} regardless
644
+ of the value of this setting.
645
645
 
646
646
  [id="plugins-{type}s-{plugin}-ilm_enabled"]
647
647
  ===== `ilm_enabled`
@@ -176,15 +176,7 @@ module LogStash; module Outputs; class ElasticSearch; class HttpClient;
176
176
  @logger.warn("Sniff returned no nodes! Will not update hosts.")
177
177
  return nil
178
178
  else
179
- case major_version(url_meta[:version])
180
- when 5, 6, 7, 8
181
- sniff_5x_and_above(nodes)
182
- when 2, 1
183
- sniff_2x_1x(nodes)
184
- else
185
- @logger.warn("Could not determine version for nodes in ES cluster!")
186
- return nil
187
- end
179
+ sniff(nodes)
188
180
  end
189
181
  end
190
182
 
@@ -192,7 +184,7 @@ module LogStash; module Outputs; class ElasticSearch; class HttpClient;
192
184
  version_string.split('.').first.to_i
193
185
  end
194
186
 
195
- def sniff_5x_and_above(nodes)
187
+ def sniff(nodes)
196
188
  nodes.map do |id,info|
197
189
  # Skip master-only nodes
198
190
  next if info["roles"] && info["roles"] == ["master"]
@@ -208,24 +200,6 @@ module LogStash; module Outputs; class ElasticSearch; class HttpClient;
208
200
  end
209
201
  end
210
202
 
211
- def sniff_2x_1x(nodes)
212
- nodes.map do |id,info|
213
- # TODO Make sure this works with shield. Does that listed
214
- # stuff as 'https_address?'
215
-
216
- addr_str = info['http_address'].to_s
217
- next unless addr_str # Skip hosts with HTTP disabled
218
-
219
- # Only connect to nodes that serve data
220
- # this will skip connecting to client, tribe, and master only nodes
221
- # Note that if 'attributes' is NOT set, then that's just a regular node
222
- # with master + data + client enabled, so we allow that
223
- attributes = info['attributes']
224
- next if attributes && attributes['data'] == 'false'
225
- address_str_to_uri(addr_str)
226
- end.compact
227
- end
228
-
229
203
  def stop_sniffer
230
204
  @sniffer.join if @sniffer
231
205
  end
@@ -4,6 +4,7 @@ require 'logstash/outputs/elasticsearch/http_client/manticore_adapter'
4
4
  require 'cgi'
5
5
  require 'zlib'
6
6
  require 'stringio'
7
+ require 'java'
7
8
 
8
9
  module LogStash; module Outputs; class ElasticSearch;
9
10
  # This is a constant instead of a config option because
@@ -92,6 +93,10 @@ module LogStash; module Outputs; class ElasticSearch;
92
93
  @pool.maximum_seen_major_version
93
94
  end
94
95
 
96
+ def alive_urls_count
97
+ @pool.alive_urls_count
98
+ end
99
+
95
100
  def bulk(actions)
96
101
  @action_count ||= 0
97
102
  @action_count += actions.size
@@ -297,6 +302,8 @@ module LogStash; module Outputs; class ElasticSearch;
297
302
  :request_timeout => timeout,
298
303
  }
299
304
 
305
+ adapter_options[:user_agent] = prepare_user_agent
306
+
300
307
  adapter_options[:proxy] = client_settings[:proxy] if client_settings[:proxy]
301
308
 
302
309
  adapter_options[:check_connection_timeout] = client_settings[:check_connection_timeout] if client_settings[:check_connection_timeout]
@@ -318,6 +325,18 @@ module LogStash; module Outputs; class ElasticSearch;
318
325
  adapter_class = ::LogStash::Outputs::ElasticSearch::HttpClient::ManticoreAdapter
319
326
  adapter = adapter_class.new(@logger, adapter_options)
320
327
  end
328
+
329
+ def prepare_user_agent
330
+ os_name = java.lang.System.getProperty('os.name')
331
+ os_version = java.lang.System.getProperty('os.version')
332
+ os_arch = java.lang.System.getProperty('os.arch')
333
+ jvm_vendor = java.lang.System.getProperty('java.vendor')
334
+ jvm_version = java.lang.System.getProperty('java.version')
335
+
336
+ plugin_version = Gem.loaded_specs['logstash-output-elasticsearch'].version
337
+ # example: Logstash/7.14.1 (OS=Linux-5.4.0-84-generic-amd64; JVM=AdoptOpenJDK-11.0.11) logstash-output-elasticsearch/11.0.1
338
+ "Logstash/#{LOGSTASH_VERSION} (OS=#{os_name}-#{os_version}-#{os_arch}; JVM=#{jvm_vendor}-#{jvm_version}) logstash-output-elasticsearch/#{plugin_version}"
339
+ end
321
340
 
322
341
  def build_pool(options)
323
342
  adapter = build_adapter(options)
@@ -16,20 +16,12 @@ module LogStash; module Outputs; class ElasticSearch
16
16
  begin
17
17
  if @ilm_enabled == 'auto'
18
18
  if ilm_on_by_default?
19
- ilm_ready, error = ilm_ready?
20
- if !ilm_ready
21
- @logger.info("Index Lifecycle Management is set to 'auto', but will be disabled - #{error}")
22
- false
23
- else
24
- ilm_alias_set?
25
- end
19
+ ilm_alias_set?
26
20
  else
27
21
  @logger.info("Index Lifecycle Management is set to 'auto', but will be disabled - Your Elasticsearch cluster is before 7.0.0, which is the minimum version required to automatically run Index Lifecycle Management")
28
22
  false
29
23
  end
30
24
  elsif @ilm_enabled.to_s == 'true'
31
- ilm_ready, error = ilm_ready?
32
- raise LogStash::ConfigurationError,"Index Lifecycle Management is set to enabled in Logstash, but cannot be used - #{error}" unless ilm_ready
33
25
  ilm_alias_set?
34
26
  else
35
27
  false
@@ -47,29 +39,6 @@ module LogStash; module Outputs; class ElasticSearch
47
39
  maximum_seen_major_version >= 7
48
40
  end
49
41
 
50
- def ilm_ready?
51
- # Check the Elasticsearch instance for ILM readiness - this means that the version has to be a non-OSS release, with ILM feature
52
- # available and enabled.
53
- begin
54
- xpack = client.get_xpack_info
55
- features = xpack.nil? || xpack.empty? ? nil : xpack["features"]
56
- ilm = features.nil? ? nil : features["ilm"]
57
- return false, "Index Lifecycle management is not installed on your Elasticsearch cluster" if features.nil? || ilm.nil?
58
- return false, "Index Lifecycle management is not available in your Elasticsearch cluster" unless ilm['available']
59
- return false, "Index Lifecycle management is not enabled in your Elasticsearch cluster" unless ilm['enabled']
60
- return true, nil
61
- rescue ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError => e
62
- # Check xpack endpoint: If no xpack endpoint, then this version of Elasticsearch is not compatible
63
- if e.response_code == 404
64
- return false, "Index Lifecycle management is not installed on your Elasticsearch cluster"
65
- elsif e.response_code == 400
66
- return false, "Index Lifecycle management is not installed on your Elasticsearch cluster"
67
- else
68
- raise e
69
- end
70
- end
71
- end
72
-
73
42
  def default_index?(index)
74
43
  index == @default_index
75
44
  end
@@ -113,4 +82,4 @@ module LogStash; module Outputs; class ElasticSearch
113
82
  LogStash::Json.load(::IO.read(policy_path))
114
83
  end
115
84
  end
116
- end; end; end
85
+ end; end; end
@@ -53,7 +53,7 @@ module LogStash; module Outputs; class ElasticSearch
53
53
  end
54
54
 
55
55
  def self.default_template_path(es_major_version, ecs_compatibility=:disabled)
56
- template_version = es_major_version == 1 ? 2 : es_major_version
56
+ template_version = es_major_version
57
57
  default_template_name = "templates/ecs-#{ecs_compatibility}/elasticsearch-#{template_version}x.json"
58
58
  ::File.expand_path(default_template_name, ::File.dirname(__FILE__))
59
59
  end
@@ -443,7 +443,7 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base
443
443
  end
444
444
 
445
445
  def routing_field_name
446
- maximum_seen_major_version >= 6 ? :routing : :_routing
446
+ :routing
447
447
  end
448
448
 
449
449
  # Determine the correct value for the 'type' field for the given event
@@ -456,9 +456,7 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base
456
456
  event.sprintf(@document_type)
457
457
  else
458
458
  major_version = maximum_seen_major_version
459
- if major_version < 6
460
- es5_event_type(event)
461
- elsif major_version == 6
459
+ if major_version == 6
462
460
  DEFAULT_EVENT_TYPE_ES6
463
461
  elsif major_version == 7
464
462
  DEFAULT_EVENT_TYPE_ES7
@@ -470,15 +468,6 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base
470
468
  type.to_s
471
469
  end
472
470
 
473
- def es5_event_type(event)
474
- type = event.get('type')
475
- return DEFAULT_EVENT_TYPE_ES6 unless type
476
- if !type.is_a?(String) && !type.is_a?(Numeric)
477
- @logger.warn("Bad event type (non-string/integer type value set)", :type_class => type.class, :type_value => type, :event => event.to_hash)
478
- end
479
- type
480
- end
481
-
482
471
  ##
483
472
  # WARNING: This method is overridden in a subclass in Logstash Core 7.7-7.8's monitoring,
484
473
  # where a `client` argument is both required and ignored. In later versions of
@@ -487,7 +476,7 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base
487
476
  # @param noop_required_client [nil]: required `nil` for legacy reasons.
488
477
  # @return [Boolean]
489
478
  def use_event_type?(noop_required_client)
490
- # always set type for ES <= 6
479
+ # always set type for ES 6
491
480
  # for ES 7 only set it if the user defined it
492
481
  (maximum_seen_major_version < 7) || (maximum_seen_major_version == 7 && @document_type)
493
482
  end
@@ -128,8 +128,12 @@ module LogStash; module PluginMixins; module ElasticSearch
128
128
  client.maximum_seen_major_version
129
129
  end
130
130
 
131
+ def alive_urls_count
132
+ client.alive_urls_count
133
+ end
134
+
131
135
  def successful_connection?
132
- !!maximum_seen_major_version
136
+ !!maximum_seen_major_version && alive_urls_count > 0
133
137
  end
134
138
 
135
139
  # launch a thread that waits for an initial successful connection to the ES cluster to call the given block
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-elasticsearch'
3
- s.version = '11.0.2'
3
+ s.version = '11.1.0'
4
4
 
5
5
  s.licenses = ['apache-2.0']
6
6
  s.summary = "Stores logs in Elasticsearch"
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  # Special flag to let us know this is actually a logstash plugin
22
22
  s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }
23
23
 
24
- s.add_runtime_dependency "manticore", '>= 0.5.4', '< 1.0.0'
24
+ s.add_runtime_dependency "manticore", '>= 0.7.1', '< 1.0.0'
25
25
  s.add_runtime_dependency 'stud', ['>= 0.0.17', '~> 0.0']
26
26
  s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
27
27
  s.add_runtime_dependency 'logstash-mixin-ecs_compatibility_support', '~>1.0'
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
30
30
  s.add_development_dependency 'logstash-devutils'
31
31
  s.add_development_dependency 'flores'
32
32
  s.add_development_dependency 'cabin', ['~> 0.6']
33
+ s.add_development_dependency 'webrick'
33
34
  # Still used in some specs, we should remove this ASAP
34
35
  s.add_development_dependency 'elasticsearch'
35
36
  end
@@ -20,7 +20,9 @@ module ESHelper
20
20
  end
21
21
 
22
22
  def get_client
23
- Elasticsearch::Client.new(:hosts => [get_host_port])
23
+ Elasticsearch::Client.new(:hosts => [get_host_port]).tap do |client|
24
+ allow(client).to receive(:verify_elasticsearch).and_return(true) # bypass client side version checking
25
+ end
24
26
  end
25
27
 
26
28
  def doc_type
@@ -53,11 +55,7 @@ module ESHelper
53
55
  end
54
56
 
55
57
  def routing_field_name
56
- if ESHelper.es_version_satisfies?(">=6")
57
- :routing
58
- else
59
- :_routing
60
- end
58
+ :routing
61
59
  end
62
60
 
63
61
  def self.es_version
@@ -82,7 +80,7 @@ module ESHelper
82
80
  end
83
81
 
84
82
  def self.es_version_satisfies?(*requirement)
85
- es_version = RSpec.configuration.filter[:es_version] || ENV['ES_VERSION'] || ENV['ELASTIC_STACK_VERSION']
83
+ es_version = nilify(RSpec.configuration.filter[:es_version]) || nilify(ENV['ES_VERSION']) || nilify(ENV['ELASTIC_STACK_VERSION'])
86
84
  if es_version.nil?
87
85
  puts "Info: ES_VERSION, ELASTIC_STACK_VERSION or 'es_version' tag wasn't set. Returning false to all `es_version_satisfies?` call."
88
86
  return false
@@ -91,6 +89,15 @@ module ESHelper
91
89
  Gem::Requirement.new(requirement).satisfied_by?(es_release_version)
92
90
  end
93
91
 
92
+ private
93
+ def self.nilify(str)
94
+ if str.nil?
95
+ return str
96
+ end
97
+ str.empty? ? nil : str
98
+ end
99
+
100
+ public
94
101
  def clean(client)
95
102
  client.indices.delete_template(:name => "*")
96
103
  client.indices.delete_index_template(:name => "logstash*") rescue nil
@@ -11,7 +11,7 @@
11
11
  "transport_address" : "http://localhost:9200",
12
12
  "host" : "localhost",
13
13
  "ip" : "127.0.0.1",
14
- "version" : "5.5.1",
14
+ "version" : "6.8.10",
15
15
  "build_hash" : "19c13d0",
16
16
  "roles" : [
17
17
  "master"
@@ -29,7 +29,7 @@
29
29
  "transport_address" : "http://localhost:9201",
30
30
  "host" : "localhost",
31
31
  "ip" : "127.0.0.1",
32
- "version" : "5.5.1",
32
+ "version" : "6.8.10",
33
33
  "build_hash" : "19c13d0",
34
34
  "roles" : [
35
35
  "data"
@@ -47,7 +47,7 @@
47
47
  "transport_address" : "http://localhost:9202",
48
48
  "host" : "localhost",
49
49
  "ip" : "127.0.0.1",
50
- "version" : "5.5.1",
50
+ "version" : "6.8.10",
51
51
  "build_hash" : "19c13d0",
52
52
  "roles" : [
53
53
  "data",
@@ -66,7 +66,7 @@
66
66
  "transport_address" : "http://localhost:9203",
67
67
  "host" : "localhost",
68
68
  "ip" : "127.0.0.1",
69
- "version" : "5.5.1",
69
+ "version" : "6.8.10",
70
70
  "build_hash" : "19c13d0",
71
71
  "roles" : [ ],
72
72
  "http" : {
@@ -78,4 +78,4 @@
78
78
  }
79
79
  }
80
80
  }
81
- }
81
+ }
@@ -8,62 +8,63 @@ RSpec::Matchers.define :a_valid_gzip_encoded_string do
8
8
  }
9
9
  end
10
10
 
11
- if ESHelper.es_version_satisfies?(">= 5")
12
- describe "indexing with http_compression turned on", :integration => true do
13
- let(:event) { LogStash::Event.new("message" => "Hello World!", "type" => type) }
14
- let(:index) { 10.times.collect { rand(10).to_s }.join("") }
15
- let(:type) { ESHelper.es_version_satisfies?("< 7") ? "doc" : "_doc" }
16
- let(:event_count) { 10000 + rand(500) }
17
- let(:events) { event_count.times.map { event }.to_a }
18
- let(:config) {
19
- {
20
- "hosts" => get_host_port,
21
- "index" => index,
22
- "http_compression" => true
23
- }
11
+ describe "indexing with http_compression turned on", :integration => true do
12
+ let(:event) { LogStash::Event.new("message" => "Hello World!", "type" => type) }
13
+ let(:index) { 10.times.collect { rand(10).to_s }.join("") }
14
+ let(:type) { ESHelper.es_version_satisfies?("< 7") ? "doc" : "_doc" }
15
+ let(:event_count) { 10000 + rand(500) }
16
+ let(:events) { event_count.times.map { event }.to_a }
17
+ let(:config) {
18
+ {
19
+ "hosts" => get_host_port,
20
+ "index" => index,
21
+ "http_compression" => true
24
22
  }
25
- subject { LogStash::Outputs::ElasticSearch.new(config) }
23
+ }
24
+ subject { LogStash::Outputs::ElasticSearch.new(config) }
26
25
 
27
- let(:es_url) { "http://#{get_host_port}" }
28
- let(:index_url) {"#{es_url}/#{index}"}
29
- let(:http_client_options) { {} }
30
- let(:http_client) do
31
- Manticore::Client.new(http_client_options)
32
- end
26
+ let(:es_url) { "http://#{get_host_port}" }
27
+ let(:index_url) {"#{es_url}/#{index}"}
28
+ let(:http_client_options) { {} }
29
+ let(:http_client) do
30
+ Manticore::Client.new(http_client_options)
31
+ end
33
32
 
34
- before do
35
- subject.register
36
- subject.multi_receive([])
37
- end
33
+ before do
34
+ subject.register
35
+ subject.multi_receive([])
36
+ end
38
37
 
39
- shared_examples "an indexer" do
40
- it "ships events" do
41
- subject.multi_receive(events)
38
+ shared_examples "an indexer" do
39
+ it "ships events" do
40
+ subject.multi_receive(events)
42
41
 
43
- http_client.post("#{es_url}/_refresh").call
42
+ http_client.post("#{es_url}/_refresh").call
44
43
 
45
- response = http_client.get("#{index_url}/_count?q=*")
46
- result = LogStash::Json.load(response.body)
47
- cur_count = result["count"]
48
- expect(cur_count).to eq(event_count)
44
+ response = http_client.get("#{index_url}/_count?q=*")
45
+ result = LogStash::Json.load(response.body)
46
+ cur_count = result["count"]
47
+ expect(cur_count).to eq(event_count)
49
48
 
50
- response = http_client.get("#{index_url}/_search?q=*&size=1000")
51
- result = LogStash::Json.load(response.body)
52
- result["hits"]["hits"].each do |doc|
53
- expect(doc["_type"]).to eq(type) if ESHelper.es_version_satisfies?(">= 6", "< 8")
54
- expect(doc).not_to include("_type") if ESHelper.es_version_satisfies?(">= 8")
55
- expect(doc["_index"]).to eq(index)
49
+ response = http_client.get("#{index_url}/_search?q=*&size=1000")
50
+ result = LogStash::Json.load(response.body)
51
+ result["hits"]["hits"].each do |doc|
52
+ if ESHelper.es_version_satisfies?("< 8")
53
+ expect(doc["_type"]).to eq(type)
54
+ else
55
+ expect(doc).not_to include("_type")
56
56
  end
57
+ expect(doc["_index"]).to eq(index)
57
58
  end
58
59
  end
60
+ end
59
61
 
60
- it "sets the correct content-encoding header and body is compressed" do
61
- expect(subject.client.pool.adapter.client).to receive(:send).
62
- with(anything, anything, {:headers=>{"Content-Encoding"=>"gzip", "Content-Type"=>"application/json"}, :body => a_valid_gzip_encoded_string}).
63
- and_call_original
64
- subject.multi_receive(events)
65
- end
66
-
67
- it_behaves_like("an indexer")
62
+ it "sets the correct content-encoding header and body is compressed" do
63
+ expect(subject.client.pool.adapter.client).to receive(:send).
64
+ with(anything, anything, {:headers=>{"Content-Encoding"=>"gzip", "Content-Type"=>"application/json"}, :body => a_valid_gzip_encoded_string}).
65
+ and_call_original
66
+ subject.multi_receive(events)
68
67
  end
68
+
69
+ it_behaves_like("an indexer")
69
70
  end
@@ -2,64 +2,62 @@ require_relative "../../../spec/es_spec_helper"
2
2
  require "logstash/outputs/elasticsearch"
3
3
 
4
4
 
5
- if ESHelper.es_version_satisfies?(">= 2")
6
- describe "Versioned delete", :integration => true do
7
- require "logstash/outputs/elasticsearch"
5
+ describe "Versioned delete", :integration => true do
6
+ require "logstash/outputs/elasticsearch"
7
+
8
+ let(:es) { get_client }
9
+
10
+ before :each do
11
+ # Delete all templates first.
12
+ # Clean ES of data before we start.
13
+ es.indices.delete_template(:name => "*")
14
+ # This can fail if there are no indexes, ignore failure.
15
+ es.indices.delete(:index => "*") rescue nil
16
+ es.indices.refresh
17
+ end
8
18
 
9
- let(:es) { get_client }
19
+ context "when delete only" do
20
+ subject { LogStash::Outputs::ElasticSearch.new(settings) }
10
21
 
11
- before :each do
12
- # Delete all templates first.
13
- # Clean ES of data before we start.
14
- es.indices.delete_template(:name => "*")
15
- # This can fail if there are no indexes, ignore failure.
16
- es.indices.delete(:index => "*") rescue nil
17
- es.indices.refresh
22
+ before do
23
+ subject.register
18
24
  end
19
25
 
20
- context "when delete only" do
21
- subject { LogStash::Outputs::ElasticSearch.new(settings) }
22
-
23
- before do
24
- subject.register
25
- end
26
-
27
- let(:settings) do
28
- {
29
- "manage_template" => true,
30
- "index" => "logstash-delete",
31
- "template_overwrite" => true,
32
- "hosts" => get_host_port(),
33
- "document_id" => "%{my_id}",
34
- "version" => "%{my_version}",
35
- "version_type" => "external",
36
- "action" => "%{my_action}"
37
- }
38
- end
39
-
40
- it "should ignore non-monotonic external version updates" do
41
- id = "ev2"
42
- subject.multi_receive([LogStash::Event.new("my_id" => id, "my_action" => "index", "message" => "foo", "my_version" => 99)])
43
- r = es.get(:index => 'logstash-delete', :type => doc_type, :id => id, :refresh => true)
44
- expect(r['_version']).to eq(99)
45
- expect(r['_source']['message']).to eq('foo')
26
+ let(:settings) do
27
+ {
28
+ "manage_template" => true,
29
+ "index" => "logstash-delete",
30
+ "template_overwrite" => true,
31
+ "hosts" => get_host_port(),
32
+ "document_id" => "%{my_id}",
33
+ "version" => "%{my_version}",
34
+ "version_type" => "external",
35
+ "action" => "%{my_action}"
36
+ }
37
+ end
46
38
 
47
- subject.multi_receive([LogStash::Event.new("my_id" => id, "my_action" => "delete", "message" => "foo", "my_version" => 98)])
48
- r2 = es.get(:index => 'logstash-delete', :type => doc_type, :id => id, :refresh => true)
49
- expect(r2['_version']).to eq(99)
50
- expect(r2['_source']['message']).to eq('foo')
51
- end
39
+ it "should ignore non-monotonic external version updates" do
40
+ id = "ev2"
41
+ subject.multi_receive([LogStash::Event.new("my_id" => id, "my_action" => "index", "message" => "foo", "my_version" => 99)])
42
+ r = es.get(:index => 'logstash-delete', :type => doc_type, :id => id, :refresh => true)
43
+ expect(r['_version']).to eq(99)
44
+ expect(r['_source']['message']).to eq('foo')
45
+
46
+ subject.multi_receive([LogStash::Event.new("my_id" => id, "my_action" => "delete", "message" => "foo", "my_version" => 98)])
47
+ r2 = es.get(:index => 'logstash-delete', :type => doc_type, :id => id, :refresh => true)
48
+ expect(r2['_version']).to eq(99)
49
+ expect(r2['_source']['message']).to eq('foo')
50
+ end
52
51
 
53
- it "should commit monotonic external version updates" do
54
- id = "ev3"
55
- subject.multi_receive([LogStash::Event.new("my_id" => id, "my_action" => "index", "message" => "foo", "my_version" => 99)])
56
- r = es.get(:index => 'logstash-delete', :type => doc_type, :id => id, :refresh => true)
57
- expect(r['_version']).to eq(99)
58
- expect(r['_source']['message']).to eq('foo')
52
+ it "should commit monotonic external version updates" do
53
+ id = "ev3"
54
+ subject.multi_receive([LogStash::Event.new("my_id" => id, "my_action" => "index", "message" => "foo", "my_version" => 99)])
55
+ r = es.get(:index => 'logstash-delete', :type => doc_type, :id => id, :refresh => true)
56
+ expect(r['_version']).to eq(99)
57
+ expect(r['_source']['message']).to eq('foo')
59
58
 
60
- subject.multi_receive([LogStash::Event.new("my_id" => id, "my_action" => "delete", "message" => "foo", "my_version" => 100)])
61
- expect { es.get(:index => 'logstash-delete', :type => doc_type, :id => id, :refresh => true) }.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
62
- end
59
+ subject.multi_receive([LogStash::Event.new("my_id" => id, "my_action" => "delete", "message" => "foo", "my_version" => 100)])
60
+ expect { es.get(:index => 'logstash-delete', :type => doc_type, :id => id, :refresh => true) }.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
63
61
  end
64
62
  end
65
63
  end