logstash-output-elasticsearch 11.22.17-java → 12.0.0-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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -20
- data/README.md +1 -3
- data/docs/index.asciidoc +21 -112
- data/lib/logstash/outputs/elasticsearch/http_client/manticore_adapter.rb +4 -1
- data/lib/logstash/outputs/elasticsearch/http_client/pool.rb +22 -12
- data/lib/logstash/outputs/elasticsearch/http_client.rb +31 -44
- data/lib/logstash/outputs/elasticsearch/http_client_builder.rb +2 -31
- data/lib/logstash/outputs/elasticsearch/template_manager.rb +1 -16
- data/lib/logstash/outputs/elasticsearch.rb +0 -47
- data/lib/logstash/plugin_mixins/elasticsearch/api_configs.rb +13 -30
- data/lib/logstash/plugin_mixins/elasticsearch/common.rb +1 -11
- data/logstash-output-elasticsearch.gemspec +2 -2
- data/spec/es_spec_helper.rb +22 -34
- data/spec/fixtures/test_certs/GENERATED_AT +1 -1
- data/spec/fixtures/test_certs/ca.crt +27 -30
- data/spec/fixtures/test_certs/ca.der.sha256 +1 -1
- data/spec/fixtures/test_certs/renew.sh +3 -2
- data/spec/fixtures/test_certs/test.crt +28 -29
- data/spec/fixtures/test_certs/test.der.sha256 +1 -1
- data/spec/fixtures/test_certs/test.p12 +0 -0
- data/spec/integration/outputs/compressed_indexing_spec.rb +1 -3
- data/spec/integration/outputs/delete_spec.rb +4 -4
- data/spec/integration/outputs/ilm_spec.rb +12 -18
- data/spec/integration/outputs/index_spec.rb +2 -12
- data/spec/integration/outputs/index_version_spec.rb +7 -7
- data/spec/integration/outputs/metrics_spec.rb +1 -4
- data/spec/integration/outputs/painless_update_spec.rb +10 -11
- data/spec/integration/outputs/unsupported_actions_spec.rb +10 -15
- data/spec/integration/outputs/update_spec.rb +9 -11
- data/spec/spec_helper.rb +0 -8
- data/spec/support/elasticsearch/api/actions/get_alias.rb +18 -0
- data/spec/support/elasticsearch/api/actions/put_alias.rb +24 -0
- data/spec/unit/outputs/elasticsearch/http_client_spec.rb +0 -77
- data/spec/unit/outputs/elasticsearch/template_manager_spec.rb +0 -71
- data/spec/unit/outputs/elasticsearch_spec.rb +3 -112
- data/spec/unit/outputs/elasticsearch_ssl_spec.rb +22 -0
- data/spec/unit/outputs/error_whitelist_spec.rb +1 -0
- metadata +25 -19
- data/version +0 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 983d99de3a0dcd5e58fb123e01ad8ee4c2396ce15fd565dda439e43c182b32e6
|
|
4
|
+
data.tar.gz: 8733e1a9b256b36e9f08a9be0803ca667817d7fe9f1e4cd1e090fe95882eb245
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f9626da6b7d428b17a16b2874a8758e260e84af265636fabea8e35dec0777ecdeae1b662910d2e065eccc4742ef706765d87b6cf475a141544a78347c69953de
|
|
7
|
+
data.tar.gz: 7997cfb3b851130a0504c0907761aba37ea31ec35deb7fc4de19eaf7f1ae00cee9df7b2575d59ace2b08c19ad7710460c534467bb79f7019c3a125478d0de5e2
|
data/CHANGELOG.md
CHANGED
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
##
|
|
2
|
-
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
## 11.22.13
|
|
14
|
-
- Add headers reporting uncompressed size and doc count for bulk requests [#1217](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1217)
|
|
15
|
-
|
|
16
|
-
## 11.22.12
|
|
17
|
-
- Properly handle http code 413 (Payload Too Large) [#1199](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1199)
|
|
18
|
-
|
|
19
|
-
## 11.22.11
|
|
20
|
-
- Remove irrelevant log warning about elastic stack version [#1202](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1202)
|
|
1
|
+
## 12.0.0
|
|
2
|
+
- SSL settings that were marked deprecated in version `11.14.0` are now marked obsolete, and will prevent the plugin from starting.
|
|
3
|
+
- These settings are:
|
|
4
|
+
- `cacert`, which should be replaced by `ssl_certificate_authorities`
|
|
5
|
+
- `keystore`, which should be replaced by `ssl_keystore_path`
|
|
6
|
+
- `keystore_password`, which should be replaced by `ssl_keystore_password`
|
|
7
|
+
- `ssl`, which should be replaced by `ssl_enabled`
|
|
8
|
+
- `ssl_certificate_verification`, which should be replaced by `ssl_verification_mode`
|
|
9
|
+
- `truststore`, which should be replaced by `ssl_truststore_path`
|
|
10
|
+
- `truststore_password`, which should be replaced by `ssl_truststore_password`
|
|
11
|
+
- [#1197](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1197)
|
|
21
12
|
|
|
22
13
|
## 11.22.10
|
|
23
14
|
- Add `x-elastic-product-origin` header to Elasticsearch requests [#1195](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1195)
|
data/README.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# Logstash Plugin
|
|
2
2
|
|
|
3
|
-
[](https://github.com/logstash-plugins/logstash-output-elasticsearch/actions/workflows/integration-tests.yml)
|
|
5
|
-
[](https://github.com/logstash-plugins/logstash-output-elasticsearch/actions/workflows/secure-integration-tests.yml)
|
|
3
|
+
[](https://travis-ci.com/logstash-plugins/logstash-output-elasticsearch)
|
|
6
4
|
|
|
7
5
|
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
|
8
6
|
|
data/docs/index.asciidoc
CHANGED
|
@@ -196,22 +196,7 @@ This plugin uses the Elasticsearch bulk API to optimize its imports into Elastic
|
|
|
196
196
|
either partial or total failures. The bulk API sends batches of requests to an HTTP endpoint. Error codes for the HTTP
|
|
197
197
|
request are handled differently than error codes for individual documents.
|
|
198
198
|
|
|
199
|
-
|
|
200
|
-
HTTP requests to the bulk API are expected to return a 200 response code. All other response codes are retried indefinitely,
|
|
201
|
-
including 413 (Payload Too Large) responses.
|
|
202
|
-
|
|
203
|
-
If you want to handle large payloads differently, you can configure 413 responses to go to the Dead Letter Queue instead:
|
|
204
|
-
|
|
205
|
-
[source,ruby]
|
|
206
|
-
-----
|
|
207
|
-
output {
|
|
208
|
-
elasticsearch {
|
|
209
|
-
hosts => ["localhost:9200"]
|
|
210
|
-
dlq_custom_codes => [413] # Send 413 errors to DLQ instead of retrying
|
|
211
|
-
}
|
|
212
|
-
-----
|
|
213
|
-
|
|
214
|
-
This will capture oversized payloads in the DLQ for analysis rather than retrying them.
|
|
199
|
+
HTTP requests to the bulk API are expected to return a 200 response code. All other response codes are retried indefinitely.
|
|
215
200
|
|
|
216
201
|
The following document errors are handled as follows:
|
|
217
202
|
|
|
@@ -340,8 +325,10 @@ When a string value on an event contains one or more byte sequences that are not
|
|
|
340
325
|
[id="plugins-{type}s-{plugin}-options"]
|
|
341
326
|
==== Elasticsearch Output Configuration Options
|
|
342
327
|
|
|
343
|
-
This plugin supports
|
|
344
|
-
|
|
328
|
+
This plugin supports these configuration options plus the <<plugins-{type}s-{plugin}-common-options>> described later.
|
|
329
|
+
|
|
330
|
+
NOTE: As of version 12.0.0 of this plugin, a number of previously deprecated SSL settings have been removed.
|
|
331
|
+
Please check out <<plugins-{type}s-{plugin}-obsolete-options>> for details.
|
|
345
332
|
|
|
346
333
|
[cols="<,<,<",options="header",]
|
|
347
334
|
|=======================================================================
|
|
@@ -456,14 +443,10 @@ For more details on actions, check out the {ref}/docs-bulk.html[Elasticsearch bu
|
|
|
456
443
|
* There is no default value for this setting.
|
|
457
444
|
|
|
458
445
|
Authenticate using Elasticsearch API key.
|
|
459
|
-
Note that this option also requires SSL/TLS, which can be enabled by supplying a <<plugins-{type}s-{plugin}-cloud_id>>, a list of HTTPS <<plugins-{type}s-{plugin}-hosts>>, or by setting <<plugins-{type}s-{plugin}-
|
|
446
|
+
Note that this option also requires SSL/TLS, which can be enabled by supplying a <<plugins-{type}s-{plugin}-cloud_id>>, a list of HTTPS <<plugins-{type}s-{plugin}-hosts>>, or by setting <<plugins-{type}s-{plugin}-ssl_enabled,`ssl_enabled => true`>>.
|
|
460
447
|
|
|
461
|
-
|
|
462
|
-
Elasticsearch
|
|
463
|
-
{ref}/security-api-create-api-key.html[Create
|
|
464
|
-
API key API]. The base64-encoded form of that pair is also accepted, as is an
|
|
465
|
-
https://www.elastic.co/docs/deploy-manage/api-keys/elastic-cloud-api-keys[Elastic Cloud API key]
|
|
466
|
-
(prefixed with `essu_`), which is used as-is.
|
|
448
|
+
Format is `id:api_key` where `id` and `api_key` are as returned by the
|
|
449
|
+
Elasticsearch {ref}/security-api-create-api-key.html[Create API key API].
|
|
467
450
|
|
|
468
451
|
[id="plugins-{type}s-{plugin}-bulk_path"]
|
|
469
452
|
===== `bulk_path`
|
|
@@ -1343,98 +1326,24 @@ https://www.elastic.co/blog/elasticsearch-versioning-support[versioning support
|
|
|
1343
1326
|
blog] and {ref}/docs-index_.html#_version_types[Version types] in the
|
|
1344
1327
|
Elasticsearch documentation.
|
|
1345
1328
|
|
|
1346
|
-
[id="plugins-{type}s-{plugin}-
|
|
1347
|
-
==== Elasticsearch Output
|
|
1348
|
-
|
|
1349
|
-
This plugin supports the following deprecated configurations.
|
|
1329
|
+
[id="plugins-{type}s-{plugin}-obsolete-options"]
|
|
1330
|
+
==== Elasticsearch Output Obsolete Configuration Options
|
|
1350
1331
|
|
|
1351
|
-
WARNING:
|
|
1332
|
+
WARNING: As of version `12.0.0` of this plugin, some configuration options have been replaced.
|
|
1333
|
+
The plugin will fail to start if it contains any of these obsolete options.
|
|
1352
1334
|
|
|
1353
|
-
[cols="
|
|
1335
|
+
[cols="<,<",options="header",]
|
|
1354
1336
|
|=======================================================================
|
|
1355
|
-
|Setting|
|
|
1356
|
-
|
|
|
1357
|
-
|
|
|
1358
|
-
|
|
|
1359
|
-
|
|
|
1360
|
-
|
|
|
1361
|
-
|
|
|
1362
|
-
|
|
|
1337
|
+
|Setting|Replaced by
|
|
1338
|
+
| cacert | <<plugins-{type}s-{plugin}-ssl_certificate_authorities>>
|
|
1339
|
+
| keystore | <<plugins-{type}s-{plugin}-ssl_keystore_path>>
|
|
1340
|
+
| keystore_password | <<plugins-{type}s-{plugin}-ssl_keystore_password>>
|
|
1341
|
+
| ssl | <<plugins-{type}s-{plugin}-ssl_enabled>>
|
|
1342
|
+
| ssl_certificate_verification | <<plugins-{type}s-{plugin}-ssl_verification_mode>>
|
|
1343
|
+
| truststore | <<plugins-{type}s-{plugin}-ssl_truststore_path>>
|
|
1344
|
+
| truststore_password | <<plugins-{type}s-{plugin}-ssl_truststore_password>>
|
|
1363
1345
|
|=======================================================================
|
|
1364
1346
|
|
|
1365
|
-
|
|
1366
|
-
[id="plugins-{type}s-{plugin}-cacert"]
|
|
1367
|
-
===== `cacert`
|
|
1368
|
-
deprecated[11.14.0, Replaced by <<plugins-{type}s-{plugin}-ssl_certificate_authorities>>]
|
|
1369
|
-
|
|
1370
|
-
* Value type is a list of <<path,path>>
|
|
1371
|
-
* There is no default value for this setting.
|
|
1372
|
-
|
|
1373
|
-
The .cer or .pem file to validate the server's certificate.
|
|
1374
|
-
|
|
1375
|
-
[id="plugins-{type}s-{plugin}-keystore"]
|
|
1376
|
-
===== `keystore`
|
|
1377
|
-
deprecated[11.14.0, Replaced by <<plugins-{type}s-{plugin}-ssl_keystore_path>>]
|
|
1378
|
-
|
|
1379
|
-
* Value type is <<path,path>>
|
|
1380
|
-
* There is no default value for this setting.
|
|
1381
|
-
|
|
1382
|
-
The keystore used to present a certificate to the server.
|
|
1383
|
-
It can be either .jks or .p12
|
|
1384
|
-
|
|
1385
|
-
NOTE: You cannot use this setting and <<plugins-{type}s-{plugin}-ssl_certificate>> at the same time.
|
|
1386
|
-
|
|
1387
|
-
[id="plugins-{type}s-{plugin}-keystore_password"]
|
|
1388
|
-
===== `keystore_password`
|
|
1389
|
-
deprecated[11.14.0, Replaced by <<plugins-{type}s-{plugin}-ssl_keystore_password>>]
|
|
1390
|
-
|
|
1391
|
-
* Value type is <<password,password>>
|
|
1392
|
-
* There is no default value for this setting.
|
|
1393
|
-
|
|
1394
|
-
Set the keystore password
|
|
1395
|
-
|
|
1396
|
-
[id="plugins-{type}s-{plugin}-ssl"]
|
|
1397
|
-
===== `ssl`
|
|
1398
|
-
deprecated[11.14.0, Replaced by <<plugins-{type}s-{plugin}-ssl_enabled>>]
|
|
1399
|
-
|
|
1400
|
-
* Value type is <<boolean,boolean>>
|
|
1401
|
-
* There is no default value for this setting.
|
|
1402
|
-
|
|
1403
|
-
Enable SSL/TLS secured communication to Elasticsearch cluster.
|
|
1404
|
-
Leaving this unspecified will use whatever scheme is specified in the URLs listed in <<plugins-{type}s-{plugin}-hosts>> or extracted from the <<plugins-{type}s-{plugin}-cloud_id>>.
|
|
1405
|
-
If no explicit protocol is specified plain HTTP will be used.
|
|
1406
|
-
|
|
1407
|
-
[id="plugins-{type}s-{plugin}-ssl_certificate_verification"]
|
|
1408
|
-
===== `ssl_certificate_verification`
|
|
1409
|
-
deprecated[11.14.0, Replaced by <<plugins-{type}s-{plugin}-ssl_verification_mode>>]
|
|
1410
|
-
|
|
1411
|
-
* Value type is <<boolean,boolean>>
|
|
1412
|
-
* Default value is `true`
|
|
1413
|
-
|
|
1414
|
-
Option to validate the server's certificate. Disabling this severely compromises security.
|
|
1415
|
-
For more information on disabling certificate verification please read
|
|
1416
|
-
https://www.cs.utexas.edu/~shmat/shmat_ccs12.pdf
|
|
1417
|
-
|
|
1418
|
-
[id="plugins-{type}s-{plugin}-truststore"]
|
|
1419
|
-
===== `truststore`
|
|
1420
|
-
deprecated[11.14.0, Replaced by <<plugins-{type}s-{plugin}-ssl_truststore_path>>]
|
|
1421
|
-
|
|
1422
|
-
* Value type is <<path,path>>
|
|
1423
|
-
* There is no default value for this setting.
|
|
1424
|
-
|
|
1425
|
-
The truststore to validate the server's certificate.
|
|
1426
|
-
It can be either `.jks` or `.p12`.
|
|
1427
|
-
Use either `:truststore` or `:cacert`.
|
|
1428
|
-
|
|
1429
|
-
[id="plugins-{type}s-{plugin}-truststore_password"]
|
|
1430
|
-
===== `truststore_password`
|
|
1431
|
-
deprecated[11.14.0, Replaced by <<plugins-{type}s-{plugin}-ssl_truststore_password>>]
|
|
1432
|
-
|
|
1433
|
-
* Value type is <<password,password>>
|
|
1434
|
-
* There is no default value for this setting.
|
|
1435
|
-
|
|
1436
|
-
Set the truststore password
|
|
1437
|
-
|
|
1438
1347
|
[id="plugins-{type}s-{plugin}-common-options"]
|
|
1439
1348
|
include::{include_path}/{type}.asciidoc[]
|
|
1440
1349
|
|
|
@@ -76,8 +76,11 @@ module LogStash; module Outputs; class ElasticSearch; class HttpClient;
|
|
|
76
76
|
raise ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::HostUnreachableError.new(e, request_uri_as_string)
|
|
77
77
|
end
|
|
78
78
|
|
|
79
|
+
# 404s are excluded because they are valid codes in the case of
|
|
80
|
+
# template installation. We might need a better story around this later
|
|
81
|
+
# but for our current purposes this is correct
|
|
79
82
|
code = resp.code
|
|
80
|
-
if code < 200 || code > 299
|
|
83
|
+
if code < 200 || code > 299 && code != 404
|
|
81
84
|
raise ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError.new(code, request_uri, body, resp.body)
|
|
82
85
|
end
|
|
83
86
|
|
|
@@ -253,11 +253,13 @@ module LogStash; module Outputs; class ElasticSearch; class HttpClient;
|
|
|
253
253
|
def health_check_request(url)
|
|
254
254
|
logger.debug("Running health check to see if an Elasticsearch connection is working",
|
|
255
255
|
:healthcheck_url => url.sanitized.to_s, :path => @healthcheck_path)
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
256
|
+
begin
|
|
257
|
+
response = perform_request_to_url(url, :head, @healthcheck_path)
|
|
258
|
+
return response, nil
|
|
259
|
+
rescue ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError => e
|
|
260
|
+
logger.warn("Health check failed", code: e.response_code, url: e.url, message: e.message)
|
|
261
|
+
return nil, e
|
|
262
|
+
end
|
|
261
263
|
end
|
|
262
264
|
|
|
263
265
|
def healthcheck!(register_phase = true)
|
|
@@ -310,11 +312,13 @@ module LogStash; module Outputs; class ElasticSearch; class HttpClient;
|
|
|
310
312
|
end
|
|
311
313
|
|
|
312
314
|
def get_root_path(url, params={})
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
315
|
+
begin
|
|
316
|
+
resp = perform_request_to_url(url, :get, ROOT_URI_PATH, params)
|
|
317
|
+
return resp, nil
|
|
318
|
+
rescue ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError => e
|
|
319
|
+
logger.warn("Elasticsearch main endpoint returns #{e.response_code}", message: e.message, body: e.response_body)
|
|
320
|
+
return nil, e
|
|
321
|
+
end
|
|
318
322
|
end
|
|
319
323
|
|
|
320
324
|
def test_serverless_connection(url, root_response)
|
|
@@ -347,7 +351,6 @@ module LogStash; module Outputs; class ElasticSearch; class HttpClient;
|
|
|
347
351
|
end
|
|
348
352
|
|
|
349
353
|
def perform_request_to_url(url, method, path, params={}, body=nil)
|
|
350
|
-
params ||= {}
|
|
351
354
|
params[:headers] = DEFAULT_EAV_HEADER.merge(params[:headers] || {}) if serverless?
|
|
352
355
|
@adapter.perform_request(url, method, path, params, body)
|
|
353
356
|
end
|
|
@@ -512,13 +515,20 @@ module LogStash; module Outputs; class ElasticSearch; class HttpClient;
|
|
|
512
515
|
major = major_version(version)
|
|
513
516
|
if @maximum_seen_major_version.nil?
|
|
514
517
|
@logger.info("Elasticsearch version determined (#{version})", es_version: major)
|
|
515
|
-
|
|
518
|
+
set_maximum_seen_major_version(major)
|
|
516
519
|
elsif major > @maximum_seen_major_version
|
|
517
520
|
warn_on_higher_major_version(major, url)
|
|
518
521
|
@maximum_seen_major_version = major
|
|
519
522
|
end
|
|
520
523
|
end
|
|
521
524
|
|
|
525
|
+
def set_maximum_seen_major_version(major)
|
|
526
|
+
if major >= 6
|
|
527
|
+
@logger.warn("Detected a 6.x and above cluster: the `type` event field won't be used to determine the document _type", es_version: major)
|
|
528
|
+
end
|
|
529
|
+
@maximum_seen_major_version = major
|
|
530
|
+
end
|
|
531
|
+
|
|
522
532
|
def warn_on_higher_major_version(major, url)
|
|
523
533
|
@logger.warn("Detected a node with a higher major version than previously observed, " +
|
|
524
534
|
"this could be the result of an Elasticsearch cluster upgrade",
|
|
@@ -21,8 +21,7 @@ module LogStash; module Outputs; class ElasticSearch;
|
|
|
21
21
|
# We wound up agreeing that a number greater than 10 MiB and less than 100MiB
|
|
22
22
|
# made sense. We picked one on the lowish side to not use too much heap.
|
|
23
23
|
TARGET_BULK_BYTES = 20 * 1024 * 1024 # 20MiB
|
|
24
|
-
|
|
25
|
-
UNCOMPRESSED_LENGTH_HEADER = "X-Elastic-Uncompressed-Request-Length".freeze
|
|
24
|
+
|
|
26
25
|
|
|
27
26
|
class HttpClient
|
|
28
27
|
attr_reader :client, :options, :logger, :pool, :action_count, :recv_count
|
|
@@ -144,11 +143,7 @@ module LogStash; module Outputs; class ElasticSearch;
|
|
|
144
143
|
:payload_size => stream_writer.pos,
|
|
145
144
|
:content_length => body_stream.size,
|
|
146
145
|
:batch_offset => (index + 1 - batch_actions.size))
|
|
147
|
-
|
|
148
|
-
EVENT_COUNT_HEADER => batch_actions.size.to_s,
|
|
149
|
-
UNCOMPRESSED_LENGTH_HEADER => stream_writer.pos.to_s
|
|
150
|
-
}
|
|
151
|
-
bulk_responses << bulk_send(body_stream, batch_actions, headers)
|
|
146
|
+
bulk_responses << bulk_send(body_stream, batch_actions)
|
|
152
147
|
body_stream.truncate(0) && body_stream.seek(0)
|
|
153
148
|
stream_writer = gzip_writer(body_stream) if compression_level?
|
|
154
149
|
batch_actions.clear
|
|
@@ -164,14 +159,7 @@ module LogStash; module Outputs; class ElasticSearch;
|
|
|
164
159
|
:payload_size => stream_writer.pos,
|
|
165
160
|
:content_length => body_stream.size,
|
|
166
161
|
:batch_offset => (actions.size - batch_actions.size))
|
|
167
|
-
|
|
168
|
-
if body_stream.size > 0
|
|
169
|
-
headers = {
|
|
170
|
-
EVENT_COUNT_HEADER => batch_actions.size.to_s,
|
|
171
|
-
UNCOMPRESSED_LENGTH_HEADER => stream_writer.pos.to_s
|
|
172
|
-
}
|
|
173
|
-
bulk_responses << bulk_send(body_stream, batch_actions, headers)
|
|
174
|
-
end
|
|
162
|
+
bulk_responses << bulk_send(body_stream, batch_actions) if body_stream.size > 0
|
|
175
163
|
|
|
176
164
|
body_stream.close unless compression_level?
|
|
177
165
|
join_bulk_responses(bulk_responses)
|
|
@@ -191,23 +179,25 @@ module LogStash; module Outputs; class ElasticSearch;
|
|
|
191
179
|
}
|
|
192
180
|
end
|
|
193
181
|
|
|
194
|
-
def bulk_send(body_stream, batch_actions
|
|
195
|
-
params = compression_level? ? {:headers =>
|
|
182
|
+
def bulk_send(body_stream, batch_actions)
|
|
183
|
+
params = compression_level? ? {:headers => {"Content-Encoding" => "gzip"}} : {}
|
|
196
184
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
185
|
+
response = @pool.post(@bulk_path, params, body_stream.string)
|
|
186
|
+
|
|
187
|
+
@bulk_response_metrics.increment(response.code.to_s)
|
|
188
|
+
|
|
189
|
+
case response.code
|
|
190
|
+
when 200 # OK
|
|
191
|
+
LogStash::Json.load(response.body)
|
|
192
|
+
when 413 # Payload Too Large
|
|
204
193
|
logger.warn("Bulk request rejected: `413 Payload Too Large`", :action_count => batch_actions.size, :content_length => body_stream.size)
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
194
|
+
emulate_batch_error_response(batch_actions, response.code, 'payload_too_large')
|
|
195
|
+
else
|
|
196
|
+
url = ::LogStash::Util::SafeURI.new(response.final_url)
|
|
197
|
+
raise ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError.new(
|
|
198
|
+
response.code, url, body_stream.to_s, response.body
|
|
199
|
+
)
|
|
208
200
|
end
|
|
209
|
-
|
|
210
|
-
LogStash::Json.load(response.body)
|
|
211
201
|
end
|
|
212
202
|
|
|
213
203
|
def emulate_batch_error_response(actions, http_code, reason)
|
|
@@ -421,9 +411,6 @@ module LogStash; module Outputs; class ElasticSearch;
|
|
|
421
411
|
def exists?(path, use_get=false)
|
|
422
412
|
response = use_get ? @pool.get(path) : @pool.head(path)
|
|
423
413
|
response.code >= 200 && response.code <= 299
|
|
424
|
-
rescue ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError => e
|
|
425
|
-
return false if e.response_code == 404
|
|
426
|
-
raise e
|
|
427
414
|
end
|
|
428
415
|
|
|
429
416
|
def template_exists?(template_endpoint, name)
|
|
@@ -433,9 +420,7 @@ module LogStash; module Outputs; class ElasticSearch;
|
|
|
433
420
|
def template_put(template_endpoint, name, template)
|
|
434
421
|
path = "#{template_endpoint}/#{name}"
|
|
435
422
|
logger.info("Installing Elasticsearch template", name: name)
|
|
436
|
-
@pool.put(path,
|
|
437
|
-
rescue ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError => e
|
|
438
|
-
raise e unless e.response_code == 404
|
|
423
|
+
@pool.put(path, nil, LogStash::Json.dump(template))
|
|
439
424
|
end
|
|
440
425
|
|
|
441
426
|
# ILM methods
|
|
@@ -447,15 +432,17 @@ module LogStash; module Outputs; class ElasticSearch;
|
|
|
447
432
|
|
|
448
433
|
# Create a new rollover alias
|
|
449
434
|
def rollover_alias_put(alias_name, alias_definition)
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
435
|
+
begin
|
|
436
|
+
@pool.put(CGI::escape(alias_name), nil, LogStash::Json.dump(alias_definition))
|
|
437
|
+
logger.info("Created rollover alias", name: alias_name)
|
|
438
|
+
# If the rollover alias already exists, ignore the error that comes back from Elasticsearch
|
|
439
|
+
rescue ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError => e
|
|
440
|
+
if e.response_code == 400
|
|
441
|
+
logger.info("Rollover alias already exists, skipping", name: alias_name)
|
|
442
|
+
return
|
|
443
|
+
end
|
|
444
|
+
raise e
|
|
457
445
|
end
|
|
458
|
-
raise e
|
|
459
446
|
end
|
|
460
447
|
|
|
461
448
|
def get_xpack_info
|
|
@@ -473,7 +460,7 @@ module LogStash; module Outputs; class ElasticSearch;
|
|
|
473
460
|
def ilm_policy_put(name, policy)
|
|
474
461
|
path = "_ilm/policy/#{name}"
|
|
475
462
|
logger.info("Installing ILM policy #{policy}", name: name)
|
|
476
|
-
@pool.put(path,
|
|
463
|
+
@pool.put(path, nil, LogStash::Json.dump(policy))
|
|
477
464
|
end
|
|
478
465
|
|
|
479
466
|
|
|
@@ -188,38 +188,9 @@ module LogStash; module Outputs; class ElasticSearch;
|
|
|
188
188
|
def self.setup_api_key(logger, params)
|
|
189
189
|
api_key = params["api_key"]
|
|
190
190
|
|
|
191
|
-
return {} unless (api_key
|
|
191
|
+
return {} unless (api_key && api_key.value)
|
|
192
192
|
|
|
193
|
-
|
|
194
|
-
{ "Authorization" => "ApiKey #{token}" }
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
# Resolves the `api_key` value into the credential used in the
|
|
198
|
-
# `Authorization: ApiKey` header. An already base64-encoded key and an Elastic
|
|
199
|
-
# Cloud API key are used as-is; a raw `id:api_key` pair is base64-encoded. An
|
|
200
|
-
# unrecognized value is rejected so a malformed key surfaces at startup rather
|
|
201
|
-
# than as a later authentication failure.
|
|
202
|
-
def self.resolve_api_key(key_value)
|
|
203
|
-
if base64?(key_value) || cloud_api_key?(key_value)
|
|
204
|
-
key_value
|
|
205
|
-
elsif key_value.match?(/\A[^:]+:[^:]+\z/)
|
|
206
|
-
Base64.strict_encode64(key_value)
|
|
207
|
-
else
|
|
208
|
-
raise LogStash::ConfigurationError, "Invalid api_key format. Expected a base64-encoded key, an 'id:api_key' pair, or a Cloud API key (essu_ prefix)."
|
|
209
|
-
end
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
# Elastic Cloud API keys (such as the unified Serverless keys) are opaque
|
|
213
|
-
# tokens prefixed with `essu_` that Elasticsearch accepts verbatim in the
|
|
214
|
-
# `Authorization: ApiKey` header, with no base64 encoding.
|
|
215
|
-
def self.cloud_api_key?(string)
|
|
216
|
-
string.match?(/\Aessu_.+/)
|
|
217
|
-
end
|
|
218
|
-
|
|
219
|
-
def self.base64?(string)
|
|
220
|
-
string == Base64.strict_encode64(Base64.strict_decode64(string))
|
|
221
|
-
rescue ArgumentError
|
|
222
|
-
false
|
|
193
|
+
{ "Authorization" => "ApiKey " + Base64.strict_encode64(api_key.value) }
|
|
223
194
|
end
|
|
224
195
|
|
|
225
196
|
private
|
|
@@ -28,7 +28,6 @@ module LogStash; module Outputs; class ElasticSearch
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
add_ilm_settings_to_template(plugin, template) if plugin.ilm_in_use?
|
|
31
|
-
strip_serverless_incompatible_settings(template) if plugin.serverless?
|
|
32
31
|
plugin.logger.debug("Attempting to install template", template: template)
|
|
33
32
|
install(plugin.client, template_endpoint(plugin), template_name(plugin), template, plugin.template_overwrite)
|
|
34
33
|
end
|
|
@@ -100,7 +99,7 @@ module LogStash; module Outputs; class ElasticSearch
|
|
|
100
99
|
end
|
|
101
100
|
|
|
102
101
|
def self.read_template_file(template_path)
|
|
103
|
-
raise LogStash::ConfigurationError, "Template file '#{template_path}' could not be found" unless ::File.
|
|
102
|
+
raise LogStash::ConfigurationError, "Template file '#{template_path}' could not be found" unless ::File.exists?(template_path)
|
|
104
103
|
template_data = ::IO.read(template_path)
|
|
105
104
|
LogStash::Json.load(template_data)
|
|
106
105
|
rescue => e
|
|
@@ -130,19 +129,5 @@ module LogStash; module Outputs; class ElasticSearch
|
|
|
130
129
|
end
|
|
131
130
|
end
|
|
132
131
|
|
|
133
|
-
SERVERLESS_INCOMPATIBLE_SETTINGS = %w[
|
|
134
|
-
number_of_shards
|
|
135
|
-
index.number_of_shards
|
|
136
|
-
number_of_replicas
|
|
137
|
-
index.number_of_replicas
|
|
138
|
-
].freeze
|
|
139
|
-
|
|
140
|
-
def self.strip_serverless_incompatible_settings(template)
|
|
141
|
-
settings = template.dig('template', 'settings') || template['settings']
|
|
142
|
-
return unless settings
|
|
143
|
-
|
|
144
|
-
SERVERLESS_INCOMPATIBLE_SETTINGS.each { |s| settings.delete(s) }
|
|
145
|
-
end
|
|
146
|
-
|
|
147
132
|
end
|
|
148
133
|
end end end
|
|
@@ -275,7 +275,6 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base
|
|
|
275
275
|
def initialize(*params)
|
|
276
276
|
super
|
|
277
277
|
setup_ecs_compatibility_related_defaults
|
|
278
|
-
setup_ssl_params!
|
|
279
278
|
setup_compression_level!
|
|
280
279
|
end
|
|
281
280
|
|
|
@@ -694,52 +693,6 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base
|
|
|
694
693
|
end
|
|
695
694
|
end
|
|
696
695
|
|
|
697
|
-
def setup_ssl_params!
|
|
698
|
-
@ssl_enabled = normalize_config(:ssl_enabled) do |normalize|
|
|
699
|
-
normalize.with_deprecated_alias(:ssl)
|
|
700
|
-
end
|
|
701
|
-
|
|
702
|
-
@ssl_certificate_authorities = normalize_config(:ssl_certificate_authorities) do |normalize|
|
|
703
|
-
normalize.with_deprecated_mapping(:cacert) do |cacert|
|
|
704
|
-
[cacert]
|
|
705
|
-
end
|
|
706
|
-
end
|
|
707
|
-
|
|
708
|
-
@ssl_keystore_path = normalize_config(:ssl_keystore_path) do |normalize|
|
|
709
|
-
normalize.with_deprecated_alias(:keystore)
|
|
710
|
-
end
|
|
711
|
-
|
|
712
|
-
@ssl_keystore_password = normalize_config(:ssl_keystore_password) do |normalize|
|
|
713
|
-
normalize.with_deprecated_alias(:keystore_password)
|
|
714
|
-
end
|
|
715
|
-
|
|
716
|
-
@ssl_truststore_path = normalize_config(:ssl_truststore_path) do |normalize|
|
|
717
|
-
normalize.with_deprecated_alias(:truststore)
|
|
718
|
-
end
|
|
719
|
-
|
|
720
|
-
@ssl_truststore_password = normalize_config(:ssl_truststore_password) do |normalize|
|
|
721
|
-
normalize.with_deprecated_alias(:truststore_password)
|
|
722
|
-
end
|
|
723
|
-
|
|
724
|
-
@ssl_verification_mode = normalize_config(:ssl_verification_mode) do |normalize|
|
|
725
|
-
normalize.with_deprecated_mapping(:ssl_certificate_verification) do |ssl_certificate_verification|
|
|
726
|
-
if ssl_certificate_verification == true
|
|
727
|
-
"full"
|
|
728
|
-
else
|
|
729
|
-
"none"
|
|
730
|
-
end
|
|
731
|
-
end
|
|
732
|
-
end
|
|
733
|
-
|
|
734
|
-
params['ssl_enabled'] = @ssl_enabled unless @ssl_enabled.nil?
|
|
735
|
-
params['ssl_certificate_authorities'] = @ssl_certificate_authorities unless @ssl_certificate_authorities.nil?
|
|
736
|
-
params['ssl_keystore_path'] = @ssl_keystore_path unless @ssl_keystore_path.nil?
|
|
737
|
-
params['ssl_keystore_password'] = @ssl_keystore_password unless @ssl_keystore_password.nil?
|
|
738
|
-
params['ssl_truststore_path'] = @ssl_truststore_path unless @ssl_truststore_path.nil?
|
|
739
|
-
params['ssl_truststore_password'] = @ssl_truststore_password unless @ssl_truststore_password.nil?
|
|
740
|
-
params['ssl_verification_mode'] = @ssl_verification_mode unless @ssl_verification_mode.nil?
|
|
741
|
-
end
|
|
742
|
-
|
|
743
696
|
def setup_compression_level!
|
|
744
697
|
@compression_level = normalize_config(:compression_level) do |normalize|
|
|
745
698
|
normalize.with_deprecated_mapping(:http_compression) do |http_compression|
|