fluent-plugin-elasticsearch 4.2.1 → 4.3.3
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/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +24 -0
- data/.github/workflows/issue-auto-closer.yml +1 -1
- data/History.md +22 -0
- data/README.ElasticsearchGenID.md +2 -2
- data/README.md +39 -2
- data/fluent-plugin-elasticsearch.gemspec +1 -1
- data/lib/fluent/plugin/elasticsearch_index_template.rb +15 -11
- data/lib/fluent/plugin/out_elasticsearch.rb +47 -15
- data/test/plugin/test_elasticsearch_fallback_selector.rb +1 -0
- data/test/plugin/test_elasticsearch_index_lifecycle_management.rb +3 -0
- data/test/plugin/test_out_elasticsearch.rb +445 -28
- metadata +4 -2
@@ -58,6 +58,7 @@ class ElasticsearchFallbackSelectorTest < Test::Unit::TestCase
|
|
58
58
|
with_transporter_log true
|
59
59
|
reload_connections true
|
60
60
|
reload_after 10
|
61
|
+
catch_transport_exception_on_retry false # For fallback testing
|
61
62
|
]
|
62
63
|
assert_raise(Elasticsearch::Transport::Transport::Errors::NotFound) do
|
63
64
|
driver(config)
|
@@ -11,6 +11,9 @@ class TestElasticsearchIndexLifecycleManagement < Test::Unit::TestCase
|
|
11
11
|
rescue LoadError
|
12
12
|
omit "ILM testcase needs elasticsearch-xpack gem."
|
13
13
|
end
|
14
|
+
if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.4.0")
|
15
|
+
omit "elastisearch-ruby v7.4.0 or later is needed for ILM."
|
16
|
+
end
|
14
17
|
Fluent::Plugin::ElasticsearchIndexLifecycleManagement.module_eval(<<-CODE)
|
15
18
|
def client
|
16
19
|
Elasticsearch::Client.new url: 'localhost:9200'
|
@@ -322,6 +322,19 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
322
322
|
assert_equal true, instance.client(nil, compressable).transport.options[:compression]
|
323
323
|
end
|
324
324
|
|
325
|
+
test 'check configure cloud_id based client' do
|
326
|
+
|
327
|
+
config = %{
|
328
|
+
cloud_id "name:bG9jYWxob3N0JGFiY2QkZWZnaA=="
|
329
|
+
cloud_auth "some:auth"
|
330
|
+
}
|
331
|
+
instance = driver(config).instance
|
332
|
+
|
333
|
+
assert_equal "name:bG9jYWxob3N0JGFiY2QkZWZnaA==", instance.cloud_id
|
334
|
+
assert_equal "some", instance.user
|
335
|
+
assert_equal "auth", instance.password
|
336
|
+
end
|
337
|
+
|
325
338
|
test 'configure Content-Type' do
|
326
339
|
config = %{
|
327
340
|
content_type application/x-ndjson
|
@@ -357,6 +370,65 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
357
370
|
}
|
358
371
|
end
|
359
372
|
|
373
|
+
sub_test_case 'Check client.info response' do
|
374
|
+
def create_driver(conf='', es_version=5, client_version="\"5.0\"")
|
375
|
+
# For request stub to detect compatibility.
|
376
|
+
@client_version ||= client_version
|
377
|
+
@default_elasticsearch_version ||= es_version
|
378
|
+
Fluent::Plugin::ElasticsearchOutput.module_eval(<<-CODE)
|
379
|
+
def detect_es_major_version
|
380
|
+
@_es_info ||= client.info
|
381
|
+
begin
|
382
|
+
unless version = @_es_info.dig("version", "number")
|
383
|
+
version = @default_elasticsearch_version
|
384
|
+
end
|
385
|
+
rescue NoMethodError => e
|
386
|
+
log.warn "#{@_es_info} can not dig version information. Assuming Elasticsearch #{@default_elasticsearch_version}", error: e
|
387
|
+
version = @default_elasticsearch_version
|
388
|
+
end
|
389
|
+
version.to_i
|
390
|
+
end
|
391
|
+
CODE
|
392
|
+
|
393
|
+
Fluent::Plugin::ElasticsearchOutput.module_eval(<<-CODE)
|
394
|
+
def client_library_version
|
395
|
+
#{@client_version}
|
396
|
+
end
|
397
|
+
CODE
|
398
|
+
@driver ||= Fluent::Test::Driver::Output.new(Fluent::Plugin::ElasticsearchOutput) {
|
399
|
+
# v0.12's test driver assume format definition. This simulates ObjectBufferedOutput format
|
400
|
+
if !defined?(Fluent::Plugin::Output)
|
401
|
+
def format(tag, time, record)
|
402
|
+
[time, record].to_msgpack
|
403
|
+
end
|
404
|
+
end
|
405
|
+
}.configure(conf)
|
406
|
+
end
|
407
|
+
|
408
|
+
def stub_elastic_info_bad(url="http://localhost:9200/", version="6.4.2")
|
409
|
+
body ="{\"version\":{\"number\":\"#{version}\"}}"
|
410
|
+
stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'text/plain' } })
|
411
|
+
end
|
412
|
+
|
413
|
+
test 'handle invalid client.info' do
|
414
|
+
stub_elastic_info_bad("https://logs.fluentd.com:24225/es//", "7.7.1")
|
415
|
+
config = %{
|
416
|
+
host logs.fluentd.com
|
417
|
+
port 24225
|
418
|
+
scheme https
|
419
|
+
path /es/
|
420
|
+
user john
|
421
|
+
password doe
|
422
|
+
default_elasticsearch_version 7
|
423
|
+
scheme https
|
424
|
+
@log_level info
|
425
|
+
}
|
426
|
+
d = create_driver(config, 7, "\"7.10.1\"")
|
427
|
+
logs = d.logs
|
428
|
+
assert_logs_include(logs, /can not dig version information. Assuming Elasticsearch 7/)
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
360
432
|
sub_test_case 'Check TLS handshake stuck warning log' do
|
361
433
|
test 'warning TLS log' do
|
362
434
|
config = %{
|
@@ -383,7 +455,13 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
383
455
|
data("legacy_template" => [true, "_template"],
|
384
456
|
"new_template" => [false, "_index_template"])
|
385
457
|
test 'valid configuration of index lifecycle management' do |data|
|
458
|
+
if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.4.0")
|
459
|
+
omit "elastisearch-ruby v7.4.0 or later is needed for ILM."
|
460
|
+
end
|
386
461
|
use_legacy_template_flag, endpoint = data
|
462
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
463
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
464
|
+
end
|
387
465
|
cwd = File.dirname(__FILE__)
|
388
466
|
template_file = File.join(cwd, 'test_template.json')
|
389
467
|
|
@@ -419,7 +497,13 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
419
497
|
data("legacy_template" => [true, "_template"],
|
420
498
|
"new_template" => [false, "_index_template"])
|
421
499
|
test 'valid configuration of overwriting ilm_policy' do |data|
|
500
|
+
if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.4.0")
|
501
|
+
omit "elastisearch-ruby v7.4.0 or later is needed for ILM."
|
502
|
+
end
|
422
503
|
use_legacy_template_flag, endpoint = data
|
504
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
505
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
506
|
+
end
|
423
507
|
cwd = File.dirname(__FILE__)
|
424
508
|
template_file = File.join(cwd, 'test_template.json')
|
425
509
|
|
@@ -823,6 +907,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
823
907
|
"new_template" => [false, "_index_template"])
|
824
908
|
def test_template_already_present(data)
|
825
909
|
use_legacy_template_flag, endpoint = data
|
910
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
911
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
912
|
+
end
|
826
913
|
config = %{
|
827
914
|
host logs.google.com
|
828
915
|
port 777
|
@@ -853,6 +940,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
853
940
|
"new_template" => [false, "_index_template"])
|
854
941
|
def test_template_create(data)
|
855
942
|
use_legacy_template_flag, endpoint = data
|
943
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
944
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
945
|
+
end
|
856
946
|
cwd = File.dirname(__FILE__)
|
857
947
|
template_file = if use_legacy_template_flag
|
858
948
|
File.join(cwd, 'test_template.json')
|
@@ -894,6 +984,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
894
984
|
"new_template" => [false, "_index_template"])
|
895
985
|
def test_template_create_with_rollover_index_and_template_related_placeholders(data)
|
896
986
|
use_legacy_template_flag, endpoint = data
|
987
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
988
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
989
|
+
end
|
897
990
|
cwd = File.dirname(__FILE__)
|
898
991
|
template_file = if use_legacy_template_flag
|
899
992
|
File.join(cwd, 'test_template.json')
|
@@ -959,6 +1052,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
959
1052
|
"new_template" => [false, "_index_template"])
|
960
1053
|
def test_template_create_with_rollover_index_and_template_related_placeholders_with_truncating_caches(data)
|
961
1054
|
use_legacy_template_flag, endpoint = data
|
1055
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
1056
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
1057
|
+
end
|
962
1058
|
cwd = File.dirname(__FILE__)
|
963
1059
|
template_file = if use_legacy_template_flag
|
964
1060
|
File.join(cwd, 'test_template.json')
|
@@ -1034,12 +1130,18 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1034
1130
|
rescue LoadError
|
1035
1131
|
omit "ILM testcase needs elasticsearch-xpack gem."
|
1036
1132
|
end
|
1133
|
+
if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.4.0")
|
1134
|
+
omit "elastisearch-ruby v7.4.0 or later is needed for ILM."
|
1135
|
+
end
|
1037
1136
|
end
|
1038
1137
|
|
1039
1138
|
data("legacy_template" => [true, "_template"],
|
1040
1139
|
"new_template" => [false, "_index_template"])
|
1041
1140
|
def test_template_create_with_rollover_index_and_default_ilm(data)
|
1042
1141
|
use_legacy_template_flag, endpoint = data
|
1142
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
1143
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
1144
|
+
end
|
1043
1145
|
cwd = File.dirname(__FILE__)
|
1044
1146
|
template_file = if use_legacy_template_flag
|
1045
1147
|
File.join(cwd, 'test_template.json')
|
@@ -1120,6 +1222,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1120
1222
|
"new_template" => [false, "_index_template"])
|
1121
1223
|
def test_template_create_with_rollover_index_and_default_ilm_on_logstash_format(data)
|
1122
1224
|
use_legacy_template_flag, endpoint = data
|
1225
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
1226
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
1227
|
+
end
|
1123
1228
|
cwd = File.dirname(__FILE__)
|
1124
1229
|
template_file = if use_legacy_template_flag
|
1125
1230
|
File.join(cwd, 'test_template.json')
|
@@ -1209,6 +1314,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1209
1314
|
"new_template" => [false, "_index_template"])
|
1210
1315
|
def test_template_create_with_rollover_index_and_default_ilm_and_ilm_policy_overwrite(data)
|
1211
1316
|
use_legacy_template_flag, endpoint = data
|
1317
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
1318
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
1319
|
+
end
|
1212
1320
|
cwd = File.dirname(__FILE__)
|
1213
1321
|
template_file = if use_legacy_template_flag
|
1214
1322
|
File.join(cwd, 'test_template.json')
|
@@ -1316,6 +1424,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1316
1424
|
"new_template" => [false, "_index_template"])
|
1317
1425
|
def test_template_create_with_rollover_index_and_default_ilm_with_empty_index_date_pattern(data)
|
1318
1426
|
use_legacy_template_flag, endpoint = data
|
1427
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
1428
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
1429
|
+
end
|
1319
1430
|
cwd = File.dirname(__FILE__)
|
1320
1431
|
template_file = if use_legacy_template_flag
|
1321
1432
|
File.join(cwd, 'test_template.json')
|
@@ -1396,6 +1507,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1396
1507
|
"new_template" => [false, "_index_template"])
|
1397
1508
|
def test_template_create_with_rollover_index_and_custom_ilm(data)
|
1398
1509
|
use_legacy_template_flag, endpoint = data
|
1510
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
1511
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
1512
|
+
end
|
1399
1513
|
cwd = File.dirname(__FILE__)
|
1400
1514
|
template_file = if use_legacy_template_flag
|
1401
1515
|
File.join(cwd, 'test_template.json')
|
@@ -1477,6 +1591,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1477
1591
|
"new_template" => [false, "_index_template"])
|
1478
1592
|
def test_template_create_with_rollover_index_and_ilm_policies_and_placeholderstest_template_create_with_rollover_index_and_ilm_policies_and_placeholders(data)
|
1479
1593
|
use_legacy_template_flag, endpoint = data
|
1594
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
1595
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
1596
|
+
end
|
1480
1597
|
cwd = File.dirname(__FILE__)
|
1481
1598
|
template_file = if use_legacy_template_flag
|
1482
1599
|
File.join(cwd, 'test_template.json')
|
@@ -1565,6 +1682,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1565
1682
|
"new_template" => [false, "_index_template"])
|
1566
1683
|
def test_tag_placeholder(data)
|
1567
1684
|
use_legacy_template_flag, endpoint = data
|
1685
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
1686
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
1687
|
+
end
|
1568
1688
|
cwd = File.dirname(__FILE__)
|
1569
1689
|
template_file = if use_legacy_template_flag
|
1570
1690
|
File.join(cwd, 'test_template.json')
|
@@ -1652,6 +1772,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1652
1772
|
"new_template" => [false, "_index_template"])
|
1653
1773
|
def test_tag_placeholder_with_multiple_policies(data)
|
1654
1774
|
use_legacy_template_flag, endpoint = data
|
1775
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
1776
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
1777
|
+
end
|
1655
1778
|
cwd = File.dirname(__FILE__)
|
1656
1779
|
template_file = if use_legacy_template_flag
|
1657
1780
|
File.join(cwd, 'test_template.json')
|
@@ -1740,6 +1863,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1740
1863
|
"new_template" => [false, "_index_template"])
|
1741
1864
|
def test_template_create_with_rollover_index_and_default_ilm_and_placeholders(data)
|
1742
1865
|
use_legacy_template_flag, endpoint = data
|
1866
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
1867
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
1868
|
+
end
|
1743
1869
|
cwd = File.dirname(__FILE__)
|
1744
1870
|
template_file = if use_legacy_template_flag
|
1745
1871
|
File.join(cwd, 'test_template.json')
|
@@ -1775,30 +1901,65 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1775
1901
|
with(basic_auth: ['john', 'doe']).
|
1776
1902
|
to_return(:status => 200, :body => "", :headers => {})
|
1777
1903
|
# check if alias exists
|
1778
|
-
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash-
|
1904
|
+
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash-tag1").
|
1779
1905
|
with(basic_auth: ['john', 'doe']).
|
1780
1906
|
to_return(:status => 404, :body => "", :headers => {})
|
1781
|
-
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash-
|
1907
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash-tag1").
|
1782
1908
|
with(basic_auth: ['john', 'doe']).
|
1783
1909
|
to_return(status: 404, body: "", headers: {})
|
1784
1910
|
if use_legacy_template_flag
|
1785
|
-
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash-
|
1911
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash-tag1").
|
1786
1912
|
with(basic_auth: ['john', 'doe'],
|
1787
|
-
body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash-
|
1913
|
+
body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash-tag1\"},\"mappings\":{\"type1\":{\"_source\":{\"enabled\":false},\"properties\":{\"host_name\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"created_at\":{\"type\":\"date\",\"format\":\"EEE MMM dd HH:mm:ss Z YYYY\"}}}},\"index_patterns\":\"logstash-tag1-*\",\"order\":52}").
|
1788
1914
|
to_return(status: 200, body: "", headers: {})
|
1789
1915
|
else
|
1790
|
-
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash-
|
1916
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash-tag1").
|
1791
1917
|
with(basic_auth: ['john', 'doe'],
|
1792
|
-
body: "{\"index_patterns\":\"logstash-
|
1918
|
+
body: "{\"index_patterns\":\"logstash-tag1-*\",\"template\":{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash-tag1\"},\"mappings\":{\"type1\":{\"_source\":{\"enabled\":false},\"properties\":{\"host_name\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"created_at\":{\"type\":\"date\",\"format\":\"EEE MMM dd HH:mm:ss Z YYYY\"}}}}},\"priority\":102}").
|
1793
1919
|
to_return(status: 200, body: "", headers: {})
|
1794
1920
|
end
|
1795
1921
|
# put the alias for the index
|
1796
|
-
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-
|
1922
|
+
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-tag1-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
|
1923
|
+
with(basic_auth: ['john', 'doe']).
|
1924
|
+
to_return(:status => 200, :body => "", :headers => {})
|
1925
|
+
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-tag1-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/#{alias_endpoint}/logstash-tag1").
|
1926
|
+
with(basic_auth: ['john', 'doe'],
|
1927
|
+
:body => "{\"aliases\":{\"logstash-tag1\":{\"is_write_index\":true}}}").
|
1928
|
+
to_return(:status => 200, :body => "", :headers => {})
|
1929
|
+
stub_request(:get, "https://logs.google.com:777/es//_xpack").
|
1930
|
+
with(basic_auth: ['john', 'doe']).
|
1931
|
+
to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
|
1932
|
+
stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
|
1797
1933
|
with(basic_auth: ['john', 'doe']).
|
1934
|
+
to_return(:status => 404, :body => "", :headers => {})
|
1935
|
+
stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
|
1936
|
+
with(basic_auth: ['john', 'doe'],
|
1937
|
+
:body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
|
1798
1938
|
to_return(:status => 200, :body => "", :headers => {})
|
1799
|
-
|
1939
|
+
# check if alias exists
|
1940
|
+
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash-tag2").
|
1941
|
+
with(basic_auth: ['john', 'doe']).
|
1942
|
+
to_return(:status => 404, :body => "", :headers => {})
|
1943
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash-tag2").
|
1944
|
+
with(basic_auth: ['john', 'doe']).
|
1945
|
+
to_return(status: 404, body: "", headers: {})
|
1946
|
+
if use_legacy_template_flag
|
1947
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash-tag2").
|
1948
|
+
with(basic_auth: ['john', 'doe'],
|
1949
|
+
body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash-tag2\"},\"mappings\":{\"type1\":{\"_source\":{\"enabled\":false},\"properties\":{\"host_name\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"created_at\":{\"type\":\"date\",\"format\":\"EEE MMM dd HH:mm:ss Z YYYY\"}}}},\"index_patterns\":\"logstash-tag2-*\",\"order\":52}").
|
1950
|
+
to_return(status: 200, body: "", headers: {})
|
1951
|
+
else
|
1952
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash-tag2").
|
1953
|
+
with(basic_auth: ['john', 'doe'],
|
1954
|
+
body: "{\"index_patterns\":\"logstash-tag2-*\",\"template\":{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash-tag2\"},\"mappings\":{\"type1\":{\"_source\":{\"enabled\":false},\"properties\":{\"host_name\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"created_at\":{\"type\":\"date\",\"format\":\"EEE MMM dd HH:mm:ss Z YYYY\"}}}}},\"priority\":102}").
|
1955
|
+
to_return(status: 200, body: "", headers: {})
|
1956
|
+
end # put the alias for the index
|
1957
|
+
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-tag2-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
|
1958
|
+
with(basic_auth: ['john', 'doe']).
|
1959
|
+
to_return(:status => 200, :body => "", :headers => {})
|
1960
|
+
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-tag2-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/#{alias_endpoint}/logstash-tag2").
|
1800
1961
|
with(basic_auth: ['john', 'doe'],
|
1801
|
-
:body => "{\"aliases\":{\"logstash-
|
1962
|
+
:body => "{\"aliases\":{\"logstash-tag2\":{\"is_write_index\":true}}}").
|
1802
1963
|
to_return(:status => 200, :body => "", :headers => {})
|
1803
1964
|
stub_request(:get, "https://logs.google.com:777/es//_xpack").
|
1804
1965
|
with(basic_auth: ['john', 'doe']).
|
@@ -1815,11 +1976,107 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1815
1976
|
|
1816
1977
|
elastic_request = stub_elastic("https://logs.google.com:777/es//_bulk")
|
1817
1978
|
driver.run(default_tag: 'test') do
|
1818
|
-
driver.feed(sample_record)
|
1979
|
+
driver.feed('tag1', event_time, sample_record)
|
1980
|
+
driver.feed('tag2', event_time, sample_record)
|
1981
|
+
driver.feed('tag1', event_time, sample_record)
|
1982
|
+
driver.feed('tag2', event_time, sample_record)
|
1819
1983
|
end
|
1820
|
-
assert_equal('logstash-
|
1984
|
+
assert_equal('logstash-tag2', index_cmds.first['index']['_index'])
|
1821
1985
|
|
1822
|
-
assert_equal ["logstash-
|
1986
|
+
assert_equal ["logstash-tag1", "logstash-tag2"], driver.instance.alias_indexes
|
1987
|
+
|
1988
|
+
assert_requested(elastic_request)
|
1989
|
+
end
|
1990
|
+
|
1991
|
+
|
1992
|
+
data("legacy_template" => [true, "_template"],
|
1993
|
+
"new_template" => [false, "_index_template"])
|
1994
|
+
def test_template_create_with_rollover_index_and_default_ilm_and_placeholders_and_index_separator(data)
|
1995
|
+
use_legacy_template_flag, endpoint = data
|
1996
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
1997
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
1998
|
+
end
|
1999
|
+
cwd = File.dirname(__FILE__)
|
2000
|
+
template_file = if use_legacy_template_flag
|
2001
|
+
File.join(cwd, 'test_template.json')
|
2002
|
+
else
|
2003
|
+
File.join(cwd, 'test_index_template.json')
|
2004
|
+
end
|
2005
|
+
|
2006
|
+
config = %{
|
2007
|
+
host logs.google.com
|
2008
|
+
port 777
|
2009
|
+
scheme https
|
2010
|
+
path /es/
|
2011
|
+
user john
|
2012
|
+
password doe
|
2013
|
+
template_name logstash
|
2014
|
+
template_file #{template_file}
|
2015
|
+
index_date_pattern now/w{xxxx.ww}
|
2016
|
+
index_name logstash.${tag}
|
2017
|
+
enable_ilm true
|
2018
|
+
index_separator "."
|
2019
|
+
use_legacy_template #{use_legacy_template_flag}
|
2020
|
+
}
|
2021
|
+
|
2022
|
+
# connection start
|
2023
|
+
stub_request(:head, "https://logs.google.com:777/es//").
|
2024
|
+
with(basic_auth: ['john', 'doe']).
|
2025
|
+
to_return(:status => 200, :body => "", :headers => {})
|
2026
|
+
# check if template exists
|
2027
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
2028
|
+
with(basic_auth: ['john', 'doe']).
|
2029
|
+
to_return(:status => 404, :body => "", :headers => {})
|
2030
|
+
# creation
|
2031
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
2032
|
+
with(basic_auth: ['john', 'doe']).
|
2033
|
+
to_return(:status => 200, :body => "", :headers => {})
|
2034
|
+
# check if alias exists
|
2035
|
+
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash.tag1").
|
2036
|
+
with(basic_auth: ['john', 'doe']).
|
2037
|
+
to_return(:status => 404, :body => "", :headers => {})
|
2038
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash.tag1").
|
2039
|
+
with(basic_auth: ['john', 'doe']).
|
2040
|
+
to_return(status: 404, body: "", headers: {})
|
2041
|
+
if use_legacy_template_flag
|
2042
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash.tag1").
|
2043
|
+
with(basic_auth: ['john', 'doe'],
|
2044
|
+
body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash.tag1\"},\"mappings\":{\"type1\":{\"_source\":{\"enabled\":false},\"properties\":{\"host_name\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"created_at\":{\"type\":\"date\",\"format\":\"EEE MMM dd HH:mm:ss Z YYYY\"}}}},\"index_patterns\":\"logstash.tag1.*\",\"order\":52}").
|
2045
|
+
to_return(status: 200, body: "", headers: {})
|
2046
|
+
else
|
2047
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash.tag1").
|
2048
|
+
with(basic_auth: ['john', 'doe'],
|
2049
|
+
body: "{\"index_patterns\":\"logstash.tag1.*\",\"template\":{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash.tag1\"},\"mappings\":{\"type1\":{\"_source\":{\"enabled\":false},\"properties\":{\"host_name\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"created_at\":{\"type\":\"date\",\"format\":\"EEE MMM dd HH:mm:ss Z YYYY\"}}}}},\"priority\":102}").
|
2050
|
+
to_return(status: 200, body: "", headers: {})
|
2051
|
+
end
|
2052
|
+
# put the alias for the index
|
2053
|
+
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash.tag1.default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
|
2054
|
+
with(basic_auth: ['john', 'doe']).
|
2055
|
+
to_return(:status => 200, :body => "", :headers => {})
|
2056
|
+
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash.tag1.default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/#{alias_endpoint}/logstash.tag1").
|
2057
|
+
with(basic_auth: ['john', 'doe'],
|
2058
|
+
:body => "{\"aliases\":{\"logstash.tag1\":{\"is_write_index\":true}}}").
|
2059
|
+
to_return(:status => 200, :body => "", :headers => {})
|
2060
|
+
stub_request(:get, "https://logs.google.com:777/es//_xpack").
|
2061
|
+
with(basic_auth: ['john', 'doe']).
|
2062
|
+
to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
|
2063
|
+
stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
|
2064
|
+
with(basic_auth: ['john', 'doe']).
|
2065
|
+
to_return(:status => 404, :body => "", :headers => {})
|
2066
|
+
stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
|
2067
|
+
with(basic_auth: ['john', 'doe'],
|
2068
|
+
:body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
|
2069
|
+
to_return(:status => 200, :body => "", :headers => {})
|
2070
|
+
|
2071
|
+
driver(config)
|
2072
|
+
|
2073
|
+
elastic_request = stub_elastic("https://logs.google.com:777/es//_bulk")
|
2074
|
+
driver.run(default_tag: 'test') do
|
2075
|
+
driver.feed('tag1', event_time, sample_record)
|
2076
|
+
end
|
2077
|
+
assert_equal('logstash.tag1', index_cmds.first['index']['_index'])
|
2078
|
+
|
2079
|
+
assert_equal ["logstash.tag1"], driver.instance.alias_indexes
|
1823
2080
|
|
1824
2081
|
assert_requested(elastic_request)
|
1825
2082
|
end
|
@@ -1828,6 +2085,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1828
2085
|
"new_template" => [false, "_index_template"])
|
1829
2086
|
def test_template_create_with_rollover_index_and_default_ilm_and_custom_and_time_placeholders(data)
|
1830
2087
|
use_legacy_template_flag, endpoint = data
|
2088
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
2089
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
2090
|
+
end
|
1831
2091
|
cwd = File.dirname(__FILE__)
|
1832
2092
|
template_file = if use_legacy_template_flag
|
1833
2093
|
File.join(cwd, 'test_template.json')
|
@@ -1922,6 +2182,10 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1922
2182
|
"new_template" => [false, "_index_template"])
|
1923
2183
|
def test_custom_template_create(data)
|
1924
2184
|
use_legacy_template_flag, endpoint = data
|
2185
|
+
|
2186
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
2187
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
2188
|
+
end
|
1925
2189
|
cwd = File.dirname(__FILE__)
|
1926
2190
|
template_file = if use_legacy_template_flag
|
1927
2191
|
File.join(cwd, 'test_alias_template.json')
|
@@ -1964,6 +2228,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1964
2228
|
"new_template" => [false, "_index_template"])
|
1965
2229
|
def test_custom_template_create_with_customize_template_related_placeholders(data)
|
1966
2230
|
use_legacy_template_flag, endpoint = data
|
2231
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
2232
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
2233
|
+
end
|
1967
2234
|
cwd = File.dirname(__FILE__)
|
1968
2235
|
template_file = if use_legacy_template_flag
|
1969
2236
|
File.join(cwd, 'test_alias_template.json')
|
@@ -2014,6 +2281,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2014
2281
|
"new_template" => [false, "_index_template"])
|
2015
2282
|
def test_custom_template_installation_for_host_placeholder(data)
|
2016
2283
|
use_legacy_template_flag, endpoint = data
|
2284
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
2285
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
2286
|
+
end
|
2017
2287
|
cwd = File.dirname(__FILE__)
|
2018
2288
|
template_file = if use_legacy_template_flag
|
2019
2289
|
File.join(cwd, 'test_template.json')
|
@@ -2060,6 +2330,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2060
2330
|
"new_template" => [false, "_index_template"])
|
2061
2331
|
def test_custom_template_with_rollover_index_create(data)
|
2062
2332
|
use_legacy_template_flag, endpoint = data
|
2333
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
2334
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
2335
|
+
end
|
2063
2336
|
cwd = File.dirname(__FILE__)
|
2064
2337
|
template_file = if use_legacy_template_flag
|
2065
2338
|
File.join(cwd, 'test_alias_template.json')
|
@@ -2118,6 +2391,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2118
2391
|
"new_template" => [false, "_index_template"])
|
2119
2392
|
def test_custom_template_with_rollover_index_create_and_deflector_alias(data)
|
2120
2393
|
use_legacy_template_flag, endpoint = data
|
2394
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
2395
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
2396
|
+
end
|
2121
2397
|
cwd = File.dirname(__FILE__)
|
2122
2398
|
template_file = if use_legacy_template_flag
|
2123
2399
|
File.join(cwd, 'test_alias_template.json')
|
@@ -2177,6 +2453,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2177
2453
|
"new_template" => [false, "_index_template"])
|
2178
2454
|
def test_custom_template_with_rollover_index_create_with_logstash_format(data)
|
2179
2455
|
use_legacy_template_flag, endpoint = data
|
2456
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
2457
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
2458
|
+
end
|
2180
2459
|
cwd = File.dirname(__FILE__)
|
2181
2460
|
template_file = if use_legacy_template_flag
|
2182
2461
|
File.join(cwd, 'test_alias_template.json')
|
@@ -2202,7 +2481,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2202
2481
|
use_legacy_template #{use_legacy_template_flag}
|
2203
2482
|
}
|
2204
2483
|
|
2205
|
-
timestr = Time.now.strftime("%Y.%m.%d")
|
2484
|
+
timestr = Time.now.getutc.strftime("%Y.%m.%d")
|
2206
2485
|
# connection start
|
2207
2486
|
stub_request(:head, "https://logs.google.com:777/es//").
|
2208
2487
|
with(basic_auth: ['john', 'doe']).
|
@@ -2245,12 +2524,18 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2245
2524
|
rescue LoadError
|
2246
2525
|
omit "ILM testcase needs elasticsearch-xpack gem."
|
2247
2526
|
end
|
2527
|
+
if Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.4.0")
|
2528
|
+
omit "elastisearch-ruby v7.4.0 or later is needed."
|
2529
|
+
end
|
2248
2530
|
end
|
2249
2531
|
|
2250
2532
|
data("legacy_template" => [true, "_template"],
|
2251
2533
|
"new_template" => [false, "_index_template"])
|
2252
2534
|
def test_custom_template_with_rollover_index_create_and_default_ilm(data)
|
2253
2535
|
use_legacy_template_flag, endpoint = data
|
2536
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
2537
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
2538
|
+
end
|
2254
2539
|
cwd = File.dirname(__FILE__)
|
2255
2540
|
template_file = if use_legacy_template_flag
|
2256
2541
|
File.join(cwd, 'test_alias_template.json')
|
@@ -2335,6 +2620,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2335
2620
|
"new_template" => [false, "_index_template"])
|
2336
2621
|
def test_custom_template_with_rollover_index_create_and_default_ilm_and_ilm_policy_overwrite(data)
|
2337
2622
|
use_legacy_template_flag, endpoint = data
|
2623
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
2624
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
2625
|
+
end
|
2338
2626
|
cwd = File.dirname(__FILE__)
|
2339
2627
|
template_file = if use_legacy_template_flag
|
2340
2628
|
File.join(cwd, 'test_alias_template.json')
|
@@ -2449,6 +2737,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2449
2737
|
"new_template" => [false, "_index_template"])
|
2450
2738
|
def test_custom_template_with_rollover_index_create_and_default_ilm_and_placeholders(data)
|
2451
2739
|
use_legacy_template_flag, endpoint = data
|
2740
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
2741
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
2742
|
+
end
|
2452
2743
|
cwd = File.dirname(__FILE__)
|
2453
2744
|
template_file = if use_legacy_template_flag
|
2454
2745
|
File.join(cwd, 'test_alias_template.json')
|
@@ -2478,6 +2769,8 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2478
2769
|
stub_request(:head, "https://logs.google.com:777/es//").
|
2479
2770
|
with(basic_auth: ['john', 'doe']).
|
2480
2771
|
to_return(:status => 200, :body => "", :headers => {})
|
2772
|
+
|
2773
|
+
# test-tag1
|
2481
2774
|
# check if template exists
|
2482
2775
|
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2483
2776
|
with(basic_auth: ['john', 'doe']).
|
@@ -2487,31 +2780,78 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2487
2780
|
with(basic_auth: ['john', 'doe']).
|
2488
2781
|
to_return(:status => 200, :body => "", :headers => {})
|
2489
2782
|
# creation of index which can rollover
|
2490
|
-
stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-
|
2783
|
+
stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-test-tag1-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
|
2491
2784
|
with(basic_auth: ['john', 'doe']).
|
2492
2785
|
to_return(:status => 200, :body => "", :headers => {})
|
2493
2786
|
# check if alias exists
|
2494
|
-
stub_request(:head, "https://logs.google.com:777/es//_alias/mylogs-
|
2787
|
+
stub_request(:head, "https://logs.google.com:777/es//_alias/mylogs-test-tag1").
|
2495
2788
|
with(basic_auth: ['john', 'doe']).
|
2496
2789
|
to_return(:status => 404, :body => "", :headers => {})
|
2497
|
-
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/mylogs-
|
2790
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/mylogs-test-tag1").
|
2498
2791
|
with(basic_auth: ['john', 'doe']).
|
2499
2792
|
to_return(status: 404, body: "", headers: {})
|
2500
2793
|
if use_legacy_template_flag
|
2501
|
-
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs-
|
2794
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs-test-tag1").
|
2502
2795
|
with(basic_auth: ['john', 'doe'],
|
2503
|
-
body: "{\"order\":8,\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"mylogs-
|
2796
|
+
body: "{\"order\":8,\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"mylogs-test-tag1\"},\"mappings\":{},\"aliases\":{\"myapp-logs-alias\":{}},\"index_patterns\":\"mylogs-test-tag1-*\"}").
|
2504
2797
|
to_return(status: 200, body: "", headers: {})
|
2505
2798
|
else
|
2506
|
-
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs-
|
2799
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs-test-tag1").
|
2507
2800
|
with(basic_auth: ['john', 'doe'],
|
2508
|
-
body: "{\"priority\":108,\"index_patterns\":\"mylogs-
|
2801
|
+
body: "{\"priority\":108,\"index_patterns\":\"mylogs-test-tag1-*\",\"template\":{\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"mylogs-test-tag1\"},\"mappings\":{},\"aliases\":{\"myapp-logs-alias\":{}}}}").
|
2509
2802
|
to_return(status: 200, body: "", headers: {})
|
2510
2803
|
end
|
2511
2804
|
# put the alias for the index
|
2512
|
-
stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-
|
2805
|
+
stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-test-tag1-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/#{alias_endpoint}/mylogs-test-tag1").
|
2513
2806
|
with(basic_auth: ['john', 'doe'],
|
2514
|
-
:body => "{\"aliases\":{\"mylogs-
|
2807
|
+
:body => "{\"aliases\":{\"mylogs-test-tag1\":{\"is_write_index\":true}}}").
|
2808
|
+
to_return(:status => 200, :body => "", :headers => {})
|
2809
|
+
stub_request(:get, "https://logs.google.com:777/es//_xpack").
|
2810
|
+
with(basic_auth: ['john', 'doe']).
|
2811
|
+
to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
|
2812
|
+
stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
|
2813
|
+
with(basic_auth: ['john', 'doe']).
|
2814
|
+
to_return(:status => 404, :body => "", :headers => {})
|
2815
|
+
stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
|
2816
|
+
with(basic_auth: ['john', 'doe'],
|
2817
|
+
:body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
|
2818
|
+
to_return(:status => 200, :body => "", :headers => {})
|
2819
|
+
|
2820
|
+
# test-tag2
|
2821
|
+
# check if template exists
|
2822
|
+
stub_request(:get, "https://logs.google.com:777/es//_template/myapp_alias_template").
|
2823
|
+
with(basic_auth: ['john', 'doe']).
|
2824
|
+
to_return(:status => 404, :body => "", :headers => {})
|
2825
|
+
# creation
|
2826
|
+
stub_request(:put, "https://logs.google.com:777/es//_template/myapp_alias_template").
|
2827
|
+
with(basic_auth: ['john', 'doe']).
|
2828
|
+
to_return(:status => 200, :body => "", :headers => {})
|
2829
|
+
# creation of index which can rollover
|
2830
|
+
stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-test-tag2-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
|
2831
|
+
with(basic_auth: ['john', 'doe']).
|
2832
|
+
to_return(:status => 200, :body => "", :headers => {})
|
2833
|
+
# check if alias exists
|
2834
|
+
stub_request(:head, "https://logs.google.com:777/es//_alias/mylogs-test-tag2").
|
2835
|
+
with(basic_auth: ['john', 'doe']).
|
2836
|
+
to_return(:status => 404, :body => "", :headers => {})
|
2837
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/mylogs-test-tag2").
|
2838
|
+
with(basic_auth: ['john', 'doe']).
|
2839
|
+
to_return(status: 404, body: "", headers: {})
|
2840
|
+
if use_legacy_template_flag
|
2841
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs-test-tag2").
|
2842
|
+
with(basic_auth: ['john', 'doe'],
|
2843
|
+
body: "{\"order\":8,\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"mylogs-test-tag2\"},\"mappings\":{},\"aliases\":{\"myapp-logs-alias\":{}},\"index_patterns\":\"mylogs-test-tag2-*\"}").
|
2844
|
+
to_return(status: 200, body: "", headers: {})
|
2845
|
+
else
|
2846
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs-test-tag2").
|
2847
|
+
with(basic_auth: ['john', 'doe'],
|
2848
|
+
body: "{\"priority\":108,\"index_patterns\":\"mylogs-test-tag2-*\",\"template\":{\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"mylogs-test-tag2\"},\"mappings\":{},\"aliases\":{\"myapp-logs-alias\":{}}}}").
|
2849
|
+
to_return(status: 200, body: "", headers: {})
|
2850
|
+
end
|
2851
|
+
# put the alias for the index
|
2852
|
+
stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-test-tag2-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/#{alias_endpoint}/mylogs-test-tag2").
|
2853
|
+
with(basic_auth: ['john', 'doe'],
|
2854
|
+
:body => "{\"aliases\":{\"mylogs-test-tag2\":{\"is_write_index\":true}}}").
|
2515
2855
|
to_return(:status => 200, :body => "", :headers => {})
|
2516
2856
|
stub_request(:get, "https://logs.google.com:777/es//_xpack").
|
2517
2857
|
with(basic_auth: ['john', 'doe']).
|
@@ -2527,12 +2867,14 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2527
2867
|
driver(config)
|
2528
2868
|
|
2529
2869
|
elastic_request = stub_elastic("https://logs.google.com:777/es//_bulk")
|
2530
|
-
driver.run(default_tag: '
|
2531
|
-
driver.feed(sample_record)
|
2870
|
+
driver.run(default_tag: 'test') do
|
2871
|
+
driver.feed("test-tag1", event_time, sample_record)
|
2872
|
+
driver.feed("test-tag2", event_time, sample_record)
|
2873
|
+
driver.feed("test-tag1", event_time, sample_record)
|
2874
|
+
driver.feed("test-tag2", event_time, sample_record)
|
2532
2875
|
end
|
2533
|
-
assert_equal('mylogs-
|
2534
|
-
|
2535
|
-
assert_equal ["mylogs-custom-test"], driver.instance.alias_indexes
|
2876
|
+
assert_equal('mylogs-test-tag2', index_cmds.first['index']['_index'])
|
2877
|
+
assert_equal ["mylogs-test-tag1", "mylogs-test-tag2"], driver.instance.alias_indexes
|
2536
2878
|
|
2537
2879
|
assert_requested(elastic_request)
|
2538
2880
|
end
|
@@ -2541,6 +2883,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2541
2883
|
"new_template" => [false, "_index_template"])
|
2542
2884
|
def test_custom_template_with_rollover_index_create_and_custom_ilm(data)
|
2543
2885
|
use_legacy_template_flag, endpoint = data
|
2886
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
2887
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
2888
|
+
end
|
2544
2889
|
cwd = File.dirname(__FILE__)
|
2545
2890
|
template_file = if use_legacy_template_flag
|
2546
2891
|
File.join(cwd, 'test_alias_template.json')
|
@@ -2619,6 +2964,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2619
2964
|
"new_template" => [false, "_index_template"])
|
2620
2965
|
def test_template_overwrite(data)
|
2621
2966
|
use_legacy_template_flag, endpoint = data
|
2967
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
2968
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
2969
|
+
end
|
2622
2970
|
cwd = File.dirname(__FILE__)
|
2623
2971
|
template_file = if use_legacy_template_flag
|
2624
2972
|
File.join(cwd, 'test_template.json')
|
@@ -2661,6 +3009,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2661
3009
|
"new_template" => [false, "_index_template"])
|
2662
3010
|
def test_custom_template_overwrite(data)
|
2663
3011
|
use_legacy_template_flag, endpoint = data
|
3012
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
3013
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
3014
|
+
end
|
2664
3015
|
cwd = File.dirname(__FILE__)
|
2665
3016
|
template_file = if use_legacy_template_flag
|
2666
3017
|
File.join(cwd, 'test_template.json')
|
@@ -2704,6 +3055,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2704
3055
|
"new_template" => [false, "_index_template"])
|
2705
3056
|
def test_custom_template_with_rollover_index_overwrite(data)
|
2706
3057
|
use_legacy_template_flag, endpoint = data
|
3058
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
3059
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
3060
|
+
end
|
2707
3061
|
cwd = File.dirname(__FILE__)
|
2708
3062
|
template_file = if use_legacy_template_flag
|
2709
3063
|
File.join(cwd, 'test_template.json')
|
@@ -2790,6 +3144,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2790
3144
|
"new_template" => [false, "_index_template"])
|
2791
3145
|
def test_template_create_for_host_placeholder(data)
|
2792
3146
|
use_legacy_template_flag, endpoint = data
|
3147
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
3148
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
3149
|
+
end
|
2793
3150
|
cwd = File.dirname(__FILE__)
|
2794
3151
|
template_file = if use_legacy_template_flag
|
2795
3152
|
File.join(cwd, 'test_template.json')
|
@@ -2838,6 +3195,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2838
3195
|
"new_template" => [false, "_index_template"])
|
2839
3196
|
def test_template_retry_install_fails(data)
|
2840
3197
|
use_legacy_template_flag, endpoint = data
|
3198
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
3199
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
3200
|
+
end
|
2841
3201
|
cwd = File.dirname(__FILE__)
|
2842
3202
|
template_file = if use_legacy_template_flag
|
2843
3203
|
File.join(cwd, 'test_template.json')
|
@@ -2873,10 +3233,54 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2873
3233
|
assert_equal(4, connection_resets)
|
2874
3234
|
end
|
2875
3235
|
|
3236
|
+
transport_errors_handled_separately = [Elasticsearch::Transport::Transport::Errors::NotFound]
|
3237
|
+
transport_errors = Elasticsearch::Transport::Transport::Errors.constants.map { |err| [err, Elasticsearch::Transport::Transport::Errors.const_get(err)] }
|
3238
|
+
transport_errors_hash = Hash[transport_errors.select { |err| !transport_errors_handled_separately.include?(err[1]) } ]
|
3239
|
+
|
3240
|
+
data(transport_errors_hash)
|
3241
|
+
def test_template_retry_transport_errors(error)
|
3242
|
+
endpoint, use_legacy_template_flag = if Gem::Version.create(::Elasticsearch::Transport::VERSION) >= Gem::Version.create("7.8.0")
|
3243
|
+
["_index_template".freeze, false]
|
3244
|
+
else
|
3245
|
+
["_template".freeze, true]
|
3246
|
+
end
|
3247
|
+
cwd = File.dirname(__FILE__)
|
3248
|
+
template_file = File.join(cwd, 'test_index_template.json')
|
3249
|
+
|
3250
|
+
config = %{
|
3251
|
+
host logs.google.com
|
3252
|
+
port 778
|
3253
|
+
scheme https
|
3254
|
+
path /es/
|
3255
|
+
user john
|
3256
|
+
password doe
|
3257
|
+
template_name logstash
|
3258
|
+
template_file #{template_file}
|
3259
|
+
max_retry_putting_template 0
|
3260
|
+
use_legacy_template #{use_legacy_template_flag}
|
3261
|
+
}
|
3262
|
+
|
3263
|
+
retries = 0
|
3264
|
+
stub_request(:get, "https://logs.google.com:778/es//#{endpoint}/logstash")
|
3265
|
+
.with(basic_auth: ['john', 'doe']) do |req|
|
3266
|
+
retries += 1
|
3267
|
+
raise error
|
3268
|
+
end
|
3269
|
+
|
3270
|
+
assert_raise(Fluent::Plugin::ElasticsearchError::RetryableOperationExhaustedFailure) do
|
3271
|
+
driver(config)
|
3272
|
+
end
|
3273
|
+
|
3274
|
+
assert_equal(1, retries)
|
3275
|
+
end
|
3276
|
+
|
2876
3277
|
data("legacy_template" => [true, "_template"],
|
2877
3278
|
"new_template" => [false, "_index_template"])
|
2878
3279
|
def test_template_retry_install_does_not_fail(data)
|
2879
3280
|
use_legacy_template_flag, endpoint = data
|
3281
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
3282
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
3283
|
+
end
|
2880
3284
|
cwd = File.dirname(__FILE__)
|
2881
3285
|
template_file = if use_legacy_template_flag
|
2882
3286
|
File.join(cwd, 'test_template.json')
|
@@ -2915,6 +3319,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2915
3319
|
"new_template" => [false, "_index_template"])
|
2916
3320
|
def test_templates_create(data)
|
2917
3321
|
use_legacy_template_flag, endpoint = data
|
3322
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
3323
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
3324
|
+
end
|
2918
3325
|
cwd = File.dirname(__FILE__)
|
2919
3326
|
template_file = if use_legacy_template_flag
|
2920
3327
|
File.join(cwd, 'test_template.json')
|
@@ -2969,6 +3376,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2969
3376
|
"new_template" => [false, "_index_template"])
|
2970
3377
|
def test_templates_overwrite(data)
|
2971
3378
|
use_legacy_template_flag, endpoint = data
|
3379
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
3380
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
3381
|
+
end
|
2972
3382
|
cwd = File.dirname(__FILE__)
|
2973
3383
|
template_file = if use_legacy_template_flag
|
2974
3384
|
File.join(cwd, 'test_template.json')
|
@@ -3023,6 +3433,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
3023
3433
|
"new_template" => [false, "_index_template"])
|
3024
3434
|
def test_templates_are_also_used(data)
|
3025
3435
|
use_legacy_template_flag, endpoint = data
|
3436
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
3437
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
3438
|
+
end
|
3026
3439
|
cwd = File.dirname(__FILE__)
|
3027
3440
|
template_file = if use_legacy_template_flag
|
3028
3441
|
File.join(cwd, 'test_template.json')
|
@@ -3079,6 +3492,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
3079
3492
|
"new_template" => [false, "_index_template"])
|
3080
3493
|
def test_templates_can_be_partially_created_if_error_occurs(data)
|
3081
3494
|
use_legacy_template_flag, endpoint = data
|
3495
|
+
if !use_legacy_template_flag && Gem::Version.create(::Elasticsearch::Transport::VERSION) < Gem::Version.create("7.8.0")
|
3496
|
+
omit "elastisearch-ruby v7.8.0 or later is needed."
|
3497
|
+
end
|
3082
3498
|
cwd = File.dirname(__FILE__)
|
3083
3499
|
template_file = if use_legacy_template_flag
|
3084
3500
|
File.join(cwd, 'test_template.json')
|
@@ -3394,6 +3810,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
3394
3810
|
driver.configure(Fluent::Config::Element.new(
|
3395
3811
|
'ROOT', '', {
|
3396
3812
|
'@type' => 'elasticsearch',
|
3813
|
+
'bulk_message_request_threshold' => 20 * 1024 * 1024,
|
3397
3814
|
}, [
|
3398
3815
|
Fluent::Config::Element.new('buffer', 'tag', {
|
3399
3816
|
'chunk_keys' => ['tag', 'time'],
|
@@ -4344,7 +4761,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
4344
4761
|
stub_elastic
|
4345
4762
|
|
4346
4763
|
ts = "2001/02/03 13:14:01,673+02:00"
|
4347
|
-
index = "logstash-#{
|
4764
|
+
index = "logstash-#{Time.now.getutc.strftime("%Y.%m.%d")}"
|
4348
4765
|
|
4349
4766
|
flexmock(driver.instance.router).should_receive(:emit_error_event)
|
4350
4767
|
.with(tag_for_error, Fluent::EventTime, Hash, ArgumentError).once
|