fluent-plugin-elasticsearch 5.1.4 → 5.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,10 +19,26 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
19
19
  @driver = nil
20
20
  log = Fluent::Engine.log
21
21
  log.out.logs.slice!(0, log.out.logs.length)
22
- @bulk_records = 0
22
+ @bulk_records = []
23
23
  end
24
24
 
25
- def driver(conf='', es_version=5, client_version="\"5.0\"")
25
+ def elasticsearch_version
26
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("7.14.0")
27
+ TRANSPORT_CLASS::VERSION
28
+ else
29
+ '5.0.0'.freeze
30
+ end
31
+ end
32
+
33
+ def ilm_endpoint
34
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
35
+ '_enrich'.freeze
36
+ else
37
+ '_ilm'.freeze
38
+ end
39
+ end
40
+
41
+ def driver(conf='', es_version=elasticsearch_version.to_i, client_version=elasticsearch_version)
26
42
  # For request stub to detect compatibility.
27
43
  @es_version ||= es_version
28
44
  @client_version ||= client_version
@@ -62,66 +78,83 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
62
78
  DUPLICATED_DATA_STREAM_EXCEPTION = {"error": {}, "status": 400}
63
79
  NONEXISTENT_DATA_STREAM_EXCEPTION = {"error": {}, "status": 404}
64
80
 
