logstash-input-elasticsearch 4.9.0 → 4.10.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.
data/spec/es_helper.rb CHANGED
@@ -1,30 +1,31 @@
1
1
  module ESHelper
2
2
  def self.get_host_port
3
- return "elasticsearch:9200" if ENV["INTEGRATION"] == "true" || ENV["SECURE_INTEGRATION"] == "true"
4
- raise "This setting is only used for integration tests"
3
+ if ENV["INTEGRATION"] == "true" || ENV["SECURE_INTEGRATION"] == "true"
4
+ "elasticsearch:9200"
5
+ else
6
+ "localhost:9200" # for local running integration specs outside docker
7
+ end
5
8
  end
6
9
 
7
- def self.get_client(options = {})
8
- ssl_options = {}
9
- hosts = [get_host_port]
10
+ def self.get_client(options)
11
+ require 'elasticsearch/transport/transport/http/faraday' # supports user/password options
12
+ host, port = get_host_port.split(':')
13
+ host_opts = { host: host, port: port, scheme: 'http' }
14
+ ssl_opts = {}
10
15
 
11
16
  if options[:ca_file]
12
- ssl_options = { :ssl => true, :ca_file => options[:ca_file] }
13
- hosts.map! do |h|
14
- host, port = h.split(":")
15
- { :host => host, :scheme => 'https', :port => port }
16
- end
17
+ ssl_opts = { ca_file: options[:ca_file], version: 'TLSv1.2', verify: false }
18
+ host_opts[:scheme] = 'https'
17
19
  end
18
20
 
19
- transport_options = {}
20
-
21
21
  if options[:user] && options[:password]
22
- token = Base64.strict_encode64("#{options[:user]}:#{options[:password]}")
23
- transport_options[:headers] = { :Authorization => "Basic #{token}" }
22
+ host_opts[:user] = options[:user]
23
+ host_opts[:password] = options[:password]
24
24
  end
25
25
 
26
- @client = Elasticsearch::Client.new(:hosts => hosts, :transport_options => transport_options, :ssl => ssl_options,
27
- :transport_class => ::Elasticsearch::Transport::Transport::HTTP::Manticore)
26
+ Elasticsearch::Client.new(hosts: [host_opts],
27
+ transport_options: { ssl: ssl_opts },
28
+ transport_class: Elasticsearch::Transport::Transport::HTTP::Faraday)
28
29
  end
29
30
 
30
31
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eKvEidlIp0gvRAoGAAurz4zYvW2QhXaR2hhaT
19
+ p2XSLXiKM8AUndo3rH3U0/lhrvrEZicZsMj2LF88xg20U27sIaD/eJo13Y4XqaPk
20
+ ykPY6D9srv574SeIeMpx/8PxPiBcoDd+BNc0L1VkgVBoouORAwq5I9HjKKBjdEmI
21
+ UDw3i0X5KYvDm6fXVAZ0HXUCgYBWc4To8KiXPqNpq2sVzrSkBaWJSmj2G7u7Q6b/
22
+ RTs3is72v3gjHG6iiaE5URY7mnu4rjlRhAP9Vnsy6uHMrCJZEBTf/sPEYHZj9iGZ
23
+ EOduOAF3U1tsmaaebbDtm8hdhSOBvITy9kQlSIZAt1r17Ulytz5pj0AySFzJUIkz
24
+ a0SZkQKBgCWixtUxiK8PAdWhyS++90WJeJn8eqjuSAz+VMtFQFRRWDUbkiHvGMRu
25
+ o/Hhk6zS46gSF2Evb1d26uUEenXnJlIp6YWzb0DLPrfy5P53kPA6YEvYq5MSAg3l
26
+ DZOJUF+ko7cWXSZkeTIBH/jrGOdP4tTALZt6DNt+Gz7xwPO5tGgV
27
+ -----END RSA PRIVATE KEY-----
@@ -8,13 +8,11 @@ require "stud/temporary"
8
8
  require "time"
9
9
  require "date"
10
10
 
11
- class LogStash::Inputs::TestableElasticsearch < LogStash::Inputs::Elasticsearch
12
- attr_reader :client
13
- end
11
+ require 'logstash/plugin_mixins/ecs_compatibility_support/spec_helper'
14
12
 
15
- describe LogStash::Inputs::TestableElasticsearch do
13
+ describe LogStash::Inputs::Elasticsearch, :ecs_compatibility_support do
16
14
 
