Skip to content

Commit 73d196e

Browse files
committed
test: Handle ES9 changes for request headers
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
1 parent 2f85fe2 commit 73d196e

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

test/plugin/test_elasticsearch_index_lifecycle_management.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def elasticsearch_version
3737
end
3838
end
3939

40+
def elasticsearch_miscellaneous_content_type?
41+
Gem::Version.create(Elasticsearch::VERSION) >= Gem::Version.new("9.0.0")
42+
end
43+
4044
def ilm_existence_endpoint(policy_id)
4145
if Gem::Version.new(Elasticsearch::VERSION) >= Gem::Version.new("8.0.0")
4246
"_ilm/policy/#{policy_id}"
@@ -90,10 +94,20 @@ def test_ilm_policy_exists
9094
def test_create_ilm_policy
9195
stub_request(:get, "http://localhost:9200/#{ilm_creation_endpoint("fluent-policy")}").
9296
to_return(:status => 404, :body => "", :headers => {'x-elastic-product' => 'Elasticsearch'})
93-
stub_request(:put, "http://localhost:9200/#{ilm_creation_endpoint("fluent-policy")}").
94-
with(:body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}",
95-
:headers => {'Content-Type'=>'application/json'}).
96-
to_return(:status => 200, :body => "", :headers => {'x-elastic-product' => 'Elasticsearch'})
97+
if elasticsearch_miscellaneous_content_type?
98+
stub_request(:put, "http://localhost:9200/#{ilm_creation_endpoint("fluent-policy")}").
99+
with(
100+
body: "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}",
101+
headers: {
102+
'Content-Type'=>'application/vnd.elasticsearch+json; compatible-with=9',
103+
}).
104+
to_return(:status => 200, :body => "", :headers => {'x-elastic-product' => 'Elasticsearch'})
105+
else
106+
stub_request(:put, "http://localhost:9200/#{ilm_creation_endpoint("fluent-policy")}").
107+
with(:body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}",
108+
:headers => {'Content-Type'=>'application/json'}).
109+
to_return(:status => 200, :body => "", :headers => {'x-elastic-product' => 'Elasticsearch'})
110+
end
97111
stub_elastic_info
98112
create_ilm_policy("fluent-policy")
99113

test/plugin/test_out_elasticsearch.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ def elastic_transport_layer?
6565
Gem::Version.create(::TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
6666
end
6767

68+
def elasticsearch_miscellaneous_content_type?
69+
Gem::Version.create(Elasticsearch::VERSION) >= Gem::Version.new("9.0.0")
70+
end
71+
6872
def default_type_name
6973
Fluent::Plugin::ElasticsearchOutput::DEFAULT_TYPE_NAME
7074
end
@@ -3889,7 +3893,12 @@ def test_password_is_required_if_specify_user
38893893
def test_content_type_header
38903894
stub_request(:head, "http://localhost:9200/").
38913895
to_return(:status => 200, :body => "", :headers => {'x-elastic-product' => 'Elasticsearch'})
3892-
if Elasticsearch::VERSION >= "6.0.2"
3896+
3897+
if elasticsearch_miscellaneous_content_type?
3898+
elastic_request = stub_request(:post, "http://localhost:9200/_bulk").
3899+
with(headers: { "Content-Type" => "application/vnd.elasticsearch+x-ndjson; compatible-with=9" }).
3900+
to_return(:status => 200, :body => "", :headers => {'x-elastic-product' => 'Elasticsearch'})
3901+
elsif Elasticsearch::VERSION >= "6.0.2"
38933902
elastic_request = stub_request(:post, "http://localhost:9200/_bulk").
38943903
with(headers: { "Content-Type" => "application/x-ndjson" }).
38953904
to_return(:status => 200, :body => "", :headers => {'x-elastic-product' => 'Elasticsearch'})

test/plugin/test_out_elasticsearch_dynamic.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ def elastic_transport_layer?
5050
Gem::Version.create(::TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
5151
end
5252

53+
def elasticsearch_miscellaneous_content_type?
54+
Gem::Version.create(Elasticsearch::VERSION) >= Gem::Version.new("9.0.0")
55+
end
56+
5357
def default_type_name
5458
Fluent::Plugin::ElasticsearchOutput::DEFAULT_TYPE_NAME
5559
end
@@ -388,7 +392,11 @@ def test_single_host_params_and_defaults_with_escape_placeholders
388392
def test_content_type_header
389393
stub_request(:head, "http://localhost:9200/").
390394
to_return(:status => 200, :body => "", :headers => {'x-elastic-product' => 'Elasticsearch'})
391-
if Elasticsearch::VERSION >= "6.0.2"
395+
if elasticsearch_miscellaneous_content_type?
396+
elastic_request = stub_request(:post, "http://localhost:9200/_bulk").
397+
with(headers: { "Content-Type" => "application/vnd.elasticsearch+x-ndjson; compatible-with=9" }).
398+
to_return(:status => 200, :body => "", :headers => {'x-elastic-product' => 'Elasticsearch'})
399+
elsif Elasticsearch::VERSION >= "6.0.2"
392400
elastic_request = stub_request(:post, "http://localhost:9200/_bulk").
393401
with(headers: { "Content-Type" => "application/x-ndjson"}).
394402
to_return(:status => 200, :body => "", :headers => {'x-elastic-product' => 'Elasticsearch'})

0 commit comments

Comments
 (0)