logstash-output-elasticsearch 11.1.0-java → 11.2.0-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8d5dde6f4643a1482c56af7db786848d73759cac4728203ade488a8eec3ca76
4
- data.tar.gz: 8c8e8b7b05589c7d86d92d3fc50c2d267c5650456c84806326c5bef488bfb819
3
+ metadata.gz: 0bd2f7b95f4a121df8712ce601a2c56c228de6e113f90c96058c58f966af31db
4
+ data.tar.gz: bac417c7d999e1676ed451cf5216b0b6085203b533fd7d5039abf3efbc070578
5
5
  SHA512:
6
- metadata.gz: aad121ec87c87db04fc35ce0bf28069eee3960b0bdca76c8297d5b1242e9e83a68b118b5f97e41ec34660073ba1f61f839e786ee2db306a56f5b2ad6c0e5dc06
7
- data.tar.gz: 5201e002ae94e3acc00e44e79da5cd721fc80d39781e876c0d009d7c53f5ab90978a6126a691c5c07b159a30bc3e2bc38ef58801d0443094bcd3b810acbd7e98
6
+ metadata.gz: '09274b381e8026eb8527b5926318c603ffc776e645538671263f61fec3d00731e7695a13e2f72cdccd4037f1d7298975a6424f03115a38060f4e2e34f7498049'
7
+ data.tar.gz: 47fddb97c3634cd68588bebaed1d0fac38d4eb33c3cc69083e59a9c13c1f74a87f7835e6fc7982762a2db19009150900ca7ac2bee213d973e56dc0a8fbcc1158
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 11.2.0
2
+ - Added preflight checks on Elasticsearch [#1026](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1026)
3
+
1
4
  ## 11.1.0
2
5
  - Feat: add `user-agent` header passed to the Elasticsearch HTTP connection [#1038](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1038)
3
6
 
@@ -37,6 +37,9 @@ module LogStash; module Outputs; class ElasticSearch; class HttpClient;
37
37
  ROOT_URI_PATH = '/'.freeze
38
38
  LICENSE_PATH = '/_license'.freeze
39
39
 
40
+ VERSION_6_TO_7 = Gem::Requirement.new([">= 6.0.0", "< 7.0.0"])
41
+ VERSION_7_TO_7_14 = Gem::Requirement.new([">= 7.0.0", "< 7.14.0"])
42
+
40
43
  DEFAULT_OPTIONS = {
41
44
  :healthcheck_path => ROOT_URI_PATH,
42
45
  :sniffing_path => "/_nodes/http",
@@ -211,7 +214,7 @@ module LogStash; module Outputs; class ElasticSearch; class HttpClient;
211
214
  def start_resurrectionist
212
215
  @resurrectionist = Thread.new do
213
216
  until_stopped("resurrection", @resurrect_delay) do
214
- healthcheck!
217
+ healthcheck!(false)
215
218
  end
216
219
  end
217
220
  end
@@ -232,11 +235,18 @@ module LogStash; module Outputs; class ElasticSearch; class HttpClient;
232
235
  perform_request_to_url(url, :head, @healthcheck_path)
233
236
  end
234
237
 
235
- def healthcheck!
238
+ def healthcheck!(register_phase = true)
236
239
  # Try to keep locking granularity low such that we don't affect IO...
237
240
  @state_mutex.synchronize { @url_info.select {|url,meta| meta[:state] != :alive } }.each do |url,meta|
238
241
  begin
239
242
  health_check_request(url)
243
+
244
+ # when called from resurrectionist skip the product check done during register phase
245
+ if register_phase
246
+ if !elasticsearch?(url)
247
+ raise LogStash::ConfigurationError, "Could not connect to a compatible version of Elasticsearch"
248
+ end
249
+ end
240
250
  # If no exception was raised it must have succeeded!
241
251
  logger.warn("Restored connection to ES instance", url: url.sanitized.to_s)
242
252
  # We reconnected to this node, check its ES version
@@ -254,6 +264,42 @@ module LogStash; module Outputs; class ElasticSearch; class HttpClient;
254
264
  end
255
265
  end
256
266
 
267
+ def elasticsearch?(url)
268
+ begin
269
+ response = perform_request_to_url(url, :get, ROOT_URI_PATH)
270
+ rescue ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError => e
271
+ return false if response.code == 401 || response.code == 403
272
+ raise e
273
+ end
274
+
275
+ version_info = LogStash::Json.load(response.body)
276
+ return false if version_info['version'].nil?
277
+
278
+ version = Gem::Version.new(version_info["version"]['number'])
279
+ return false if version < Gem::Version.new('6.0.0')
280
+
281
+ if VERSION_6_TO_7.satisfied_by?(version)
282
+ return valid_tagline?(version_info)
283
+ elsif VERSION_7_TO_7_14.satisfied_by?(version)
284
+ build_flavor = version_info["version"]['build_flavor']
285
+ return false if build_flavor.nil? || build_flavor != 'default' || !valid_tagline?(version_info)
286
+ else
287
+ # case >= 7.14
288
+ lower_headers = response.headers.transform_keys {|key| key.to_s.downcase }
289
+ product_header = lower_headers['x-elastic-product']
290
+ return false if product_header != 'Elasticsearch'
291
+ end
292
+ return true
293
+ rescue => e
294
+ logger.error("Unable to retrieve Elasticsearch version", url: url.sanitized.to_s, exception: e.class, message: e.message)
295
+ false
296
+ end
297
+
298
+ def valid_tagline?(version_info)
299
+ tagline = version_info['tagline']
300
+ tagline == "You Know, for Search"
301
+ end
302
+
257
303
  def stop_resurrectionist
258
304
  @resurrectionist.join if @resurrectionist
259
305
  end