fluent-plugin-elasticsearch 5.1.5 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ae6214f54783c402097e26276b9247f1d58866b08cdc80be47d3b4638516d54
4
- data.tar.gz: b69af374d04f84b2b1137189916c2b78f25eae71c2294d9a0cc196c30c09db29
3
+ metadata.gz: 4c4d872817c5c5f788b40c89adfddec72dc5765666ab90046a38d5e881ba4f2d
4
+ data.tar.gz: 8e83854fa3eea144ba97e44ba52885dd5f28ef3801fe293c69cf5158e7839789
5
5
  SHA512:
6
- metadata.gz: 29173c2331bc0e533aa1d3aa66aa555bad7802e5fbb4207641b11aebc0a18c0d4e44ebed0b167c8fe4bddf403d2dd5a61349afeffecfc28a65359c3bb4cce26b
7
- data.tar.gz: 7fdf58624182bdd4e354cad2d4f9ba001cff5a8c8c0ba02ac043607a87e2372311deb85bc0306d3aa167e98170a6049f33f3203b202ebcf25eac75e65dc23a17
6
+ metadata.gz: 65eb51a5cd710eb39c54f822f3748bb6ba202ebc87d9aab563adf4befec9696279219f452cc99a1d7528e4c484e03807f195cba8695ec16cc0b3525793a872be
7
+ data.tar.gz: 3ce726708a2b1900f27999518a56bbf857c28337ce1e3d82ab0acd8fbdb58d92488ddb7e9ccf5a8482768b2c4da1c261b96835f02237321b1a941c6d3b0eb2dc
data/Gemfile CHANGED
@@ -7,5 +7,5 @@ gem 'simplecov', require: false
7
7
  gem 'coveralls', ">= 0.8.0", require: false
8
8
  gem 'strptime', require: false if RUBY_ENGINE == "ruby" && RUBY_VERSION =~ /^2/
9
9
  gem "irb" if RUBY_ENGINE == "ruby" && RUBY_VERSION >= "2.6"
10
- gem "elasticsearch-xpack"
10
+ gem "elasticsearch-xpack" if ENV["USE_XPACK"]
11
11
  gem "oj"
data/History.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  ### [Unreleased]
4
4
 