65
- def stub_ilm_policy(name="foo_ilm_policy")
66
- stub_request(:put, "http://localhost:9200/_ilm/policy/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
81
+ def stub_ilm_policy(name="foo_ilm_policy", url="http://localhost:9200")
82
+ stub_request(:put, "#{url}/#{ilm_endpoint}/policy/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
67
83
  end
68
84
 
69
- def stub_index_template(name="foo_tpl")
70
- stub_request(:put, "http://localhost:9200/_index_template/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
85
+ def stub_index_template(name="foo_tpl", url="http://localhost:9200")
86
+ stub_request(:put, "#{url}/_index_template/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
71
87
  end
72
88
 
73
- def stub_data_stream(name="foo")
74
- stub_request(:put, "http://localhost:9200/_data_stream/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
89
+ def stub_data_stream(name="foo", url="http://localhost:9200")
90
+ stub_request(:put, "#{url}/_data_stream/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
75
91
  end
76
92
 
77
- def stub_existent_data_stream?(name="foo")
78
- stub_request(:get, "http://localhost:9200/_data_stream/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
93
+ def stub_existent_data_stream?(name="foo", url="http://localhost:9200")
94
+ stub_request(:get, "#{url}/_data_stream/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
79
95
  end
80
96
 
81
- def stub_existent_ilm?(name="foo_ilm_policy")
82
- stub_request(:get, "http://localhost:9200/_ilm/policy/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
97
+ def stub_existent_ilm?(name="foo_ilm_policy", url="http://localhost:9200")
98
+
99
+ stub_request(:get, "#{url}/#{ilm_endpoint}/policy/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
83
100
  end
84
101
 
85
- def stub_existent_template?(name="foo_tpl")
86
- stub_request(:get, "http://localhost:9200/_index_template/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
102
+ def stub_existent_template?(name="foo_tpl", url="http://localhost:9200")
103
+ stub_request(:get, "#{url}/_index_template/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
87
104
  end
88
105
 
89
- def stub_nonexistent_data_stream?(name="foo")
90
- stub_request(:get, "http://localhost:9200/_data_stream/#{name}").to_return(:status => [404, Elasticsearch::Transport::Transport::Errors::NotFound])
106
+ def stub_nonexistent_data_stream?(name="foo", url="http://localhost:9200")
107
+ stub_request(:get, "#{url}/_data_stream/#{name}").to_return(:status => [404, TRANSPORT_CLASS::Transport::Errors::NotFound])
91
108
  end
92
109
 
93
- def stub_nonexistent_ilm?(name="foo_ilm_policy")
94
- stub_request(:get, "http://localhost:9200/_ilm/policy/#{name}").to_return(:status => [404, Elasticsearch::Transport::Transport::Errors::NotFound])
110
+ def stub_nonexistent_ilm?(name="foo_ilm_policy", url="http://localhost:9200")
111
+ stub_request(:get, "#{url}/#{ilm_endpoint}/policy/#{name}").to_return(:status => [404, TRANSPORT_CLASS::Transport::Errors::NotFound])
95
112
  end
96
113
 
97
- def stub_nonexistent_template?(name="foo_tpl")
98
- stub_request(:get, "http://localhost:9200/_index_template/#{name}").to_return(:status => [404, Elasticsearch::Transport::Transport::Errors::NotFound])
114
+ def stub_nonexistent_template?(name="foo_tpl", url="http://localhost:9200")
115
+ stub_request(:get, "#{url}/_index_template/#{name}").to_return(:status => [404, TRANSPORT_CLASS::Transport::Errors::NotFound])
99
116
  end
100
117
 
101
- def stub_bulk_feed(datastream_name="foo", ilm_name="foo_ilm_policy", template_name="foo_tpl")
102
- stub_request(:post, "http://localhost:9200/#{datastream_name}/_bulk").with do |req|
118
+
119
+ def push_bulk_request(req_body)
120
+ # bulk data must be pair of OP and records
121
+ # {"create": {}}\nhttp://localhost:9200/_ilm/policy/foo_ilm_bar
122
+ # {"@timestamp": ...}
123
+ ops = req_body.split("\n")
124
+ @bulk_records += ops.values_at(
125
+ * ops.each_index.select {|i| i.odd? }
126
+ ).map{ |i| JSON.parse(i) }
127
+ end
128
+
129
+ def stub_nonexistent_template_retry?(name="foo_tpl", url="http://localhost:9200")
130
+ stub_request(:get, "#{url}/_index_template/#{name}").
131
+ to_return({ status: 500, body: 'Internal Server Error' }, { status: 404, body: '{}' })
132
+ end
133
+
134
+ def stub_bulk_feed(datastream_name="foo", ilm_name="foo_ilm_policy", template_name="foo_tpl", url="http://localhost:9200")
135
+ stub_request(:post, "#{url}/#{datastream_name}/_bulk").with do |req|
103
136
  # bulk data must be pair of OP and records
104
137
  # {"create": {}}\nhttp://localhost:9200/_ilm/policy/foo_ilm_bar
105
138
  # {"@timestamp": ...}
106
- @bulk_records += req.body.split("\n").size / 2
139
+ push_bulk_request(req.body)
107
140
  end
108
- stub_request(:post, "http://localhost:9200/#{ilm_name}/_bulk").with do |req|
141
+ stub_request(:post, "#{url}/#{ilm_name}/_bulk").with do |req|
109
142
  # bulk data must be pair of OP and records
110
143
  # {"create": {}}\nhttp://localhost:9200/_ilm/policy/foo_ilm_bar
111
144
  # {"@timestamp": ...}
112
- @bulk_records += req.body.split("\n").size / 2
145
+ push_bulk_request(req.body)
113
146
  end
114
- stub_request(:post, "http://localhost:9200/#{template_name}/_bulk").with do |req|
147
+ stub_request(:post, "#{url}/#{template_name}/_bulk").with do |req|
115
148
  # bulk data must be pair of OP and records
116
149
  # {"create": {}}\nhttp://localhost:9200/_ilm/policy/foo_ilm_bar
117
150
  # {"@timestamp": ...}
118
- @bulk_records += req.body.split("\n").size / 2
151
+ push_bulk_request(req.body)
119
152
  end
120
153
  end
121
154
 
122
- def stub_elastic_info(url="http://localhost:9200/", version="7.9.0")
155
+ def stub_elastic_info(url="http://localhost:9200/", version=elasticsearch_version, headers={})
123
156
  body ="{\"version\":{\"number\":\"#{version}\", \"build_flavor\":\"default\"},\"tagline\" : \"You Know, for Search\"}"
124
- stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json' } })
157
+ stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json', 'x-elastic-product' => 'Elasticsearch' }.merge(headers) })
125
158
  end
126
159
 
127
160
  def stub_default(datastream_name="foo", ilm_name="foo_ilm_policy", template_name="foo_tpl", host="http://localhost:9200")
@@ -135,7 +168,7 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
135
168
  end
136
169
 
137
170
  def data_stream_supported?
138
- Gem::Version.create(::Elasticsearch::Transport::VERSION) >= Gem::Version.create("7.9.0")
171
+ Gem::Version.create(::TRANSPORT_CLASS::VERSION) >= Gem::Version.create("7.9.0")
139
172
  end
140
173
 
141
174
  # ref. https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-create-data-stream.html
@@ -437,6 +470,56 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
437
470
  assert_equal "foo", driver(conf).instance.data_stream_name
438
471
  end
439
472
 
473
+ def test_datastream_configure_retry
474
+ stub_elastic_info
475
+ stub_nonexistent_ilm?
476
+ stub_ilm_policy
477
+ stub_nonexistent_template_retry?
478
+ stub_index_template
479
+ stub_nonexistent_data_stream?
480
+ stub_data_stream
481
+ conf = config_element(
482
+ 'ROOT', '', {
483
+ '@type' => ELASTIC_DATA_STREAM_TYPE,
484
+ 'data_stream_name' => 'foo',
485
+ 'data_stream_ilm_name' => "foo_ilm_policy",
486
+ 'data_stream_template_name' => "foo_tpl"
487
+ })
488
+ assert_equal "foo", driver(conf).instance.data_stream_name
489
+ end
490
+
491
+ def test_hosts_list_configure
492
+ config = %{
493
+ hosts https://john:password@host1:443/elastic/,http://host2
494
+ path /default_path
495
+ user default_user
496
+ password default_password
497
+ data_stream_name default
498
+ }
499
+ stub_elastic_info("https://host1:443/elastic//", elasticsearch_version,
500
+ {'Authorization'=>"Basic #{Base64.encode64('john:password').split.first}"})
501
+ stub_elastic_info("http://host2/default_path/_data_stream/default", elasticsearch_version,
502
+ {'Authorization'=>"Basic #{Base64.encode64('john:password').split.first}"})
503
+ stub_existent_data_stream?("default", "https://host1/elastic/")
504
+ instance = driver(config).instance
505
+
506
+ assert_equal 2, instance.get_connection_options[:hosts].length
507
+ host1, host2 = instance.get_connection_options[:hosts]
508
+
509
+ assert_equal 'host1', host1[:host]
510
+ assert_equal 443, host1[:port]
511
+ assert_equal 'https', host1[:scheme]
512
+ assert_equal 'john', host1[:user]
513
+ assert_equal 'password', host1[:password]
514
+ assert_equal '/elastic/', host1[:path]
515
+
516
+ assert_equal 'host2', host2[:host]
517
+ assert_equal 'http', host2[:scheme]
518
+ assert_equal 'default_user', host2[:user]
519
+ assert_equal 'default_password', host2[:password]
520
+ assert_equal '/default_path', host2[:path]
521
+ end
522
+
440
523
  def test_existent_data_stream
441
524
  omit REQUIRED_ELASTIC_MESSAGE unless data_stream_supported?
442
525
 
@@ -528,7 +611,7 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
528
611
  driver(conf).run(default_tag: 'test') do
529
612
  driver.feed(sample_record)
530
613
  end
531
- assert_equal 1, @bulk_records
614
+ assert_equal 1, @bulk_records.length
532
615
  end
533
616
 
534
617
  def test_placeholder_params_unset
@@ -547,7 +630,7 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
547
630
  driver(conf).run(default_tag: 'test') do
548
631
  driver.feed(sample_record)
549
632
  end
550
- assert_equal 1, @bulk_records
633
+ assert_equal 1, @bulk_records.length
551
634
  end
552
635
 
553
636
 
@@ -573,7 +656,7 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
573
656
  driver(conf).run(default_tag: 'test') do
574
657
  driver.feed(sample_record)
575
658
  end
576
- assert_equal 1, @bulk_records
659
+ assert_equal 1, @bulk_records.length
577
660
  end
578
661
 
579
662
  def test_custom_record_placeholder
@@ -603,7 +686,7 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
603
686
  driver.feed(record)
604
687
  end
605
688
  end
606
- assert_equal keys.count, @bulk_records
689
+ assert_equal keys.count, @bulk_records.length
607
690
  end
608
691
 
609
692
  def test_bulk_insert_feed
@@ -621,7 +704,7 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
621
704
  driver(conf).run(default_tag: 'test') do
622
705
  driver.feed(sample_record)
623
706
  end
624
- assert_equal 1, @bulk_records
707
+ assert_equal 1, @bulk_records.length
625
708
  end
626
709
 
627
710
  def test_template_retry_install_fails
@@ -659,4 +742,152 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
659
742
 
660
743
  assert_equal(4, connection_resets)
661
744
  end
745
+
746
+ def test_doesnt_update_ilm_policy_if_overwrite_unset
747
+ omit REQUIRED_ELASTIC_MESSAGE unless data_stream_supported?
748
+
749
+ config = %{
750
+ data_stream_name foo
751
+ data_stream_ilm_name foo_ilm_policy
752
+ data_stream_ilm_policy {"policy":{"phases":{"hot":{"actions":{"rollover":{"max_age":"15d"}}}}}}
753
+ }
754
+
755
+ stub_elastic_info
756
+ stub_index_template
757
+ stub_existent_data_stream?
758
+ stub_existent_ilm?
759
+ stub_data_stream
760
+
761
+ stub_request(:put, "http://localhost:9200/#{ilm_endpoint}/policy/foo_ilm_policy").
762
+ to_return(:status => 200, :body => "", :headers => {})
763
+
764
+ assert_nothing_raised {
765
+ driver(config)
766
+ }
767
+ assert_requested(:put, "http://localhost:9200/#{ilm_endpoint}/policy/foo_ilm_policy", times: 0)
768
+ end
769
+
770
+ def test_updates_ilm_policy_if_overwrite_set
771
+ omit REQUIRED_ELASTIC_MESSAGE unless data_stream_supported?
772
+
773
+ config = %{
774
+ data_stream_name foo
775
+ data_stream_ilm_name foo_ilm_policy
776
+ data_stream_ilm_policy {"policy":{"phases":{"hot":{"actions":{"rollover":{"max_age":"15d"}}}}}}
777
+ data_stream_ilm_policy_overwrite true
778
+ }
779
+
780
+ stub_elastic_info
781
+ stub_index_template
782
+ stub_existent_data_stream?
783
+ stub_existent_ilm?
784
+ stub_data_stream
785
+
786
+ stub_request(:put, "http://localhost:9200/#{ilm_endpoint}/policy/foo_ilm_policy").
787
+ to_return(:status => 200, :body => "", :headers => {})
788
+
789
+ assert_nothing_raised {
790
+ driver(config)
791
+ }
792
+
793
+ assert_requested(:put, "http://localhost:9200/#{ilm_endpoint}/policy/foo_ilm_policy", times: 1)
794
+ assert_requested(:put, "http://localhost:9200/#{ilm_endpoint}/policy/foo_ilm_policy",
795
+ body: '{"policy":{"phases":{"hot":{"actions":{"rollover":{"max_age":"15d"}}}}}}',
796
+ times: 1)
797
+ end
798
+
799
+ def test_creates_custom_ilm_policy_if_none_exists
800
+ omit REQUIRED_ELASTIC_MESSAGE unless data_stream_supported?
801
+
802
+ config = %{
803
+ data_stream_name foo
804
+ data_stream_ilm_name foo_ilm_policy
805
+ data_stream_ilm_policy {"policy":{"phases":{"hot":{"actions":{"rollover":{"max_age":"15d"}}}}}}
806
+ }
807
+
808
+ stub_elastic_info
809
+ stub_index_template("foo_template")
810
+ stub_data_stream
811
+ stub_nonexistent_data_stream?
812
+ stub_nonexistent_ilm?
813
+ stub_nonexistent_template?("foo_template")
814
+
815
+ stub_request(:put, "http://localhost:9200/#{ilm_endpoint}/policy/foo_ilm_policy").
816
+ to_return(:status => 200, :body => "", :headers => {})
817
+
818
+ assert_nothing_raised {
819
+ driver(config)
820
+ }
821
+
822
+ assert_requested(:put, "http://localhost:9200/#{ilm_endpoint}/policy/foo_ilm_policy", times: 1)
823
+ assert_requested(:put, "http://localhost:9200/#{ilm_endpoint}/policy/foo_ilm_policy",
824
+ body: '{"policy":{"phases":{"hot":{"actions":{"rollover":{"max_age":"15d"}}}}}}',
825
+ times: 1)
826
+ end
827
+
828
+ def test_doesnt_add_tag_key_when_not_configured
829
+ omit REQUIRED_ELASTIC_MESSAGE unless data_stream_supported?
830
+
831
+ config = %{
832
+ data_stream_name foo
833
+ data_stream_template_name foo_tpl
834
+ data_stream_ilm_name foo_ilm_policy
835
+ }
836
+
837
+ stub_default
838
+ stub_bulk_feed
839
+ driver(config)
840
+ driver.run(default_tag: 'mytag') do
841
+ driver.feed(sample_record)
842
+ end
843
+
844
+ assert_equal(1, @bulk_records.length)
845
+ assert_false(@bulk_records[0].has_key?('tag'))
846
+ end
847
+
848
+
849
+ def test_adds_tag_key_when_configured
850
+ omit REQUIRED_ELASTIC_MESSAGE unless data_stream_supported?
851
+
852
+ config = %{
853
+ data_stream_name foo
854
+ data_stream_template_name foo_tpl
855
+ data_stream_ilm_name foo_ilm_policy
856
+ include_tag_key true
857
+ }
858
+
859
+ stub_default
860
+ stub_bulk_feed
861
+ driver(config)
862
+ driver.run(default_tag: 'mytag') do
863
+ driver.feed(sample_record)
864
+ end
865
+
866
+ assert_equal(1, @bulk_records.length)
867
+ assert(@bulk_records[0].has_key?('tag'))
868
+ assert_equal('mytag', @bulk_records[0]['tag'])
869
+ end
870
+
871
+ def test_adds_custom_tag_key_when_configured
872
+ omit REQUIRED_ELASTIC_MESSAGE unless data_stream_supported?
873
+
874
+ config = %{
875
+ data_stream_name foo
876
+ data_stream_template_name foo_tpl
877
+ data_stream_ilm_name foo_ilm_policy
878
+ include_tag_key true
879
+ tag_key custom_tag_key
880
+ }
881
+
882
+ stub_default
883
+ stub_bulk_feed
884
+ driver(config)
885
+ driver.run(default_tag: 'mytag') do
886
+ driver.feed(sample_record)
887
+ end
888
+
889
+ assert_equal(1, @bulk_records.length)
890
+ assert(@bulk_records[0].has_key?('custom_tag_key'))
891
+ assert_equal('mytag', @bulk_records[0]['custom_tag_key'])
892
+ end
662
893
  end
@@ -16,7 +16,15 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
16
16
  @driver = nil
17
17
  end
18
18
 
19
- def driver(conf='', es_version=5)
19
+ def elasticsearch_version
20
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("7.14.0")
21
+ TRANSPORT_CLASS::VERSION
22
+ else
23
+ '6.4.2'.freeze
24
+ end
25
+ end
26
+
27
+ def driver(conf='', es_version=elasticsearch_version.to_i)
20
28
  # For request stub to detect compatibility.
21
29
  @es_version ||= es_version
22
30
  Fluent::Plugin::ElasticsearchOutputDynamic.module_eval(<<-CODE)
@@ -35,7 +43,11 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
35
43
  end
36
44
 
37
45
  def elasticsearch_transport_layer_decoupling?
38
- Gem::Version.create(::Elasticsearch::Transport::VERSION) >= Gem::Version.new("7.14.0")
46
+ Gem::Version.create(::TRANSPORT_CLASS::VERSION) >= Gem::Version.new("7.14.0")
47
+ end
48
+
49
+ def elastic_transport_layer?
50
+ Gem::Version.create(::TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
39
51
  end
40
52
 
41
53
  def default_type_name
@@ -58,9 +70,9 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
58
70
  end
59
71
  end
60
72
 
61
- def stub_elastic_info(url="http://localhost:9200/", version="6.4.2")
73
+ def stub_elastic_info(url="http://localhost:9200/", version=elasticsearch_version)
62
74
  body ="{\"version\":{\"number\":\"#{version}\", \"build_flavor\":\"default\"},\"tagline\" : \"You Know, for Search\"}"
63
- stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json' } })
75
+ stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json', 'x-elastic-product' => 'Elasticsearch' } })
64
76
  end
65
77
 
66
78
  def stub_elastic_unavailable(url="http://localhost:9200/_bulk")
@@ -132,7 +144,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
132
144
  end
133
145
 
134
146
  test 'configure compression' do
135
- omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.2.0")
147
+ omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.2.0")
136
148
 
137
149
  config = %{
138
150
  compression_level best_compression
@@ -143,7 +155,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
143
155
  end
144
156
 
145
157
  test 'check compression strategy' do
146
- omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.2.0")
158
+ omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.2.0")
147
159
 
148
160
  config = %{
149
161
  compression_level best_speed
@@ -154,14 +166,16 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
154
166
  end
155
167
 
156
168
  test 'check content-encoding header with compression' do
157
- omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.2.0")
169
+ omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.2.0")
158
170
 
159
171
  config = %{
160
172
  compression_level best_compression
161
173
  }
162
174
  instance = driver(config).instance
163
175
 
164
- if elasticsearch_transport_layer_decoupling?
176
+ if elastic_transport_layer?
177
+ assert_equal nil, instance.client.transport.options[:transport_options][:headers]["Content-Encoding"]
178
+ elsif elasticsearch_transport_layer_decoupling?
165
179
  assert_equal nil, instance.client.transport.transport.options[:transport_options][:headers]["Content-Encoding"]
166
180
  else
167
181
  assert_equal nil, instance.client.transport.options[:transport_options][:headers]["Content-Encoding"]
@@ -175,7 +189,9 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
175
189
  end
176
190
  compressable = instance.compressable_connection
177
191
 
178
- if elasticsearch_transport_layer_decoupling?
192
+ if elastic_transport_layer?
193
+ assert_equal "gzip", instance.client(nil, compressable).transport.options[:transport_options][:headers]["Content-Encoding"]
194
+ elsif elasticsearch_transport_layer_decoupling?
179
195
  assert_equal "gzip", instance.client(nil, compressable).transport.transport.options[:transport_options][:headers]["Content-Encoding"]
180
196
  else
181
197
  assert_equal "gzip", instance.client(nil, compressable).transport.options[:transport_options][:headers]["Content-Encoding"]
@@ -183,14 +199,16 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
183
199
  end
184
200
 
185
201
  test 'check compression option is passed to transport' do
186
- omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.2.0")
202
+ omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.2.0")
187
203
 
188
204
  config = %{
189
205
  compression_level best_compression
190
206
  }
191
207
  instance = driver(config).instance
192
208
 
193
- if elasticsearch_transport_layer_decoupling?
209
+ if elastic_transport_layer?
210
+ assert_equal false, instance.client.transport.options[:compression]
211
+ elsif elasticsearch_transport_layer_decoupling?
194
212
  assert_equal false, instance.client.transport.transport.options[:compression]
195
213
  else
196
214
  assert_equal false, instance.client.transport.options[:compression]
@@ -204,7 +222,9 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
204
222
  end
205
223
  compressable = instance.compressable_connection
206
224
 
207
- if elasticsearch_transport_layer_decoupling?
225
+ if elastic_transport_layer?
226
+ assert_equal true, instance.client(nil, compressable).transport.options[:compression]
227
+ elsif elasticsearch_transport_layer_decoupling?
208
228
  assert_equal true, instance.client(nil, compressable).transport.transport.options[:compression]
209
229
  else
210
230
  assert_equal true, instance.client(nil, compressable).transport.options[:compression]
@@ -402,7 +422,7 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
402
422
  end
403
423
 
404
424
  def test_writes_to_default_index_with_compression
405
- omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.2.0")
425
+ omit "elastisearch-ruby v7.2.0 or later is needed." if Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.2.0")
406
426
 
407
427
  config = %[
408
428
  compression_level default_compression
@@ -441,7 +461,13 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
441
461
  driver.run(default_tag: 'test') do
442
462
  driver.feed(sample_record)
443
463
  end
444
- assert_equal(default_type_name, index_cmds.first['index']['_type'])
464
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
465
+ assert_nil(index_cmds.first['index']['_type'])
466
+ elsif Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("7.0.0")
467
+ assert_equal("_doc", index_cmds.first['index']['_type'])
468
+ else
469
+ assert_equal("fluentd", index_cmds.first['index']['_type'])
470
+ end
445
471
  end
446
472
 
447
473
  def test_writes_to_specified_index
@@ -471,7 +497,13 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
471
497
  driver.run(default_tag: 'test') do
472
498
  driver.feed(sample_record)
473
499
  end
474
- assert_equal('mytype', index_cmds.first['index']['_type'])
500
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
501
+ assert_nil(index_cmds.first['index']['_type'])
502
+ elsif Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("7.0.0")
503
+ assert_equal("_doc", index_cmds.first['index']['_type'])
504
+ else
505
+ assert_equal("mytype", index_cmds.first['index']['_type'])
506
+ end
475
507
  end
476
508
 
477
509
  def test_writes_to_specified_host
@@ -971,7 +1003,8 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
971
1003
  driver.run(default_tag: 'test') do
972
1004
  driver.feed(nested_sample_record)
973
1005
  end
974
- assert_equal('routing', index_cmds[0]['index']['_routing'])
1006
+ routing_key = driver.instance.instance_variable_get(:@routing_key_name)
1007
+ assert_equal('routing', index_cmds[0]['index'][routing_key])
975
1008
  end
976
1009
 
977
1010
  def test_adds_nested_routing_key_with_dollar_dot
@@ -981,7 +1014,8 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
981
1014
  driver.run(default_tag: 'test') do
982
1015
  driver.feed(nested_sample_record)
983
1016
  end
984
- assert_equal('routing', index_cmds[0]['index']['_routing'])
1017
+ routing_key = driver.instance.instance_variable_get(:@routing_key_name)
1018
+ assert_equal('routing', index_cmds[0]['index'][routing_key])
985
1019
  end
986
1020
 
987
1021
  def test_adds_nested_routing_key_with_bracket
@@ -991,7 +1025,8 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
991
1025
  driver.run(default_tag: 'test') do
992
1026
  driver.feed(nested_sample_record)
993
1027
  end
994
- assert_equal('routing', index_cmds[0]['index']['_routing'])
1028
+ routing_key = driver.instance.instance_variable_get(:@routing_key_name)
1029
+ assert_equal('routing', index_cmds[0]['index'][routing_key])
995
1030
  end
996
1031
  end
997
1032
 
@@ -1002,7 +1037,8 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
1002
1037
  driver.run(default_tag: 'test') do
1003
1038
  driver.feed(sample_record)
1004
1039
  end
1005
- assert(!index_cmds[0]['index'].has_key?('_routing'))
1040
+ routing_key = driver.instance.instance_variable_get(:@routing_key_name)
1041
+ assert(!index_cmds[0]['index'].has_key?(routing_key))
1006
1042
  end
1007
1043
 
1008
1044
  def test_adds_routing_key_when_not_configured
@@ -1011,7 +1047,8 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
1011
1047
  driver.run(default_tag: 'test') do
1012
1048
  driver.feed(sample_record)
1013
1049
  end
1014
- assert(!index_cmds[0]['index'].has_key?('_routing'))
1050
+ routing_key = driver.instance.instance_variable_get(:@routing_key_name)
1051
+ assert(!index_cmds[0]['index'].has_key?(routing_key))
1015
1052
  end
1016
1053
 
1017
1054
  def test_remove_one_key
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.4
4
+ version: 5.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - diogo
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-11-22 00:00:00.000000000 Z
13
+ date: 2022-03-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: fluentd
@@ -171,6 +171,7 @@ files:
171
171
  - gemfiles/Gemfile.elasticsearch.v6
172
172
  - lib/fluent/log-ext.rb
173
173
  - lib/fluent/plugin/default-ilm-policy.json
174
+ - lib/fluent/plugin/elasticsearch_compat.rb
174
175
  - lib/fluent/plugin/elasticsearch_constants.rb
175
176
  - lib/fluent/plugin/elasticsearch_error.rb
176
177
  - lib/fluent/plugin/elasticsearch_error_handler.rb