17
- let(:plugin) { LogStash::Inputs::TestableElasticsearch.new(config) }
15
+ let(:plugin) { described_class.new(config) }
18
16
  let(:queue) { Queue.new }
19
17
 
20
18
  it_behaves_like "an interruptible input plugin" do
@@ -40,7 +38,13 @@ describe LogStash::Inputs::TestableElasticsearch do
40
38
  end
41
39
  end
42
40
 
43
- context 'creating events from Elasticsearch' do
41
+
42
+ ecs_compatibility_matrix(:disabled, :v1, :v8) do |ecs_select|
43
+
44
+ before(:each) do
45
+ allow_any_instance_of(described_class).to receive(:ecs_compatibility).and_return(ecs_compatibility)
46
+ end
47
+
44
48
  let(:config) do
45
49
  %q[
46
50
  input {
@@ -97,7 +101,6 @@ describe LogStash::Inputs::TestableElasticsearch do
97
101
  end
98
102
 
99
103
  expect(event).to be_a(LogStash::Event)
100
- puts event.to_hash_with_metadata
101
104
  expect(event.get("message")).to eql [ "ohayo" ]
102
105
  end
103
106
 
@@ -120,10 +123,10 @@ describe LogStash::Inputs::TestableElasticsearch do
120
123
  end
121
124
 
122
125
  expect(event).to be_a(LogStash::Event)
123
- puts event.to_hash_with_metadata
124
126
  expect(event.get("[@metadata][_source][message]")).to eql [ "ohayo" ]
125
127
  end
126
128
  end
129
+
127
130
  end
128
131
 
129
132
  # This spec is an adapter-spec, ensuring that we send the right sequence of messages to our Elasticsearch Client
@@ -135,6 +138,7 @@ describe LogStash::Inputs::TestableElasticsearch do
135
138
  'query' => "#{LogStash::Json.dump(query)}",
136
139
  'slices' => slices,
137
140
  'docinfo' => true, # include ids
141
+ 'docinfo_target' => '[@metadata]'
138
142
  }
139
143
  end
140
144
  let(:query) do
@@ -166,7 +170,7 @@ describe LogStash::Inputs::TestableElasticsearch do
166
170
  end
167
171
 
168
172
  context 'without slices directive' do
169
- let(:config) { super.tap { |h| h.delete('slices') } }
173
+ let(:config) { super().tap { |h| h.delete('slices') } }
170
174
  it 'runs just one slice' do
171
175
  expect(plugin).to receive(:do_run_slice).with(duck_type(:<<))
172
176
  expect(Thread).to_not receive(:new)
@@ -405,127 +409,140 @@ describe LogStash::Inputs::TestableElasticsearch do
405
409
  allow(client).to receive(:clear_scroll).and_return(nil)
406
410
  end
407
411
 
408
- context 'when defining docinfo' do
409
- let(:config_metadata) do
410
- %q[
411
- input {
412
- elasticsearch {
413
- hosts => ["localhost"]
414
- query => '{ "query": { "match": { "city_name": "Okinawa" } }, "fields": ["message"] }'
415
- docinfo => true
416
- }
417
- }
418
- ]
419
- end
412
+ ecs_compatibility_matrix(:disabled, :v1, :v8) do |ecs_select|
420
413
 
421
- it 'merges the values if the `docinfo_target` already exist in the `_source` document' do
422
- config_metadata_with_hash = %Q[
423
- input {
424
- elasticsearch {
425
- hosts => ["localhost"]
426
- query => '{ "query": { "match": { "city_name": "Okinawa" } }, "fields": ["message"] }'
427
- docinfo => true
428
- docinfo_target => 'metadata_with_hash'
414
+ before(:each) do
415
+ allow_any_instance_of(described_class).to receive(:ecs_compatibility).and_return(ecs_compatibility)
416
+ end
417
+
418
+ context 'with docinfo enabled' do
419
+ let(:config_metadata) do
420
+ %q[
421
+ input {
422
+ elasticsearch {
423
+ hosts => ["localhost"]
424
+ query => '{ "query": { "match": { "city_name": "Okinawa" } }, "fields": ["message"] }'
425
+ docinfo => true
426
+ }
429
427
  }
430
- }
431
- ]
432
-
433
- event = input(config_metadata_with_hash) do |pipeline, queue|
434
- queue.pop
428
+ ]
435
429
  end
436
430
 
437
- expect(event.get("[metadata_with_hash][_index]")).to eq('logstash-2014.10.12')
438
- expect(event.get("[metadata_with_hash][_type]")).to eq('logs')
439
- expect(event.get("[metadata_with_hash][_id]")).to eq('C5b2xLQwTZa76jBmHIbwHQ')
440
- expect(event.get("[metadata_with_hash][awesome]")).to eq("logstash")
441
- end
442
-
443
- context 'if the `docinfo_target` exist but is not of type hash' do
444
- let (:config) { {
445
- "hosts" => ["localhost"],
446
- "query" => '{ "query": { "match": { "city_name": "Okinawa" } }, "fields": ["message"] }',
447
- "docinfo" => true,
448
- "docinfo_target" => 'metadata_with_string'
449
- } }
450
- it 'thows an exception if the `docinfo_target` exist but is not of type hash' do
451
- expect(client).not_to receive(:clear_scroll)
452
- plugin.register
453
- expect { plugin.run([]) }.to raise_error(Exception, /incompatible event/)
431
+ it "provides document info under metadata" do
432
+ event = input(config_metadata) do |pipeline, queue|
433
+ queue.pop
434
+ end
435
+
436
+ if ecs_select.active_mode == :disabled
437
+ expect(event.get("[@metadata][_index]")).to eq('logstash-2014.10.12')
438
+ expect(event.get("[@metadata][_type]")).to eq('logs')
439
+ expect(event.get("[@metadata][_id]")).to eq('C5b2xLQwTZa76jBmHIbwHQ')
440
+ else
441
+ expect(event.get("[@metadata][input][elasticsearch][_index]")).to eq('logstash-2014.10.12')
442
+ expect(event.get("[@metadata][input][elasticsearch][_type]")).to eq('logs')
443
+ expect(event.get("[@metadata][input][elasticsearch][_id]")).to eq('C5b2xLQwTZa76jBmHIbwHQ')
444
+ end
454
445
  end
455
- end
456
446
 
457
- it "should move the document info to the @metadata field" do
458
- event = input(config_metadata) do |pipeline, queue|
459
- queue.pop
447
+ it 'merges values if the `docinfo_target` already exist in the `_source` document' do
448
+ config_metadata_with_hash = %Q[
449
+ input {
450
+ elasticsearch {
451
+ hosts => ["localhost"]
452
+ query => '{ "query": { "match": { "city_name": "Okinawa" } }, "fields": ["message"] }'
453
+ docinfo => true
454
+ docinfo_target => 'metadata_with_hash'
455
+ }
456
+ }
457
+ ]
458
+
459
+ event = input(config_metadata_with_hash) do |pipeline, queue|
460
+ queue.pop
461
+ end
462
+
463
+ expect(event.get("[metadata_with_hash][_index]")).to eq('logstash-2014.10.12')
464
+ expect(event.get("[metadata_with_hash][_type]")).to eq('logs')
465
+ expect(event.get("[metadata_with_hash][_id]")).to eq('C5b2xLQwTZa76jBmHIbwHQ')
466
+ expect(event.get("[metadata_with_hash][awesome]")).to eq("logstash")
460
467
  end
461
468
 
462
- expect(event.get("[@metadata][_index]")).to eq('logstash-2014.10.12')
463
- expect(event.get("[@metadata][_type]")).to eq('logs')
464
- expect(event.get("[@metadata][_id]")).to eq('C5b2xLQwTZa76jBmHIbwHQ')
465
- end
469
+ context 'if the `docinfo_target` exist but is not of type hash' do
470
+ let (:config) { {
471
+ "hosts" => ["localhost"],
472
+ "query" => '{ "query": { "match": { "city_name": "Okinawa" } }, "fields": ["message"] }',
473
+ "docinfo" => true,
474
+ "docinfo_target" => 'metadata_with_string'
475
+ } }
476
+ it 'thows an exception if the `docinfo_target` exist but is not of type hash' do
477
+ expect(client).not_to receive(:clear_scroll)
478
+ plugin.register
479
+ expect { plugin.run([]) }.to raise_error(Exception, /incompatible event/)
480
+ end
481
+ end
466
482
 
467
- it 'should move the document information to the specified field' do
468
- config = %q[
469
- input {
470
- elasticsearch {
471
- hosts => ["localhost"]
472
- query => '{ "query": { "match": { "city_name": "Okinawa" } }, "fields": ["message"] }'
473
- docinfo => true
474
- docinfo_target => 'meta'
483
+ it 'should move the document information to the specified field' do
484
+ config = %q[
485
+ input {
486
+ elasticsearch {
487
+ hosts => ["localhost"]
488
+ query => '{ "query": { "match": { "city_name": "Okinawa" } }, "fields": ["message"] }'
489
+ docinfo => true
490
+ docinfo_target => 'meta'
491
+ }
475
492
  }
476
- }
477
- ]
478
- event = input(config) do |pipeline, queue|
479
- queue.pop
493
+ ]
494
+ event = input(config) do |pipeline, queue|
495
+ queue.pop
496
+ end
497
+
498
+ expect(event.get("[meta][_index]")).to eq('logstash-2014.10.12')
499
+ expect(event.get("[meta][_type]")).to eq('logs')
500
+ expect(event.get("[meta][_id]")).to eq('C5b2xLQwTZa76jBmHIbwHQ')
480
501
  end
481
502
 
482
- expect(event.get("[meta][_index]")).to eq('logstash-2014.10.12')
483
- expect(event.get("[meta][_type]")).to eq('logs')
484
- expect(event.get("[meta][_id]")).to eq('C5b2xLQwTZa76jBmHIbwHQ')
485
- end
503
+ it "allows to specify which fields from the document info to save to metadata" do
504
+ fields = ["_index"]
505
+ config = %Q[
506
+ input {
507
+ elasticsearch {
508
+ hosts => ["localhost"]
509
+ query => '{ "query": { "match": { "city_name": "Okinawa" } }, "fields": ["message"] }'
510
+ docinfo => true
511
+ docinfo_fields => #{fields}
512
+ }
513
+ }]
514
+
515
+ event = input(config) do |pipeline, queue|
516
+ queue.pop
517
+ end
518
+
519
+ meta_base = event.get(ecs_select.active_mode == :disabled ? "@metadata" : "[@metadata][input][elasticsearch]")
520
+ expect(meta_base.keys).to eq(fields)
521
+ end
486
522
 
487
- it "should allow to specify which fields from the document info to save to the @metadata field" do
488
- fields = ["_index"]
489
- config = %Q[
523
+ it 'should be able to reference metadata fields in `add_field` decorations' do
524
+ config = %q[
490
525
  input {
491
526
  elasticsearch {
492
527
  hosts => ["localhost"]
493
528
  query => '{ "query": { "match": { "city_name": "Okinawa" } }, "fields": ["message"] }'
494
529
  docinfo => true
495
- docinfo_fields => #{fields}
496
- }
497
- }]
498
-
499
- event = input(config) do |pipeline, queue|
500
- queue.pop
501
- end
502
-
503
- expect(event.get("@metadata").keys).to eq(fields)
504
- expect(event.get("[@metadata][_type]")).to eq(nil)
505
- expect(event.get("[@metadata][_index]")).to eq('logstash-2014.10.12')
506
- expect(event.get("[@metadata][_id]")).to eq(nil)
507
- end
508
-
509
- it 'should be able to reference metadata fields in `add_field` decorations' do
510
- config = %q[
511
- input {
512
- elasticsearch {
513
- hosts => ["localhost"]
514
- query => '{ "query": { "match": { "city_name": "Okinawa" } }, "fields": ["message"] }'
515
- docinfo => true
516
- add_field => {
517
- 'identifier' => "foo:%{[@metadata][_type]}:%{[@metadata][_id]}"
530
+ add_field => {
531
+ 'identifier' => "foo:%{[@metadata][_type]}:%{[@metadata][_id]}"
532
+ }
518
533
  }
519
534
  }
520
- }
521
- ]
535
+ ]
522
536
 
523
- event = input(config) do |pipeline, queue|
524
- queue.pop
525
- end
537
+ event = input(config) do |pipeline, queue|
538
+ queue.pop
539
+ end
540
+
541
+ expect(event.get('identifier')).to eq('foo:logs:C5b2xLQwTZa76jBmHIbwHQ')
542
+ end if ecs_select.active_mode == :disabled
526
543
 
527
- expect(event.get('identifier')).to eq('foo:logs:C5b2xLQwTZa76jBmHIbwHQ')
528
544
  end
545
+
529
546
  end
530
547
 
531
548
  context "when not defining the docinfo" do
@@ -542,9 +559,7 @@ describe LogStash::Inputs::TestableElasticsearch do
542
559
  queue.pop
543
560
  end
544
561
 
545
- expect(event.get("[@metadata][_index]")).to eq(nil)
546
- expect(event.get("[@metadata][_type]")).to eq(nil)
547
- expect(event.get("[@metadata][_id]")).to eq(nil)
562
+ expect(event.get("[@metadata]")).to be_empty
548
563
  end
549
564
  end
550
565
  end
@@ -563,22 +578,22 @@ describe LogStash::Inputs::TestableElasticsearch do
563
578
  'sample:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvJGFjMzFlYmI5MDI0MTc3MzE1NzA0M2MzNGZkMjZmZDQ2OjkyNDMkYTRjMDYyMzBlNDhjOGZjZTdiZTg4YTA3NGEzYmIzZTA6OTI0NA=='
564
579
  end
565
580
 
566
- let(:config) { super.merge({ 'cloud_id' => valid_cloud_id }) }
581
+ let(:config) { super().merge({ 'cloud_id' => valid_cloud_id }) }
567
582
 
568
583
  it "should set host(s)" do
569
584
  plugin.register
570
585
  client = plugin.send(:client)
571
- expect( client.transport.hosts ).to eql [{
572
- :scheme => "https",
573
- :host => "ac31ebb90241773157043c34fd26fd46.us-central1.gcp.cloud.es.io",
574
- :port => 9243,
575
- :path => "",
576
- :protocol => "https"
577
- }]
586
+ expect( extract_transport(client).hosts ).to eql [{
587
+ :scheme => "https",
588
+ :host => "ac31ebb90241773157043c34fd26fd46.us-central1.gcp.cloud.es.io",
589
+ :port => 9243,
590
+ :path => "",
591
+ :protocol => "https"
592
+ }]
578
593
  end
579
594
 
580
595
  context 'invalid' do
581
- let(:config) { super.merge({ 'cloud_id' => 'invalid:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlv' }) }
596
+ let(:config) { super().merge({ 'cloud_id' => 'invalid:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlv' }) }
582
597
 
583
598
  it "should fail" do
584
599
  expect { plugin.register }.to raise_error LogStash::ConfigurationError, /cloud_id.*? is invalid/
@@ -586,7 +601,7 @@ describe LogStash::Inputs::TestableElasticsearch do
586
601
  end
587
602
 
588
603
  context 'hosts also set' do
589
- let(:config) { super.merge({ 'cloud_id' => valid_cloud_id, 'hosts' => [ 'localhost:9200' ] }) }
604
+ let(:config) { super().merge({ 'cloud_id' => valid_cloud_id, 'hosts' => [ 'localhost:9200' ] }) }
590
605
 
591
606
  it "should fail" do
592
607
  expect { plugin.register }.to raise_error LogStash::ConfigurationError, /cloud_id and hosts/
@@ -595,18 +610,18 @@ describe LogStash::Inputs::TestableElasticsearch do
595
610
  end if LOGSTASH_VERSION > '6.0'
596
611
 
597
612
  describe "cloud.auth" do
598
- let(:config) { super.merge({ 'cloud_auth' => LogStash::Util::Password.new('elastic:my-passwd-00') }) }
613
+ let(:config) { super().merge({ 'cloud_auth' => LogStash::Util::Password.new('elastic:my-passwd-00') }) }
599
614
 
600
615
  it "should set authorization" do
601
616
  plugin.register
602
617
  client = plugin.send(:client)
603
- auth_header = client.transport.options[:transport_options][:headers][:Authorization]
618
+ auth_header = extract_transport(client).options[:transport_options][:headers]['Authorization']
604
619
 
605
620
  expect( auth_header ).to eql "Basic #{Base64.encode64('elastic:my-passwd-00').rstrip}"
606
621
  end
607
622
 
608
623
  context 'invalid' do
609
- let(:config) { super.merge({ 'cloud_auth' => 'invalid-format' }) }
624
+ let(:config) { super().merge({ 'cloud_auth' => 'invalid-format' }) }
610
625
 
611
626
  it "should fail" do
612
627
  expect { plugin.register }.to raise_error LogStash::ConfigurationError, /cloud_auth.*? format/
@@ -614,7 +629,7 @@ describe LogStash::Inputs::TestableElasticsearch do
614
629
  end
615
630
 
616
631
  context 'user also set' do
617
- let(:config) { super.merge({ 'cloud_auth' => 'elastic:my-passwd-00', 'user' => 'another' }) }
632
+ let(:config) { super().merge({ 'cloud_auth' => 'elastic:my-passwd-00', 'user' => 'another' }) }
618
633
 
619
634
  it "should fail" do
620
635
  expect { plugin.register }.to raise_error LogStash::ConfigurationError, /Multiple authentication options are specified/
@@ -624,7 +639,7 @@ describe LogStash::Inputs::TestableElasticsearch do
624
639
 
625
640
  describe "api_key" do
626
641
  context "without ssl" do
627
- let(:config) { super.merge({ 'api_key' => LogStash::Util::Password.new('foo:bar') }) }
642
+ let(:config) { super().merge({ 'api_key' => LogStash::Util::Password.new('foo:bar') }) }
628
643
 
629
644
  it "should fail" do
630
645
  expect { plugin.register }.to raise_error LogStash::ConfigurationError, /api_key authentication requires SSL\/TLS/
@@ -632,18 +647,18 @@ describe LogStash::Inputs::TestableElasticsearch do
632
647
  end
633
648
 
634
649
  context "with ssl" do
635
- let(:config) { super.merge({ 'api_key' => LogStash::Util::Password.new('foo:bar'), "ssl" => true }) }
650
+ let(:config) { super().merge({ 'api_key' => LogStash::Util::Password.new('foo:bar'), "ssl" => true }) }
636
651
 
637
652
  it "should set authorization" do
638
653
  plugin.register
639
654
  client = plugin.send(:client)
640
- auth_header = client.transport.options[:transport_options][:headers][:Authorization]
655
+ auth_header = extract_transport(client).options[:transport_options][:headers]['Authorization']
641
656
 
642
657
  expect( auth_header ).to eql "ApiKey #{Base64.strict_encode64('foo:bar')}"
643
658
  end
644
659
 
645
660
  context 'user also set' do
646
- let(:config) { super.merge({ 'api_key' => 'foo:bar', 'user' => 'another' }) }
661
+ let(:config) { super().merge({ 'api_key' => 'foo:bar', 'user' => 'another' }) }
647
662
 
648
663
  it "should fail" do
649
664
  expect { plugin.register }.to raise_error LogStash::ConfigurationError, /Multiple authentication options are specified/
@@ -653,24 +668,24 @@ describe LogStash::Inputs::TestableElasticsearch do
653
668
  end if LOGSTASH_VERSION > '6.0'
654
669
 
655
670
  describe "proxy" do
656
- let(:config) { super.merge({ 'proxy' => 'http://localhost:1234' }) }
671
+ let(:config) { super().merge({ 'proxy' => 'http://localhost:1234' }) }
657
672
 
658
673
  it "should set proxy" do
659
674
  plugin.register
660
675
  client = plugin.send(:client)
661
- proxy = client.transport.options[:transport_options][:proxy]
676
+ proxy = extract_transport(client).options[:transport_options][:proxy]
662
677
 
663
678
  expect( proxy ).to eql "http://localhost:1234"
664
679
  end
665
680
 
666
681
  context 'invalid' do
667
- let(:config) { super.merge({ 'proxy' => '${A_MISSING_ENV_VAR:}' }) }
682
+ let(:config) { super().merge({ 'proxy' => '${A_MISSING_ENV_VAR:}' }) }
668
683
 
669
684
  it "should not set proxy" do
670
685
  plugin.register
671
686
  client = plugin.send(:client)
672
687
 
673
- expect( client.transport.options[:transport_options] ).to_not include(:proxy)
688
+ expect( extract_transport(client).options[:transport_options] ).to_not include(:proxy)
674
689
  end
675
690
  end
676
691
  end
@@ -756,4 +771,10 @@ describe LogStash::Inputs::TestableElasticsearch do
756
771
  end
757
772
 
758
773
  end
774
+
775
+ # @note can be removed once we depends on elasticsearch gem >= 6.x
776
+ def extract_transport(client) # on 7.x client.transport is a ES::Transport::Client
777
+ client.transport.respond_to?(:transport) ? client.transport.transport : client.transport
778
+ end
779
+
759
780
  end