5
+ ### 5.2.0
6
+ - Migrate to handle Elasticsearch 8 (#949)
7
+
5
8
  ### 5.1.5
6
9
  - Make retryable DataStreams creation at configure phase (#943)
7
10
  - Handle @hosts parameter on data_stream plugin (#942)
@@ -3,7 +3,7 @@ $:.push File.expand_path('../lib', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'fluent-plugin-elasticsearch'
6
- s.version = '5.1.5'
6
+ s.version = '5.2.0'
7
7
  s.authors = ['diogo', 'pitr', 'Hiroshi Hatake']
8
8
  s.email = ['pitr.vern@gmail.com', 'me@diogoterror.com', 'cosmo0920.wp@gmail.com']
9
9
  s.description = %q{Elasticsearch output plugin for Fluent event collector}
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'elastic/transport'
3
+ ::TRANSPORT_CLASS = Elastic::Transport
4
+ rescue LoadError
5
+ end
6
+ begin
7
+ require 'elasticsearch/transport'
8
+ ::TRANSPORT_CLASS = Elasticsearch::Transport
9
+ rescue LoadError
10
+ end
11
+ if Gem::Version.new(Elasticsearch::VERSION) < Gem::Version.new("8.0.0")
12
+ begin
13
+ require 'elasticsearch/xpack'
14
+ rescue LoadError
15
+ end
16
+ end
17
+
18
+ begin
19
+ require 'elastic/transport/transport/connections/selector'
20
+ ::SELECTOR_CLASS = Elastic::Transport::Transport::Connections::Selector
21
+ rescue LoadError
22
+ end
23
+ begin
24
+ require 'elasticsearch/transport/transport/connections/selector'
25
+ ::SELECTOR_CLASS = Elasticsearch::Transport::Transport::Connections::Selector
26
+ rescue LoadError
27
+ end
@@ -1,7 +1,7 @@
1
- require 'elasticsearch/transport/transport/connections/selector'
1
+ require_relative 'elasticsearch_compat'
2
2
 
3
3
  class Fluent::Plugin::ElasticseatchFallbackSelector
4
- include Elasticsearch::Transport::Transport::Connections::Selector::Base
4
+ include SELECTOR_CLASS::Base
5
5
 
6
6
  def select(options={})
7
7
  connections.first
@@ -1,3 +1,5 @@
1
+ require_relative 'elasticsearch_compat'
2
+
1
3
  module Fluent::Plugin::ElasticsearchIndexLifecycleManagement
2
4
  ILM_DEFAULT_POLICY_PATH = "default-ilm-policy.json"
3
5
 
@@ -21,7 +23,7 @@ module Fluent::Plugin::ElasticsearchIndexLifecycleManagement
21
23
  raise Fluent::ConfigError, "Index Lifecycle management is enabled in Fluentd, but not available in your Elasticsearch" unless ilm['available']
22
24
  raise Fluent::ConfigError, "Index Lifecycle management is enabled in Fluentd, but not enabled in your Elasticsearch" unless ilm['enabled']
23
25
 
24
- rescue Elasticsearch::Transport::Transport::Error => e
26
+ rescue ::TRANSPORT_CLASS::Transport::Error => e
25
27
  raise Fluent::ConfigError, "Index Lifecycle management is enabled in Fluentd, but not installed on your Elasticsearch", error: e
26
28
  end
27
29
  end
@@ -43,12 +45,20 @@ module Fluent::Plugin::ElasticsearchIndexLifecycleManagement
43
45
  end
44
46
 
45
47
  def get_ilm_policy
46
- client.ilm.get_policy
48
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) < Gem::Version.new("8.0.0")
49
+ client.ilm.get_policy
50
+ else
51
+ client.enrich.get_policy
52
+ end
47
53
  end
48
54
 
49
55
  def ilm_policy_exists?(policy_id)
50
56
  begin
51
- client.ilm.get_policy(policy_id: policy_id)
57
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) < Gem::Version.new("8.0.0")
58
+ client.ilm.get_policy(policy_id: policy_id)
59
+ else
60
+ client.enrich.get_policy(name: policy_id)
61
+ end
52
62
  true
53
63
  rescue
54
64
  false
@@ -57,7 +67,11 @@ module Fluent::Plugin::ElasticsearchIndexLifecycleManagement
57
67
 
58
68
  def ilm_policy_put(policy_id, policy)
59
69
  log.info("Installing ILM policy: #{policy}")
60
- client.ilm.put_policy(policy_id: policy_id, body: policy)
70
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) < Gem::Version.new("8.0.0")
71
+ client.ilm.put_policy(policy_id: policy_id, body: policy)
72
+ else
73
+ client.enrich.put_policy(name: policy_id, body: policy)
74
+ end
61
75
  end
62
76
 
63
77
  def default_policy_payload
@@ -28,12 +28,16 @@ module Fluent::ElasticsearchIndexTemplate
28
28
  client(host).indices.get_index_template(:name => name)
29
29
  end
30
30
  return true
31
- rescue Elasticsearch::Transport::Transport::Errors::NotFound
31
+ rescue TRANSPORT_CLASS::Transport::Errors::NotFound
32
32
  return false
33
33
  end
34
34
 
35
35
  def host_unreachable_exceptions
36
- if Gem::Version.new(::Elasticsearch::Transport::VERSION) >= Gem::Version.new("7.14.0")
36
+ if Gem::Version.new(::TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
37
+ # elasticsearch-ruby 8.0.0's elastic-transport uses
38
+ # direct callable #host_unreachable_exceptions again.
39
+ client.transport.host_unreachable_exceptions
40
+ elsif Gem::Version.new(::TRANSPORT_CLASS::VERSION) >= Gem::Version.new("7.14.0")
37
41
  # elasticsearch-ruby 7.14.0's elasticsearch-transport does not extends
38
42
  # Elasticsearch class on Transport.
39
43
  # This is why #host_unreachable_exceptions is not callable directly
@@ -47,7 +51,7 @@ module Fluent::ElasticsearchIndexTemplate
47
51
  def retry_operate(max_retries, fail_on_retry_exceed = true, catch_trasport_exceptions = true)
48
52
  return unless block_given?
49
53
  retries = 0
50
- transport_errors = Elasticsearch::Transport::Transport::Errors.constants.map{ |c| Elasticsearch::Transport::Transport::Errors.const_get c } if catch_trasport_exceptions
54
+ transport_errors = TRANSPORT_CLASS::Transport::Errors.constants.map{ |c| TRANSPORT_CLASS::Transport::Errors.const_get c } if catch_trasport_exceptions
51
55
  begin
52
56
  yield
53
57
  rescue *host_unreachable_exceptions, *transport_errors, Timeout::Error => e
@@ -78,7 +82,7 @@ module Fluent::ElasticsearchIndexTemplate
78
82
 
79
83
  def indexcreation(index_name, host = nil)
80
84
  client(host).indices.create(:index => index_name)
81
- rescue Elasticsearch::Transport::Transport::Error => e
85
+ rescue TRANSPORT_CLASS::Transport::Error => e
82
86
  if e.message =~ /"already exists"/ || e.message =~ /resource_already_exists_exception/
83
87
  log.debug("Index #{index_name} already exists")
84
88
  else
@@ -1,6 +1,7 @@
1
1
  require 'elasticsearch'
2
+ require_relative 'elasticsearch_compat'
2
3
 
3
- class Fluent::Plugin::ElasticsearchSimpleSniffer < Elasticsearch::Transport::Transport::Sniffer
4
+ class Fluent::Plugin::ElasticsearchSimpleSniffer < TRANSPORT_CLASS::Transport::Sniffer
4
5
 
5
6
  def hosts
6
7
  @transport.logger.debug "In Fluent::Plugin::ElasticsearchSimpleSniffer hosts #{@transport.hosts}" if @transport.logger
@@ -3,6 +3,7 @@ require 'elasticsearch'
3
3
  require 'fluent/log-ext'
4
4
  require 'fluent/plugin/input'
5
5
  require_relative 'elasticsearch_constants'
6
+ require_relative 'elasticsearch_compat'
6
7
 
7
8
  module Fluent::Plugin
8
9
  class ElasticsearchInput < Input
@@ -218,7 +219,7 @@ module Fluent::Plugin
218
219
 
219
220
  headers = { 'Content-Type' => "application/json" }.merge(@custom_headers)
220
221
 
221
- transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(
222
+ transport = TRANSPORT_CLASS::Transport::HTTP::Faraday.new(
222
223
  connection_options.merge(
223
224
  options: {
224
225
  reload_connections: local_reload_connections,
@@ -1,10 +1,11 @@
1
1
  require 'oj'
2
+ require_relative 'elasticsearch_compat'
2
3
 
3
4
  module Fluent::Plugin
4
5
  module Serializer
5
6
 
6
7
  class Oj
7
- include Elasticsearch::Transport::Transport::Serializer::Base
8
+ include TRANSPORT_CLASS::Transport::Serializer::Base
8
9
 
9
10
  # De-serialize a Hash from JSON string
10
11
  #
@@ -3,10 +3,6 @@ require 'date'
3
3
  require 'excon'
4
4
  require 'elasticsearch'
5
5
  require 'set'
6
- begin
7
- require 'elasticsearch/xpack'
8
- rescue LoadError
9
- end
10
6
  require 'json'
11
7
  require 'uri'
12
8
  require 'base64'
@@ -23,6 +19,7 @@ require 'fluent/time'
23
19
  require 'fluent/unique_id'
24
20
  require 'fluent/log-ext'
25
21
  require 'zlib'
22
+ require_relative 'elasticsearch_compat'
26
23
  require_relative 'elasticsearch_constants'
27
24
  require_relative 'elasticsearch_error'
28
25
  require_relative 'elasticsearch_error_handler'
@@ -413,11 +410,11 @@ EOC
413
410
  end
414
411
  end
415
412
 
416
- if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.2.0")
413
+ if Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.2.0")
417
414
  if compression
418
415
  raise Fluent::ConfigError, <<-EOC
419
416
  Cannot use compression with elasticsearch-transport plugin version < 7.2.0
420
- Your elasticsearch-transport plugin version version is #{Elasticsearch::Transport::VERSION}.
417
+ Your elasticsearch-transport plugin version version is #{TRANSPORT_CLASS::VERSION}.
421
418
  Please consider to upgrade ES client.
422
419
  EOC
423
420
  end
@@ -613,7 +610,7 @@ EOC
613
610
  .merge(gzip_headers)
614
611
  ssl_options = { verify: @ssl_verify, ca_file: @ca_file}.merge(@ssl_version_options)
615
612
 
616
- transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(connection_options.merge(
613
+ transport = TRANSPORT_CLASS::Transport::HTTP::Faraday.new(connection_options.merge(
617
614
  options: {
618
615
  reload_connections: local_reload_connections,
619
616
  reload_on_failure: @reload_on_failure,
@@ -23,11 +23,19 @@ module Fluent::Plugin
23
23
  def configure(conf)
24
24
  super
25
25
 
26
- begin
27
- require 'elasticsearch/api'
28
- require 'elasticsearch/xpack'
29
- rescue LoadError
30
- raise Fluent::ConfigError, "'elasticsearch/api', 'elasticsearch/xpack' are required for <@elasticsearch_data_stream>."
26
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) < Gem::Version.new("8.0.0")
27
+ begin
28
+ require 'elasticsearch/api'
29
+ require 'elasticsearch/xpack'
30
+ rescue LoadError
31
+ raise Fluent::ConfigError, "'elasticsearch/api', 'elasticsearch/xpack' are required for <@elasticsearch_data_stream>."
32
+ end
33
+ else
34
+ begin
35
+ require 'elasticsearch/api'
36
+ rescue LoadError
37
+ raise Fluent::ConfigError, "'elasticsearch/api is required for <@elasticsearch_data_stream>."
38
+ end
31
39
  end
32
40
 
33
41
  @data_stream_ilm_name = "#{@data_stream_name}_policy" if @data_stream_ilm_name.nil?
@@ -89,13 +97,16 @@ module Fluent::Plugin
89
97
  end
90
98
 
91
99
  params = {
92
- policy_id: ilm_name,
93
100
  body: @data_stream_ilm_policy
94
101
  }
95
102
  retry_operate(@max_retry_putting_template,
96
103
  @fail_on_putting_template_retry_exceed,
97
104
  @catch_transport_exception_on_retry) do
98
- client(host).xpack.ilm.put_policy(params)
105
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
106
+ client(host).enrich.put_policy(params.merge(name: ilm_name))
107
+ else
108
+ client(host).xpack.ilm.put_policy(params.merge(policy_id: ilm_name))
109
+ end
99
110
  end
100
111
  end
101
112
 
@@ -127,8 +138,8 @@ module Fluent::Plugin
127
138
  }
128
139
  begin
129
140
  response = client(host).indices.get_data_stream(params)
130
- return (not response.is_a?(Elasticsearch::Transport::Transport::Errors::NotFound))
131
- rescue Elasticsearch::Transport::Transport::Errors::NotFound => e
141
+ return (not response.is_a?(TRANSPORT_CLASS::Transport::Errors::NotFound))
142
+ rescue TRANSPORT_CLASS::Transport::Errors::NotFound => e
132
143
  log.info "Specified data stream does not exist. Will be created: <#{e}>"
133
144
  return false
134
145
  end
@@ -148,7 +159,11 @@ module Fluent::Plugin
148
159
 
149
160
  def ilm_policy_exists?(policy_id, host = nil)
150
161
  begin
151
- client(host).ilm.get_policy(policy_id: policy_id)
162
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
163
+ client(host).enrich.get_policy(name: policy_id)
164
+ else
165
+ client(host).ilm.get_policy(policy_id: policy_id)
166
+ end
152
167
  true
153
168
  rescue
154
169
  false
@@ -162,7 +177,7 @@ module Fluent::Plugin
162
177
  client(host).indices.get_index_template(:name => name)
163
178
  end
164
179
  return true
165
- rescue Elasticsearch::Transport::Transport::Errors::NotFound
180
+ rescue TRANSPORT_CLASS::Transport::Errors::NotFound
166
181
  return false
167
182
  end
168
183
 
@@ -53,7 +53,7 @@ module Fluent::Plugin
53
53
  end
54
54
  headers = { 'Content-Type' => @content_type.to_s, }.merge(gzip_headers)
55
55
  ssl_options = { verify: @ssl_verify, ca_file: @ca_file}.merge(@ssl_version_options)
56
- transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(connection_options.merge(
56
+ transport = TRANSPORT_CLASS::Transport::HTTP::Faraday.new(connection_options.merge(
57
57
  options: {
58
58
  reload_connections: @reload_connections,
59
59
  reload_on_failure: @reload_on_failure,
@@ -18,17 +18,25 @@ class ElasticsearchFallbackSelectorTest < Test::Unit::TestCase
18
18
  end
19
19
  end
20
20
 
21
- def stub_elastic_info(url="http://localhost:9200/", version="6.4.2")
21
+ def elasticsearch_version
22
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("7.14.0")
23
+ TRANSPORT_CLASS::VERSION
24
+ else
25
+ '6.4.2'.freeze
26
+ end
27
+ end
28
+
29
+ def stub_elastic_info(url="http://localhost:9200/", version=elasticsearch_version)
22
30
  body ="{\"version\":{\"number\":\"#{version}\", \"build_flavor\":\"default\"},\"tagline\" : \"You Know, for Search\"}"
23
- stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json' } })
31
+ stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json', 'x-elastic-product' => 'Elasticsearch' } })
24
32
  end
25
33
 
26
- def stub_elastic_info_not_found(url="http://localhost:9200/", version="6.4.2")
27
- stub_request(:get, url).to_return(:status => [404, "Not Found"])
34
+ def stub_elastic_info_not_found(url="http://localhost:9200/", version=elasticsearch_version)
35
+ stub_request(:get, url).to_return(:status => [404, "Not Found"], headers: {'x-elastic-product' => 'Elasticsearch' })
28
36
  end
29
37
 
30
- def stub_elastic_info_unavailable(url="http://localhost:9200/", version="6.4.2")
31
- stub_request(:get, url).to_return(:status => [503, "Service Unavailable"])
38
+ def stub_elastic_info_unavailable(url="http://localhost:9200/", version=elasticsearch_version)
39
+ stub_request(:get, url).to_return(:status => [503, "Service Unavailable"], headers: {'x-elastic-product' => 'Elasticsearch' })
32
40
  end
33
41
 
34
42
  def sample_record(content={})
@@ -60,7 +68,7 @@ class ElasticsearchFallbackSelectorTest < Test::Unit::TestCase
60
68
  reload_after 10
61
69
  catch_transport_exception_on_retry false # For fallback testing
62
70
  ]
63
- assert_raise(Elasticsearch::Transport::Transport::Errors::NotFound) do
71
+ assert_raise(TRANSPORT_CLASS::Transport::Errors::NotFound) do
64
72
  driver(config)
65
73
  end
66
74
  driver.run(default_tag: 'test') do
@@ -6,12 +6,14 @@ class TestElasticsearchIndexLifecycleManagement < Test::Unit::TestCase
6
6
  include Fluent::Plugin::ElasticsearchIndexLifecycleManagement
7
7
 
8
8
  def setup
9
- begin
10
- require "elasticsearch/xpack"
11
- rescue LoadError
12
- omit "ILM testcase needs elasticsearch-xpack gem."
9
+ if Gem::Version.new(Elasticsearch::VERSION) < Gem::Version.new("7.14.0")
10
+ begin
11
+ require "elasticsearch/xpack"
12
+ rescue LoadError
13
+ omit "ILM testcase needs elasticsearch-xpack gem."
14
+ end
13
15
  end
14
- if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.4.0")
16
+ if Gem::Version.create(::TRANSPORT_CLASS::VERSION) < Gem::Version.create("7.4.0")
15
17
  omit "elastisearch-ruby v7.4.0 or later is needed for ILM."
16
18
  end
17
19
  Fluent::Plugin::ElasticsearchIndexLifecycleManagement.module_eval(<<-CODE)
@@ -27,50 +29,78 @@ class TestElasticsearchIndexLifecycleManagement < Test::Unit::TestCase
27
29
  CODE
28
30
  end
29
31
 
30
- def stub_elastic_info(url="http://localhost:9200/", version="7.9.0")
32
+ def elasticsearch_version
33
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
34
+ TRANSPORT_CLASS::VERSION
35
+ else
36
+ '6.4.2'.freeze
37
+ end
38
+ end
39
+
40
+ def ilm_existence_endpoint(policy_id)
41
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
42
+ "_enrich/policy/#{policy_id}"
43
+ else
44
+ "_ilm/policy/%7B:policy_id=%3E%22#{policy_id}%22%7D"
45
+ end
46
+ end
47
+
48
+ def ilm_creation_endpoint(policy_id)
49
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
50
+ "_enrich/policy/#{policy_id}"
51
+ else
52
+ "_ilm/policy/#{policy_id}"
53
+ end
54
+ end
55
+
56
+ def stub_elastic_info(url="http://localhost:9200/", version=elasticsearch_version)
31
57
  body ="{\"version\":{\"number\":\"#{version}\", \"build_flavor\":\"default\"},\"tagline\" : \"You Know, for Search\"}"
32
- stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json' } })
58
+ stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json', 'x-elastic-product' => 'Elasticsearch' } })
33
59
  end
34
60
 
35
61
  def test_xpack_info
36
62
  stub_request(:get, "http://localhost:9200/_xpack").
37
- to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
63
+ to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json" })
38
64
  stub_elastic_info
39
65
  expected = {"features"=>{"ilm"=>{"available"=>true, "enabled"=>true}}}
40
- assert_equal(expected, xpack_info)
66
+ if xpack_info.is_a?(Elasticsearch::API::Response)
67
+ assert_equal(expected, xpack_info.body)
68
+ else
69
+ assert_equal(expected, xpack_info)
70
+ end
41
71
  end
42
72
 
43
73
  def test_verify_ilm_working
44
74
  stub_request(:get, "http://localhost:9200/_xpack").
45
- to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
75
+ to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json" })
46
76
  stub_elastic_info
47
77
  assert_nothing_raised { verify_ilm_working }
48
78
  end
49
79
 
50
80
  def test_ilm_policy_doesnt_exists
51
- stub_request(:get, "http://localhost:9200/_ilm/policy/%7B:policy_id=%3E%22fluentd-policy%22%7D").
81
+ stub_request(:get, "http://localhost:9200/#{ilm_existence_endpoint("fluentd-policy")}").
52
82
  to_return(:status => 404, :body => "", :headers => {})
53
83
  stub_elastic_info
54
- assert_false(ilm_policy_exists?(policy_id: "fluentd-policy"))
84
+ assert_false(ilm_policy_exists?("fluentd-policy"))
55
85
  end
56
86
 
57
87
  def test_ilm_policy_exists
58
- stub_request(:get, "http://localhost:9200/_ilm/policy/%7B:policy_id=%3E%22fluent-policy%22%7D").
88
+ stub_request(:get, "http://localhost:9200/#{ilm_existence_endpoint("fluent-policy")}").
59
89
  to_return(:status => 200, :body => "", :headers => {})
60
90
  stub_elastic_info
61
- assert_true(ilm_policy_exists?(policy_id: "fluent-policy"))
91
+ assert_true(ilm_policy_exists?("fluent-policy"))
62
92
  end
63
93
 
64
94
  def test_create_ilm_policy
65
- stub_request(:get, "http://localhost:9200/_ilm/policy/fluent-policy").
95
+ stub_request(:get, "http://localhost:9200/#{ilm_creation_endpoint("fluent-policy")}").
66
96
  to_return(:status => 404, :body => "", :headers => {})
67
- stub_request(:put, "http://localhost:9200/_ilm/policy/fluent-policy").
97
+ stub_request(:put, "http://localhost:9200/#{ilm_creation_endpoint("fluent-policy")}").
68
98
  with(:body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}",
69
99
  :headers => {'Content-Type'=>'application/json'}).
70
100
  to_return(:status => 200, :body => "", :headers => {})
71
101
  stub_elastic_info
72
102
  create_ilm_policy("fluent-policy")
73
103
 
74
- assert_requested(:put, "http://localhost:9200/_ilm/policy/fluent-policy", times: 1)
104
+ assert_requested(:put, "http://localhost:9200/#{ilm_creation_endpoint("fluent-policy")}", times: 1)
75
105
  end
76
106
  end
@@ -31,9 +31,17 @@ class ElasticsearchInputTest < Test::Unit::TestCase
31
31
  @driver ||= Fluent::Test::Driver::Input.new(Fluent::Plugin::ElasticsearchInput).configure(conf)
32
32
  end
33
33
 
34
- def stub_elastic_info(url="http://localhost:9200/", version="7.9.0")
34
+ def elasticsearch_version
35
+ if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("7.14.0")
36
+ TRANSPORT_CLASS::VERSION
37
+ else
38
+ '7.9.0'.freeze
39
+ end
40
+ end
41
+
42
+ def stub_elastic_info(url="http://localhost:9200/", version=elasticsearch_version)
35
43
  body ="{\"version\":{\"number\":\"#{version}\", \"build_flavor\":\"default\"},\"tagline\" : \"You Know, for Search\"}"
36
- stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json' } })
44
+ stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json', 'x-elastic-product' => 'Elasticsearch' } })
37
45
  end
38
46
 
39
47
  def sample_response(index_name="fluentd")