fluent-plugin-elasticsearch 5.1.5 → 5.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ae6214f54783c402097e26276b9247f1d58866b08cdc80be47d3b4638516d54
4
- data.tar.gz: b69af374d04f84b2b1137189916c2b78f25eae71c2294d9a0cc196c30c09db29
3
+ metadata.gz: 62c61f26ed869460900c3f05d6c70bc4bbb06dd9747f3a23c92accd4c878756f
4
+ data.tar.gz: 1ed0894c48a957b5359739303b8fef7e9df9ce8ec80b1b0101b2b17d40a72967
5
5
  SHA512:
6
- metadata.gz: 29173c2331bc0e533aa1d3aa66aa555bad7802e5fbb4207641b11aebc0a18c0d4e44ebed0b167c8fe4bddf403d2dd5a61349afeffecfc28a65359c3bb4cce26b
7
- data.tar.gz: 7fdf58624182bdd4e354cad2d4f9ba001cff5a8c8c0ba02ac043607a87e2372311deb85bc0306d3aa167e98170a6049f33f3203b202ebcf25eac75e65dc23a17
6
+ metadata.gz: c63a8ea452e6f3691497e4601b46393c851ae188b9583ebfeaacff507e7791206430145db01bea4298d7c0021d610e9e2a229da9cca5394bea731ae36e204b9b
7
+ data.tar.gz: 1e4ed30e6d00e372781d8744262bc711937ddaffdfc92f9f0407c7f367f0e4ac7807ba635a119b3287a09d2780c9d7efbe2e1e031330a0aacd527a4ff2a177bd
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,18 @@
2
2
 
3
3
  ### [Unreleased]
4
4
 
