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.
@@ -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")