fluent-plugin-elasticsearch 5.1.4 → 5.2.1
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 +4 -4
- data/Gemfile +1 -1
- data/History.md +13 -0
- data/README.md +16 -1
- data/fluent-plugin-elasticsearch.gemspec +1 -1
- data/lib/fluent/plugin/elasticsearch_compat.rb +30 -0
- data/lib/fluent/plugin/elasticsearch_fallback_selector.rb +2 -2
- data/lib/fluent/plugin/elasticsearch_index_lifecycle_management.rb +18 -4
- data/lib/fluent/plugin/elasticsearch_index_template.rb +8 -4
- data/lib/fluent/plugin/elasticsearch_simple_sniffer.rb +2 -1
- data/lib/fluent/plugin/in_elasticsearch.rb +2 -1
- data/lib/fluent/plugin/oj_serializer.rb +2 -1
- data/lib/fluent/plugin/out_elasticsearch.rb +9 -8
- data/lib/fluent/plugin/out_elasticsearch_data_stream.rb +59 -29
- data/lib/fluent/plugin/out_elasticsearch_dynamic.rb +3 -1
- data/test/plugin/test_elasticsearch_fallback_selector.rb +15 -7
- data/test/plugin/test_elasticsearch_index_lifecycle_management.rb +47 -17
- data/test/plugin/test_in_elasticsearch.rb +10 -2
- data/test/plugin/test_out_elasticsearch.rb +281 -122
- data/test/plugin/test_out_elasticsearch_data_stream.rb +266 -35
- data/test/plugin/test_out_elasticsearch_dynamic.rb +57 -20
- metadata +3 -2
@@ -6,12 +6,14 @@ class TestElasticsearchIndexLifecycleManagement < Test::Unit::TestCase
|
|
6
6
|
include Fluent::Plugin::ElasticsearchIndexLifecycleManagement
|
7
7
|
|
8
8
|
def setup
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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(::
|
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
|
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
|
-
|
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
|
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?(
|
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
|
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?(
|
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
|
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
|
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
|
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
|
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")
|