5
+ ### 5.2.2
6
+ - Add missing top level class markers (#961)
7
+ - Ensure use_record_as_seed for same records (#960)
8
+
9
+ ### 5.2.1
10
+ - respect include\_tag\_key and tag\_key setting when using data streams (#936)
11
+ - Handle unsupported version error (#956)
12
+ - Display deprecated warning on ES dynamic plugin (#955)
13
+
14
+ ### 5.2.0
15
+ - Migrate to handle Elasticsearch 8 (#949)
16
+
5
17
  ### 5.1.5
6
18
  - Make retryable DataStreams creation at configure phase (#943)
7
19
  - 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.2'
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,30 @@
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
28
+ unless defined?(::Elasticsearch::UnsupportedProductError)
29
+ class ::Elasticsearch::UnsupportedProductError < StandardError; end
30
+ 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
@@ -53,7 +53,7 @@ module Fluent::Plugin
53
53
  seed += tag + separator if @include_tag_in_seed
54
54
  seed += time.to_s + separator if @include_time_in_seed
55
55
  if @use_entire_record
56
- record.each {|k,v| seed += "|#{k}|#{v}"}
56
+ record.keys.sort.each {|k| seed += "|#{k}|#{record[k]}"}
57
57
  else
58
58
  seed += record_keys.map {|k| record[k]}.join(separator)
59
59
  end
@@ -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
@@ -495,7 +492,11 @@ EOC
495
492
  end
496
493
 
497
494
  def detect_es_major_version
498
- @_es_info ||= client.info
495
+ begin
496
+ @_es_info ||= client.info
497
+ rescue ::Elasticsearch::UnsupportedProductError => e
498
+ raise Fluent::ConfigError, "Using Elasticsearch client #{client_library_version} is not compatible for your Elasticsearch server. Please check your using elasticsearch gem version and Elasticsearch server."
499
+ end
499
500
  begin
500
501
  unless version = @_es_info.dig("version", "number")
501
502
  version = @default_elasticsearch_version
@@ -613,7 +614,7 @@ EOC
613
614
  .merge(gzip_headers)
614
615
  ssl_options = { verify: @ssl_verify, ca_file: @ca_file}.merge(@ssl_version_options)
615
616
 
616
- transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(connection_options.merge(
617
+ transport = TRANSPORT_CLASS::Transport::HTTP::Faraday.new(connection_options.merge(
617
618
  options: {
618
619
  reload_connections: local_reload_connections,
619
620
  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
 
@@ -228,6 +243,10 @@ module Fluent::Plugin
228
243
  chunk.msgpack_each do |time, record|
229
244
  next unless record.is_a? Hash
230
245
 
246
+ if @include_tag_key
247
+ record[@tag_key] = tag
248
+ end
249
+
231
250
  begin
232
251
  record.merge!({"@timestamp" => Time.at(time).iso8601(@time_precision)})
233
252
  bulk_message = append_record_to_messages(CREATE_OP, {}, headers, record, bulk_message)
@@ -28,6 +28,8 @@ module Fluent::Plugin
28
28
  @dynamic_config[key] = value.to_s
29
29
  }
30
30
  # end eval all configs
31
+
32
+ log.warn "Elasticsearch dynamic plugin will be deprecated and removed in the future. Please consider to use normal Elasticsearch plugin"
31
33
  end
32
34
 
33
35
  def create_meta_config_map
@@ -53,7 +55,7 @@ module Fluent::Plugin
53
55
  end
54
56
  headers = { 'Content-Type' => @content_type.to_s, }.merge(gzip_headers)
55
57
  ssl_options = { verify: @ssl_verify, ca_file: @ca_file}.merge(@ssl_version_options)
56
- transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(connection_options.merge(
58
+ transport = TRANSPORT_CLASS::Transport::HTTP::Faraday.new(connection_options.merge(
57
59
  options: {
58
60
  reload_connections: @reload_connections,
59
61
  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
@@ -132,10 +132,10 @@ class ElasticsearchGenidFilterTest < Test::Unit::TestCase
132
132
  end
133
133
 
134
134
  class UseEntireRecordAsSeedTest < self
135
- data("md5" => ["md5", "MuMU0gHOP1cWvvg/J4aEFg=="],
136
- "sha1" => ["sha1", "GZ6Iup9Ywyk5spCWtPQbtZnfK0U="],
137
- "sha256" => ["sha256", "O4YN0RiXCUAYeaR97UUULRLxgra/R2dvTV47viir5l4="],
138
- "sha512" => ["sha512", "FtbwO1xsLUq0KcO0mj0l80rbwFH5rGE3vL+Vgh90+4R/9j+/Ni/ipwhiOoUcetDxj1r5Vf/92B54La+QTu3eMA=="],)
135
+ data("md5" => ["md5", "OAod7J0DR9s9/rOQnkeSFw=="],
136
+ "sha1" => ["sha1", "0CT4aMJ4gxMT3TKaYPCYApiVsq8="],
137
+ "sha256" => ["sha256", "mbAuKF5can0TTj/JBk71AXtOyoVqw5W5gMPUxx6pxLk="],
138
+ "sha512" => ["sha512", "f7kz5KVuDy+riENePDzqBjGQfbuRNpRBSQMzT2/6hrljXbYtBy3YFmxB86ofIf3zz4ZBao2QM2W7YvcwbRtK1w=="],)
139
139
  def test_record
140
140
  hash_type, expected = data
141
141
  d = create_driver(%[
@@ -151,10 +151,10 @@ class ElasticsearchGenidFilterTest < Test::Unit::TestCase
151
151
  d.filtered.map {|e| e.last}.first[d.instance.hash_id_key])
152
152
  end
153
153
 
154
- data("md5" => ["md5", "GJfpWe8ofiGzn97bc9Gh0Q=="],
155
- "sha1" => ["sha1", "AVaK67Tz0bEJ8xNEzjOQ6r9fAu4="],
156
- "sha256" => ["sha256", "WIXWAuf/Z94Uw95mudloo2bgjhSsSduQIwkKTQsNFgU="],
157
- "sha512" => ["sha512", "yjMGGxy8uc7gCrPgm8W6MzJGLFk0GtUwJ6w/91laf6WNywuvG/7T6kNHLagAV8rSW8xzxmtEfyValBO5scuoKw=="],)
154
+ data("md5" => ["md5", "Hb0jwxofNQP+ufQTKK1U4g=="],
155
+ "sha1" => ["sha1", "BakTtlotl/u+yOON6YcViTz6nms="],
156
+ "sha256" => ["sha256", "eLuTCsFqDlk6PfABNyD39r36+yNIBeDTHyNKfJ8fZQw="],
157
+ "sha512" => ["sha512", "PhPCNGalM4H4xT19DnCBnpwr56lbvCo8wJGyCiH9dWcyhn1nA5l1diYSZlF2fNiq1+wzMqfGvJILIjgQrlAPcg=="],)
158
158
  def test_record_with_tag
159
159
  hash_type, expected = data
160
160
  d = create_driver(%[
@@ -171,10 +171,10 @@ class ElasticsearchGenidFilterTest < Test::Unit::TestCase
171
171
  d.filtered.map {|e| e.last}.first[d.instance.hash_id_key])
172
172
  end
173
173
 
174
- data("md5" => ["md5", "5nQSaJ4F1p9rDFign13Lfg=="],
175
- "sha1" => ["sha1", "hyo9+0ZFBpizKl2NShs3C8yQcGw="],
176
- "sha256" => ["sha256", "romVsZSIksbqYsOSnUzolZQw76ankcy0DgvDZ3CayTo="],
177
- "sha512" => ["sha512", "RPU7K2Pt0iVyvV7p5usqcUIIOmfTajD1aa7pkR9qZ89UARH/lpm6ESY9iwuYJj92lxOUuF5OxlEwvV7uXJ07iA=="],)
174
+ data("md5" => ["md5", "C8vfhC4kecNCNutFCuC6MA=="],
175
+ "sha1" => ["sha1", "+YWVqUEL90wpKJRrionUJwNgXHg="],
176
+ "sha256" => ["sha256", "eSqGZqjnO6Uum/4CNfJaolX49+2XKogiGMHGNHiO91Q="],
177
+ "sha512" => ["sha512", "iVmuD0D+i/WtBwNza09ZXSIW8Xg8/yrUwK/M/EZaCMjz/x5FyyCiVkb1VVKsgNnJy0SYt4w21dhHewu1aXM6HA=="],)
178
178
  def test_record_with_time
179
179
  hash_type, expected = data
180
180
  d = create_driver(%[
@@ -191,10 +191,10 @@ class ElasticsearchGenidFilterTest < Test::Unit::TestCase
191
191
  d.filtered.map {|e| e.last}.first[d.instance.hash_id_key])
192
192
  end
193
193
 
194
- data("md5" => ["md5", "zGQF35KlMUibJAcgkgQDtw=="],
195
- "sha1" => ["sha1", "1x9RZO1xEuWps090qq4DUIsU9x8="],
196
- "sha256" => ["sha256", "eulMz0eF56lBEf31aIs0OG2TGCH/aoPfZbRqfEOkAwk="],
197
- "sha512" => ["sha512", "mIiYATtpdUFEFCIZg1FdKssIs7oWY0gJjhSSbet0ddUmqB+CiQAcAMTmrXO6AVSH0vsMvao/8vtC8AsIPfF1fA=="],)
194
+ data("md5" => ["md5", "lU7d4EiF+2M1zxWcsmBbjg=="],
195
+ "sha1" => ["sha1", "nghmz1y3KTEFxalfS2/Oe4n4yfQ="],
196
+ "sha256" => ["sha256", "d0le9UOnUeuGPF/2yEBRM1YzOYeHtxYOE1UU6JgJrvU="],
197
+ "sha512" => ["sha512", "n7rhisGHUBne6c4Cs9DRMbPror8O5Y/vYajDqAtOaiUTys/Z1EKBMnZQA0iVNFw7joX33cenBW3Yyccct3xSew=="],)
198
198
  def test_record_with_tag_and_time
199
199
  hash_type, expected = data
200
200
  d = create_driver(%[
@@ -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")