fluent-plugin-elasticsearch 4.1.1 → 4.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/.github/workflows/linux.yml +1 -1
- data/.github/workflows/macos.yml +1 -1
- data/.github/workflows/windows.yml +1 -1
- data/History.md +21 -0
- data/README.ElasticsearchGenID.md +2 -2
- data/README.md +78 -6
- data/fluent-plugin-elasticsearch.gemspec +1 -1
- data/lib/fluent/plugin/elasticsearch_index_template.rb +32 -8
- data/lib/fluent/plugin/out_elasticsearch.rb +41 -3
- data/test/plugin/test_elasticsearch_tls.rb +8 -2
- data/test/plugin/test_in_elasticsearch.rb +14 -9
- data/test/plugin/test_index_alias_template.json +11 -0
- data/test/plugin/test_index_template.json +25 -0
- data/test/plugin/test_out_elasticsearch.rb +678 -250
- data/test/plugin/test_out_elasticsearch_dynamic.rb +7 -2
- metadata +9 -5
@@ -0,0 +1,25 @@
|
|
1
|
+
{
|
2
|
+
"index_patterns": "te*",
|
3
|
+
"template": {
|
4
|
+
"settings": {
|
5
|
+
"number_of_shards": 1
|
6
|
+
},
|
7
|
+
"mappings": {
|
8
|
+
"type1": {
|
9
|
+
"_source": {
|
10
|
+
"enabled": false
|
11
|
+
},
|
12
|
+
"properties": {
|
13
|
+
"host_name": {
|
14
|
+
"type": "string",
|
15
|
+
"index": "not_analyzed"
|
16
|
+
},
|
17
|
+
"created_at": {
|
18
|
+
"type": "date",
|
19
|
+
"format": "EEE MMM dd HH:mm:ss Z YYYY"
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
@@ -230,8 +230,13 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
230
230
|
assert_nil instance.ssl_max_version
|
231
231
|
assert_nil instance.ssl_min_version
|
232
232
|
if Fluent::Plugin::ElasticsearchTLS::USE_TLS_MINMAX_VERSION
|
233
|
-
|
234
|
-
|
233
|
+
if defined?(OpenSSL::SSL::TLS1_3_VERSION)
|
234
|
+
assert_equal({max_version: OpenSSL::SSL::TLS1_3_VERSION, min_version: OpenSSL::SSL::TLS1_2_VERSION},
|
235
|
+
instance.ssl_version_options)
|
236
|
+
else
|
237
|
+
assert_equal({max_version: nil, min_version: OpenSSL::SSL::TLS1_2_VERSION},
|
238
|
+
instance.ssl_version_options)
|
239
|
+
end
|
235
240
|
else
|
236
241
|
assert_equal({version: Fluent::Plugin::ElasticsearchTLS::DEFAULT_VERSION},
|
237
242
|
instance.ssl_version_options)
|
@@ -252,6 +257,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
252
257
|
assert_false instance.compression
|
253
258
|
assert_equal :no_compression, instance.compression_level
|
254
259
|
assert_true instance.http_backend_excon_nonblock
|
260
|
+
assert_equal({}, instance.api_key_header)
|
255
261
|
end
|
256
262
|
|
257
263
|
test 'configure compression' do
|
@@ -374,7 +380,10 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
374
380
|
end
|
375
381
|
end
|
376
382
|
|
377
|
-
|
383
|
+
data("legacy_template" => [true, "_template"],
|
384
|
+
"new_template" => [false, "_index_template"])
|
385
|
+
test 'valid configuration of index lifecycle management' do |data|
|
386
|
+
use_legacy_template_flag, endpoint = data
|
378
387
|
cwd = File.dirname(__FILE__)
|
379
388
|
template_file = File.join(cwd, 'test_template.json')
|
380
389
|
|
@@ -382,8 +391,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
382
391
|
enable_ilm true
|
383
392
|
template_name logstash
|
384
393
|
template_file #{template_file}
|
394
|
+
use_legacy_template #{use_legacy_template_flag}
|
385
395
|
}
|
386
|
-
stub_request(:get, "http://localhost:9200/
|
396
|
+
stub_request(:get, "http://localhost:9200/#{endpoint}/fluentd").
|
387
397
|
to_return(status: 200, body: "", headers: {})
|
388
398
|
stub_request(:head, "http://localhost:9200/_alias/fluentd").
|
389
399
|
to_return(status: 404, body: "", headers: {})
|
@@ -406,7 +416,10 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
406
416
|
}
|
407
417
|
end
|
408
418
|
|
409
|
-
|
419
|
+
data("legacy_template" => [true, "_template"],
|
420
|
+
"new_template" => [false, "_index_template"])
|
421
|
+
test 'valid configuration of overwriting ilm_policy' do |data|
|
422
|
+
use_legacy_template_flag, endpoint = data
|
410
423
|
cwd = File.dirname(__FILE__)
|
411
424
|
template_file = File.join(cwd, 'test_template.json')
|
412
425
|
|
@@ -416,8 +429,9 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
416
429
|
template_file #{template_file}
|
417
430
|
ilm_policy_overwrite true
|
418
431
|
ilm_policy {"policy":{"phases":{"hot":{"actions":{"rollover":{"max_size":"75gb","max_age": "50d"}}}}}}
|
432
|
+
use_legacy_template #{use_legacy_template_flag}
|
419
433
|
}
|
420
|
-
stub_request(:get, "http://localhost:9200/
|
434
|
+
stub_request(:get, "http://localhost:9200/#{endpoint}/fluentd").
|
421
435
|
to_return(status: 200, body: "", headers: {})
|
422
436
|
stub_request(:head, "http://localhost:9200/_alias/fluentd").
|
423
437
|
to_return(status: 404, body: "", headers: {})
|
@@ -707,7 +721,10 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
707
721
|
Fluent::Plugin::ElasticsearchOutput.module_eval(<<-CODE)
|
708
722
|
def detect_es_major_version
|
709
723
|
@_es_info ||= client.info
|
710
|
-
@_es_info
|
724
|
+
unless version = @_es_info.dig("version", "number")
|
725
|
+
version = @default_elasticsearch_version
|
726
|
+
end
|
727
|
+
version.to_i
|
711
728
|
end
|
712
729
|
CODE
|
713
730
|
Fluent::Plugin::ElasticsearchOutput.module_eval(<<-CODE)
|
@@ -753,7 +770,10 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
753
770
|
Fluent::Plugin::ElasticsearchOutput.module_eval(<<-CODE)
|
754
771
|
def detect_es_major_version
|
755
772
|
@_es_info ||= client.info
|
756
|
-
@_es_info
|
773
|
+
unless version = @_es_info.dig("version", "number")
|
774
|
+
version = @default_elasticsearch_version
|
775
|
+
end
|
776
|
+
version.to_i
|
757
777
|
end
|
758
778
|
CODE
|
759
779
|
Fluent::Plugin::ElasticsearchOutput.module_eval(<<-CODE)
|
@@ -799,7 +819,10 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
799
819
|
end
|
800
820
|
end
|
801
821
|
|
802
|
-
|
822
|
+
data("legacy_template" => [true, "_template"],
|
823
|
+
"new_template" => [false, "_index_template"])
|
824
|
+
def test_template_already_present(data)
|
825
|
+
use_legacy_template_flag, endpoint = data
|
803
826
|
config = %{
|
804
827
|
host logs.google.com
|
805
828
|
port 777
|
@@ -809,6 +832,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
809
832
|
password doe
|
810
833
|
template_name logstash
|
811
834
|
template_file /abc123
|
835
|
+
use_legacy_template #{use_legacy_template_flag}
|
812
836
|
}
|
813
837
|
|
814
838
|
# connection start
|
@@ -816,18 +840,25 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
816
840
|
with(basic_auth: ['john', 'doe']).
|
817
841
|
to_return(:status => 200, :body => "", :headers => {})
|
818
842
|
# check if template exists
|
819
|
-
stub_request(:get, "https://logs.google.com:777/es
|
843
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
820
844
|
with(basic_auth: ['john', 'doe']).
|
821
845
|
to_return(:status => 200, :body => "", :headers => {})
|
822
846
|
|
823
847
|
driver(config)
|
824
848
|
|
825
|
-
assert_not_requested(:put, "https://logs.google.com:777/es
|
849
|
+
assert_not_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash")
|
826
850
|
end
|
827
851
|
|
828
|
-
|
852
|
+
data("legacy_template" => [true, "_template"],
|
853
|
+
"new_template" => [false, "_index_template"])
|
854
|
+
def test_template_create(data)
|
855
|
+
use_legacy_template_flag, endpoint = data
|
829
856
|
cwd = File.dirname(__FILE__)
|
830
|
-
template_file =
|
857
|
+
template_file = if use_legacy_template_flag
|
858
|
+
File.join(cwd, 'test_template.json')
|
859
|
+
else
|
860
|
+
File.join(cwd, 'test_index_template.json')
|
861
|
+
end
|
831
862
|
|
832
863
|
config = %{
|
833
864
|
host logs.google.com
|
@@ -838,6 +869,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
838
869
|
password doe
|
839
870
|
template_name logstash
|
840
871
|
template_file #{template_file}
|
872
|
+
use_legacy_template #{use_legacy_template_flag}
|
841
873
|
}
|
842
874
|
|
843
875
|
# connection start
|
@@ -845,22 +877,29 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
845
877
|
with(basic_auth: ['john', 'doe']).
|
846
878
|
to_return(:status => 200, :body => "", :headers => {})
|
847
879
|
# check if template exists
|
848
|
-
stub_request(:get, "https://logs.google.com:777/es
|
880
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
849
881
|
with(basic_auth: ['john', 'doe']).
|
850
882
|
to_return(:status => 404, :body => "", :headers => {})
|
851
883
|
# creation
|
852
|
-
stub_request(:put, "https://logs.google.com:777/es
|
884
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
853
885
|
with(basic_auth: ['john', 'doe']).
|
854
886
|
to_return(:status => 200, :body => "", :headers => {})
|
855
887
|
|
856
888
|
driver(config)
|
857
889
|
|
858
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
890
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash", times: 1)
|
859
891
|
end
|
860
892
|
|
861
|
-
|
893
|
+
data("legacy_template" => [true, "_template"],
|
894
|
+
"new_template" => [false, "_index_template"])
|
895
|
+
def test_template_create_with_rollover_index_and_template_related_placeholders(data)
|
896
|
+
use_legacy_template_flag, endpoint = data
|
862
897
|
cwd = File.dirname(__FILE__)
|
863
|
-
template_file =
|
898
|
+
template_file = if use_legacy_template_flag
|
899
|
+
File.join(cwd, 'test_template.json')
|
900
|
+
else
|
901
|
+
File.join(cwd, 'test_index_template.json')
|
902
|
+
end
|
864
903
|
config = %{
|
865
904
|
host logs.google.com
|
866
905
|
port 777
|
@@ -874,6 +913,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
874
913
|
index_date_pattern ""
|
875
914
|
index_name fluentd-${tag}
|
876
915
|
deflector_alias myapp_deflector-${tag}
|
916
|
+
use_legacy_template #{use_legacy_template_flag}
|
877
917
|
}
|
878
918
|
|
879
919
|
# connection start
|
@@ -881,11 +921,11 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
881
921
|
with(basic_auth: ['john', 'doe']).
|
882
922
|
to_return(:status => 200, :body => "", :headers => {})
|
883
923
|
# check if template exists
|
884
|
-
stub_request(:get, "https://logs.google.com:777/es
|
924
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash-test.template").
|
885
925
|
with(basic_auth: ['john', 'doe']).
|
886
926
|
to_return(:status => 404, :body => "", :headers => {})
|
887
927
|
# create template
|
888
|
-
stub_request(:put, "https://logs.google.com:777/es
|
928
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash-test.template").
|
889
929
|
with(basic_auth: ['john', 'doe']).
|
890
930
|
to_return(:status => 200, :body => "", :headers => {})
|
891
931
|
# check if alias exists
|
@@ -915,9 +955,16 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
915
955
|
assert_requested(elastic_request)
|
916
956
|
end
|
917
957
|
|
918
|
-
|
958
|
+
data("legacy_template" => [true, "_template"],
|
959
|
+
"new_template" => [false, "_index_template"])
|
960
|
+
def test_template_create_with_rollover_index_and_template_related_placeholders_with_truncating_caches(data)
|
961
|
+
use_legacy_template_flag, endpoint = data
|
919
962
|
cwd = File.dirname(__FILE__)
|
920
|
-
template_file =
|
963
|
+
template_file = if use_legacy_template_flag
|
964
|
+
File.join(cwd, 'test_template.json')
|
965
|
+
else
|
966
|
+
File.join(cwd, 'test_index_template.json')
|
967
|
+
end
|
921
968
|
config = %{
|
922
969
|
host logs.google.com
|
923
970
|
port 777
|
@@ -932,6 +979,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
932
979
|
index_name fluentd-${tag}
|
933
980
|
deflector_alias myapp_deflector-${tag}
|
934
981
|
truncate_caches_interval 2s
|
982
|
+
use_legacy_template #{use_legacy_template_flag}
|
935
983
|
}
|
936
984
|
|
937
985
|
# connection start
|
@@ -939,11 +987,11 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
939
987
|
with(basic_auth: ['john', 'doe']).
|
940
988
|
to_return(:status => 200, :body => "", :headers => {})
|
941
989
|
# check if template exists
|
942
|
-
stub_request(:get, "https://logs.google.com:777/es
|
990
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash-test.template").
|
943
991
|
with(basic_auth: ['john', 'doe']).
|
944
992
|
to_return(:status => 404, :body => "", :headers => {})
|
945
993
|
# create template
|
946
|
-
stub_request(:put, "https://logs.google.com:777/es
|
994
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash-test.template").
|
947
995
|
with(basic_auth: ['john', 'doe']).
|
948
996
|
to_return(:status => 200, :body => "", :headers => {})
|
949
997
|
# check if alias exists
|
@@ -988,9 +1036,16 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
988
1036
|
end
|
989
1037
|
end
|
990
1038
|
|
991
|
-
|
1039
|
+
data("legacy_template" => [true, "_template"],
|
1040
|
+
"new_template" => [false, "_index_template"])
|
1041
|
+
def test_template_create_with_rollover_index_and_default_ilm(data)
|
1042
|
+
use_legacy_template_flag, endpoint = data
|
992
1043
|
cwd = File.dirname(__FILE__)
|
993
|
-
template_file =
|
1044
|
+
template_file = if use_legacy_template_flag
|
1045
|
+
File.join(cwd, 'test_template.json')
|
1046
|
+
else
|
1047
|
+
File.join(cwd, 'test_index_template.json')
|
1048
|
+
end
|
994
1049
|
|
995
1050
|
config = %{
|
996
1051
|
host logs.google.com
|
@@ -1004,6 +1059,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1004
1059
|
index_date_pattern now/w{xxxx.ww}
|
1005
1060
|
index_name logstash
|
1006
1061
|
enable_ilm true
|
1062
|
+
use_legacy_template #{use_legacy_template_flag}
|
1007
1063
|
}
|
1008
1064
|
|
1009
1065
|
# connection start
|
@@ -1011,24 +1067,31 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1011
1067
|
with(basic_auth: ['john', 'doe']).
|
1012
1068
|
to_return(:status => 200, :body => "", :headers => {})
|
1013
1069
|
# check if template exists
|
1014
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1070
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1015
1071
|
with(basic_auth: ['john', 'doe']).
|
1016
1072
|
to_return(:status => 404, :body => "", :headers => {})
|
1017
1073
|
# creation
|
1018
|
-
stub_request(:put, "https://logs.google.com:777/es
|
1074
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1019
1075
|
with(basic_auth: ['john', 'doe']).
|
1020
1076
|
to_return(:status => 200, :body => "", :headers => {})
|
1021
1077
|
# check if alias exists
|
1022
1078
|
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash").
|
1023
1079
|
with(basic_auth: ['john', 'doe']).
|
1024
1080
|
to_return(:status => 404, :body => "", :headers => {})
|
1025
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1081
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1026
1082
|
with(basic_auth: ['john', 'doe']).
|
1027
1083
|
to_return(status: 404, body: "", headers: {})
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1084
|
+
if use_legacy_template_flag
|
1085
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1086
|
+
with(basic_auth: ['john', 'doe'],
|
1087
|
+
body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash\"},\"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-*\",\"order\":51}").
|
1088
|
+
to_return(status: 200, body: "", headers: {})
|
1089
|
+
else
|
1090
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1091
|
+
with(basic_auth: ['john', 'doe'],
|
1092
|
+
body: "{\"index_patterns\":\"logstash-*\",\"template\":{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash\"},\"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\":101}").
|
1093
|
+
to_return(status: 200, body: "", headers: {})
|
1094
|
+
end
|
1032
1095
|
# put the alias for the index
|
1033
1096
|
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
|
1034
1097
|
with(basic_auth: ['john', 'doe']).
|
@@ -1050,12 +1113,19 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1050
1113
|
|
1051
1114
|
driver(config)
|
1052
1115
|
|
1053
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
1116
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash", times: 1)
|
1054
1117
|
end
|
1055
1118
|
|
1056
|
-
|
1119
|
+
data("legacy_template" => [true, "_template"],
|
1120
|
+
"new_template" => [false, "_index_template"])
|
1121
|
+
def test_template_create_with_rollover_index_and_default_ilm_on_logstash_format(data)
|
1122
|
+
use_legacy_template_flag, endpoint = data
|
1057
1123
|
cwd = File.dirname(__FILE__)
|
1058
|
-
template_file =
|
1124
|
+
template_file = if use_legacy_template_flag
|
1125
|
+
File.join(cwd, 'test_template.json')
|
1126
|
+
else
|
1127
|
+
File.join(cwd, 'test_index_template.json')
|
1128
|
+
end
|
1059
1129
|
|
1060
1130
|
config = %{
|
1061
1131
|
host logs.google.com
|
@@ -1070,6 +1140,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1070
1140
|
enable_ilm true
|
1071
1141
|
logstash_format true
|
1072
1142
|
application_name log
|
1143
|
+
use_legacy_template #{use_legacy_template_flag}
|
1073
1144
|
}
|
1074
1145
|
|
1075
1146
|
date_str = Time.now.strftime("%Y.%m.%d")
|
@@ -1078,24 +1149,31 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1078
1149
|
with(basic_auth: ['john', 'doe']).
|
1079
1150
|
to_return(:status => 200, :body => "", :headers => {})
|
1080
1151
|
# check if template exists
|
1081
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1152
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash-#{date_str}").
|
1082
1153
|
with(basic_auth: ['john', 'doe']).
|
1083
1154
|
to_return(:status => 404, :body => "", :headers => {})
|
1084
1155
|
# creation
|
1085
|
-
stub_request(:put, "https://logs.google.com:777/es
|
1156
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash-#{date_str}").
|
1086
1157
|
with(basic_auth: ['john', 'doe']).
|
1087
1158
|
to_return(:status => 200, :body => "", :headers => {})
|
1088
1159
|
# check if alias exists
|
1089
1160
|
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash-#{date_str}").
|
1090
1161
|
with(basic_auth: ['john', 'doe']).
|
1091
1162
|
to_return(:status => 404, :body => "", :headers => {})
|
1092
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1163
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash-#{date_str}").
|
1093
1164
|
with(basic_auth: ['john', 'doe']).
|
1094
1165
|
to_return(status: 404, body: "", headers: {})
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1166
|
+
if use_legacy_template_flag
|
1167
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash-#{date_str}").
|
1168
|
+
with(basic_auth: ['john', 'doe'],
|
1169
|
+
body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash-log-#{date_str}\"},\"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-log-#{date_str}-*\",\"order\":53}").
|
1170
|
+
to_return(status: 200, body: "", headers: {})
|
1171
|
+
else
|
1172
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash-#{date_str}").
|
1173
|
+
with(basic_auth: ['john', 'doe'],
|
1174
|
+
body: "{\"index_patterns\":\"logstash-log-2020.09.21-*\",\"template\":{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash-2020.09.21\"},\"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\":103}").
|
1175
|
+
to_return(status: 200, body: "", headers: {})
|
1176
|
+
end
|
1099
1177
|
# put the alias for the index
|
1100
1178
|
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-log-#{date_str}-000001%3E").
|
1101
1179
|
with(basic_auth: ['john', 'doe']).
|
@@ -1122,14 +1200,21 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1122
1200
|
driver.run(default_tag: 'test') do
|
1123
1201
|
driver.feed(sample_record)
|
1124
1202
|
end
|
1125
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
1203
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash-#{date_str}", times: 1)
|
1126
1204
|
|
1127
1205
|
assert_requested(elastic_request)
|
1128
1206
|
end
|
1129
1207
|
|
1130
|
-
|
1208
|
+
data("legacy_template" => [true, "_template"],
|
1209
|
+
"new_template" => [false, "_index_template"])
|
1210
|
+
def test_template_create_with_rollover_index_and_default_ilm_and_ilm_policy_overwrite(data)
|
1211
|
+
use_legacy_template_flag, endpoint = data
|
1131
1212
|
cwd = File.dirname(__FILE__)
|
1132
|
-
template_file =
|
1213
|
+
template_file = if use_legacy_template_flag
|
1214
|
+
File.join(cwd, 'test_template.json')
|
1215
|
+
else
|
1216
|
+
File.join(cwd, 'test_index_template.json')
|
1217
|
+
end
|
1133
1218
|
|
1134
1219
|
config = %{
|
1135
1220
|
host logs.google.com
|
@@ -1145,6 +1230,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1145
1230
|
enable_ilm true
|
1146
1231
|
ilm_policy_overwrite true
|
1147
1232
|
ilm_policy {"policy":{"phases":{"hot":{"actions":{"rollover":{"max_size":"60gb","max_age": "45d"}}}}}}
|
1233
|
+
use_legacy_template #{use_legacy_template_flag}
|
1148
1234
|
}
|
1149
1235
|
|
1150
1236
|
# connection start
|
@@ -1152,24 +1238,31 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1152
1238
|
with(basic_auth: ['john', 'doe']).
|
1153
1239
|
to_return(:status => 200, :body => "", :headers => {})
|
1154
1240
|
# check if template exists
|
1155
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1241
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1156
1242
|
with(basic_auth: ['john', 'doe']).
|
1157
1243
|
to_return(:status => 404, :body => "", :headers => {})
|
1158
1244
|
# creation
|
1159
|
-
stub_request(:put, "https://logs.google.com:777/es
|
1245
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1160
1246
|
with(basic_auth: ['john', 'doe']).
|
1161
1247
|
to_return(:status => 200, :body => "", :headers => {})
|
1162
1248
|
# check if alias exists
|
1163
1249
|
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash").
|
1164
1250
|
with(basic_auth: ['john', 'doe']).
|
1165
1251
|
to_return(:status => 404, :body => "", :headers => {})
|
1166
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1252
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1167
1253
|
with(basic_auth: ['john', 'doe']).
|
1168
1254
|
to_return(status: 404, body: "", headers: {})
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1255
|
+
if use_legacy_template_flag
|
1256
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1257
|
+
with(basic_auth: ['john', 'doe'],
|
1258
|
+
body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash\"},\"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-*\",\"order\":51}").
|
1259
|
+
to_return(status: 200, body: "", headers: {})
|
1260
|
+
else
|
1261
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1262
|
+
with(basic_auth: ['john', 'doe'],
|
1263
|
+
body: "{\"index_patterns\":\"logstash-*\",\"template\":{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash\"},\"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\":101}").
|
1264
|
+
to_return(status: 200, body: "", headers: {})
|
1265
|
+
end
|
1173
1266
|
# put the alias for the index
|
1174
1267
|
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
|
1175
1268
|
with(basic_auth: ['john', 'doe']).
|
@@ -1191,7 +1284,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1191
1284
|
|
1192
1285
|
driver(config)
|
1193
1286
|
|
1194
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
1287
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash", times: 1)
|
1195
1288
|
end
|
1196
1289
|
|
1197
1290
|
def test_template_create_with_rollover_index_and_default_ilm_with_deflector_alias
|
@@ -1219,9 +1312,16 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1219
1312
|
end
|
1220
1313
|
end
|
1221
1314
|
|
1222
|
-
|
1315
|
+
data("legacy_template" => [true, "_template"],
|
1316
|
+
"new_template" => [false, "_index_template"])
|
1317
|
+
def test_template_create_with_rollover_index_and_default_ilm_with_empty_index_date_pattern(data)
|
1318
|
+
use_legacy_template_flag, endpoint = data
|
1223
1319
|
cwd = File.dirname(__FILE__)
|
1224
|
-
template_file =
|
1320
|
+
template_file = if use_legacy_template_flag
|
1321
|
+
File.join(cwd, 'test_template.json')
|
1322
|
+
else
|
1323
|
+
File.join(cwd, 'test_index_template.json')
|
1324
|
+
end
|
1225
1325
|
|
1226
1326
|
config = %{
|
1227
1327
|
host logs.google.com
|
@@ -1235,6 +1335,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1235
1335
|
index_date_pattern ""
|
1236
1336
|
index_name logstash
|
1237
1337
|
enable_ilm true
|
1338
|
+
use_legacy_template #{use_legacy_template_flag}
|
1238
1339
|
}
|
1239
1340
|
|
1240
1341
|
# connection start
|
@@ -1242,24 +1343,31 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1242
1343
|
with(basic_auth: ['john', 'doe']).
|
1243
1344
|
to_return(:status => 200, :body => "", :headers => {})
|
1244
1345
|
# check if template exists
|
1245
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1346
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1246
1347
|
with(basic_auth: ['john', 'doe']).
|
1247
1348
|
to_return(:status => 404, :body => "", :headers => {})
|
1248
1349
|
# creation
|
1249
|
-
stub_request(:put, "https://logs.google.com:777/es
|
1350
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1250
1351
|
with(basic_auth: ['john', 'doe']).
|
1251
1352
|
to_return(:status => 200, :body => "", :headers => {})
|
1252
1353
|
# check if alias exists
|
1253
1354
|
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash").
|
1254
1355
|
with(basic_auth: ['john', 'doe']).
|
1255
1356
|
to_return(:status => 404, :body => "", :headers => {})
|
1256
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1357
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1257
1358
|
with(basic_auth: ['john', 'doe']).
|
1258
1359
|
to_return(status: 404, body: "", headers: {})
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1360
|
+
if use_legacy_template_flag
|
1361
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_deflector").
|
1362
|
+
with(basic_auth: ['john', 'doe'],
|
1363
|
+
body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash\"},\"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-*\",\"order\":51}").
|
1364
|
+
to_return(status: 200, body: "", headers: {})
|
1365
|
+
else
|
1366
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_deflector").
|
1367
|
+
with(basic_auth: ['john', 'doe'],
|
1368
|
+
body: "{\"index_patterns\":\"logstash-*\",\"template\":{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash\"},\"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\":101}").
|
1369
|
+
to_return(status: 200, body: "", headers: {})
|
1370
|
+
end
|
1263
1371
|
# put the alias for the index
|
1264
1372
|
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-000001%3E").
|
1265
1373
|
with(basic_auth: ['john', 'doe']).
|
@@ -1281,12 +1389,19 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1281
1389
|
|
1282
1390
|
driver(config)
|
1283
1391
|
|
1284
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
1392
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash", times: 1)
|
1285
1393
|
end
|
1286
1394
|
|
1287
|
-
|
1395
|
+
data("legacy_template" => [true, "_template"],
|
1396
|
+
"new_template" => [false, "_index_template"])
|
1397
|
+
def test_template_create_with_rollover_index_and_custom_ilm(data)
|
1398
|
+
use_legacy_template_flag, endpoint = data
|
1288
1399
|
cwd = File.dirname(__FILE__)
|
1289
|
-
template_file =
|
1400
|
+
template_file = if use_legacy_template_flag
|
1401
|
+
File.join(cwd, 'test_template.json')
|
1402
|
+
else
|
1403
|
+
File.join(cwd, 'test_index_template.json')
|
1404
|
+
end
|
1290
1405
|
|
1291
1406
|
config = %{
|
1292
1407
|
host logs.google.com
|
@@ -1302,6 +1417,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1302
1417
|
enable_ilm true
|
1303
1418
|
index_name logstash
|
1304
1419
|
ilm_policy {"policy":{"phases":{"hot":{"actions":{"rollover":{"max_size":"70gb", "max_age":"30d"}}}}}}
|
1420
|
+
use_legacy_template #{use_legacy_template_flag}
|
1305
1421
|
}
|
1306
1422
|
|
1307
1423
|
# connection start
|
@@ -1309,24 +1425,31 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1309
1425
|
with(basic_auth: ['john', 'doe']).
|
1310
1426
|
to_return(:status => 200, :body => "", :headers => {})
|
1311
1427
|
# check if template exists
|
1312
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1428
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1313
1429
|
with(basic_auth: ['john', 'doe']).
|
1314
1430
|
to_return(:status => 404, :body => "", :headers => {})
|
1315
1431
|
# creation
|
1316
|
-
stub_request(:put, "https://logs.google.com:777/es
|
1432
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1317
1433
|
with(basic_auth: ['john', 'doe']).
|
1318
1434
|
to_return(:status => 200, :body => "", :headers => {})
|
1319
1435
|
# check if alias exists
|
1320
1436
|
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash").
|
1321
1437
|
with(basic_auth: ['john', 'doe']).
|
1322
1438
|
to_return(:status => 404, :body => "", :headers => {})
|
1323
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1439
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1324
1440
|
with(basic_auth: ['john', 'doe']).
|
1325
1441
|
to_return(status: 404, body: "", headers: {})
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1442
|
+
if use_legacy_template_flag
|
1443
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1444
|
+
with(basic_auth: ['john', 'doe'],
|
1445
|
+
body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"myalogs\"},\"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\":\"mylogs-*\",\"order\":51}").
|
1446
|
+
to_return(status: 200, body: "", headers: {})
|
1447
|
+
else
|
1448
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1449
|
+
with(basic_auth: ['john', 'doe'],
|
1450
|
+
body: "{\"index_patterns\":\"logstash-*\",\"template\":{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"logstash\"},\"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\":101}").
|
1451
|
+
to_return(status: 200, body: "", headers: {})
|
1452
|
+
end
|
1330
1453
|
# put the alias for the index
|
1331
1454
|
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
|
1332
1455
|
with(basic_auth: ['john', 'doe']).
|
@@ -1347,12 +1470,19 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1347
1470
|
|
1348
1471
|
driver(config)
|
1349
1472
|
|
1350
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
1473
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash", times: 1)
|
1351
1474
|
end
|
1352
1475
|
|
1353
|
-
|
1476
|
+
data("legacy_template" => [true, "_template"],
|
1477
|
+
"new_template" => [false, "_index_template"])
|
1478
|
+
def test_template_create_with_rollover_index_and_ilm_policies_and_placeholderstest_template_create_with_rollover_index_and_ilm_policies_and_placeholders(data)
|
1479
|
+
use_legacy_template_flag, endpoint = data
|
1354
1480
|
cwd = File.dirname(__FILE__)
|
1355
|
-
template_file =
|
1481
|
+
template_file = if use_legacy_template_flag
|
1482
|
+
File.join(cwd, 'test_template.json')
|
1483
|
+
else
|
1484
|
+
File.join(cwd, 'test_index_template.json')
|
1485
|
+
end
|
1356
1486
|
|
1357
1487
|
config = %{
|
1358
1488
|
host logs.google.com
|
@@ -1368,6 +1498,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1368
1498
|
enable_ilm true
|
1369
1499
|
index_name logstash
|
1370
1500
|
ilm_policies {"fluentd-policy":{"policy":{"phases":{"hot":{"actions":{"rollover":{"max_size":"70gb", "max_age":"30d"}}}}}}}
|
1501
|
+
use_legacy_template #{use_legacy_template_flag}
|
1371
1502
|
}
|
1372
1503
|
|
1373
1504
|
# connection start
|
@@ -1375,24 +1506,31 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1375
1506
|
with(basic_auth: ['john', 'doe']).
|
1376
1507
|
to_return(:status => 200, :body => "", :headers => {})
|
1377
1508
|
# check if template exists
|
1378
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1509
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1379
1510
|
with(basic_auth: ['john', 'doe']).
|
1380
1511
|
to_return(:status => 404, :body => "", :headers => {})
|
1381
1512
|
# creation
|
1382
|
-
stub_request(:put, "https://logs.google.com:777/es
|
1513
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1383
1514
|
with(basic_auth: ['john', 'doe']).
|
1384
1515
|
to_return(:status => 200, :body => "", :headers => {})
|
1385
1516
|
# check if alias exists
|
1386
1517
|
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash").
|
1387
1518
|
with(basic_auth: ['john', 'doe']).
|
1388
1519
|
to_return(:status => 404, :body => "", :headers => {})
|
1389
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1520
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1390
1521
|
with(basic_auth: ['john', 'doe']).
|
1391
1522
|
to_return(status: 404, body: "", headers: {})
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1523
|
+
if use_legacy_template_flag
|
1524
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1525
|
+
with(basic_auth: ['john', 'doe'],
|
1526
|
+
body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"myalogs\"},\"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\":\"mylogs-*\",\"order\":51}").
|
1527
|
+
to_return(status: 200, body: "", headers: {})
|
1528
|
+
else
|
1529
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1530
|
+
with(basic_auth: ['john', 'doe'],
|
1531
|
+
body: "{\"index_patterns\":\"logstash-*\",\"template\":{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"logstash\"},\"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\":101}").
|
1532
|
+
to_return(status: 200, body: "", headers: {})
|
1533
|
+
end
|
1396
1534
|
# put the alias for the index
|
1397
1535
|
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
|
1398
1536
|
with(basic_auth: ['john', 'doe']).
|
@@ -1417,15 +1555,22 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1417
1555
|
driver.run(default_tag: 'test') do
|
1418
1556
|
driver.feed(sample_record)
|
1419
1557
|
end
|
1420
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
1558
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash", times: 1)
|
1421
1559
|
|
1422
1560
|
assert_requested(elastic_request)
|
1423
1561
|
end
|
1424
1562
|
|
1425
1563
|
class TemplateCreateWithRolloverIndexAndILMPoliciesWithPlaceholdersTest < self
|
1426
|
-
|
1564
|
+
data("legacy_template" => [true, "_template"],
|
1565
|
+
"new_template" => [false, "_index_template"])
|
1566
|
+
def test_tag_placeholder(data)
|
1567
|
+
use_legacy_template_flag, endpoint = data
|
1427
1568
|
cwd = File.dirname(__FILE__)
|
1428
|
-
template_file =
|
1569
|
+
template_file = if use_legacy_template_flag
|
1570
|
+
File.join(cwd, 'test_template.json')
|
1571
|
+
else
|
1572
|
+
File.join(cwd, 'test_index_template.json')
|
1573
|
+
end
|
1429
1574
|
|
1430
1575
|
config = %{
|
1431
1576
|
host logs.google.com
|
@@ -1441,6 +1586,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1441
1586
|
enable_ilm true
|
1442
1587
|
index_name logstash
|
1443
1588
|
ilm_policies {"fluentd-policy":{"policy":{"phases":{"hot":{"actions":{"rollover":{"max_size":"70gb", "max_age":"30d"}}}}}}}
|
1589
|
+
use_legacy_template #{use_legacy_template_flag}
|
1444
1590
|
}
|
1445
1591
|
|
1446
1592
|
# connection start
|
@@ -1448,24 +1594,31 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1448
1594
|
with(basic_auth: ['john', 'doe']).
|
1449
1595
|
to_return(:status => 200, :body => "", :headers => {})
|
1450
1596
|
# check if template exists
|
1451
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1597
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1452
1598
|
with(basic_auth: ['john', 'doe']).
|
1453
1599
|
to_return(:status => 404, :body => "", :headers => {})
|
1454
1600
|
# creation
|
1455
|
-
stub_request(:put, "https://logs.google.com:777/es
|
1601
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1456
1602
|
with(basic_auth: ['john', 'doe']).
|
1457
1603
|
to_return(:status => 200, :body => "", :headers => {})
|
1458
1604
|
# check if alias exists
|
1459
1605
|
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash").
|
1460
1606
|
with(basic_auth: ['john', 'doe']).
|
1461
1607
|
to_return(:status => 404, :body => "", :headers => {})
|
1462
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1608
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1463
1609
|
with(basic_auth: ['john', 'doe']).
|
1464
1610
|
to_return(status: 404, body: "", headers: {})
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1611
|
+
if use_legacy_template_flag
|
1612
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1613
|
+
with(basic_auth: ['john', 'doe'],
|
1614
|
+
body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"myalogs\"},\"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\":\"mylogs-*\",\"order\":51}").
|
1615
|
+
to_return(status: 200, body: "", headers: {})
|
1616
|
+
else
|
1617
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1618
|
+
with(basic_auth: ['john', 'doe'],
|
1619
|
+
body: "{\"index_patterns\":\"logstash-*\",\"template\":{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"logstash\"},\"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\":101}").
|
1620
|
+
to_return(status: 200, body: "", headers: {})
|
1621
|
+
end
|
1469
1622
|
# put the alias for the index
|
1470
1623
|
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
|
1471
1624
|
with(basic_auth: ['john', 'doe']).
|
@@ -1490,14 +1643,21 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1490
1643
|
driver.run(default_tag: 'fluentd-policy') do
|
1491
1644
|
driver.feed(sample_record)
|
1492
1645
|
end
|
1493
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
1646
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash", times: 1)
|
1494
1647
|
|
1495
1648
|
assert_requested(elastic_request)
|
1496
1649
|
end
|
1497
1650
|
|
1498
|
-
|
1651
|
+
data("legacy_template" => [true, "_template"],
|
1652
|
+
"new_template" => [false, "_index_template"])
|
1653
|
+
def test_tag_placeholder_with_multiple_policies(data)
|
1654
|
+
use_legacy_template_flag, endpoint = data
|
1499
1655
|
cwd = File.dirname(__FILE__)
|
1500
|
-
template_file =
|
1656
|
+
template_file = if use_legacy_template_flag
|
1657
|
+
File.join(cwd, 'test_template.json')
|
1658
|
+
else
|
1659
|
+
File.join(cwd, 'test_index_template.json')
|
1660
|
+
end
|
1501
1661
|
|
1502
1662
|
config = %{
|
1503
1663
|
host logs.google.com
|
@@ -1513,6 +1673,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1513
1673
|
enable_ilm true
|
1514
1674
|
index_name logstash
|
1515
1675
|
ilm_policies {"fluentd-policy":{"policy":{"phases":{"hot":{"actions":{"rollover":{"max_size":"70gb", "max_age":"30d"}}}}}}, "fluentd-policy2":{"policy":{"phases":{"hot":{"actions":{"rollover":{"max_size":"80gb", "max_age":"20d"}}}}}}}
|
1676
|
+
use_legacy_template #{use_legacy_template_flag}
|
1516
1677
|
}
|
1517
1678
|
|
1518
1679
|
# connection start
|
@@ -1520,24 +1681,31 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1520
1681
|
with(basic_auth: ['john', 'doe']).
|
1521
1682
|
to_return(:status => 200, :body => "", :headers => {})
|
1522
1683
|
# check if template exists
|
1523
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1684
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1524
1685
|
with(basic_auth: ['john', 'doe']).
|
1525
1686
|
to_return(:status => 404, :body => "", :headers => {})
|
1526
1687
|
# creation
|
1527
|
-
stub_request(:put, "https://logs.google.com:777/es
|
1688
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1528
1689
|
with(basic_auth: ['john', 'doe']).
|
1529
1690
|
to_return(:status => 200, :body => "", :headers => {})
|
1530
1691
|
# check if alias exists
|
1531
1692
|
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash").
|
1532
1693
|
with(basic_auth: ['john', 'doe']).
|
1533
1694
|
to_return(:status => 404, :body => "", :headers => {})
|
1534
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1695
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1535
1696
|
with(basic_auth: ['john', 'doe']).
|
1536
1697
|
to_return(status: 404, body: "", headers: {})
|
1537
|
-
|
1538
|
-
|
1539
|
-
|
1540
|
-
|
1698
|
+
if use_legacy_template_flag
|
1699
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1700
|
+
with(basic_auth: ['john', 'doe'],
|
1701
|
+
body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"fluentd-policy2\",\"index.lifecycle.rollover_alias\":\"logstash\"},\"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-*\",\"order\":51}").
|
1702
|
+
to_return(status: 200, body: "", headers: {})
|
1703
|
+
else
|
1704
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1705
|
+
with(basic_auth: ['john', 'doe'],
|
1706
|
+
body: "{\"index_patterns\":\"logstash-*\",\"template\":{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"fluentd-policy2\",\"index.lifecycle.rollover_alias\":\"logstash\"},\"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\":101}").
|
1707
|
+
to_return(status: 200, body: "", headers: {})
|
1708
|
+
end
|
1541
1709
|
# put the alias for the index
|
1542
1710
|
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
|
1543
1711
|
with(basic_auth: ['john', 'doe']).
|
@@ -1562,15 +1730,22 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1562
1730
|
driver.run(default_tag: 'fluentd-policy2') do
|
1563
1731
|
driver.feed(sample_record)
|
1564
1732
|
end
|
1565
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
1733
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash", times: 1)
|
1566
1734
|
|
1567
1735
|
assert_requested(elastic_request)
|
1568
1736
|
end
|
1569
1737
|
end
|
1570
1738
|
|
1571
|
-
|
1739
|
+
data("legacy_template" => [true, "_template"],
|
1740
|
+
"new_template" => [false, "_index_template"])
|
1741
|
+
def test_template_create_with_rollover_index_and_default_ilm_and_placeholders(data)
|
1742
|
+
use_legacy_template_flag, endpoint = data
|
1572
1743
|
cwd = File.dirname(__FILE__)
|
1573
|
-
template_file =
|
1744
|
+
template_file = if use_legacy_template_flag
|
1745
|
+
File.join(cwd, 'test_template.json')
|
1746
|
+
else
|
1747
|
+
File.join(cwd, 'test_index_template.json')
|
1748
|
+
end
|
1574
1749
|
|
1575
1750
|
config = %{
|
1576
1751
|
host logs.google.com
|
@@ -1584,6 +1759,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1584
1759
|
index_date_pattern now/w{xxxx.ww}
|
1585
1760
|
index_name logstash-${tag}
|
1586
1761
|
enable_ilm true
|
1762
|
+
use_legacy_template #{use_legacy_template_flag}
|
1587
1763
|
}
|
1588
1764
|
|
1589
1765
|
# connection start
|
@@ -1591,24 +1767,31 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1591
1767
|
with(basic_auth: ['john', 'doe']).
|
1592
1768
|
to_return(:status => 200, :body => "", :headers => {})
|
1593
1769
|
# check if template exists
|
1594
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1770
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1595
1771
|
with(basic_auth: ['john', 'doe']).
|
1596
1772
|
to_return(:status => 404, :body => "", :headers => {})
|
1597
1773
|
# creation
|
1598
|
-
stub_request(:put, "https://logs.google.com:777/es
|
1774
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1599
1775
|
with(basic_auth: ['john', 'doe']).
|
1600
1776
|
to_return(:status => 200, :body => "", :headers => {})
|
1601
1777
|
# check if alias exists
|
1602
1778
|
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash-test").
|
1603
1779
|
with(basic_auth: ['john', 'doe']).
|
1604
1780
|
to_return(:status => 404, :body => "", :headers => {})
|
1605
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1781
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash-test").
|
1606
1782
|
with(basic_auth: ['john', 'doe']).
|
1607
1783
|
to_return(status: 404, body: "", headers: {})
|
1608
|
-
|
1609
|
-
|
1610
|
-
|
1611
|
-
|
1784
|
+
if use_legacy_template_flag
|
1785
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash-test").
|
1786
|
+
with(basic_auth: ['john', 'doe'],
|
1787
|
+
body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash-test\"},\"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-test-*\",\"order\":52}").
|
1788
|
+
to_return(status: 200, body: "", headers: {})
|
1789
|
+
else
|
1790
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash-test").
|
1791
|
+
with(basic_auth: ['john', 'doe'],
|
1792
|
+
body: "{\"index_patterns\":\"logstash-test-*\",\"template\":{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash-test\"},\"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
|
+
to_return(status: 200, body: "", headers: {})
|
1794
|
+
end
|
1612
1795
|
# put the alias for the index
|
1613
1796
|
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-test-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
|
1614
1797
|
with(basic_auth: ['john', 'doe']).
|
@@ -1641,9 +1824,16 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1641
1824
|
assert_requested(elastic_request)
|
1642
1825
|
end
|
1643
1826
|
|
1644
|
-
|
1827
|
+
data("legacy_template" => [true, "_template"],
|
1828
|
+
"new_template" => [false, "_index_template"])
|
1829
|
+
def test_template_create_with_rollover_index_and_default_ilm_and_custom_and_time_placeholders(data)
|
1830
|
+
use_legacy_template_flag, endpoint = data
|
1645
1831
|
cwd = File.dirname(__FILE__)
|
1646
|
-
template_file =
|
1832
|
+
template_file = if use_legacy_template_flag
|
1833
|
+
File.join(cwd, 'test_template.json')
|
1834
|
+
else
|
1835
|
+
File.join(cwd, 'test_index_template.json')
|
1836
|
+
end
|
1647
1837
|
|
1648
1838
|
config = Fluent::Config::Element.new(
|
1649
1839
|
'ROOT', '', {
|
@@ -1659,6 +1849,8 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1659
1849
|
'index_date_pattern' => 'now/w{xxxx.ww}',
|
1660
1850
|
'index_name' => "${taskDef}-%Y.%m",
|
1661
1851
|
'enable_ilm' => true,
|
1852
|
+
'use_legacy_template' => use_legacy_template_flag,
|
1853
|
+
|
1662
1854
|
}, [
|
1663
1855
|
Fluent::Config::Element.new('buffer', 'tag, time, taskDef', {
|
1664
1856
|
'chunk_keys' => ['tag', 'time', 'taskDef'],
|
@@ -1674,14 +1866,21 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1674
1866
|
with(basic_auth: ['john', 'doe']).
|
1675
1867
|
to_return(:status => 200, :body => "", :headers => {})
|
1676
1868
|
# check if template exists
|
1677
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1869
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/#{task_def_value}-#{date_str}").
|
1678
1870
|
with(basic_auth: ['john', 'doe']).
|
1679
1871
|
to_return(:status => 404, :body => "", :headers => {})
|
1680
1872
|
# creation
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1684
|
-
|
1873
|
+
if use_legacy_template_flag
|
1874
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/#{task_def_value}-#{date_str}").
|
1875
|
+
with(basic_auth: ['john', 'doe'],
|
1876
|
+
body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"#{task_def_value}-#{date_str}\"},\"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\":\"#{task_def_value}-#{date_str}-*\",\"order\":52}").
|
1877
|
+
to_return(:status => 200, :body => "", :headers => {})
|
1878
|
+
else
|
1879
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/#{task_def_value}-#{date_str}").
|
1880
|
+
with(basic_auth: ['john', 'doe'],
|
1881
|
+
body: "{\"index_patterns\":\"task_definition-#{date_str}-*\",\"template\":{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"task_definition-#{date_str}\"},\"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}").
|
1882
|
+
to_return(:status => 200, :body => "", :headers => {})
|
1883
|
+
end
|
1685
1884
|
# check if alias exists
|
1686
1885
|
stub_request(:head, "https://logs.google.com:777/es//_alias/#{task_def_value}-#{date_str}").
|
1687
1886
|
with(basic_auth: ['john', 'doe']).
|
@@ -1719,9 +1918,16 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1719
1918
|
end
|
1720
1919
|
end
|
1721
1920
|
|
1722
|
-
|
1921
|
+
data("legacy_template" => [true, "_template"],
|
1922
|
+
"new_template" => [false, "_index_template"])
|
1923
|
+
def test_custom_template_create(data)
|
1924
|
+
use_legacy_template_flag, endpoint = data
|
1723
1925
|
cwd = File.dirname(__FILE__)
|
1724
|
-
template_file =
|
1926
|
+
template_file = if use_legacy_template_flag
|
1927
|
+
File.join(cwd, 'test_alias_template.json')
|
1928
|
+
else
|
1929
|
+
File.join(cwd, 'test_index_alias_template.json')
|
1930
|
+
end
|
1725
1931
|
|
1726
1932
|
config = %{
|
1727
1933
|
host logs.google.com
|
@@ -1733,6 +1939,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1733
1939
|
template_name myapp_alias_template
|
1734
1940
|
template_file #{template_file}
|
1735
1941
|
customize_template {"--appid--": "myapp-logs","--index_prefix--":"mylogs"}
|
1942
|
+
use_legacy_template #{use_legacy_template_flag}
|
1736
1943
|
}
|
1737
1944
|
|
1738
1945
|
# connection start
|
@@ -1740,22 +1947,29 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1740
1947
|
with(basic_auth: ['john', 'doe']).
|
1741
1948
|
to_return(:status => 200, :body => "", :headers => {})
|
1742
1949
|
# check if template exists
|
1743
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1950
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
1744
1951
|
with(basic_auth: ['john', 'doe']).
|
1745
1952
|
to_return(:status => 404, :body => "", :headers => {})
|
1746
1953
|
# creation
|
1747
|
-
stub_request(:put, "https://logs.google.com:777/es
|
1954
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
1748
1955
|
with(basic_auth: ['john', 'doe']).
|
1749
1956
|
to_return(:status => 200, :body => "", :headers => {})
|
1750
1957
|
|
1751
1958
|
driver(config)
|
1752
1959
|
|
1753
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
1960
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template", times: 1)
|
1754
1961
|
end
|
1755
1962
|
|
1756
|
-
|
1963
|
+
data("legacy_template" => [true, "_template"],
|
1964
|
+
"new_template" => [false, "_index_template"])
|
1965
|
+
def test_custom_template_create_with_customize_template_related_placeholders(data)
|
1966
|
+
use_legacy_template_flag, endpoint = data
|
1757
1967
|
cwd = File.dirname(__FILE__)
|
1758
|
-
template_file =
|
1968
|
+
template_file = if use_legacy_template_flag
|
1969
|
+
File.join(cwd, 'test_alias_template.json')
|
1970
|
+
else
|
1971
|
+
File.join(cwd, 'test_index_alias_template.json')
|
1972
|
+
end
|
1759
1973
|
|
1760
1974
|
config = %{
|
1761
1975
|
host logs.google.com
|
@@ -1767,6 +1981,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1767
1981
|
template_name myapp_alias_template-${tag}
|
1768
1982
|
template_file #{template_file}
|
1769
1983
|
customize_template {"--appid--": "${tag}-logs","--index_prefix--":"${tag}"}
|
1984
|
+
use_legacy_template #{use_legacy_template_flag}
|
1770
1985
|
}
|
1771
1986
|
|
1772
1987
|
# connection start
|
@@ -1774,11 +1989,11 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1774
1989
|
with(basic_auth: ['john', 'doe']).
|
1775
1990
|
to_return(:status => 200, :body => "", :headers => {})
|
1776
1991
|
# check if template exists
|
1777
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1992
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template-test.template").
|
1778
1993
|
with(basic_auth: ['john', 'doe']).
|
1779
1994
|
to_return(:status => 404, :body => "", :headers => {})
|
1780
1995
|
# creation
|
1781
|
-
stub_request(:put, "https://logs.google.com:777/es
|
1996
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template-test.template").
|
1782
1997
|
with(basic_auth: ['john', 'doe']).
|
1783
1998
|
to_return(:status => 200, :body => "", :headers => {})
|
1784
1999
|
|
@@ -1792,12 +2007,19 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1792
2007
|
driver.feed(sample_record)
|
1793
2008
|
end
|
1794
2009
|
|
1795
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2010
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template-test.template", times: 1)
|
1796
2011
|
end
|
1797
2012
|
|
1798
|
-
|
2013
|
+
data("legacy_template" => [true, "_template"],
|
2014
|
+
"new_template" => [false, "_index_template"])
|
2015
|
+
def test_custom_template_installation_for_host_placeholder(data)
|
2016
|
+
use_legacy_template_flag, endpoint = data
|
1799
2017
|
cwd = File.dirname(__FILE__)
|
1800
|
-
template_file =
|
2018
|
+
template_file = if use_legacy_template_flag
|
2019
|
+
File.join(cwd, 'test_template.json')
|
2020
|
+
else
|
2021
|
+
File.join(cwd, 'test_index_template.json')
|
2022
|
+
end
|
1801
2023
|
|
1802
2024
|
config = %{
|
1803
2025
|
host logs-${tag}.google.com
|
@@ -1811,6 +2033,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1811
2033
|
verify_es_version_at_startup false
|
1812
2034
|
default_elasticsearch_version 6
|
1813
2035
|
customize_template {"--appid--": "myapp-logs","--index_prefix--":"mylogs"}
|
2036
|
+
use_legacy_template #{use_legacy_template_flag}
|
1814
2037
|
}
|
1815
2038
|
|
1816
2039
|
# connection start
|
@@ -1818,10 +2041,10 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1818
2041
|
with(basic_auth: ['john', 'doe']).
|
1819
2042
|
to_return(:status => 200, :body => "", :headers => {})
|
1820
2043
|
# check if template exists
|
1821
|
-
stub_request(:get, "https://logs-test.google.com:777/es
|
2044
|
+
stub_request(:get, "https://logs-test.google.com:777/es//#{endpoint}/logstash").
|
1822
2045
|
with(basic_auth: ['john', 'doe']).
|
1823
2046
|
to_return(:status => 404, :body => "", :headers => {})
|
1824
|
-
stub_request(:put, "https://logs-test.google.com:777/es
|
2047
|
+
stub_request(:put, "https://logs-test.google.com:777/es//#{endpoint}/logstash").
|
1825
2048
|
with(basic_auth: ['john', 'doe']).
|
1826
2049
|
to_return(status: 200, body: "", headers: {})
|
1827
2050
|
|
@@ -1833,9 +2056,16 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1833
2056
|
end
|
1834
2057
|
end
|
1835
2058
|
|
1836
|
-
|
2059
|
+
data("legacy_template" => [true, "_template"],
|
2060
|
+
"new_template" => [false, "_index_template"])
|
2061
|
+
def test_custom_template_with_rollover_index_create(data)
|
2062
|
+
use_legacy_template_flag, endpoint = data
|
1837
2063
|
cwd = File.dirname(__FILE__)
|
1838
|
-
template_file =
|
2064
|
+
template_file = if use_legacy_template_flag
|
2065
|
+
File.join(cwd, 'test_alias_template.json')
|
2066
|
+
else
|
2067
|
+
File.join(cwd, 'test_index_alias_template.json')
|
2068
|
+
end
|
1839
2069
|
|
1840
2070
|
config = %{
|
1841
2071
|
host logs.google.com
|
@@ -1851,6 +2081,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1851
2081
|
index_date_pattern now/w{xxxx.ww}
|
1852
2082
|
index_name mylogs
|
1853
2083
|
application_name myapp
|
2084
|
+
use_legacy_template #{use_legacy_template_flag}
|
1854
2085
|
}
|
1855
2086
|
|
1856
2087
|
# connection start
|
@@ -1858,11 +2089,11 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1858
2089
|
with(basic_auth: ['john', 'doe']).
|
1859
2090
|
to_return(:status => 200, :body => "", :headers => {})
|
1860
2091
|
# check if template exists
|
1861
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2092
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
1862
2093
|
with(basic_auth: ['john', 'doe']).
|
1863
2094
|
to_return(:status => 404, :body => "", :headers => {})
|
1864
2095
|
# creation
|
1865
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2096
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
1866
2097
|
with(basic_auth: ['john', 'doe']).
|
1867
2098
|
to_return(:status => 200, :body => "", :headers => {})
|
1868
2099
|
# creation of index which can rollover
|
@@ -1880,12 +2111,19 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1880
2111
|
|
1881
2112
|
driver(config)
|
1882
2113
|
|
1883
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2114
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template", times: 1)
|
1884
2115
|
end
|
1885
2116
|
|
1886
|
-
|
2117
|
+
data("legacy_template" => [true, "_template"],
|
2118
|
+
"new_template" => [false, "_index_template"])
|
2119
|
+
def test_custom_template_with_rollover_index_create_and_deflector_alias(data)
|
2120
|
+
use_legacy_template_flag, endpoint = data
|
1887
2121
|
cwd = File.dirname(__FILE__)
|
1888
|
-
template_file =
|
2122
|
+
template_file = if use_legacy_template_flag
|
2123
|
+
File.join(cwd, 'test_alias_template.json')
|
2124
|
+
else
|
2125
|
+
File.join(cwd, 'test_index_alias_template.json')
|
2126
|
+
end
|
1889
2127
|
|
1890
2128
|
config = %{
|
1891
2129
|
host logs.google.com
|
@@ -1902,6 +2140,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1902
2140
|
deflector_alias myapp_deflector
|
1903
2141
|
index_name mylogs
|
1904
2142
|
application_name myapp
|
2143
|
+
use_legacy_template #{use_legacy_template_flag}
|
1905
2144
|
}
|
1906
2145
|
|
1907
2146
|
# connection start
|
@@ -1909,11 +2148,11 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1909
2148
|
with(basic_auth: ['john', 'doe']).
|
1910
2149
|
to_return(:status => 200, :body => "", :headers => {})
|
1911
2150
|
# check if template exists
|
1912
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2151
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
1913
2152
|
with(basic_auth: ['john', 'doe']).
|
1914
2153
|
to_return(:status => 404, :body => "", :headers => {})
|
1915
2154
|
# creation
|
1916
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2155
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
1917
2156
|
with(basic_auth: ['john', 'doe']).
|
1918
2157
|
to_return(:status => 200, :body => "", :headers => {})
|
1919
2158
|
# creation of index which can rollover
|
@@ -1931,12 +2170,19 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1931
2170
|
|
1932
2171
|
driver(config)
|
1933
2172
|
|
1934
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2173
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template", times: 1)
|
1935
2174
|
end
|
1936
2175
|
|
1937
|
-
|
2176
|
+
data("legacy_template" => [true, "_template"],
|
2177
|
+
"new_template" => [false, "_index_template"])
|
2178
|
+
def test_custom_template_with_rollover_index_create_with_logstash_format(data)
|
2179
|
+
use_legacy_template_flag, endpoint = data
|
1938
2180
|
cwd = File.dirname(__FILE__)
|
1939
|
-
template_file =
|
2181
|
+
template_file = if use_legacy_template_flag
|
2182
|
+
File.join(cwd, 'test_alias_template.json')
|
2183
|
+
else
|
2184
|
+
File.join(cwd, 'test_index_alias_template.json')
|
2185
|
+
end
|
1940
2186
|
|
1941
2187
|
config = %{
|
1942
2188
|
host logs.google.com
|
@@ -1953,6 +2199,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1953
2199
|
logstash_format true
|
1954
2200
|
logstash_prefix mylogs
|
1955
2201
|
application_name myapp
|
2202
|
+
use_legacy_template #{use_legacy_template_flag}
|
1956
2203
|
}
|
1957
2204
|
|
1958
2205
|
timestr = Time.now.strftime("%Y.%m.%d")
|
@@ -1961,11 +2208,11 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1961
2208
|
with(basic_auth: ['john', 'doe']).
|
1962
2209
|
to_return(:status => 200, :body => "", :headers => {})
|
1963
2210
|
# check if template exists
|
1964
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2211
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
1965
2212
|
with(basic_auth: ['john', 'doe']).
|
1966
2213
|
to_return(:status => 404, :body => "", :headers => {})
|
1967
2214
|
# creation
|
1968
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2215
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
1969
2216
|
with(basic_auth: ['john', 'doe']).
|
1970
2217
|
to_return(:status => 200, :body => "", :headers => {})
|
1971
2218
|
# creation of index which can rollover
|
@@ -2000,9 +2247,16 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2000
2247
|
end
|
2001
2248
|
end
|
2002
2249
|
|
2003
|
-
|
2250
|
+
data("legacy_template" => [true, "_template"],
|
2251
|
+
"new_template" => [false, "_index_template"])
|
2252
|
+
def test_custom_template_with_rollover_index_create_and_default_ilm(data)
|
2253
|
+
use_legacy_template_flag, endpoint = data
|
2004
2254
|
cwd = File.dirname(__FILE__)
|
2005
|
-
template_file =
|
2255
|
+
template_file = if use_legacy_template_flag
|
2256
|
+
File.join(cwd, 'test_alias_template.json')
|
2257
|
+
else
|
2258
|
+
File.join(cwd, 'test_index_alias_template.json')
|
2259
|
+
end
|
2006
2260
|
|
2007
2261
|
config = %{
|
2008
2262
|
host logs.google.com
|
@@ -2019,6 +2273,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2019
2273
|
application_name myapp
|
2020
2274
|
ilm_policy_id fluentd-policy
|
2021
2275
|
enable_ilm true
|
2276
|
+
use_legacy_template #{use_legacy_template_flag}
|
2022
2277
|
}
|
2023
2278
|
|
2024
2279
|
# connection start
|
@@ -2026,11 +2281,11 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2026
2281
|
with(basic_auth: ['john', 'doe']).
|
2027
2282
|
to_return(:status => 200, :body => "", :headers => {})
|
2028
2283
|
# check if template exists
|
2029
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2284
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2030
2285
|
with(basic_auth: ['john', 'doe']).
|
2031
2286
|
to_return(:status => 404, :body => "", :headers => {})
|
2032
2287
|
# creation
|
2033
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2288
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2034
2289
|
with(basic_auth: ['john', 'doe']).
|
2035
2290
|
to_return(:status => 200, :body => "", :headers => {})
|
2036
2291
|
# creation of index which can rollover
|
@@ -2041,13 +2296,20 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2041
2296
|
stub_request(:head, "https://logs.google.com:777/es//_alias/mylogs").
|
2042
2297
|
with(basic_auth: ['john', 'doe']).
|
2043
2298
|
to_return(:status => 404, :body => "", :headers => {})
|
2044
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2299
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/mylogs").
|
2045
2300
|
with(basic_auth: ['john', 'doe']).
|
2046
2301
|
to_return(status: 404, body: "", headers: {})
|
2047
|
-
|
2048
|
-
|
2049
|
-
|
2050
|
-
|
2302
|
+
if use_legacy_template_flag
|
2303
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs").
|
2304
|
+
with(basic_auth: ['john', 'doe'],
|
2305
|
+
body: "{\"order\":6,\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"mylogs\"},\"mappings\":{},\"aliases\":{\"myapp-logs-alias\":{}},\"index_patterns\":\"mylogs-*\"}").
|
2306
|
+
to_return(status: 200, body: "", headers: {})
|
2307
|
+
else
|
2308
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs").
|
2309
|
+
with(basic_auth: ['john', 'doe'],
|
2310
|
+
body: "{\"priority\":106,\"index_patterns\":\"mylogs-*\",\"template\":{\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"mylogs\"},\"mappings\":{},\"aliases\":{\"myapp-logs-alias\":{}}}}").
|
2311
|
+
to_return(status: 200, body: "", headers: {})
|
2312
|
+
end
|
2051
2313
|
# put the alias for the index
|
2052
2314
|
stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/#{alias_endpoint}/mylogs").
|
2053
2315
|
with(basic_auth: ['john', 'doe'],
|
@@ -2066,12 +2328,19 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2066
2328
|
|
2067
2329
|
driver(config)
|
2068
2330
|
|
2069
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2331
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs", times: 1)
|
2070
2332
|
end
|
2071
2333
|
|
2072
|
-
|
2334
|
+
data("legacy_template" => [true, "_template"],
|
2335
|
+
"new_template" => [false, "_index_template"])
|
2336
|
+
def test_custom_template_with_rollover_index_create_and_default_ilm_and_ilm_policy_overwrite(data)
|
2337
|
+
use_legacy_template_flag, endpoint = data
|
2073
2338
|
cwd = File.dirname(__FILE__)
|
2074
|
-
template_file =
|
2339
|
+
template_file = if use_legacy_template_flag
|
2340
|
+
File.join(cwd, 'test_alias_template.json')
|
2341
|
+
else
|
2342
|
+
File.join(cwd, 'test_index_alias_template.json')
|
2343
|
+
end
|
2075
2344
|
|
2076
2345
|
config = %{
|
2077
2346
|
host logs.google.com
|
@@ -2090,6 +2359,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2090
2359
|
enable_ilm true
|
2091
2360
|
ilm_policy_overwrite true
|
2092
2361
|
ilm_policy {"policy":{"phases":{"hot":{"actions":{"rollover":{"max_size":"60gb","max_age": "45d"}}}}}}
|
2362
|
+
use_legacy_template #{use_legacy_template_flag}
|
2093
2363
|
}
|
2094
2364
|
|
2095
2365
|
# connection start
|
@@ -2097,11 +2367,11 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2097
2367
|
with(basic_auth: ['john', 'doe']).
|
2098
2368
|
to_return(:status => 200, :body => "", :headers => {})
|
2099
2369
|
# check if template exists
|
2100
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2370
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2101
2371
|
with(basic_auth: ['john', 'doe']).
|
2102
2372
|
to_return(:status => 404, :body => "", :headers => {})
|
2103
2373
|
# creation
|
2104
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2374
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2105
2375
|
with(basic_auth: ['john', 'doe']).
|
2106
2376
|
to_return(:status => 200, :body => "", :headers => {})
|
2107
2377
|
# creation of index which can rollover
|
@@ -2112,13 +2382,20 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2112
2382
|
stub_request(:head, "https://logs.google.com:777/es//_alias/mylogs").
|
2113
2383
|
with(basic_auth: ['john', 'doe']).
|
2114
2384
|
to_return(:status => 404, :body => "", :headers => {})
|
2115
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2385
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/mylogs").
|
2116
2386
|
with(basic_auth: ['john', 'doe']).
|
2117
2387
|
to_return(status: 404, body: "", headers: {})
|
2118
|
-
|
2119
|
-
|
2120
|
-
|
2121
|
-
|
2388
|
+
if use_legacy_template_flag
|
2389
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs").
|
2390
|
+
with(basic_auth: ['john', 'doe'],
|
2391
|
+
body: "{\"order\":6,\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"mylogs\"},\"mappings\":{},\"aliases\":{\"myapp-logs-alias\":{}},\"index_patterns\":\"mylogs-*\"}").
|
2392
|
+
to_return(status: 200, body: "", headers: {})
|
2393
|
+
else
|
2394
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs").
|
2395
|
+
with(basic_auth: ['john', 'doe'],
|
2396
|
+
body: "{\"priority\":106,\"index_patterns\":\"mylogs-*\",\"template\":{\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"mylogs\"},\"mappings\":{},\"aliases\":{\"myapp-logs-alias\":{}}}}").
|
2397
|
+
to_return(status: 200, body: "", headers: {})
|
2398
|
+
end
|
2122
2399
|
# put the alias for the index
|
2123
2400
|
stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/#{alias_endpoint}/mylogs").
|
2124
2401
|
with(basic_auth: ['john', 'doe'],
|
@@ -2137,7 +2414,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2137
2414
|
|
2138
2415
|
driver(config)
|
2139
2416
|
|
2140
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2417
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs", times: 1)
|
2141
2418
|
end
|
2142
2419
|
|
2143
2420
|
def test_custom_template_with_rollover_index_create_and_default_ilm_with_deflector_alias
|
@@ -2168,9 +2445,16 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2168
2445
|
end
|
2169
2446
|
end
|
2170
2447
|
|
2171
|
-
|
2448
|
+
data("legacy_template" => [true, "_template"],
|
2449
|
+
"new_template" => [false, "_index_template"])
|
2450
|
+
def test_custom_template_with_rollover_index_create_and_default_ilm_and_placeholders(data)
|
2451
|
+
use_legacy_template_flag, endpoint = data
|
2172
2452
|
cwd = File.dirname(__FILE__)
|
2173
|
-
template_file =
|
2453
|
+
template_file = if use_legacy_template_flag
|
2454
|
+
File.join(cwd, 'test_alias_template.json')
|
2455
|
+
else
|
2456
|
+
File.join(cwd, 'test_index_alias_template.json')
|
2457
|
+
end
|
2174
2458
|
|
2175
2459
|
config = %{
|
2176
2460
|
host logs.google.com
|
@@ -2187,6 +2471,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2187
2471
|
application_name myapp
|
2188
2472
|
ilm_policy_id fluentd-policy
|
2189
2473
|
enable_ilm true
|
2474
|
+
use_legacy_template #{use_legacy_template_flag}
|
2190
2475
|
}
|
2191
2476
|
|
2192
2477
|
# connection start
|
@@ -2194,11 +2479,11 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2194
2479
|
with(basic_auth: ['john', 'doe']).
|
2195
2480
|
to_return(:status => 200, :body => "", :headers => {})
|
2196
2481
|
# check if template exists
|
2197
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2482
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2198
2483
|
with(basic_auth: ['john', 'doe']).
|
2199
2484
|
to_return(:status => 404, :body => "", :headers => {})
|
2200
2485
|
# creation
|
2201
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2486
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2202
2487
|
with(basic_auth: ['john', 'doe']).
|
2203
2488
|
to_return(:status => 200, :body => "", :headers => {})
|
2204
2489
|
# creation of index which can rollover
|
@@ -2209,13 +2494,20 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2209
2494
|
stub_request(:head, "https://logs.google.com:777/es//_alias/mylogs-custom-test").
|
2210
2495
|
with(basic_auth: ['john', 'doe']).
|
2211
2496
|
to_return(:status => 404, :body => "", :headers => {})
|
2212
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2497
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/mylogs-custom-test").
|
2213
2498
|
with(basic_auth: ['john', 'doe']).
|
2214
2499
|
to_return(status: 404, body: "", headers: {})
|
2215
|
-
|
2216
|
-
|
2217
|
-
|
2218
|
-
|
2500
|
+
if use_legacy_template_flag
|
2501
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs-custom-test").
|
2502
|
+
with(basic_auth: ['john', 'doe'],
|
2503
|
+
body: "{\"order\":8,\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"mylogs-custom-test\"},\"mappings\":{},\"aliases\":{\"myapp-logs-alias\":{}},\"index_patterns\":\"mylogs-custom-test-*\"}").
|
2504
|
+
to_return(status: 200, body: "", headers: {})
|
2505
|
+
else
|
2506
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs-custom-test").
|
2507
|
+
with(basic_auth: ['john', 'doe'],
|
2508
|
+
body: "{\"priority\":108,\"index_patterns\":\"mylogs-custom-test-*\",\"template\":{\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"mylogs-custom-test\"},\"mappings\":{},\"aliases\":{\"myapp-logs-alias\":{}}}}").
|
2509
|
+
to_return(status: 200, body: "", headers: {})
|
2510
|
+
end
|
2219
2511
|
# put the alias for the index
|
2220
2512
|
stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-custom-test-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/#{alias_endpoint}/mylogs-custom-test").
|
2221
2513
|
with(basic_auth: ['john', 'doe'],
|
@@ -2245,9 +2537,16 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2245
2537
|
assert_requested(elastic_request)
|
2246
2538
|
end
|
2247
2539
|
|
2248
|
-
|
2540
|
+
data("legacy_template" => [true, "_template"],
|
2541
|
+
"new_template" => [false, "_index_template"])
|
2542
|
+
def test_custom_template_with_rollover_index_create_and_custom_ilm(data)
|
2543
|
+
use_legacy_template_flag, endpoint = data
|
2249
2544
|
cwd = File.dirname(__FILE__)
|
2250
|
-
template_file =
|
2545
|
+
template_file = if use_legacy_template_flag
|
2546
|
+
File.join(cwd, 'test_alias_template.json')
|
2547
|
+
else
|
2548
|
+
File.join(cwd, 'test_index_alias_template.json')
|
2549
|
+
end
|
2251
2550
|
|
2252
2551
|
config = %{
|
2253
2552
|
host logs.google.com
|
@@ -2265,6 +2564,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2265
2564
|
ilm_policy_id fluentd-policy
|
2266
2565
|
enable_ilm true
|
2267
2566
|
ilm_policy {"policy":{"phases":{"hot":{"actions":{"rollover":{"max_size":"70gb", "max_age":"30d"}}}}}}
|
2567
|
+
use_legacy_template #{use_legacy_template_flag}
|
2268
2568
|
}
|
2269
2569
|
|
2270
2570
|
# connection start
|
@@ -2272,11 +2572,11 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2272
2572
|
with(basic_auth: ['john', 'doe']).
|
2273
2573
|
to_return(:status => 200, :body => "", :headers => {})
|
2274
2574
|
# check if template exists
|
2275
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2575
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2276
2576
|
with(basic_auth: ['john', 'doe']).
|
2277
2577
|
to_return(:status => 404, :body => "", :headers => {})
|
2278
2578
|
# creation
|
2279
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2579
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2280
2580
|
with(basic_auth: ['john', 'doe']).
|
2281
2581
|
to_return(:status => 200, :body => "", :headers => {})
|
2282
2582
|
# creation of index which can rollover
|
@@ -2287,10 +2587,10 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2287
2587
|
stub_request(:head, "https://logs.google.com:777/es//_alias/mylogs").
|
2288
2588
|
with(basic_auth: ['john', 'doe']).
|
2289
2589
|
to_return(:status => 404, :body => "", :headers => {})
|
2290
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2590
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/mylogs").
|
2291
2591
|
with(basic_auth: ['john', 'doe']).
|
2292
2592
|
to_return(status: 404, body: "", headers: {})
|
2293
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2593
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs").
|
2294
2594
|
with(basic_auth: ['john', 'doe']).
|
2295
2595
|
to_return(status: 200, body: "", headers: {})
|
2296
2596
|
# put the alias for the index
|
@@ -2311,13 +2611,20 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2311
2611
|
|
2312
2612
|
driver(config)
|
2313
2613
|
|
2314
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2614
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs", times: 1)
|
2315
2615
|
end
|
2316
2616
|
end
|
2317
2617
|
|
2318
|
-
|
2618
|
+
data("legacy_template" => [true, "_template"],
|
2619
|
+
"new_template" => [false, "_index_template"])
|
2620
|
+
def test_template_overwrite(data)
|
2621
|
+
use_legacy_template_flag, endpoint = data
|
2319
2622
|
cwd = File.dirname(__FILE__)
|
2320
|
-
template_file =
|
2623
|
+
template_file = if use_legacy_template_flag
|
2624
|
+
File.join(cwd, 'test_template.json')
|
2625
|
+
else
|
2626
|
+
File.join(cwd, 'test_index_template.json')
|
2627
|
+
end
|
2321
2628
|
|
2322
2629
|
config = %{
|
2323
2630
|
host logs.google.com
|
@@ -2329,6 +2636,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2329
2636
|
template_name logstash
|
2330
2637
|
template_file #{template_file}
|
2331
2638
|
template_overwrite true
|
2639
|
+
use_legacy_template #{use_legacy_template_flag}
|
2332
2640
|
}
|
2333
2641
|
|
2334
2642
|
# connection start
|
@@ -2336,22 +2644,29 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2336
2644
|
with(basic_auth: ['john', 'doe']).
|
2337
2645
|
to_return(:status => 200, :body => "", :headers => {})
|
2338
2646
|
# check if template exists
|
2339
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2647
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
2340
2648
|
with(basic_auth: ['john', 'doe']).
|
2341
2649
|
to_return(:status => 200, :body => "", :headers => {})
|
2342
2650
|
# creation
|
2343
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2651
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
2344
2652
|
with(basic_auth: ['john', 'doe']).
|
2345
2653
|
to_return(:status => 200, :body => "", :headers => {})
|
2346
2654
|
|
2347
2655
|
driver(config)
|
2348
2656
|
|
2349
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2657
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash", times: 1)
|
2350
2658
|
end
|
2351
2659
|
|
2352
|
-
|
2660
|
+
data("legacy_template" => [true, "_template"],
|
2661
|
+
"new_template" => [false, "_index_template"])
|
2662
|
+
def test_custom_template_overwrite(data)
|
2663
|
+
use_legacy_template_flag, endpoint = data
|
2353
2664
|
cwd = File.dirname(__FILE__)
|
2354
|
-
template_file =
|
2665
|
+
template_file = if use_legacy_template_flag
|
2666
|
+
File.join(cwd, 'test_template.json')
|
2667
|
+
else
|
2668
|
+
File.join(cwd, 'test_index_template.json')
|
2669
|
+
end
|
2355
2670
|
|
2356
2671
|
config = %{
|
2357
2672
|
host logs.google.com
|
@@ -2364,6 +2679,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2364
2679
|
template_file #{template_file}
|
2365
2680
|
template_overwrite true
|
2366
2681
|
customize_template {"--appid--": "myapp-logs","--index_prefix--":"mylogs"}
|
2682
|
+
use_legacy_template #{use_legacy_template_flag}
|
2367
2683
|
}
|
2368
2684
|
|
2369
2685
|
# connection start
|
@@ -2371,22 +2687,29 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2371
2687
|
with(basic_auth: ['john', 'doe']).
|
2372
2688
|
to_return(:status => 200, :body => "", :headers => {})
|
2373
2689
|
# check if template exists
|
2374
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2690
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2375
2691
|
with(basic_auth: ['john', 'doe']).
|
2376
2692
|
to_return(:status => 200, :body => "", :headers => {})
|
2377
2693
|
# creation
|
2378
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2694
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2379
2695
|
with(basic_auth: ['john', 'doe']).
|
2380
2696
|
to_return(:status => 200, :body => "", :headers => {})
|
2381
2697
|
|
2382
2698
|
driver(config)
|
2383
2699
|
|
2384
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2700
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template", times: 1)
|
2385
2701
|
end
|
2386
2702
|
|
2387
|
-
|
2703
|
+
data("legacy_template" => [true, "_template"],
|
2704
|
+
"new_template" => [false, "_index_template"])
|
2705
|
+
def test_custom_template_with_rollover_index_overwrite(data)
|
2706
|
+
use_legacy_template_flag, endpoint = data
|
2388
2707
|
cwd = File.dirname(__FILE__)
|
2389
|
-
template_file =
|
2708
|
+
template_file = if use_legacy_template_flag
|
2709
|
+
File.join(cwd, 'test_template.json')
|
2710
|
+
else
|
2711
|
+
File.join(cwd, 'test_index_template.json')
|
2712
|
+
end
|
2390
2713
|
|
2391
2714
|
config = %{
|
2392
2715
|
host logs.google.com
|
@@ -2403,6 +2726,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2403
2726
|
rollover_index true
|
2404
2727
|
index_name mylogs
|
2405
2728
|
application_name myapp
|
2729
|
+
use_legacy_template #{use_legacy_template_flag}
|
2406
2730
|
}
|
2407
2731
|
|
2408
2732
|
# connection start
|
@@ -2410,11 +2734,11 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2410
2734
|
with(basic_auth: ['john', 'doe']).
|
2411
2735
|
to_return(:status => 200, :body => "", :headers => {})
|
2412
2736
|
# check if template exists
|
2413
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2737
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2414
2738
|
with(basic_auth: ['john', 'doe']).
|
2415
2739
|
to_return(:status => 200, :body => "", :headers => {})
|
2416
2740
|
# creation
|
2417
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2741
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2418
2742
|
with(basic_auth: ['john', 'doe']).
|
2419
2743
|
to_return(:status => 200, :body => "", :headers => {})
|
2420
2744
|
# creation of index which can rollover
|
@@ -2432,7 +2756,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2432
2756
|
|
2433
2757
|
driver(config)
|
2434
2758
|
|
2435
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2759
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template", times: 1)
|
2436
2760
|
end
|
2437
2761
|
|
2438
2762
|
def test_template_create_invalid_filename
|
@@ -2462,9 +2786,16 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2462
2786
|
}
|
2463
2787
|
end
|
2464
2788
|
|
2465
|
-
|
2789
|
+
data("legacy_template" => [true, "_template"],
|
2790
|
+
"new_template" => [false, "_index_template"])
|
2791
|
+
def test_template_create_for_host_placeholder(data)
|
2792
|
+
use_legacy_template_flag, endpoint = data
|
2466
2793
|
cwd = File.dirname(__FILE__)
|
2467
|
-
template_file =
|
2794
|
+
template_file = if use_legacy_template_flag
|
2795
|
+
File.join(cwd, 'test_template.json')
|
2796
|
+
else
|
2797
|
+
File.join(cwd, 'test_index_template.json')
|
2798
|
+
end
|
2468
2799
|
|
2469
2800
|
config = %{
|
2470
2801
|
host logs-${tag}.google.com
|
@@ -2477,6 +2808,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2477
2808
|
template_file #{template_file}
|
2478
2809
|
verify_es_version_at_startup false
|
2479
2810
|
default_elasticsearch_version 6
|
2811
|
+
use_legacy_template #{use_legacy_template_flag}
|
2480
2812
|
}
|
2481
2813
|
|
2482
2814
|
# connection start
|
@@ -2484,10 +2816,10 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2484
2816
|
with(basic_auth: ['john', 'doe']).
|
2485
2817
|
to_return(:status => 200, :body => "", :headers => {})
|
2486
2818
|
# check if template exists
|
2487
|
-
stub_request(:get, "https://logs-test.google.com:777/es
|
2819
|
+
stub_request(:get, "https://logs-test.google.com:777/es//#{endpoint}/logstash").
|
2488
2820
|
with(basic_auth: ['john', 'doe']).
|
2489
2821
|
to_return(:status => 404, :body => "", :headers => {})
|
2490
|
-
stub_request(:put, "https://logs-test.google.com:777/es
|
2822
|
+
stub_request(:put, "https://logs-test.google.com:777/es//#{endpoint}/logstash").
|
2491
2823
|
with(basic_auth: ['john', 'doe']).
|
2492
2824
|
to_return(status: 200, body: "", headers: {})
|
2493
2825
|
stub_request(:post, "https://logs-test.google.com:777/es//_bulk").
|
@@ -2502,9 +2834,16 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2502
2834
|
end
|
2503
2835
|
end
|
2504
2836
|
|
2505
|
-
|
2837
|
+
data("legacy_template" => [true, "_template"],
|
2838
|
+
"new_template" => [false, "_index_template"])
|
2839
|
+
def test_template_retry_install_fails(data)
|
2840
|
+
use_legacy_template_flag, endpoint = data
|
2506
2841
|
cwd = File.dirname(__FILE__)
|
2507
|
-
template_file =
|
2842
|
+
template_file = if use_legacy_template_flag
|
2843
|
+
File.join(cwd, 'test_template.json')
|
2844
|
+
else
|
2845
|
+
File.join(cwd, 'test_index_template.json')
|
2846
|
+
end
|
2508
2847
|
|
2509
2848
|
config = %{
|
2510
2849
|
host logs.google.com
|
@@ -2516,11 +2855,12 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2516
2855
|
template_name logstash
|
2517
2856
|
template_file #{template_file}
|
2518
2857
|
max_retry_putting_template 3
|
2858
|
+
use_legacy_template #{use_legacy_template_flag}
|
2519
2859
|
}
|
2520
2860
|
|
2521
2861
|
connection_resets = 0
|
2522
2862
|
# check if template exists
|
2523
|
-
stub_request(:get, "https://logs.google.com:778/es
|
2863
|
+
stub_request(:get, "https://logs.google.com:778/es//#{endpoint}/logstash")
|
2524
2864
|
.with(basic_auth: ['john', 'doe']) do |req|
|
2525
2865
|
connection_resets += 1
|
2526
2866
|
raise Faraday::ConnectionFailed, "Test message"
|
@@ -2533,9 +2873,16 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2533
2873
|
assert_equal(4, connection_resets)
|
2534
2874
|
end
|
2535
2875
|
|
2536
|
-
|
2876
|
+
data("legacy_template" => [true, "_template"],
|
2877
|
+
"new_template" => [false, "_index_template"])
|
2878
|
+
def test_template_retry_install_does_not_fail(data)
|
2879
|
+
use_legacy_template_flag, endpoint = data
|
2537
2880
|
cwd = File.dirname(__FILE__)
|
2538
|
-
template_file =
|
2881
|
+
template_file = if use_legacy_template_flag
|
2882
|
+
File.join(cwd, 'test_template.json')
|
2883
|
+
else
|
2884
|
+
File.join(cwd, 'test_index_template.json')
|
2885
|
+
end
|
2539
2886
|
|
2540
2887
|
config = %{
|
2541
2888
|
host logs.google.com
|
@@ -2548,11 +2895,12 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2548
2895
|
template_file #{template_file}
|
2549
2896
|
max_retry_putting_template 3
|
2550
2897
|
fail_on_putting_template_retry_exceed false
|
2898
|
+
use_legacy_template #{use_legacy_template_flag}
|
2551
2899
|
}
|
2552
2900
|
|
2553
2901
|
connection_resets = 0
|
2554
2902
|
# check if template exists
|
2555
|
-
stub_request(:get, "https://logs.google.com:778/es
|
2903
|
+
stub_request(:get, "https://logs.google.com:778/es//#{endpoint}/logstash")
|
2556
2904
|
.with(basic_auth: ['john', 'doe']) do |req|
|
2557
2905
|
connection_resets += 1
|
2558
2906
|
raise Faraday::ConnectionFailed, "Test message"
|
@@ -2563,9 +2911,17 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2563
2911
|
assert_equal(4, connection_resets)
|
2564
2912
|
end
|
2565
2913
|
|
2566
|
-
|
2914
|
+
data("legacy_template" => [true, "_template"],
|
2915
|
+
"new_template" => [false, "_index_template"])
|
2916
|
+
def test_templates_create(data)
|
2917
|
+
use_legacy_template_flag, endpoint = data
|
2567
2918
|
cwd = File.dirname(__FILE__)
|
2568
|
-
template_file =
|
2919
|
+
template_file = if use_legacy_template_flag
|
2920
|
+
File.join(cwd, 'test_template.json')
|
2921
|
+
else
|
2922
|
+
File.join(cwd, 'test_index_template.json')
|
2923
|
+
end
|
2924
|
+
|
2569
2925
|
config = %{
|
2570
2926
|
host logs.google.com
|
2571
2927
|
port 777
|
@@ -2574,43 +2930,52 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2574
2930
|
user john
|
2575
2931
|
password doe
|
2576
2932
|
templates {"logstash1":"#{template_file}", "logstash2":"#{template_file}","logstash3":"#{template_file}" }
|
2933
|
+
use_legacy_template #{use_legacy_template_flag}
|
2577
2934
|
}
|
2578
2935
|
|
2579
2936
|
stub_request(:head, "https://logs.google.com:777/es//").
|
2580
2937
|
with(basic_auth: ['john', 'doe']).
|
2581
2938
|
to_return(:status => 200, :body => "", :headers => {})
|
2582
2939
|
# check if template exists
|
2583
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2940
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash1").
|
2584
2941
|
with(basic_auth: ['john', 'doe']).
|
2585
2942
|
to_return(:status => 404, :body => "", :headers => {})
|
2586
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2943
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash2").
|
2587
2944
|
with(basic_auth: ['john', 'doe']).
|
2588
2945
|
to_return(:status => 404, :body => "", :headers => {})
|
2589
2946
|
|
2590
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2947
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash3").
|
2591
2948
|
with(basic_auth: ['john', 'doe']).
|
2592
2949
|
to_return(:status => 200, :body => "", :headers => {}) #exists
|
2593
2950
|
|
2594
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2951
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash1").
|
2595
2952
|
with(basic_auth: ['john', 'doe']).
|
2596
2953
|
to_return(:status => 200, :body => "", :headers => {})
|
2597
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2954
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash2").
|
2598
2955
|
with(basic_auth: ['john', 'doe']).
|
2599
2956
|
to_return(:status => 200, :body => "", :headers => {})
|
2600
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2957
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash3").
|
2601
2958
|
with(basic_auth: ['john', 'doe']).
|
2602
2959
|
to_return(:status => 200, :body => "", :headers => {})
|
2603
2960
|
|
2604
2961
|
driver(config)
|
2605
2962
|
|
2606
|
-
assert_requested( :put, "https://logs.google.com:777/es
|
2607
|
-
assert_requested( :put, "https://logs.google.com:777/es
|
2608
|
-
assert_not_requested(:put, "https://logs.google.com:777/es
|
2963
|
+
assert_requested( :put, "https://logs.google.com:777/es//#{endpoint}/logstash1", times: 1)
|
2964
|
+
assert_requested( :put, "https://logs.google.com:777/es//#{endpoint}/logstash2", times: 1)
|
2965
|
+
assert_not_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash3") #exists
|
2609
2966
|
end
|
2610
2967
|
|
2611
|
-
|
2968
|
+
data("legacy_template" => [true, "_template"],
|
2969
|
+
"new_template" => [false, "_index_template"])
|
2970
|
+
def test_templates_overwrite(data)
|
2971
|
+
use_legacy_template_flag, endpoint = data
|
2612
2972
|
cwd = File.dirname(__FILE__)
|
2613
|
-
template_file =
|
2973
|
+
template_file = if use_legacy_template_flag
|
2974
|
+
File.join(cwd, 'test_template.json')
|
2975
|
+
else
|
2976
|
+
File.join(cwd, 'test_index_template.json')
|
2977
|
+
end
|
2978
|
+
|
2614
2979
|
config = %{
|
2615
2980
|
host logs.google.com
|
2616
2981
|
port 777
|
@@ -2620,42 +2985,50 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2620
2985
|
password doe
|
2621
2986
|
templates {"logstash1":"#{template_file}", "logstash2":"#{template_file}","logstash3":"#{template_file}" }
|
2622
2987
|
template_overwrite true
|
2988
|
+
use_legacy_template #{use_legacy_template_flag}
|
2623
2989
|
}
|
2624
2990
|
|
2625
2991
|
stub_request(:head, "https://logs.google.com:777/es//").
|
2626
2992
|
with(basic_auth: ['john', 'doe']).
|
2627
2993
|
to_return(:status => 200, :body => "", :headers => {})
|
2628
2994
|
# check if template exists
|
2629
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2995
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash1").
|
2630
2996
|
with(basic_auth: ['john', 'doe']).
|
2631
2997
|
to_return(:status => 200, :body => "", :headers => {})
|
2632
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2998
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash2").
|
2633
2999
|
with(basic_auth: ['john', 'doe']).
|
2634
3000
|
to_return(:status => 200, :body => "", :headers => {})
|
2635
|
-
stub_request(:get, "https://logs.google.com:777/es
|
3001
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash3").
|
2636
3002
|
with(basic_auth: ['john', 'doe']).
|
2637
3003
|
to_return(:status => 200, :body => "", :headers => {}) #exists
|
2638
3004
|
|
2639
|
-
stub_request(:put, "https://logs.google.com:777/es
|
3005
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash1").
|
2640
3006
|
with(basic_auth: ['john', 'doe']).
|
2641
3007
|
to_return(:status => 200, :body => "", :headers => {})
|
2642
|
-
stub_request(:put, "https://logs.google.com:777/es
|
3008
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash2").
|
2643
3009
|
with(basic_auth: ['john', 'doe']).
|
2644
3010
|
to_return(:status => 200, :body => "", :headers => {})
|
2645
|
-
stub_request(:put, "https://logs.google.com:777/es
|
3011
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash3").
|
2646
3012
|
with(basic_auth: ['john', 'doe']).
|
2647
3013
|
to_return(:status => 200, :body => "", :headers => {})
|
2648
3014
|
|
2649
3015
|
driver(config)
|
2650
3016
|
|
2651
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2652
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2653
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
3017
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash1", times: 1)
|
3018
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash2", times: 1)
|
3019
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash3", times: 1)
|
2654
3020
|
end
|
2655
3021
|
|
2656
|
-
|
3022
|
+
data("legacy_template" => [true, "_template"],
|
3023
|
+
"new_template" => [false, "_index_template"])
|
3024
|
+
def test_templates_are_also_used(data)
|
3025
|
+
use_legacy_template_flag, endpoint = data
|
2657
3026
|
cwd = File.dirname(__FILE__)
|
2658
|
-
template_file =
|
3027
|
+
template_file = if use_legacy_template_flag
|
3028
|
+
File.join(cwd, 'test_template.json')
|
3029
|
+
else
|
3030
|
+
File.join(cwd, 'test_index_template.json')
|
3031
|
+
end
|
2659
3032
|
|
2660
3033
|
config = %{
|
2661
3034
|
host logs.google.com
|
@@ -2667,43 +3040,52 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2667
3040
|
template_name logstash
|
2668
3041
|
template_file #{template_file}
|
2669
3042
|
templates {"logstash1":"#{template_file}", "logstash2":"#{template_file}" }
|
3043
|
+
use_legacy_template #{use_legacy_template_flag}
|
2670
3044
|
}
|
2671
3045
|
# connection start
|
2672
3046
|
stub_request(:head, "https://logs.google.com:777/es//").
|
2673
3047
|
with(basic_auth: ['john', 'doe']).
|
2674
3048
|
to_return(:status => 200, :body => "", :headers => {})
|
2675
3049
|
# check if template exists
|
2676
|
-
stub_request(:get, "https://logs.google.com:777/es
|
3050
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
2677
3051
|
with(basic_auth: ['john', 'doe']).
|
2678
3052
|
to_return(:status => 404, :body => "", :headers => {})
|
2679
|
-
stub_request(:get, "https://logs.google.com:777/es
|
3053
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash1").
|
2680
3054
|
with(basic_auth: ['john', 'doe']).
|
2681
3055
|
to_return(:status => 404, :body => "", :headers => {})
|
2682
|
-
stub_request(:get, "https://logs.google.com:777/es
|
3056
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash2").
|
2683
3057
|
with(basic_auth: ['john', 'doe']).
|
2684
3058
|
to_return(:status => 404, :body => "", :headers => {})
|
2685
3059
|
#creation
|
2686
|
-
stub_request(:put, "https://logs.google.com:777/es
|
3060
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
2687
3061
|
with(basic_auth: ['john', 'doe']).
|
2688
3062
|
to_return(:status => 200, :body => "", :headers => {})
|
2689
|
-
stub_request(:put, "https://logs.google.com:777/es
|
3063
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash1").
|
2690
3064
|
with(basic_auth: ['john', 'doe']).
|
2691
3065
|
to_return(:status => 200, :body => "", :headers => {})
|
2692
|
-
stub_request(:put, "https://logs.google.com:777/es
|
3066
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash2").
|
2693
3067
|
with(basic_auth: ['john', 'doe']).
|
2694
3068
|
to_return(:status => 200, :body => "", :headers => {})
|
2695
3069
|
|
2696
3070
|
driver(config)
|
2697
3071
|
|
2698
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
3072
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash", times: 1)
|
2699
3073
|
|
2700
|
-
|
2701
|
-
|
3074
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash1")
|
3075
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash2")
|
2702
3076
|
end
|
2703
3077
|
|
2704
|
-
|
3078
|
+
data("legacy_template" => [true, "_template"],
|
3079
|
+
"new_template" => [false, "_index_template"])
|
3080
|
+
def test_templates_can_be_partially_created_if_error_occurs(data)
|
3081
|
+
use_legacy_template_flag, endpoint = data
|
2705
3082
|
cwd = File.dirname(__FILE__)
|
2706
|
-
template_file =
|
3083
|
+
template_file = if use_legacy_template_flag
|
3084
|
+
File.join(cwd, 'test_template.json')
|
3085
|
+
else
|
3086
|
+
File.join(cwd, 'test_index_template.json')
|
3087
|
+
end
|
3088
|
+
|
2707
3089
|
config = %{
|
2708
3090
|
host logs.google.com
|
2709
3091
|
port 777
|
@@ -2712,22 +3094,23 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2712
3094
|
user john
|
2713
3095
|
password doe
|
2714
3096
|
templates {"logstash1":"#{template_file}", "logstash2":"/abc" }
|
3097
|
+
use_legacy_template #{use_legacy_template_flag}
|
2715
3098
|
}
|
2716
3099
|
stub_request(:head, "https://logs.google.com:777/es//").
|
2717
3100
|
with(basic_auth: ['john', 'doe']).
|
2718
3101
|
to_return(:status => 200, :body => "", :headers => {})
|
2719
3102
|
# check if template exists
|
2720
|
-
stub_request(:get, "https://logs.google.com:777/es
|
3103
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash1").
|
2721
3104
|
with(basic_auth: ['john', 'doe']).
|
2722
3105
|
to_return(:status => 404, :body => "", :headers => {})
|
2723
|
-
stub_request(:get, "https://logs.google.com:777/es
|
3106
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash2").
|
2724
3107
|
with(basic_auth: ['john', 'doe']).
|
2725
3108
|
to_return(:status => 404, :body => "", :headers => {})
|
2726
3109
|
|
2727
|
-
stub_request(:put, "https://logs.google.com:777/es
|
3110
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash1").
|
2728
3111
|
with(basic_auth: ['john', 'doe']).
|
2729
3112
|
to_return(:status => 200, :body => "", :headers => {})
|
2730
|
-
stub_request(:put, "https://logs.google.com:777/es
|
3113
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash2").
|
2731
3114
|
with(basic_auth: ['john', 'doe']).
|
2732
3115
|
to_return(:status => 200, :body => "", :headers => {})
|
2733
3116
|
|
@@ -2735,8 +3118,8 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2735
3118
|
driver(config)
|
2736
3119
|
}
|
2737
3120
|
|
2738
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2739
|
-
assert_not_requested(:put, "https://logs.google.com:777/es
|
3121
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash1", times: 1)
|
3122
|
+
assert_not_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash2")
|
2740
3123
|
end
|
2741
3124
|
|
2742
3125
|
def test_legacy_hosts_list
|
@@ -2904,6 +3287,18 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2904
3287
|
assert_requested(elastic_request)
|
2905
3288
|
end
|
2906
3289
|
|
3290
|
+
def test_api_key_header
|
3291
|
+
stub_request(:head, "http://localhost:9200/").
|
3292
|
+
to_return(:status => 200, :body => "", :headers => {})
|
3293
|
+
elastic_request = stub_request(:post, "http://localhost:9200/_bulk").
|
3294
|
+
with(headers: {'Authorization'=>'ApiKey dGVzdGF1dGhoZWFkZXI='})
|
3295
|
+
driver.configure(%[api_key testauthheader])
|
3296
|
+
driver.run(default_tag: 'test') do
|
3297
|
+
driver.feed(sample_record)
|
3298
|
+
end
|
3299
|
+
assert_requested(elastic_request)
|
3300
|
+
end
|
3301
|
+
|
2907
3302
|
def test_write_message_with_bad_chunk
|
2908
3303
|
driver.configure("target_index_key bad_value\n@log_level debug\n")
|
2909
3304
|
stub_elastic
|
@@ -3014,6 +3409,39 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
3014
3409
|
assert_requested(request, times: 2)
|
3015
3410
|
end
|
3016
3411
|
|
3412
|
+
def test_writes_with_record_metadata
|
3413
|
+
chunk_id_key = "metadata_key".freeze
|
3414
|
+
driver.configure(Fluent::Config::Element.new(
|
3415
|
+
'ROOT', '', {
|
3416
|
+
'@type' => 'elasticsearch',
|
3417
|
+
}, [
|
3418
|
+
Fluent::Config::Element.new('metadata', '', {
|
3419
|
+
'include_chunk_id' => true,
|
3420
|
+
'chunk_id_key' => chunk_id_key,
|
3421
|
+
}, [])
|
3422
|
+
]
|
3423
|
+
))
|
3424
|
+
stub_request(:post, "http://localhost:9200/_bulk").
|
3425
|
+
with(
|
3426
|
+
body: /{"index":{"_index":"fluentd","_type":"fluentd"}}\n{"age":26,"request_id":"42","parent_id":"parent","routing_id":"routing","#{chunk_id_key}":".*"}\n/) do |req|
|
3427
|
+
@index_cmds = req.body.split("\n").map {|r| JSON.parse(r) }
|
3428
|
+
end
|
3429
|
+
driver.run(default_tag: 'test', shutdown: false) do
|
3430
|
+
driver.feed(sample_record)
|
3431
|
+
end
|
3432
|
+
assert_true index_cmds[1].has_key?(chunk_id_key)
|
3433
|
+
first_chunk_id = index_cmds[1].fetch(chunk_id_key)
|
3434
|
+
|
3435
|
+
driver.run(default_tag: 'test') do
|
3436
|
+
driver.feed(sample_record)
|
3437
|
+
end
|
3438
|
+
assert_true index_cmds[1].has_key?(chunk_id_key)
|
3439
|
+
second_chunk_id = index_cmds[1].fetch(chunk_id_key)
|
3440
|
+
assert do
|
3441
|
+
first_chunk_id != second_chunk_id
|
3442
|
+
end
|
3443
|
+
end
|
3444
|
+
|
3017
3445
|
def test_writes_with_huge_records_but_uncheck
|
3018
3446
|
driver.configure(Fluent::Config::Element.new(
|
3019
3447
|
'ROOT', '', {
|