logstash-input-elasticsearch 4.22.0 → 5.0.0
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 +7 -12
- data/docs/index.asciidoc +19 -233
- data/lib/logstash/inputs/elasticsearch/aggregation.rb +8 -11
- data/lib/logstash/inputs/elasticsearch/paginated_search.rb +2 -12
- data/lib/logstash/inputs/elasticsearch.rb +21 -137
- data/logstash-input-elasticsearch.gemspec +3 -3
- data/spec/fixtures/test_certs/ca.crt +18 -17
- data/spec/fixtures/test_certs/ca.der.sha256 +1 -1
- data/spec/fixtures/test_certs/es.crt +18 -17
- data/spec/inputs/elasticsearch_spec.rb +22 -126
- data/spec/inputs/integration/elasticsearch_spec.rb +2 -10
- metadata +3 -18
- data/lib/logstash/inputs/elasticsearch/cursor_tracker.rb +0 -58
- data/spec/fixtures/test_certs/GENERATED_AT +0 -1
- data/spec/fixtures/test_certs/es.chain.crt +0 -38
- data/spec/fixtures/test_certs/renew.sh +0 -15
- data/spec/inputs/cursor_tracker_spec.rb +0 -72
@@ -13,7 +13,9 @@ require "logstash/plugin_mixins/normalize_config_support"
|
|
13
13
|
require "base64"
|
14
14
|
|
15
15
|
require "elasticsearch"
|
16
|
-
require "manticore"
|
16
|
+
require "elasticsearch/transport/transport/http/manticore"
|
17
|
+
require_relative "elasticsearch/patches/_elasticsearch_transport_http_manticore"
|
18
|
+
require_relative "elasticsearch/patches/_elasticsearch_transport_connections_selector"
|
17
19
|
|
18
20
|
# .Compatibility Note
|
19
21
|
# [NOTE]
|
@@ -73,7 +75,6 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
|
|
73
75
|
|
74
76
|
require 'logstash/inputs/elasticsearch/paginated_search'
|
75
77
|
require 'logstash/inputs/elasticsearch/aggregation'
|
76
|
-
require 'logstash/inputs/elasticsearch/cursor_tracker'
|
77
78
|
|
78
79
|
include LogStash::PluginMixins::ECSCompatibilitySupport(:disabled, :v1, :v8 => :v1)
|
79
80
|
include LogStash::PluginMixins::ECSCompatibilitySupport::TargetCheck
|
@@ -125,20 +126,6 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
|
|
125
126
|
# by this pipeline input.
|
126
127
|
config :slices, :validate => :number
|
127
128
|
|
128
|
-
# Enable tracking the value of a given field to be used as a cursor
|
129
|
-
# Main concerns:
|
130
|
-
# * using anything other than _event.timestamp easily leads to data loss
|
131
|
-
# * the first "synchronization run can take a long time"
|
132
|
-
config :tracking_field, :validate => :string
|
133
|
-
|
134
|
-
# Define the initial seed value of the tracking_field
|
135
|
-
config :tracking_field_seed, :validate => :string, :default => "1970-01-01T00:00:00.000000000Z"
|
136
|
-
|
137
|
-
# The location of where the tracking field value will be stored
|
138
|
-
# The value is persisted after each scheduled run (and not per result)
|
139
|
-
# If it's not set it defaults to '${path.data}/plugins/inputs/elasticsearch/<pipeline_id>/last_run_value'
|
140
|
-
config :last_run_metadata_path, :validate => :string
|
141
|
-
|
142
129
|
# If set, include Elasticsearch document information such as index, type, and
|
143
130
|
# the id in the event.
|
144
131
|
#
|
@@ -214,23 +201,12 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
|
|
214
201
|
# Set the address of a forward HTTP proxy.
|
215
202
|
config :proxy, :validate => :uri_or_empty
|
216
203
|
|
217
|
-
# SSL
|
218
|
-
config :ssl, :validate => :boolean, :default => false, :deprecated => "Set 'ssl_enabled' instead."
|
219
|
-
|
220
|
-
# SSL Certificate Authority file in PEM encoded format, must also include any chain certificates as necessary
|
221
|
-
config :ca_file, :validate => :path, :deprecated => "Set 'ssl_certificate_authorities' instead."
|
222
|
-
|
223
204
|
# OpenSSL-style X.509 certificate certificate to authenticate the client
|
224
205
|
config :ssl_certificate, :validate => :path
|
225
206
|
|
226
207
|
# SSL Certificate Authority files in PEM encoded format, must also include any chain certificates as necessary
|
227
208
|
config :ssl_certificate_authorities, :validate => :path, :list => true
|
228
209
|
|
229
|
-
# Option to validate the server's certificate. Disabling this severely compromises security.
|
230
|
-
# For more information on the importance of certificate verification please read
|
231
|
-
# https://www.cs.utexas.edu/~shmat/shmat_ccs12.pdf
|
232
|
-
config :ssl_certificate_verification, :validate => :boolean, :default => true, :deprecated => "Set 'ssl_verification_mode' instead."
|
233
|
-
|
234
210
|
# The list of cipher suites to use, listed by priorities.
|
235
211
|
# Supported cipher suites vary depending on which version of Java is used.
|
236
212
|
config :ssl_cipher_suites, :validate => :string, :list => true
|
@@ -258,7 +234,6 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
|
|
258
234
|
config :ssl_truststore_password, :validate => :password
|
259
235
|
|
260
236
|
# The JKS truststore to validate the server's certificate.
|
261
|
-
# Use either `:ssl_truststore_path` or `:ssl_certificate_authorities`
|
262
237
|
config :ssl_truststore_path, :validate => :path
|
263
238
|
|
264
239
|
# The format of the truststore file. It must be either jks or pkcs12
|
@@ -277,13 +252,14 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
|
|
277
252
|
# exactly once.
|
278
253
|
config :schedule, :validate => :string
|
279
254
|
|
280
|
-
# Allow scheduled runs to overlap (enabled by default). Setting to false will
|
281
|
-
# only start a new scheduled run after the previous one completes.
|
282
|
-
config :schedule_overlap, :validate => :boolean
|
283
|
-
|
284
255
|
# If set, the _source of each hit will be added nested under the target instead of at the top-level
|
285
256
|
config :target, :validate => :field_reference
|
286
257
|
|
258
|
+
# Obsolete Settings
|
259
|
+
config :ssl, :obsolete => "Set 'ssl_enabled' instead."
|
260
|
+
config :ca_file, :obsolete => "Set 'ssl_certificate_authorities' instead."
|
261
|
+
config :ssl_certificate_verification, :obsolete => "Set 'ssl_verification_mode' instead."
|
262
|
+
|
287
263
|
# config :ca_trusted_fingerprint, :validate => :sha_256_hex
|
288
264
|
include LogStash::PluginMixins::CATrustedFingerprintSupport
|
289
265
|
|
@@ -340,7 +316,7 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
|
|
340
316
|
@client_options = {
|
341
317
|
:hosts => hosts,
|
342
318
|
:transport_options => transport_options,
|
343
|
-
:transport_class =>
|
319
|
+
:transport_class => ::Elasticsearch::Transport::Transport::HTTP::Manticore,
|
344
320
|
:ssl => ssl_options
|
345
321
|
}
|
346
322
|
|
@@ -354,55 +330,26 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
|
|
354
330
|
|
355
331
|
setup_query_executor
|
356
332
|
|
357
|
-
setup_cursor_tracker
|
358
|
-
|
359
333
|
@client
|
360
334
|
end
|
361
335
|
|
362
336
|
def run(output_queue)
|
363
337
|
if @schedule
|
364
|
-
scheduler.cron(@schedule
|
365
|
-
@query_executor.do_run(output_queue, get_query_object())
|
366
|
-
end
|
338
|
+
scheduler.cron(@schedule) { @query_executor.do_run(output_queue) }
|
367
339
|
scheduler.join
|
368
340
|
else
|
369
|
-
@query_executor.do_run(output_queue
|
370
|
-
end
|
371
|
-
end
|
372
|
-
|
373
|
-
def get_query_object
|
374
|
-
if @cursor_tracker
|
375
|
-
query = @cursor_tracker.inject_cursor(@query)
|
376
|
-
@logger.debug("new query is #{query}")
|
377
|
-
else
|
378
|
-
query = @query
|
341
|
+
@query_executor.do_run(output_queue)
|
379
342
|
end
|
380
|
-
LogStash::Json.load(query)
|
381
343
|
end
|
382
344
|
|
383
345
|
##
|
384
346
|
# This can be called externally from the query_executor
|
385
347
|
public
|
386
348
|
def push_hit(hit, output_queue, root_field = '_source')
|
387
|
-
event = event_from_hit(hit, root_field)
|
388
|
-
decorate(event)
|
389
|
-
output_queue << event
|
390
|
-
record_last_value(event)
|
391
|
-
end
|
392
|
-
|
393
|
-
def record_last_value(event)
|
394
|
-
@cursor_tracker.record_last_value(event) if @tracking_field
|
395
|
-
end
|
396
|
-
|
397
|
-
def event_from_hit(hit, root_field)
|
398
349
|
event = targeted_event_factory.new_event hit[root_field]
|
399
350
|
set_docinfo_fields(hit, event) if @docinfo
|
400
|
-
|
401
|
-
event
|
402
|
-
rescue => e
|
403
|
-
serialized_hit = hit.to_json
|
404
|
-
logger.warn("Event creation error, original data now in [event][original] field", message: e.message, exception: e.class, data: serialized_hit)
|
405
|
-
return event_factory.new_event('event' => { 'original' => serialized_hit }, 'tags' => ['_elasticsearch_input_failure'])
|
351
|
+
decorate(event)
|
352
|
+
output_queue << event
|
406
353
|
end
|
407
354
|
|
408
355
|
def set_docinfo_fields(hit, event)
|
@@ -410,8 +357,10 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
|
|
410
357
|
docinfo_target = event.get(@docinfo_target) || {}
|
411
358
|
|
412
359
|
unless docinfo_target.is_a?(Hash)
|
413
|
-
|
414
|
-
|
360
|
+
@logger.error("Incompatible Event, incompatible type for the docinfo_target=#{@docinfo_target} field in the `_source` document, expected a hash got:", :docinfo_target_type => docinfo_target.class, :event => event.to_hash_with_metadata)
|
361
|
+
|
362
|
+
# TODO: (colin) I am not sure raising is a good strategy here?
|
363
|
+
raise Exception.new("Elasticsearch input: incompatible event")
|
415
364
|
end
|
416
365
|
|
417
366
|
@docinfo_fields.each do |field|
|
@@ -456,8 +405,6 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
|
|
456
405
|
ssl_options[:ssl] = true if @ssl_enabled
|
457
406
|
|
458
407
|
unless @ssl_enabled
|
459
|
-
# Keep it backward compatible with the deprecated `ssl` option
|
460
|
-
ssl_options[:trust_strategy] = trust_strategy_for_ca_trusted_fingerprint if original_params.include?('ssl')
|
461
408
|
return ssl_options
|
462
409
|
end
|
463
410
|
|
@@ -521,38 +468,11 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
|
|
521
468
|
end
|
522
469
|
|
523
470
|
def setup_ssl_params!
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
# Infer the value if neither the deprecate `ssl` and `ssl_enabled` were set
|
529
|
-
infer_ssl_enabled_from_hosts
|
530
|
-
|
531
|
-
@ssl_certificate_authorities = normalize_config(:ssl_certificate_authorities) do |normalize|
|
532
|
-
normalize.with_deprecated_mapping(:ca_file) do |ca_file|
|
533
|
-
[ca_file]
|
534
|
-
end
|
471
|
+
# Only infer ssl_enabled if it wasn't explicitly set
|
472
|
+
unless original_params.include?('ssl_enabled')
|
473
|
+
@ssl_enabled = effectively_ssl?
|
474
|
+
params['ssl_enabled'] = @ssl_enabled
|
535
475
|
end
|
536
|
-
|
537
|
-
@ssl_verification_mode = normalize_config(:ssl_verification_mode) do |normalize|
|
538
|
-
normalize.with_deprecated_mapping(:ssl_certificate_verification) do |ssl_certificate_verification|
|
539
|
-
if ssl_certificate_verification == true
|
540
|
-
"full"
|
541
|
-
else
|
542
|
-
"none"
|
543
|
-
end
|
544
|
-
end
|
545
|
-
end
|
546
|
-
|
547
|
-
params['ssl_enabled'] = @ssl_enabled
|
548
|
-
params['ssl_certificate_authorities'] = @ssl_certificate_authorities unless @ssl_certificate_authorities.nil?
|
549
|
-
params['ssl_verification_mode'] = @ssl_verification_mode unless @ssl_verification_mode.nil?
|
550
|
-
end
|
551
|
-
|
552
|
-
def infer_ssl_enabled_from_hosts
|
553
|
-
return if original_params.include?('ssl') || original_params.include?('ssl_enabled')
|
554
|
-
|
555
|
-
@ssl_enabled = params['ssl_enabled'] = effectively_ssl?
|
556
476
|
end
|
557
477
|
|
558
478
|
def setup_hosts
|
@@ -714,42 +634,6 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
|
|
714
634
|
end
|
715
635
|
end
|
716
636
|
|
717
|
-
def setup_cursor_tracker
|
718
|
-
return unless @tracking_field
|
719
|
-
return unless @query_executor.is_a?(LogStash::Inputs::Elasticsearch::SearchAfter)
|
720
|
-
|
721
|
-
if @resolved_search_api != "search_after" || @response_type != "hits"
|
722
|
-
raise ConfigurationError.new("The `tracking_field` feature can only be used with `search_after` non-aggregation queries")
|
723
|
-
end
|
724
|
-
|
725
|
-
@cursor_tracker = CursorTracker.new(last_run_metadata_path: last_run_metadata_path,
|
726
|
-
tracking_field: @tracking_field,
|
727
|
-
tracking_field_seed: @tracking_field_seed)
|
728
|
-
@query_executor.cursor_tracker = @cursor_tracker
|
729
|
-
end
|
730
|
-
|
731
|
-
def last_run_metadata_path
|
732
|
-
return @last_run_metadata_path if @last_run_metadata_path
|
733
|
-
|
734
|
-
last_run_metadata_path = ::File.join(LogStash::SETTINGS.get_value("path.data"), "plugins", "inputs", "elasticsearch", pipeline_id, "last_run_value")
|
735
|
-
FileUtils.mkdir_p ::File.dirname(last_run_metadata_path)
|
736
|
-
last_run_metadata_path
|
737
|
-
end
|
738
|
-
|
739
|
-
def get_transport_client_class
|
740
|
-
# LS-core includes `elasticsearch` gem. The gem is composed of two separate gems: `elasticsearch-api` and `elasticsearch-transport`
|
741
|
-
# And now `elasticsearch-transport` is old, instead we have `elastic-transport`.
|
742
|
-
# LS-core updated `elasticsearch` > 8: https://github.com/elastic/logstash/pull/17161
|
743
|
-
# Following source bits are for the compatibility to support both `elasticsearch-transport` and `elastic-transport` gems
|
744
|
-
require "elasticsearch/transport/transport/http/manticore"
|
745
|
-
require_relative "elasticsearch/patches/_elasticsearch_transport_http_manticore"
|
746
|
-
require_relative "elasticsearch/patches/_elasticsearch_transport_connections_selector"
|
747
|
-
::Elasticsearch::Transport::Transport::HTTP::Manticore
|
748
|
-
rescue ::LoadError
|
749
|
-
require "elastic/transport/transport/http/manticore"
|
750
|
-
::Elastic::Transport::Transport::HTTP::Manticore
|
751
|
-
end
|
752
|
-
|
753
637
|
module URIOrEmptyValidator
|
754
638
|
##
|
755
639
|
# @override to provide :uri_or_empty validator
|
@@ -1,13 +1,13 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-input-elasticsearch'
|
4
|
-
s.version = '
|
4
|
+
s.version = '5.0.0'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "Reads query results from an Elasticsearch cluster"
|
7
7
|
s.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"
|
8
8
|
s.authors = ["Elastic"]
|
9
9
|
s.email = 'info@elastic.co'
|
10
|
-
s.homepage = "
|
10
|
+
s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
|
11
11
|
s.require_paths = ["lib"]
|
12
12
|
|
13
13
|
# Files
|
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.add_runtime_dependency "logstash-mixin-validator_support", '~> 1.0'
|
27
27
|
s.add_runtime_dependency "logstash-mixin-scheduler", '~> 1.0'
|
28
28
|
|
29
|
-
s.add_runtime_dependency 'elasticsearch', '>= 7.17.9'
|
29
|
+
s.add_runtime_dependency 'elasticsearch', '>= 7.17.9'
|
30
30
|
s.add_runtime_dependency 'logstash-mixin-ca_trusted_fingerprint_support', '~> 1.0'
|
31
31
|
s.add_runtime_dependency 'logstash-mixin-normalize_config_support', '~>1.0'
|
32
32
|
|
@@ -1,19 +1,20 @@
|
|
1
1
|
-----BEGIN CERTIFICATE-----
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
2
|
+
MIIDSTCCAjGgAwIBAgIUUcAg9c8B8jiliCkOEJyqoAHrmccwDQYJKoZIhvcNAQEL
|
3
|
+
BQAwNDEyMDAGA1UEAxMpRWxhc3RpYyBDZXJ0aWZpY2F0ZSBUb29sIEF1dG9nZW5l
|
4
|
+
cmF0ZWQgQ0EwHhcNMjEwODEyMDUxNDU1WhcNMjQwODExMDUxNDU1WjA0MTIwMAYD
|
5
|
+
VQQDEylFbGFzdGljIENlcnRpZmljYXRlIFRvb2wgQXV0b2dlbmVyYXRlZCBDQTCC
|
6
|
+
ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAK1HuusRuGNsztd4EQvqwcMr
|
7
|
+
8XvnNNa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b+a/OndG90z+dTwhShW
|
15
|
+
f0oZdIe/1rDCdiRU4ceCZA4ybKrFDIbW8gOKZOx9rsgEx9XNELj4ocZTBqxjQmNE
|
16
|
+
Ho91fli5aEm0EL2vJgejh4hcfDeElQ6go9gtvAHQ57XEADQSenvt69jOICOupnS+
|
17
|
+
LSjDVhv/VLi3CAip0B+lD5fX/DVQdrJ62eRGuQYxoouE3saCO58qUUrKB39yD9KA
|
18
|
+
qRA/sVxyLogxaU+5dLfc0NJdOqSzStxQ2vdMvAWo9tZZ2UBGFrk5SdwCQe7Yv5mX
|
19
|
+
qi02i4q6meHGcw==
|
19
20
|
-----END CERTIFICATE-----
|
@@ -21,13 +21,6 @@ describe LogStash::Inputs::Elasticsearch, :ecs_compatibility_support do
|
|
21
21
|
let(:es_version) { "7.5.0" }
|
22
22
|
let(:cluster_info) { {"version" => {"number" => es_version, "build_flavor" => build_flavor}, "tagline" => "You Know, for Search"} }
|
23
23
|
|
24
|
-
def elastic_ruby_v8_client_available?
|
25
|
-
Elasticsearch::Transport
|
26
|
-
false
|
27
|
-
rescue NameError # NameError: uninitialized constant Elasticsearch::Transport if Elastic Ruby client is not available
|
28
|
-
true
|
29
|
-
end
|
30
|
-
|
31
24
|
before(:each) do
|
32
25
|
Elasticsearch::Client.send(:define_method, :ping) { } # define no-action ping method
|
33
26
|
allow_any_instance_of(Elasticsearch::Client).to receive(:info).and_return(cluster_info)
|
@@ -65,6 +58,19 @@ describe LogStash::Inputs::Elasticsearch, :ecs_compatibility_support do
|
|
65
58
|
end
|
66
59
|
end
|
67
60
|
|
61
|
+
describe 'handling obsolete settings' do
|
62
|
+
[{:name => 'ssl', :replacement => 'ssl_enabled', :sample_value => true},
|
63
|
+
{:name => 'ca_file', :replacement => 'ssl_certificate_authorities', :sample_value => 'spec/fixtures/test_certs/ca.crt'},
|
64
|
+
{:name => 'ssl_certificate_verification', :replacement => 'ssl_verification_mode', :sample_value => false }].each do | obsolete_setting|
|
65
|
+
context "with obsolete #{obsolete_setting[:name]}" do
|
66
|
+
let (:config) { {obsolete_setting[:name] => obsolete_setting[:sample_value]} }
|
67
|
+
it "should raise a config error with the appropriate message" do
|
68
|
+
expect { plugin.register }.to raise_error LogStash::ConfigurationError, /The setting `#{obsolete_setting[:name]}` in plugin `elasticsearch` is obsolete and is no longer available. Set '#{obsolete_setting[:replacement]}' instead/i
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
68
74
|
context "against not authentic Elasticsearch" do
|
69
75
|
before(:each) do
|
70
76
|
Elasticsearch::Client.send(:define_method, :ping) { raise Elasticsearch::UnsupportedProductError.new("Fake error") } # define error ping method
|
@@ -86,11 +92,9 @@ describe LogStash::Inputs::Elasticsearch, :ecs_compatibility_support do
|
|
86
92
|
|
87
93
|
before do
|
88
94
|
allow(Elasticsearch::Client).to receive(:new).and_return(es_client)
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
allow(es_client).to receive(:info).and_raise(Elasticsearch::Transport::Transport::Errors::BadRequest.new)
|
93
|
-
end
|
95
|
+
allow(es_client).to receive(:info).and_raise(
|
96
|
+
Elasticsearch::Transport::Transport::Errors::BadRequest.new
|
97
|
+
)
|
94
98
|
end
|
95
99
|
|
96
100
|
it "raises an exception" do
|
@@ -662,28 +666,11 @@ describe LogStash::Inputs::Elasticsearch, :ecs_compatibility_support do
|
|
662
666
|
context 'if the `docinfo_target` exist but is not of type hash' do
|
663
667
|
let(:config) { base_config.merge 'docinfo' => true, "docinfo_target" => 'metadata_with_string' }
|
664
668
|
let(:do_register) { false }
|
665
|
-
let(:mock_queue) { double('Queue', :<< => nil) }
|
666
|
-
let(:hit) { response.dig('hits', 'hits').first }
|
667
|
-
|
668
|
-
it 'emits a tagged event with JSON-serialized event in [event][original]' do
|
669
|
-
allow(plugin).to receive(:logger).and_return(double('Logger').as_null_object)
|
670
669
|
|
670
|
+
it 'raises an exception if the `docinfo_target` exist but is not of type hash' do
|
671
|
+
expect(client).not_to receive(:clear_scroll)
|
671
672
|
plugin.register
|
672
|
-
plugin.run(
|
673
|
-
|
674
|
-
expect(mock_queue).to have_received(:<<) do |event|
|
675
|
-
expect(event).to be_a_kind_of LogStash::Event
|
676
|
-
|
677
|
-
expect(event.get('tags')).to include("_elasticsearch_input_failure")
|
678
|
-
expect(event.get('[event][original]')).to be_a_kind_of String
|
679
|
-
expect(JSON.load(event.get('[event][original]'))).to eq hit
|
680
|
-
end
|
681
|
-
|
682
|
-
expect(plugin.logger)
|
683
|
-
.to have_received(:warn).with(
|
684
|
-
a_string_including("Event creation error, original data now in [event][original] field"),
|
685
|
-
a_hash_including(:message => a_string_including('unable to merge docinfo fields into docinfo_target=`metadata_with_string`'),
|
686
|
-
:data => a_string_including('"_id":"C5b2xLQwTZa76jBmHIbwHQ"')))
|
673
|
+
expect { plugin.run([]) }.to raise_error(Exception, /incompatible event/)
|
687
674
|
end
|
688
675
|
|
689
676
|
end
|
@@ -740,13 +727,8 @@ describe LogStash::Inputs::Elasticsearch, :ecs_compatibility_support do
|
|
740
727
|
it "should set host(s)" do
|
741
728
|
plugin.register
|
742
729
|
client = plugin.send(:client)
|
743
|
-
|
744
|
-
|
745
|
-
Elasticsearch::Transport::Client
|
746
|
-
rescue
|
747
|
-
target_field = :@hosts
|
748
|
-
end
|
749
|
-
expect( client.transport.instance_variable_get(target_field) ).to eql [{
|
730
|
+
|
731
|
+
expect( client.transport.instance_variable_get(:@seeds) ).to eql [{
|
750
732
|
:scheme => "https",
|
751
733
|
:host => "ac31ebb90241773157043c34fd26fd46.us-central1.gcp.cloud.es.io",
|
752
734
|
:port => 9243,
|
@@ -1152,7 +1134,7 @@ describe LogStash::Inputs::Elasticsearch, :ecs_compatibility_support do
|
|
1152
1134
|
|
1153
1135
|
context "when there's an exception" do
|
1154
1136
|
before(:each) do
|
1155
|
-
allow(client).to receive(:search).and_raise RuntimeError
|
1137
|
+
allow(client).to receive(:search).and_raise RuntimeError
|
1156
1138
|
end
|
1157
1139
|
it 'produces no events' do
|
1158
1140
|
plugin.run queue
|
@@ -1266,92 +1248,6 @@ describe LogStash::Inputs::Elasticsearch, :ecs_compatibility_support do
|
|
1266
1248
|
end
|
1267
1249
|
end
|
1268
1250
|
|
1269
|
-
context '#push_hit' do
|
1270
|
-
let(:config) do
|
1271
|
-
{
|
1272
|
-
'docinfo' => true, # include ids
|
1273
|
-
'docinfo_target' => '[@metadata][docinfo]'
|
1274
|
-
}
|
1275
|
-
end
|
1276
|
-
|
1277
|
-
let(:hit) do
|
1278
|
-
JSON.load(<<~EOJSON)
|
1279
|
-
{
|
1280
|
-
"_index" : "test_bulk_index_2",
|
1281
|
-
"_type" : "_doc",
|
1282
|
-
"_id" : "sHe6A3wBesqF7ydicQvG",
|
1283
|
-
"_score" : 1.0,
|
1284
|
-
"_source" : {
|
1285
|
-
"@timestamp" : "2021-09-20T15:02:02.557Z",
|
1286
|
-
"message" : "ping",
|
1287
|
-
"@version" : "17",
|
1288
|
-
"sequence" : 7,
|
1289
|
-
"host" : {
|
1290
|
-
"name" : "maybe.local",
|
1291
|
-
"ip" : "127.0.0.1"
|
1292
|
-
}
|
1293
|
-
}
|
1294
|
-
}
|
1295
|
-
EOJSON
|
1296
|
-
end
|
1297
|
-
|
1298
|
-
let(:mock_queue) { double('queue', :<< => nil) }
|
1299
|
-
|
1300
|
-
before(:each) do
|
1301
|
-
plugin.send(:setup_cursor_tracker)
|
1302
|
-
end
|
1303
|
-
|
1304
|
-
it 'pushes a generated event to the queue' do
|
1305
|
-
plugin.send(:push_hit, hit, mock_queue)
|
1306
|
-
expect(mock_queue).to have_received(:<<) do |event|
|
1307
|
-
expect(event).to be_a_kind_of LogStash::Event
|
1308
|
-
|
1309
|
-
# fields overriding defaults
|
1310
|
-
expect(event.timestamp.to_s).to eq("2021-09-20T15:02:02.557Z")
|
1311
|
-
expect(event.get('@version')).to eq("17")
|
1312
|
-
|
1313
|
-
# structure from hit's _source
|
1314
|
-
expect(event.get('message')).to eq("ping")
|
1315
|
-
expect(event.get('sequence')).to eq(7)
|
1316
|
-
expect(event.get('[host][name]')).to eq("maybe.local")
|
1317
|
-
expect(event.get('[host][ip]')).to eq("127.0.0.1")
|
1318
|
-
|
1319
|
-
# docinfo fields
|
1320
|
-
expect(event.get('[@metadata][docinfo][_index]')).to eq("test_bulk_index_2")
|
1321
|
-
expect(event.get('[@metadata][docinfo][_type]')).to eq("_doc")
|
1322
|
-
expect(event.get('[@metadata][docinfo][_id]')).to eq("sHe6A3wBesqF7ydicQvG")
|
1323
|
-
end
|
1324
|
-
end
|
1325
|
-
|
1326
|
-
context 'when event creation fails' do
|
1327
|
-
before(:each) do
|
1328
|
-
allow(plugin).to receive(:logger).and_return(double('Logger').as_null_object)
|
1329
|
-
|
1330
|
-
allow(plugin.event_factory).to receive(:new_event).and_call_original
|
1331
|
-
allow(plugin.event_factory).to receive(:new_event).with(a_hash_including hit['_source']).and_raise(RuntimeError, 'intentional')
|
1332
|
-
end
|
1333
|
-
|
1334
|
-
it 'pushes a tagged event containing a JSON-encoded hit in [event][original]' do
|
1335
|
-
plugin.send(:push_hit, hit, mock_queue)
|
1336
|
-
|
1337
|
-
expect(mock_queue).to have_received(:<<) do |event|
|
1338
|
-
expect(event).to be_a_kind_of LogStash::Event
|
1339
|
-
|
1340
|
-
expect(event.get('tags')).to include("_elasticsearch_input_failure")
|
1341
|
-
expect(event.get('[event][original]')).to be_a_kind_of String
|
1342
|
-
expect(JSON.load(event.get('[event][original]'))).to eq hit
|
1343
|
-
end
|
1344
|
-
|
1345
|
-
expect(plugin.logger)
|
1346
|
-
.to have_received(:warn).with(
|
1347
|
-
a_string_including("Event creation error, original data now in [event][original] field"),
|
1348
|
-
a_hash_including(:message => a_string_including('intentional'),
|
1349
|
-
:data => a_string_including('"_id":"sHe6A3wBesqF7ydicQvG"')))
|
1350
|
-
|
1351
|
-
end
|
1352
|
-
end
|
1353
|
-
end
|
1354
|
-
|
1355
1251
|
# @note can be removed once we depends on elasticsearch gem >= 6.x
|
1356
1252
|
def extract_transport(client) # on 7.x client.transport is a ES::Transport::Client
|
1357
1253
|
client.transport.respond_to?(:transport) ? client.transport.transport : client.transport
|
@@ -4,7 +4,7 @@ require "logstash/plugin"
|
|
4
4
|
require "logstash/inputs/elasticsearch"
|
5
5
|
require_relative "../../../spec/es_helper"
|
6
6
|
|
7
|
-
describe LogStash::Inputs::Elasticsearch do
|
7
|
+
describe LogStash::Inputs::Elasticsearch, :integration => true do
|
8
8
|
|
9
9
|
SECURE_INTEGRATION = ENV['SECURE_INTEGRATION'].eql? 'true'
|
10
10
|
|
@@ -76,14 +76,6 @@ describe LogStash::Inputs::Elasticsearch do
|
|
76
76
|
shared_examples 'secured_elasticsearch' do
|
77
77
|
it_behaves_like 'an elasticsearch index plugin'
|
78
78
|
|
79
|
-
let(:unauth_exception_class) do
|
80
|
-
begin
|
81
|
-
Elasticsearch::Transport::Transport::Errors::Unauthorized
|
82
|
-
rescue
|
83
|
-
Elastic::Transport::Transport::Errors::Unauthorized
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
79
|
context "incorrect auth credentials" do
|
88
80
|
|
89
81
|
let(:config) do
|
@@ -93,7 +85,7 @@ describe LogStash::Inputs::Elasticsearch do
|
|
93
85
|
let(:queue) { [] }
|
94
86
|
|
95
87
|
it "fails to run the plugin" do
|
96
|
-
expect { plugin.register }.to raise_error
|
88
|
+
expect { plugin.register }.to raise_error Elasticsearch::Transport::Transport::Errors::Unauthorized
|
97
89
|
end
|
98
90
|
end
|
99
91
|
end
|