fluent-plugin-elasticsearch 4.1.2 → 4.2.2
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 +24 -0
- data/README.ElasticsearchGenID.md +2 -2
- data/README.md +85 -2
- data/fluent-plugin-elasticsearch.gemspec +1 -1
- data/lib/fluent/plugin/elasticsearch_index_template.rb +42 -15
- data/lib/fluent/plugin/out_elasticsearch.rb +46 -9
- 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 +864 -263
- data/test/plugin/test_out_elasticsearch_dynamic.rb +7 -2
- metadata +6 -2
@@ -62,8 +62,14 @@ class TestElasticsearchTLS < Test::Unit::TestCase
|
|
62
62
|
d = driver('')
|
63
63
|
ssl_version_options = d.instance.set_tls_minmax_version_config(d.instance.ssl_version, nil, nil)
|
64
64
|
if @use_tls_minmax_version
|
65
|
-
|
66
|
-
|
65
|
+
if @enabled_tlsv1_3
|
66
|
+
assert_equal({max_version: OpenSSL::SSL::TLS1_3_VERSION,
|
67
|
+
min_version: OpenSSL::SSL::TLS1_2_VERSION}, ssl_version_options)
|
68
|
+
else
|
69
|
+
assert_equal({max_version: nil,
|
70
|
+
min_version: OpenSSL::SSL::TLS1_2_VERSION}, ssl_version_options)
|
71
|
+
|
72
|
+
end
|
67
73
|
else
|
68
74
|
assert_equal({version: Fluent::Plugin::ElasticsearchTLS::DEFAULT_VERSION}, ssl_version_options)
|
69
75
|
end
|
@@ -20,6 +20,11 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
20
20
|
@driver = nil
|
21
21
|
log = Fluent::Engine.log
|
22
22
|
log.out.logs.slice!(0, log.out.logs.length)
|
23
|
+
@http_method = if Gem::Version.new(Elasticsearch::VERSION) >= Gem::Version.new("7.9.0")
|
24
|
+
:post
|
25
|
+
else
|
26
|
+
:get
|
27
|
+
end
|
23
28
|
end
|
24
29
|
|
25
30
|
def driver(conf='')
|
@@ -313,7 +318,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
313
318
|
end
|
314
319
|
|
315
320
|
def test_emit
|
316
|
-
stub_request(
|
321
|
+
stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
|
317
322
|
with(body: "{\"sort\":[\"_doc\"]}").
|
318
323
|
to_return(status: 200, body: sample_response.to_s,
|
319
324
|
headers: {'Content-Type' => 'application/json'})
|
@@ -328,7 +333,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
328
333
|
|
329
334
|
def test_emit_with_custom_index_name
|
330
335
|
index_name = "logstash"
|
331
|
-
stub_request(
|
336
|
+
stub_request(@http_method, "http://localhost:9200/#{index_name}/_search?scroll=1m&size=1000").
|
332
337
|
with(body: "{\"sort\":[\"_doc\"]}").
|
333
338
|
to_return(status: 200, body: sample_response(index_name).to_s,
|
334
339
|
headers: {'Content-Type' => 'application/json'})
|
@@ -343,7 +348,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
343
348
|
|
344
349
|
def test_emit_with_parse_timestamp
|
345
350
|
index_name = "fluentd"
|
346
|
-
stub_request(
|
351
|
+
stub_request(@http_method, "http://localhost:9200/#{index_name}/_search?scroll=1m&size=1000").
|
347
352
|
with(body: "{\"sort\":[\"_doc\"]}").
|
348
353
|
to_return(status: 200, body: sample_response(index_name).to_s,
|
349
354
|
headers: {'Content-Type' => 'application/json'})
|
@@ -361,7 +366,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
361
366
|
|
362
367
|
def test_emit_with_parse_timestamp_and_timstamp_format
|
363
368
|
index_name = "fluentd"
|
364
|
-
stub_request(
|
369
|
+
stub_request(@http_method, "http://localhost:9200/#{index_name}/_search?scroll=1m&size=1000").
|
365
370
|
with(body: "{\"sort\":[\"_doc\"]}").
|
366
371
|
to_return(status: 200, body: sample_response(index_name).to_s,
|
367
372
|
headers: {'Content-Type' => 'application/json'})
|
@@ -380,7 +385,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
380
385
|
end
|
381
386
|
|
382
387
|
def test_emit_with_docinfo
|
383
|
-
stub_request(
|
388
|
+
stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
|
384
389
|
with(body: "{\"sort\":[\"_doc\"]}").
|
385
390
|
to_return(status: 200, body: sample_response.to_s,
|
386
391
|
headers: {'Content-Type' => 'application/json'})
|
@@ -399,11 +404,11 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
399
404
|
end
|
400
405
|
|
401
406
|
def test_emit_with_slices
|
402
|
-
stub_request(
|
407
|
+
stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
|
403
408
|
with(body: "{\"sort\":[\"_doc\"],\"slice\":{\"id\":0,\"max\":2}}").
|
404
409
|
to_return(status: 200, body: sample_response.to_s,
|
405
410
|
headers: {'Content-Type' => 'application/json'})
|
406
|
-
stub_request(
|
411
|
+
stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
|
407
412
|
with(body: "{\"sort\":[\"_doc\"],\"slice\":{\"id\":1,\"max\":2}}").
|
408
413
|
to_return(status: 200, body: sample_response.to_s,
|
409
414
|
headers: {'Content-Type' => 'application/json'})
|
@@ -419,12 +424,12 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
419
424
|
end
|
420
425
|
|
421
426
|
def test_emit_with_size
|
422
|
-
stub_request(
|
427
|
+
stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1").
|
423
428
|
with(body: "{\"sort\":[\"_doc\"]}").
|
424
429
|
to_return(status: 200, body: sample_scroll_response.to_s,
|
425
430
|
headers: {'Content-Type' => 'application/json'})
|
426
431
|
connection = 0
|
427
|
-
scroll_request = stub_request(
|
432
|
+
scroll_request = stub_request(@http_method, "http://localhost:9200/_search/scroll?scroll=1m").
|
428
433
|
with(
|
429
434
|
body: "{\"scroll_id\":\"WomkoUKG0QPB679Ulo6TqQgh3pIGRUmrl9qXXGK3EeiQh9rbYNasTkspZQcJ01uz\"}") do
|
430
435
|
connection += 1
|
@@ -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: {})
|
@@ -805,7 +819,10 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
805
819
|
end
|
806
820
|
end
|
807
821
|
|
808
|
-
|
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
|
809
826
|
config = %{
|
810
827
|
host logs.google.com
|
811
828
|
port 777
|
@@ -815,6 +832,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
815
832
|
password doe
|
816
833
|
template_name logstash
|
817
834
|
template_file /abc123
|
835
|
+
use_legacy_template #{use_legacy_template_flag}
|
818
836
|
}
|
819
837
|
|
820
838
|
# connection start
|
@@ -822,18 +840,25 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
822
840
|
with(basic_auth: ['john', 'doe']).
|
823
841
|
to_return(:status => 200, :body => "", :headers => {})
|
824
842
|
# check if template exists
|
825
|
-
stub_request(:get, "https://logs.google.com:777/es
|
843
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
826
844
|
with(basic_auth: ['john', 'doe']).
|
827
845
|
to_return(:status => 200, :body => "", :headers => {})
|
828
846
|
|
829
847
|
driver(config)
|
830
848
|
|
831
|
-
assert_not_requested(:put, "https://logs.google.com:777/es
|
849
|
+
assert_not_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash")
|
832
850
|
end
|
833
851
|
|
834
|
-
|
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
|
835
856
|
cwd = File.dirname(__FILE__)
|
836
|
-
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
|
837
862
|
|
838
863
|
config = %{
|
839
864
|
host logs.google.com
|
@@ -844,6 +869,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
844
869
|
password doe
|
845
870
|
template_name logstash
|
846
871
|
template_file #{template_file}
|
872
|
+
use_legacy_template #{use_legacy_template_flag}
|
847
873
|
}
|
848
874
|
|
849
875
|
# connection start
|
@@ -851,22 +877,29 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
851
877
|
with(basic_auth: ['john', 'doe']).
|
852
878
|
to_return(:status => 200, :body => "", :headers => {})
|
853
879
|
# check if template exists
|
854
|
-
stub_request(:get, "https://logs.google.com:777/es
|
880
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
855
881
|
with(basic_auth: ['john', 'doe']).
|
856
882
|
to_return(:status => 404, :body => "", :headers => {})
|
857
883
|
# creation
|
858
|
-
stub_request(:put, "https://logs.google.com:777/es
|
884
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
859
885
|
with(basic_auth: ['john', 'doe']).
|
860
886
|
to_return(:status => 200, :body => "", :headers => {})
|
861
887
|
|
862
888
|
driver(config)
|
863
889
|
|
864
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
890
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash", times: 1)
|
865
891
|
end
|
866
892
|
|
867
|
-
|
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
|
868
897
|
cwd = File.dirname(__FILE__)
|
869
|
-
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
|
870
903
|
config = %{
|
871
904
|
host logs.google.com
|
872
905
|
port 777
|
@@ -880,6 +913,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
880
913
|
index_date_pattern ""
|
881
914
|
index_name fluentd-${tag}
|
882
915
|
deflector_alias myapp_deflector-${tag}
|
916
|
+
use_legacy_template #{use_legacy_template_flag}
|
883
917
|
}
|
884
918
|
|
885
919
|
# connection start
|
@@ -887,11 +921,11 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
887
921
|
with(basic_auth: ['john', 'doe']).
|
888
922
|
to_return(:status => 200, :body => "", :headers => {})
|
889
923
|
# check if template exists
|
890
|
-
stub_request(:get, "https://logs.google.com:777/es
|
924
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash-test.template").
|
891
925
|
with(basic_auth: ['john', 'doe']).
|
892
926
|
to_return(:status => 404, :body => "", :headers => {})
|
893
927
|
# create template
|
894
|
-
stub_request(:put, "https://logs.google.com:777/es
|
928
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash-test.template").
|
895
929
|
with(basic_auth: ['john', 'doe']).
|
896
930
|
to_return(:status => 200, :body => "", :headers => {})
|
897
931
|
# check if alias exists
|
@@ -921,9 +955,16 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
921
955
|
assert_requested(elastic_request)
|
922
956
|
end
|
923
957
|
|
924
|
-
|
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
|
925
962
|
cwd = File.dirname(__FILE__)
|
926
|
-
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
|
927
968
|
config = %{
|
928
969
|
host logs.google.com
|
929
970
|
port 777
|
@@ -938,6 +979,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
938
979
|
index_name fluentd-${tag}
|
939
980
|
deflector_alias myapp_deflector-${tag}
|
940
981
|
truncate_caches_interval 2s
|
982
|
+
use_legacy_template #{use_legacy_template_flag}
|
941
983
|
}
|
942
984
|
|
943
985
|
# connection start
|
@@ -945,11 +987,11 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
945
987
|
with(basic_auth: ['john', 'doe']).
|
946
988
|
to_return(:status => 200, :body => "", :headers => {})
|
947
989
|
# check if template exists
|
948
|
-
stub_request(:get, "https://logs.google.com:777/es
|
990
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash-test.template").
|
949
991
|
with(basic_auth: ['john', 'doe']).
|
950
992
|
to_return(:status => 404, :body => "", :headers => {})
|
951
993
|
# create template
|
952
|
-
stub_request(:put, "https://logs.google.com:777/es
|
994
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash-test.template").
|
953
995
|
with(basic_auth: ['john', 'doe']).
|
954
996
|
to_return(:status => 200, :body => "", :headers => {})
|
955
997
|
# check if alias exists
|
@@ -994,9 +1036,16 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
994
1036
|
end
|
995
1037
|
end
|
996
1038
|
|
997
|
-
|
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
|
998
1043
|
cwd = File.dirname(__FILE__)
|
999
|
-
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
|
1000
1049
|
|
1001
1050
|
config = %{
|
1002
1051
|
host logs.google.com
|
@@ -1010,6 +1059,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1010
1059
|
index_date_pattern now/w{xxxx.ww}
|
1011
1060
|
index_name logstash
|
1012
1061
|
enable_ilm true
|
1062
|
+
use_legacy_template #{use_legacy_template_flag}
|
1013
1063
|
}
|
1014
1064
|
|
1015
1065
|
# connection start
|
@@ -1017,24 +1067,31 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1017
1067
|
with(basic_auth: ['john', 'doe']).
|
1018
1068
|
to_return(:status => 200, :body => "", :headers => {})
|
1019
1069
|
# check if template exists
|
1020
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1070
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1021
1071
|
with(basic_auth: ['john', 'doe']).
|
1022
1072
|
to_return(:status => 404, :body => "", :headers => {})
|
1023
1073
|
# creation
|
1024
|
-
stub_request(:put, "https://logs.google.com:777/es
|
1074
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1025
1075
|
with(basic_auth: ['john', 'doe']).
|
1026
1076
|
to_return(:status => 200, :body => "", :headers => {})
|
1027
1077
|
# check if alias exists
|
1028
1078
|
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash").
|
1029
1079
|
with(basic_auth: ['john', 'doe']).
|
1030
1080
|
to_return(:status => 404, :body => "", :headers => {})
|
1031
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1081
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1032
1082
|
with(basic_auth: ['john', 'doe']).
|
1033
1083
|
to_return(status: 404, body: "", headers: {})
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
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
|
1038
1095
|
# put the alias for the index
|
1039
1096
|
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
|
1040
1097
|
with(basic_auth: ['john', 'doe']).
|
@@ -1056,12 +1113,19 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1056
1113
|
|
1057
1114
|
driver(config)
|
1058
1115
|
|
1059
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
1116
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash", times: 1)
|
1060
1117
|
end
|
1061
1118
|
|
1062
|
-
|
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
|
1063
1123
|
cwd = File.dirname(__FILE__)
|
1064
|
-
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
|
1065
1129
|
|
1066
1130
|
config = %{
|
1067
1131
|
host logs.google.com
|
@@ -1076,6 +1140,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1076
1140
|
enable_ilm true
|
1077
1141
|
logstash_format true
|
1078
1142
|
application_name log
|
1143
|
+
use_legacy_template #{use_legacy_template_flag}
|
1079
1144
|
}
|
1080
1145
|
|
1081
1146
|
date_str = Time.now.strftime("%Y.%m.%d")
|
@@ -1084,24 +1149,31 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1084
1149
|
with(basic_auth: ['john', 'doe']).
|
1085
1150
|
to_return(:status => 200, :body => "", :headers => {})
|
1086
1151
|
# check if template exists
|
1087
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1152
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash-#{date_str}").
|
1088
1153
|
with(basic_auth: ['john', 'doe']).
|
1089
1154
|
to_return(:status => 404, :body => "", :headers => {})
|
1090
1155
|
# creation
|
1091
|
-
stub_request(:put, "https://logs.google.com:777/es
|
1156
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash-#{date_str}").
|
1092
1157
|
with(basic_auth: ['john', 'doe']).
|
1093
1158
|
to_return(:status => 200, :body => "", :headers => {})
|
1094
1159
|
# check if alias exists
|
1095
1160
|
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash-#{date_str}").
|
1096
1161
|
with(basic_auth: ['john', 'doe']).
|
1097
1162
|
to_return(:status => 404, :body => "", :headers => {})
|
1098
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1163
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash-#{date_str}").
|
1099
1164
|
with(basic_auth: ['john', 'doe']).
|
1100
1165
|
to_return(status: 404, body: "", headers: {})
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
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
|
1105
1177
|
# put the alias for the index
|
1106
1178
|
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-log-#{date_str}-000001%3E").
|
1107
1179
|
with(basic_auth: ['john', 'doe']).
|
@@ -1128,14 +1200,21 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1128
1200
|
driver.run(default_tag: 'test') do
|
1129
1201
|
driver.feed(sample_record)
|
1130
1202
|
end
|
1131
|
-
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)
|
1132
1204
|
|
1133
1205
|
assert_requested(elastic_request)
|
1134
1206
|
end
|
1135
1207
|
|
1136
|
-
|
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
|
1137
1212
|
cwd = File.dirname(__FILE__)
|
1138
|
-
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
|
1139
1218
|
|
1140
1219
|
config = %{
|
1141
1220
|
host logs.google.com
|
@@ -1151,6 +1230,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1151
1230
|
enable_ilm true
|
1152
1231
|
ilm_policy_overwrite true
|
1153
1232
|
ilm_policy {"policy":{"phases":{"hot":{"actions":{"rollover":{"max_size":"60gb","max_age": "45d"}}}}}}
|
1233
|
+
use_legacy_template #{use_legacy_template_flag}
|
1154
1234
|
}
|
1155
1235
|
|
1156
1236
|
# connection start
|
@@ -1158,24 +1238,31 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1158
1238
|
with(basic_auth: ['john', 'doe']).
|
1159
1239
|
to_return(:status => 200, :body => "", :headers => {})
|
1160
1240
|
# check if template exists
|
1161
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1241
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1162
1242
|
with(basic_auth: ['john', 'doe']).
|
1163
1243
|
to_return(:status => 404, :body => "", :headers => {})
|
1164
1244
|
# creation
|
1165
|
-
stub_request(:put, "https://logs.google.com:777/es
|
1245
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1166
1246
|
with(basic_auth: ['john', 'doe']).
|
1167
1247
|
to_return(:status => 200, :body => "", :headers => {})
|
1168
1248
|
# check if alias exists
|
1169
1249
|
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash").
|
1170
1250
|
with(basic_auth: ['john', 'doe']).
|
1171
1251
|
to_return(:status => 404, :body => "", :headers => {})
|
1172
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1252
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1173
1253
|
with(basic_auth: ['john', 'doe']).
|
1174
1254
|
to_return(status: 404, body: "", headers: {})
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
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
|
1179
1266
|
# put the alias for the index
|
1180
1267
|
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
|
1181
1268
|
with(basic_auth: ['john', 'doe']).
|
@@ -1197,7 +1284,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1197
1284
|
|
1198
1285
|
driver(config)
|
1199
1286
|
|
1200
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
1287
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash", times: 1)
|
1201
1288
|
end
|
1202
1289
|
|
1203
1290
|
def test_template_create_with_rollover_index_and_default_ilm_with_deflector_alias
|
@@ -1225,9 +1312,16 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1225
1312
|
end
|
1226
1313
|
end
|
1227
1314
|
|
1228
|
-
|
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
|
1229
1319
|
cwd = File.dirname(__FILE__)
|
1230
|
-
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
|
1231
1325
|
|
1232
1326
|
config = %{
|
1233
1327
|
host logs.google.com
|
@@ -1241,6 +1335,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1241
1335
|
index_date_pattern ""
|
1242
1336
|
index_name logstash
|
1243
1337
|
enable_ilm true
|
1338
|
+
use_legacy_template #{use_legacy_template_flag}
|
1244
1339
|
}
|
1245
1340
|
|
1246
1341
|
# connection start
|
@@ -1248,24 +1343,31 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1248
1343
|
with(basic_auth: ['john', 'doe']).
|
1249
1344
|
to_return(:status => 200, :body => "", :headers => {})
|
1250
1345
|
# check if template exists
|
1251
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1346
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1252
1347
|
with(basic_auth: ['john', 'doe']).
|
1253
1348
|
to_return(:status => 404, :body => "", :headers => {})
|
1254
1349
|
# creation
|
1255
|
-
stub_request(:put, "https://logs.google.com:777/es
|
1350
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1256
1351
|
with(basic_auth: ['john', 'doe']).
|
1257
1352
|
to_return(:status => 200, :body => "", :headers => {})
|
1258
1353
|
# check if alias exists
|
1259
1354
|
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash").
|
1260
1355
|
with(basic_auth: ['john', 'doe']).
|
1261
1356
|
to_return(:status => 404, :body => "", :headers => {})
|
1262
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1357
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1263
1358
|
with(basic_auth: ['john', 'doe']).
|
1264
1359
|
to_return(status: 404, body: "", headers: {})
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
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
|
1269
1371
|
# put the alias for the index
|
1270
1372
|
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-000001%3E").
|
1271
1373
|
with(basic_auth: ['john', 'doe']).
|
@@ -1287,12 +1389,19 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1287
1389
|
|
1288
1390
|
driver(config)
|
1289
1391
|
|
1290
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
1392
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash", times: 1)
|
1291
1393
|
end
|
1292
1394
|
|
1293
|
-
|
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
|
1294
1399
|
cwd = File.dirname(__FILE__)
|
1295
|
-
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
|
1296
1405
|
|
1297
1406
|
config = %{
|
1298
1407
|
host logs.google.com
|
@@ -1308,6 +1417,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1308
1417
|
enable_ilm true
|
1309
1418
|
index_name logstash
|
1310
1419
|
ilm_policy {"policy":{"phases":{"hot":{"actions":{"rollover":{"max_size":"70gb", "max_age":"30d"}}}}}}
|
1420
|
+
use_legacy_template #{use_legacy_template_flag}
|
1311
1421
|
}
|
1312
1422
|
|
1313
1423
|
# connection start
|
@@ -1315,24 +1425,31 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1315
1425
|
with(basic_auth: ['john', 'doe']).
|
1316
1426
|
to_return(:status => 200, :body => "", :headers => {})
|
1317
1427
|
# check if template exists
|
1318
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1428
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1319
1429
|
with(basic_auth: ['john', 'doe']).
|
1320
1430
|
to_return(:status => 404, :body => "", :headers => {})
|
1321
1431
|
# creation
|
1322
|
-
stub_request(:put, "https://logs.google.com:777/es
|
1432
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1323
1433
|
with(basic_auth: ['john', 'doe']).
|
1324
1434
|
to_return(:status => 200, :body => "", :headers => {})
|
1325
1435
|
# check if alias exists
|
1326
1436
|
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash").
|
1327
1437
|
with(basic_auth: ['john', 'doe']).
|
1328
1438
|
to_return(:status => 404, :body => "", :headers => {})
|
1329
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1439
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1330
1440
|
with(basic_auth: ['john', 'doe']).
|
1331
1441
|
to_return(status: 404, body: "", headers: {})
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
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
|
1336
1453
|
# put the alias for the index
|
1337
1454
|
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
|
1338
1455
|
with(basic_auth: ['john', 'doe']).
|
@@ -1353,12 +1470,19 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1353
1470
|
|
1354
1471
|
driver(config)
|
1355
1472
|
|
1356
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
1473
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash", times: 1)
|
1357
1474
|
end
|
1358
1475
|
|
1359
|
-
|
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
|
1360
1480
|
cwd = File.dirname(__FILE__)
|
1361
|
-
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
|
1362
1486
|
|
1363
1487
|
config = %{
|
1364
1488
|
host logs.google.com
|
@@ -1374,6 +1498,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1374
1498
|
enable_ilm true
|
1375
1499
|
index_name logstash
|
1376
1500
|
ilm_policies {"fluentd-policy":{"policy":{"phases":{"hot":{"actions":{"rollover":{"max_size":"70gb", "max_age":"30d"}}}}}}}
|
1501
|
+
use_legacy_template #{use_legacy_template_flag}
|
1377
1502
|
}
|
1378
1503
|
|
1379
1504
|
# connection start
|
@@ -1381,24 +1506,31 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1381
1506
|
with(basic_auth: ['john', 'doe']).
|
1382
1507
|
to_return(:status => 200, :body => "", :headers => {})
|
1383
1508
|
# check if template exists
|
1384
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1509
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1385
1510
|
with(basic_auth: ['john', 'doe']).
|
1386
1511
|
to_return(:status => 404, :body => "", :headers => {})
|
1387
1512
|
# creation
|
1388
|
-
stub_request(:put, "https://logs.google.com:777/es
|
1513
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1389
1514
|
with(basic_auth: ['john', 'doe']).
|
1390
1515
|
to_return(:status => 200, :body => "", :headers => {})
|
1391
1516
|
# check if alias exists
|
1392
1517
|
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash").
|
1393
1518
|
with(basic_auth: ['john', 'doe']).
|
1394
1519
|
to_return(:status => 404, :body => "", :headers => {})
|
1395
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1520
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1396
1521
|
with(basic_auth: ['john', 'doe']).
|
1397
1522
|
to_return(status: 404, body: "", headers: {})
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
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
|
1402
1534
|
# put the alias for the index
|
1403
1535
|
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
|
1404
1536
|
with(basic_auth: ['john', 'doe']).
|
@@ -1423,15 +1555,22 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1423
1555
|
driver.run(default_tag: 'test') do
|
1424
1556
|
driver.feed(sample_record)
|
1425
1557
|
end
|
1426
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
1558
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash", times: 1)
|
1427
1559
|
|
1428
1560
|
assert_requested(elastic_request)
|
1429
1561
|
end
|
1430
1562
|
|
1431
1563
|
class TemplateCreateWithRolloverIndexAndILMPoliciesWithPlaceholdersTest < self
|
1432
|
-
|
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
|
1433
1568
|
cwd = File.dirname(__FILE__)
|
1434
|
-
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
|
1435
1574
|
|
1436
1575
|
config = %{
|
1437
1576
|
host logs.google.com
|
@@ -1447,6 +1586,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1447
1586
|
enable_ilm true
|
1448
1587
|
index_name logstash
|
1449
1588
|
ilm_policies {"fluentd-policy":{"policy":{"phases":{"hot":{"actions":{"rollover":{"max_size":"70gb", "max_age":"30d"}}}}}}}
|
1589
|
+
use_legacy_template #{use_legacy_template_flag}
|
1450
1590
|
}
|
1451
1591
|
|
1452
1592
|
# connection start
|
@@ -1454,24 +1594,31 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1454
1594
|
with(basic_auth: ['john', 'doe']).
|
1455
1595
|
to_return(:status => 200, :body => "", :headers => {})
|
1456
1596
|
# check if template exists
|
1457
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1597
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1458
1598
|
with(basic_auth: ['john', 'doe']).
|
1459
1599
|
to_return(:status => 404, :body => "", :headers => {})
|
1460
1600
|
# creation
|
1461
|
-
stub_request(:put, "https://logs.google.com:777/es
|
1601
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1462
1602
|
with(basic_auth: ['john', 'doe']).
|
1463
1603
|
to_return(:status => 200, :body => "", :headers => {})
|
1464
1604
|
# check if alias exists
|
1465
1605
|
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash").
|
1466
1606
|
with(basic_auth: ['john', 'doe']).
|
1467
1607
|
to_return(:status => 404, :body => "", :headers => {})
|
1468
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1608
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1469
1609
|
with(basic_auth: ['john', 'doe']).
|
1470
1610
|
to_return(status: 404, body: "", headers: {})
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
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
|
1475
1622
|
# put the alias for the index
|
1476
1623
|
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
|
1477
1624
|
with(basic_auth: ['john', 'doe']).
|
@@ -1496,14 +1643,21 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1496
1643
|
driver.run(default_tag: 'fluentd-policy') do
|
1497
1644
|
driver.feed(sample_record)
|
1498
1645
|
end
|
1499
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
1646
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash", times: 1)
|
1500
1647
|
|
1501
1648
|
assert_requested(elastic_request)
|
1502
1649
|
end
|
1503
1650
|
|
1504
|
-
|
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
|
1505
1655
|
cwd = File.dirname(__FILE__)
|
1506
|
-
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
|
1507
1661
|
|
1508
1662
|
config = %{
|
1509
1663
|
host logs.google.com
|
@@ -1519,6 +1673,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1519
1673
|
enable_ilm true
|
1520
1674
|
index_name logstash
|
1521
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}
|
1522
1677
|
}
|
1523
1678
|
|
1524
1679
|
# connection start
|
@@ -1526,24 +1681,31 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1526
1681
|
with(basic_auth: ['john', 'doe']).
|
1527
1682
|
to_return(:status => 200, :body => "", :headers => {})
|
1528
1683
|
# check if template exists
|
1529
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1684
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1530
1685
|
with(basic_auth: ['john', 'doe']).
|
1531
1686
|
to_return(:status => 404, :body => "", :headers => {})
|
1532
1687
|
# creation
|
1533
|
-
stub_request(:put, "https://logs.google.com:777/es
|
1688
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1534
1689
|
with(basic_auth: ['john', 'doe']).
|
1535
1690
|
to_return(:status => 200, :body => "", :headers => {})
|
1536
1691
|
# check if alias exists
|
1537
1692
|
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash").
|
1538
1693
|
with(basic_auth: ['john', 'doe']).
|
1539
1694
|
to_return(:status => 404, :body => "", :headers => {})
|
1540
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1695
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1541
1696
|
with(basic_auth: ['john', 'doe']).
|
1542
1697
|
to_return(status: 404, body: "", headers: {})
|
1543
|
-
|
1544
|
-
|
1545
|
-
|
1546
|
-
|
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
|
1547
1709
|
# put the alias for the index
|
1548
1710
|
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
|
1549
1711
|
with(basic_auth: ['john', 'doe']).
|
@@ -1568,15 +1730,22 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1568
1730
|
driver.run(default_tag: 'fluentd-policy2') do
|
1569
1731
|
driver.feed(sample_record)
|
1570
1732
|
end
|
1571
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
1733
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash", times: 1)
|
1572
1734
|
|
1573
1735
|
assert_requested(elastic_request)
|
1574
1736
|
end
|
1575
1737
|
end
|
1576
1738
|
|
1577
|
-
|
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
|
1578
1743
|
cwd = File.dirname(__FILE__)
|
1579
|
-
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
|
1580
1749
|
|
1581
1750
|
config = %{
|
1582
1751
|
host logs.google.com
|
@@ -1590,6 +1759,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1590
1759
|
index_date_pattern now/w{xxxx.ww}
|
1591
1760
|
index_name logstash-${tag}
|
1592
1761
|
enable_ilm true
|
1762
|
+
use_legacy_template #{use_legacy_template_flag}
|
1593
1763
|
}
|
1594
1764
|
|
1595
1765
|
# connection start
|
@@ -1597,31 +1767,166 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1597
1767
|
with(basic_auth: ['john', 'doe']).
|
1598
1768
|
to_return(:status => 200, :body => "", :headers => {})
|
1599
1769
|
# check if template exists
|
1600
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1770
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1601
1771
|
with(basic_auth: ['john', 'doe']).
|
1602
1772
|
to_return(:status => 404, :body => "", :headers => {})
|
1603
1773
|
# creation
|
1604
|
-
stub_request(:put, "https://logs.google.com:777/es
|
1774
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1605
1775
|
with(basic_auth: ['john', 'doe']).
|
1606
1776
|
to_return(:status => 200, :body => "", :headers => {})
|
1607
1777
|
# check if alias exists
|
1608
|
-
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash-
|
1778
|
+
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash-tag1").
|
1609
1779
|
with(basic_auth: ['john', 'doe']).
|
1610
1780
|
to_return(:status => 404, :body => "", :headers => {})
|
1611
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1781
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash-tag1").
|
1612
1782
|
with(basic_auth: ['john', 'doe']).
|
1613
1783
|
to_return(status: 404, body: "", headers: {})
|
1614
|
-
|
1784
|
+
if use_legacy_template_flag
|
1785
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash-tag1").
|
1786
|
+
with(basic_auth: ['john', 'doe'],
|
1787
|
+
body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash-tag1\"},\"mappings\":{\"type1\":{\"_source\":{\"enabled\":false},\"properties\":{\"host_name\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"created_at\":{\"type\":\"date\",\"format\":\"EEE MMM dd HH:mm:ss Z YYYY\"}}}},\"index_patterns\":\"logstash-tag1-*\",\"order\":52}").
|
1788
|
+
to_return(status: 200, body: "", headers: {})
|
1789
|
+
else
|
1790
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash-tag1").
|
1791
|
+
with(basic_auth: ['john', 'doe'],
|
1792
|
+
body: "{\"index_patterns\":\"logstash-tag1-*\",\"template\":{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash-tag1\"},\"mappings\":{\"type1\":{\"_source\":{\"enabled\":false},\"properties\":{\"host_name\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"created_at\":{\"type\":\"date\",\"format\":\"EEE MMM dd HH:mm:ss Z YYYY\"}}}}},\"priority\":102}").
|
1793
|
+
to_return(status: 200, body: "", headers: {})
|
1794
|
+
end
|
1795
|
+
# put the alias for the index
|
1796
|
+
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-tag1-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
|
1797
|
+
with(basic_auth: ['john', 'doe']).
|
1798
|
+
to_return(:status => 200, :body => "", :headers => {})
|
1799
|
+
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-tag1-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/#{alias_endpoint}/logstash-tag1").
|
1615
1800
|
with(basic_auth: ['john', 'doe'],
|
1616
|
-
body
|
1617
|
-
to_return(status
|
1801
|
+
:body => "{\"aliases\":{\"logstash-tag1\":{\"is_write_index\":true}}}").
|
1802
|
+
to_return(:status => 200, :body => "", :headers => {})
|
1803
|
+
stub_request(:get, "https://logs.google.com:777/es//_xpack").
|
1804
|
+
with(basic_auth: ['john', 'doe']).
|
1805
|
+
to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
|
1806
|
+
stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
|
1807
|
+
with(basic_auth: ['john', 'doe']).
|
1808
|
+
to_return(:status => 404, :body => "", :headers => {})
|
1809
|
+
stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
|
1810
|
+
with(basic_auth: ['john', 'doe'],
|
1811
|
+
:body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
|
1812
|
+
to_return(:status => 200, :body => "", :headers => {})
|
1813
|
+
# check if alias exists
|
1814
|
+
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash-tag2").
|
1815
|
+
with(basic_auth: ['john', 'doe']).
|
1816
|
+
to_return(:status => 404, :body => "", :headers => {})
|
1817
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash-tag2").
|
1818
|
+
with(basic_auth: ['john', 'doe']).
|
1819
|
+
to_return(status: 404, body: "", headers: {})
|
1820
|
+
if use_legacy_template_flag
|
1821
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash-tag2").
|
1822
|
+
with(basic_auth: ['john', 'doe'],
|
1823
|
+
body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash-tag2\"},\"mappings\":{\"type1\":{\"_source\":{\"enabled\":false},\"properties\":{\"host_name\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"created_at\":{\"type\":\"date\",\"format\":\"EEE MMM dd HH:mm:ss Z YYYY\"}}}},\"index_patterns\":\"logstash-tag2-*\",\"order\":52}").
|
1824
|
+
to_return(status: 200, body: "", headers: {})
|
1825
|
+
else
|
1826
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash-tag2").
|
1827
|
+
with(basic_auth: ['john', 'doe'],
|
1828
|
+
body: "{\"index_patterns\":\"logstash-tag2-*\",\"template\":{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash-tag2\"},\"mappings\":{\"type1\":{\"_source\":{\"enabled\":false},\"properties\":{\"host_name\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"created_at\":{\"type\":\"date\",\"format\":\"EEE MMM dd HH:mm:ss Z YYYY\"}}}}},\"priority\":102}").
|
1829
|
+
to_return(status: 200, body: "", headers: {})
|
1830
|
+
end # put the alias for the index
|
1831
|
+
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-tag2-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
|
1832
|
+
with(basic_auth: ['john', 'doe']).
|
1833
|
+
to_return(:status => 200, :body => "", :headers => {})
|
1834
|
+
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-tag2-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/#{alias_endpoint}/logstash-tag2").
|
1835
|
+
with(basic_auth: ['john', 'doe'],
|
1836
|
+
:body => "{\"aliases\":{\"logstash-tag2\":{\"is_write_index\":true}}}").
|
1837
|
+
to_return(:status => 200, :body => "", :headers => {})
|
1838
|
+
stub_request(:get, "https://logs.google.com:777/es//_xpack").
|
1839
|
+
with(basic_auth: ['john', 'doe']).
|
1840
|
+
to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
|
1841
|
+
stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
|
1842
|
+
with(basic_auth: ['john', 'doe']).
|
1843
|
+
to_return(:status => 404, :body => "", :headers => {})
|
1844
|
+
stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
|
1845
|
+
with(basic_auth: ['john', 'doe'],
|
1846
|
+
:body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
|
1847
|
+
to_return(:status => 200, :body => "", :headers => {})
|
1848
|
+
|
1849
|
+
driver(config)
|
1850
|
+
|
1851
|
+
elastic_request = stub_elastic("https://logs.google.com:777/es//_bulk")
|
1852
|
+
driver.run(default_tag: 'test') do
|
1853
|
+
driver.feed('tag1', event_time, sample_record)
|
1854
|
+
driver.feed('tag2', event_time, sample_record)
|
1855
|
+
driver.feed('tag1', event_time, sample_record)
|
1856
|
+
driver.feed('tag2', event_time, sample_record)
|
1857
|
+
end
|
1858
|
+
assert_equal('logstash-tag2', index_cmds.first['index']['_index'])
|
1859
|
+
|
1860
|
+
assert_equal ["logstash-tag1", "logstash-tag2"], driver.instance.alias_indexes
|
1861
|
+
|
1862
|
+
assert_requested(elastic_request)
|
1863
|
+
end
|
1864
|
+
|
1865
|
+
|
1866
|
+
data("legacy_template" => [true, "_template"],
|
1867
|
+
"new_template" => [false, "_index_template"])
|
1868
|
+
def test_template_create_with_rollover_index_and_default_ilm_and_placeholders_and_index_separator(data)
|
1869
|
+
use_legacy_template_flag, endpoint = data
|
1870
|
+
cwd = File.dirname(__FILE__)
|
1871
|
+
template_file = if use_legacy_template_flag
|
1872
|
+
File.join(cwd, 'test_template.json')
|
1873
|
+
else
|
1874
|
+
File.join(cwd, 'test_index_template.json')
|
1875
|
+
end
|
1876
|
+
|
1877
|
+
config = %{
|
1878
|
+
host logs.google.com
|
1879
|
+
port 777
|
1880
|
+
scheme https
|
1881
|
+
path /es/
|
1882
|
+
user john
|
1883
|
+
password doe
|
1884
|
+
template_name logstash
|
1885
|
+
template_file #{template_file}
|
1886
|
+
index_date_pattern now/w{xxxx.ww}
|
1887
|
+
index_name logstash.${tag}
|
1888
|
+
enable_ilm true
|
1889
|
+
index_separator "."
|
1890
|
+
use_legacy_template #{use_legacy_template_flag}
|
1891
|
+
}
|
1892
|
+
|
1893
|
+
# connection start
|
1894
|
+
stub_request(:head, "https://logs.google.com:777/es//").
|
1895
|
+
with(basic_auth: ['john', 'doe']).
|
1896
|
+
to_return(:status => 200, :body => "", :headers => {})
|
1897
|
+
# check if template exists
|
1898
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1899
|
+
with(basic_auth: ['john', 'doe']).
|
1900
|
+
to_return(:status => 404, :body => "", :headers => {})
|
1901
|
+
# creation
|
1902
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
1903
|
+
with(basic_auth: ['john', 'doe']).
|
1904
|
+
to_return(:status => 200, :body => "", :headers => {})
|
1905
|
+
# check if alias exists
|
1906
|
+
stub_request(:head, "https://logs.google.com:777/es//_alias/logstash.tag1").
|
1907
|
+
with(basic_auth: ['john', 'doe']).
|
1908
|
+
to_return(:status => 404, :body => "", :headers => {})
|
1909
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash.tag1").
|
1910
|
+
with(basic_auth: ['john', 'doe']).
|
1911
|
+
to_return(status: 404, body: "", headers: {})
|
1912
|
+
if use_legacy_template_flag
|
1913
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash.tag1").
|
1914
|
+
with(basic_auth: ['john', 'doe'],
|
1915
|
+
body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash.tag1\"},\"mappings\":{\"type1\":{\"_source\":{\"enabled\":false},\"properties\":{\"host_name\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"created_at\":{\"type\":\"date\",\"format\":\"EEE MMM dd HH:mm:ss Z YYYY\"}}}},\"index_patterns\":\"logstash.tag1.*\",\"order\":52}").
|
1916
|
+
to_return(status: 200, body: "", headers: {})
|
1917
|
+
else
|
1918
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash.tag1").
|
1919
|
+
with(basic_auth: ['john', 'doe'],
|
1920
|
+
body: "{\"index_patterns\":\"logstash.tag1.*\",\"template\":{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash.tag1\"},\"mappings\":{\"type1\":{\"_source\":{\"enabled\":false},\"properties\":{\"host_name\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"created_at\":{\"type\":\"date\",\"format\":\"EEE MMM dd HH:mm:ss Z YYYY\"}}}}},\"priority\":102}").
|
1921
|
+
to_return(status: 200, body: "", headers: {})
|
1922
|
+
end
|
1618
1923
|
# put the alias for the index
|
1619
|
-
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash
|
1924
|
+
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash.tag1.default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
|
1620
1925
|
with(basic_auth: ['john', 'doe']).
|
1621
1926
|
to_return(:status => 200, :body => "", :headers => {})
|
1622
|
-
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash
|
1927
|
+
stub_request(:put, "https://logs.google.com:777/es//%3Clogstash.tag1.default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/#{alias_endpoint}/logstash.tag1").
|
1623
1928
|
with(basic_auth: ['john', 'doe'],
|
1624
|
-
:body => "{\"aliases\":{\"logstash
|
1929
|
+
:body => "{\"aliases\":{\"logstash.tag1\":{\"is_write_index\":true}}}").
|
1625
1930
|
to_return(:status => 200, :body => "", :headers => {})
|
1626
1931
|
stub_request(:get, "https://logs.google.com:777/es//_xpack").
|
1627
1932
|
with(basic_auth: ['john', 'doe']).
|
@@ -1638,18 +1943,25 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1638
1943
|
|
1639
1944
|
elastic_request = stub_elastic("https://logs.google.com:777/es//_bulk")
|
1640
1945
|
driver.run(default_tag: 'test') do
|
1641
|
-
driver.feed(sample_record)
|
1946
|
+
driver.feed('tag1', event_time, sample_record)
|
1642
1947
|
end
|
1643
|
-
assert_equal('logstash
|
1948
|
+
assert_equal('logstash.tag1', index_cmds.first['index']['_index'])
|
1644
1949
|
|
1645
|
-
assert_equal ["logstash
|
1950
|
+
assert_equal ["logstash.tag1"], driver.instance.alias_indexes
|
1646
1951
|
|
1647
1952
|
assert_requested(elastic_request)
|
1648
1953
|
end
|
1649
1954
|
|
1650
|
-
|
1955
|
+
data("legacy_template" => [true, "_template"],
|
1956
|
+
"new_template" => [false, "_index_template"])
|
1957
|
+
def test_template_create_with_rollover_index_and_default_ilm_and_custom_and_time_placeholders(data)
|
1958
|
+
use_legacy_template_flag, endpoint = data
|
1651
1959
|
cwd = File.dirname(__FILE__)
|
1652
|
-
template_file =
|
1960
|
+
template_file = if use_legacy_template_flag
|
1961
|
+
File.join(cwd, 'test_template.json')
|
1962
|
+
else
|
1963
|
+
File.join(cwd, 'test_index_template.json')
|
1964
|
+
end
|
1653
1965
|
|
1654
1966
|
config = Fluent::Config::Element.new(
|
1655
1967
|
'ROOT', '', {
|
@@ -1665,6 +1977,8 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1665
1977
|
'index_date_pattern' => 'now/w{xxxx.ww}',
|
1666
1978
|
'index_name' => "${taskDef}-%Y.%m",
|
1667
1979
|
'enable_ilm' => true,
|
1980
|
+
'use_legacy_template' => use_legacy_template_flag,
|
1981
|
+
|
1668
1982
|
}, [
|
1669
1983
|
Fluent::Config::Element.new('buffer', 'tag, time, taskDef', {
|
1670
1984
|
'chunk_keys' => ['tag', 'time', 'taskDef'],
|
@@ -1680,14 +1994,21 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1680
1994
|
with(basic_auth: ['john', 'doe']).
|
1681
1995
|
to_return(:status => 200, :body => "", :headers => {})
|
1682
1996
|
# check if template exists
|
1683
|
-
stub_request(:get, "https://logs.google.com:777/es
|
1997
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/#{task_def_value}-#{date_str}").
|
1684
1998
|
with(basic_auth: ['john', 'doe']).
|
1685
1999
|
to_return(:status => 404, :body => "", :headers => {})
|
1686
2000
|
# creation
|
1687
|
-
|
1688
|
-
|
1689
|
-
|
1690
|
-
|
2001
|
+
if use_legacy_template_flag
|
2002
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/#{task_def_value}-#{date_str}").
|
2003
|
+
with(basic_auth: ['john', 'doe'],
|
2004
|
+
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}").
|
2005
|
+
to_return(:status => 200, :body => "", :headers => {})
|
2006
|
+
else
|
2007
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/#{task_def_value}-#{date_str}").
|
2008
|
+
with(basic_auth: ['john', 'doe'],
|
2009
|
+
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}").
|
2010
|
+
to_return(:status => 200, :body => "", :headers => {})
|
2011
|
+
end
|
1691
2012
|
# check if alias exists
|
1692
2013
|
stub_request(:head, "https://logs.google.com:777/es//_alias/#{task_def_value}-#{date_str}").
|
1693
2014
|
with(basic_auth: ['john', 'doe']).
|
@@ -1725,9 +2046,16 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1725
2046
|
end
|
1726
2047
|
end
|
1727
2048
|
|
1728
|
-
|
2049
|
+
data("legacy_template" => [true, "_template"],
|
2050
|
+
"new_template" => [false, "_index_template"])
|
2051
|
+
def test_custom_template_create(data)
|
2052
|
+
use_legacy_template_flag, endpoint = data
|
1729
2053
|
cwd = File.dirname(__FILE__)
|
1730
|
-
template_file =
|
2054
|
+
template_file = if use_legacy_template_flag
|
2055
|
+
File.join(cwd, 'test_alias_template.json')
|
2056
|
+
else
|
2057
|
+
File.join(cwd, 'test_index_alias_template.json')
|
2058
|
+
end
|
1731
2059
|
|
1732
2060
|
config = %{
|
1733
2061
|
host logs.google.com
|
@@ -1739,6 +2067,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1739
2067
|
template_name myapp_alias_template
|
1740
2068
|
template_file #{template_file}
|
1741
2069
|
customize_template {"--appid--": "myapp-logs","--index_prefix--":"mylogs"}
|
2070
|
+
use_legacy_template #{use_legacy_template_flag}
|
1742
2071
|
}
|
1743
2072
|
|
1744
2073
|
# connection start
|
@@ -1746,22 +2075,29 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1746
2075
|
with(basic_auth: ['john', 'doe']).
|
1747
2076
|
to_return(:status => 200, :body => "", :headers => {})
|
1748
2077
|
# check if template exists
|
1749
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2078
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
1750
2079
|
with(basic_auth: ['john', 'doe']).
|
1751
2080
|
to_return(:status => 404, :body => "", :headers => {})
|
1752
2081
|
# creation
|
1753
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2082
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
1754
2083
|
with(basic_auth: ['john', 'doe']).
|
1755
2084
|
to_return(:status => 200, :body => "", :headers => {})
|
1756
2085
|
|
1757
2086
|
driver(config)
|
1758
2087
|
|
1759
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2088
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template", times: 1)
|
1760
2089
|
end
|
1761
2090
|
|
1762
|
-
|
2091
|
+
data("legacy_template" => [true, "_template"],
|
2092
|
+
"new_template" => [false, "_index_template"])
|
2093
|
+
def test_custom_template_create_with_customize_template_related_placeholders(data)
|
2094
|
+
use_legacy_template_flag, endpoint = data
|
1763
2095
|
cwd = File.dirname(__FILE__)
|
1764
|
-
template_file =
|
2096
|
+
template_file = if use_legacy_template_flag
|
2097
|
+
File.join(cwd, 'test_alias_template.json')
|
2098
|
+
else
|
2099
|
+
File.join(cwd, 'test_index_alias_template.json')
|
2100
|
+
end
|
1765
2101
|
|
1766
2102
|
config = %{
|
1767
2103
|
host logs.google.com
|
@@ -1773,6 +2109,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1773
2109
|
template_name myapp_alias_template-${tag}
|
1774
2110
|
template_file #{template_file}
|
1775
2111
|
customize_template {"--appid--": "${tag}-logs","--index_prefix--":"${tag}"}
|
2112
|
+
use_legacy_template #{use_legacy_template_flag}
|
1776
2113
|
}
|
1777
2114
|
|
1778
2115
|
# connection start
|
@@ -1780,11 +2117,11 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1780
2117
|
with(basic_auth: ['john', 'doe']).
|
1781
2118
|
to_return(:status => 200, :body => "", :headers => {})
|
1782
2119
|
# check if template exists
|
1783
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2120
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template-test.template").
|
1784
2121
|
with(basic_auth: ['john', 'doe']).
|
1785
2122
|
to_return(:status => 404, :body => "", :headers => {})
|
1786
2123
|
# creation
|
1787
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2124
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template-test.template").
|
1788
2125
|
with(basic_auth: ['john', 'doe']).
|
1789
2126
|
to_return(:status => 200, :body => "", :headers => {})
|
1790
2127
|
|
@@ -1798,12 +2135,19 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1798
2135
|
driver.feed(sample_record)
|
1799
2136
|
end
|
1800
2137
|
|
1801
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2138
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template-test.template", times: 1)
|
1802
2139
|
end
|
1803
2140
|
|
1804
|
-
|
2141
|
+
data("legacy_template" => [true, "_template"],
|
2142
|
+
"new_template" => [false, "_index_template"])
|
2143
|
+
def test_custom_template_installation_for_host_placeholder(data)
|
2144
|
+
use_legacy_template_flag, endpoint = data
|
1805
2145
|
cwd = File.dirname(__FILE__)
|
1806
|
-
template_file =
|
2146
|
+
template_file = if use_legacy_template_flag
|
2147
|
+
File.join(cwd, 'test_template.json')
|
2148
|
+
else
|
2149
|
+
File.join(cwd, 'test_index_template.json')
|
2150
|
+
end
|
1807
2151
|
|
1808
2152
|
config = %{
|
1809
2153
|
host logs-${tag}.google.com
|
@@ -1817,6 +2161,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1817
2161
|
verify_es_version_at_startup false
|
1818
2162
|
default_elasticsearch_version 6
|
1819
2163
|
customize_template {"--appid--": "myapp-logs","--index_prefix--":"mylogs"}
|
2164
|
+
use_legacy_template #{use_legacy_template_flag}
|
1820
2165
|
}
|
1821
2166
|
|
1822
2167
|
# connection start
|
@@ -1824,10 +2169,10 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1824
2169
|
with(basic_auth: ['john', 'doe']).
|
1825
2170
|
to_return(:status => 200, :body => "", :headers => {})
|
1826
2171
|
# check if template exists
|
1827
|
-
stub_request(:get, "https://logs-test.google.com:777/es
|
2172
|
+
stub_request(:get, "https://logs-test.google.com:777/es//#{endpoint}/logstash").
|
1828
2173
|
with(basic_auth: ['john', 'doe']).
|
1829
2174
|
to_return(:status => 404, :body => "", :headers => {})
|
1830
|
-
stub_request(:put, "https://logs-test.google.com:777/es
|
2175
|
+
stub_request(:put, "https://logs-test.google.com:777/es//#{endpoint}/logstash").
|
1831
2176
|
with(basic_auth: ['john', 'doe']).
|
1832
2177
|
to_return(status: 200, body: "", headers: {})
|
1833
2178
|
|
@@ -1839,9 +2184,16 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1839
2184
|
end
|
1840
2185
|
end
|
1841
2186
|
|
1842
|
-
|
2187
|
+
data("legacy_template" => [true, "_template"],
|
2188
|
+
"new_template" => [false, "_index_template"])
|
2189
|
+
def test_custom_template_with_rollover_index_create(data)
|
2190
|
+
use_legacy_template_flag, endpoint = data
|
1843
2191
|
cwd = File.dirname(__FILE__)
|
1844
|
-
template_file =
|
2192
|
+
template_file = if use_legacy_template_flag
|
2193
|
+
File.join(cwd, 'test_alias_template.json')
|
2194
|
+
else
|
2195
|
+
File.join(cwd, 'test_index_alias_template.json')
|
2196
|
+
end
|
1845
2197
|
|
1846
2198
|
config = %{
|
1847
2199
|
host logs.google.com
|
@@ -1857,6 +2209,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1857
2209
|
index_date_pattern now/w{xxxx.ww}
|
1858
2210
|
index_name mylogs
|
1859
2211
|
application_name myapp
|
2212
|
+
use_legacy_template #{use_legacy_template_flag}
|
1860
2213
|
}
|
1861
2214
|
|
1862
2215
|
# connection start
|
@@ -1864,11 +2217,11 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1864
2217
|
with(basic_auth: ['john', 'doe']).
|
1865
2218
|
to_return(:status => 200, :body => "", :headers => {})
|
1866
2219
|
# check if template exists
|
1867
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2220
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
1868
2221
|
with(basic_auth: ['john', 'doe']).
|
1869
2222
|
to_return(:status => 404, :body => "", :headers => {})
|
1870
2223
|
# creation
|
1871
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2224
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
1872
2225
|
with(basic_auth: ['john', 'doe']).
|
1873
2226
|
to_return(:status => 200, :body => "", :headers => {})
|
1874
2227
|
# creation of index which can rollover
|
@@ -1886,12 +2239,19 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1886
2239
|
|
1887
2240
|
driver(config)
|
1888
2241
|
|
1889
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2242
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template", times: 1)
|
1890
2243
|
end
|
1891
2244
|
|
1892
|
-
|
2245
|
+
data("legacy_template" => [true, "_template"],
|
2246
|
+
"new_template" => [false, "_index_template"])
|
2247
|
+
def test_custom_template_with_rollover_index_create_and_deflector_alias(data)
|
2248
|
+
use_legacy_template_flag, endpoint = data
|
1893
2249
|
cwd = File.dirname(__FILE__)
|
1894
|
-
template_file =
|
2250
|
+
template_file = if use_legacy_template_flag
|
2251
|
+
File.join(cwd, 'test_alias_template.json')
|
2252
|
+
else
|
2253
|
+
File.join(cwd, 'test_index_alias_template.json')
|
2254
|
+
end
|
1895
2255
|
|
1896
2256
|
config = %{
|
1897
2257
|
host logs.google.com
|
@@ -1908,6 +2268,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1908
2268
|
deflector_alias myapp_deflector
|
1909
2269
|
index_name mylogs
|
1910
2270
|
application_name myapp
|
2271
|
+
use_legacy_template #{use_legacy_template_flag}
|
1911
2272
|
}
|
1912
2273
|
|
1913
2274
|
# connection start
|
@@ -1915,11 +2276,11 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1915
2276
|
with(basic_auth: ['john', 'doe']).
|
1916
2277
|
to_return(:status => 200, :body => "", :headers => {})
|
1917
2278
|
# check if template exists
|
1918
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2279
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
1919
2280
|
with(basic_auth: ['john', 'doe']).
|
1920
2281
|
to_return(:status => 404, :body => "", :headers => {})
|
1921
2282
|
# creation
|
1922
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2283
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
1923
2284
|
with(basic_auth: ['john', 'doe']).
|
1924
2285
|
to_return(:status => 200, :body => "", :headers => {})
|
1925
2286
|
# creation of index which can rollover
|
@@ -1937,12 +2298,19 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1937
2298
|
|
1938
2299
|
driver(config)
|
1939
2300
|
|
1940
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2301
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template", times: 1)
|
1941
2302
|
end
|
1942
2303
|
|
1943
|
-
|
2304
|
+
data("legacy_template" => [true, "_template"],
|
2305
|
+
"new_template" => [false, "_index_template"])
|
2306
|
+
def test_custom_template_with_rollover_index_create_with_logstash_format(data)
|
2307
|
+
use_legacy_template_flag, endpoint = data
|
1944
2308
|
cwd = File.dirname(__FILE__)
|
1945
|
-
template_file =
|
2309
|
+
template_file = if use_legacy_template_flag
|
2310
|
+
File.join(cwd, 'test_alias_template.json')
|
2311
|
+
else
|
2312
|
+
File.join(cwd, 'test_index_alias_template.json')
|
2313
|
+
end
|
1946
2314
|
|
1947
2315
|
config = %{
|
1948
2316
|
host logs.google.com
|
@@ -1959,19 +2327,20 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
1959
2327
|
logstash_format true
|
1960
2328
|
logstash_prefix mylogs
|
1961
2329
|
application_name myapp
|
2330
|
+
use_legacy_template #{use_legacy_template_flag}
|
1962
2331
|
}
|
1963
2332
|
|
1964
|
-
timestr = Time.now.strftime("%Y.%m.%d")
|
2333
|
+
timestr = Time.now.getutc.strftime("%Y.%m.%d")
|
1965
2334
|
# connection start
|
1966
2335
|
stub_request(:head, "https://logs.google.com:777/es//").
|
1967
2336
|
with(basic_auth: ['john', 'doe']).
|
1968
2337
|
to_return(:status => 200, :body => "", :headers => {})
|
1969
2338
|
# check if template exists
|
1970
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2339
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
1971
2340
|
with(basic_auth: ['john', 'doe']).
|
1972
2341
|
to_return(:status => 404, :body => "", :headers => {})
|
1973
2342
|
# creation
|
1974
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2343
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
1975
2344
|
with(basic_auth: ['john', 'doe']).
|
1976
2345
|
to_return(:status => 200, :body => "", :headers => {})
|
1977
2346
|
# creation of index which can rollover
|
@@ -2006,9 +2375,16 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2006
2375
|
end
|
2007
2376
|
end
|
2008
2377
|
|
2009
|
-
|
2378
|
+
data("legacy_template" => [true, "_template"],
|
2379
|
+
"new_template" => [false, "_index_template"])
|
2380
|
+
def test_custom_template_with_rollover_index_create_and_default_ilm(data)
|
2381
|
+
use_legacy_template_flag, endpoint = data
|
2010
2382
|
cwd = File.dirname(__FILE__)
|
2011
|
-
template_file =
|
2383
|
+
template_file = if use_legacy_template_flag
|
2384
|
+
File.join(cwd, 'test_alias_template.json')
|
2385
|
+
else
|
2386
|
+
File.join(cwd, 'test_index_alias_template.json')
|
2387
|
+
end
|
2012
2388
|
|
2013
2389
|
config = %{
|
2014
2390
|
host logs.google.com
|
@@ -2025,6 +2401,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2025
2401
|
application_name myapp
|
2026
2402
|
ilm_policy_id fluentd-policy
|
2027
2403
|
enable_ilm true
|
2404
|
+
use_legacy_template #{use_legacy_template_flag}
|
2028
2405
|
}
|
2029
2406
|
|
2030
2407
|
# connection start
|
@@ -2032,11 +2409,11 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2032
2409
|
with(basic_auth: ['john', 'doe']).
|
2033
2410
|
to_return(:status => 200, :body => "", :headers => {})
|
2034
2411
|
# check if template exists
|
2035
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2412
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2036
2413
|
with(basic_auth: ['john', 'doe']).
|
2037
2414
|
to_return(:status => 404, :body => "", :headers => {})
|
2038
2415
|
# creation
|
2039
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2416
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2040
2417
|
with(basic_auth: ['john', 'doe']).
|
2041
2418
|
to_return(:status => 200, :body => "", :headers => {})
|
2042
2419
|
# creation of index which can rollover
|
@@ -2047,13 +2424,20 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2047
2424
|
stub_request(:head, "https://logs.google.com:777/es//_alias/mylogs").
|
2048
2425
|
with(basic_auth: ['john', 'doe']).
|
2049
2426
|
to_return(:status => 404, :body => "", :headers => {})
|
2050
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2427
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/mylogs").
|
2051
2428
|
with(basic_auth: ['john', 'doe']).
|
2052
2429
|
to_return(status: 404, body: "", headers: {})
|
2053
|
-
|
2054
|
-
|
2055
|
-
|
2056
|
-
|
2430
|
+
if use_legacy_template_flag
|
2431
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs").
|
2432
|
+
with(basic_auth: ['john', 'doe'],
|
2433
|
+
body: "{\"order\":6,\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"mylogs\"},\"mappings\":{},\"aliases\":{\"myapp-logs-alias\":{}},\"index_patterns\":\"mylogs-*\"}").
|
2434
|
+
to_return(status: 200, body: "", headers: {})
|
2435
|
+
else
|
2436
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs").
|
2437
|
+
with(basic_auth: ['john', 'doe'],
|
2438
|
+
body: "{\"priority\":106,\"index_patterns\":\"mylogs-*\",\"template\":{\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"mylogs\"},\"mappings\":{},\"aliases\":{\"myapp-logs-alias\":{}}}}").
|
2439
|
+
to_return(status: 200, body: "", headers: {})
|
2440
|
+
end
|
2057
2441
|
# put the alias for the index
|
2058
2442
|
stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/#{alias_endpoint}/mylogs").
|
2059
2443
|
with(basic_auth: ['john', 'doe'],
|
@@ -2072,12 +2456,19 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2072
2456
|
|
2073
2457
|
driver(config)
|
2074
2458
|
|
2075
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2459
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs", times: 1)
|
2076
2460
|
end
|
2077
2461
|
|
2078
|
-
|
2462
|
+
data("legacy_template" => [true, "_template"],
|
2463
|
+
"new_template" => [false, "_index_template"])
|
2464
|
+
def test_custom_template_with_rollover_index_create_and_default_ilm_and_ilm_policy_overwrite(data)
|
2465
|
+
use_legacy_template_flag, endpoint = data
|
2079
2466
|
cwd = File.dirname(__FILE__)
|
2080
|
-
template_file =
|
2467
|
+
template_file = if use_legacy_template_flag
|
2468
|
+
File.join(cwd, 'test_alias_template.json')
|
2469
|
+
else
|
2470
|
+
File.join(cwd, 'test_index_alias_template.json')
|
2471
|
+
end
|
2081
2472
|
|
2082
2473
|
config = %{
|
2083
2474
|
host logs.google.com
|
@@ -2096,6 +2487,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2096
2487
|
enable_ilm true
|
2097
2488
|
ilm_policy_overwrite true
|
2098
2489
|
ilm_policy {"policy":{"phases":{"hot":{"actions":{"rollover":{"max_size":"60gb","max_age": "45d"}}}}}}
|
2490
|
+
use_legacy_template #{use_legacy_template_flag}
|
2099
2491
|
}
|
2100
2492
|
|
2101
2493
|
# connection start
|
@@ -2103,11 +2495,11 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2103
2495
|
with(basic_auth: ['john', 'doe']).
|
2104
2496
|
to_return(:status => 200, :body => "", :headers => {})
|
2105
2497
|
# check if template exists
|
2106
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2498
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2107
2499
|
with(basic_auth: ['john', 'doe']).
|
2108
2500
|
to_return(:status => 404, :body => "", :headers => {})
|
2109
2501
|
# creation
|
2110
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2502
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2111
2503
|
with(basic_auth: ['john', 'doe']).
|
2112
2504
|
to_return(:status => 200, :body => "", :headers => {})
|
2113
2505
|
# creation of index which can rollover
|
@@ -2118,13 +2510,20 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2118
2510
|
stub_request(:head, "https://logs.google.com:777/es//_alias/mylogs").
|
2119
2511
|
with(basic_auth: ['john', 'doe']).
|
2120
2512
|
to_return(:status => 404, :body => "", :headers => {})
|
2121
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2513
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/mylogs").
|
2122
2514
|
with(basic_auth: ['john', 'doe']).
|
2123
2515
|
to_return(status: 404, body: "", headers: {})
|
2124
|
-
|
2125
|
-
|
2126
|
-
|
2127
|
-
|
2516
|
+
if use_legacy_template_flag
|
2517
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs").
|
2518
|
+
with(basic_auth: ['john', 'doe'],
|
2519
|
+
body: "{\"order\":6,\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"mylogs\"},\"mappings\":{},\"aliases\":{\"myapp-logs-alias\":{}},\"index_patterns\":\"mylogs-*\"}").
|
2520
|
+
to_return(status: 200, body: "", headers: {})
|
2521
|
+
else
|
2522
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs").
|
2523
|
+
with(basic_auth: ['john', 'doe'],
|
2524
|
+
body: "{\"priority\":106,\"index_patterns\":\"mylogs-*\",\"template\":{\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"mylogs\"},\"mappings\":{},\"aliases\":{\"myapp-logs-alias\":{}}}}").
|
2525
|
+
to_return(status: 200, body: "", headers: {})
|
2526
|
+
end
|
2128
2527
|
# put the alias for the index
|
2129
2528
|
stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/#{alias_endpoint}/mylogs").
|
2130
2529
|
with(basic_auth: ['john', 'doe'],
|
@@ -2143,7 +2542,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2143
2542
|
|
2144
2543
|
driver(config)
|
2145
2544
|
|
2146
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2545
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs", times: 1)
|
2147
2546
|
end
|
2148
2547
|
|
2149
2548
|
def test_custom_template_with_rollover_index_create_and_default_ilm_with_deflector_alias
|
@@ -2174,9 +2573,16 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2174
2573
|
end
|
2175
2574
|
end
|
2176
2575
|
|
2177
|
-
|
2576
|
+
data("legacy_template" => [true, "_template"],
|
2577
|
+
"new_template" => [false, "_index_template"])
|
2578
|
+
def test_custom_template_with_rollover_index_create_and_default_ilm_and_placeholders(data)
|
2579
|
+
use_legacy_template_flag, endpoint = data
|
2178
2580
|
cwd = File.dirname(__FILE__)
|
2179
|
-
template_file =
|
2581
|
+
template_file = if use_legacy_template_flag
|
2582
|
+
File.join(cwd, 'test_alias_template.json')
|
2583
|
+
else
|
2584
|
+
File.join(cwd, 'test_index_alias_template.json')
|
2585
|
+
end
|
2180
2586
|
|
2181
2587
|
config = %{
|
2182
2588
|
host logs.google.com
|
@@ -2193,12 +2599,62 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2193
2599
|
application_name myapp
|
2194
2600
|
ilm_policy_id fluentd-policy
|
2195
2601
|
enable_ilm true
|
2602
|
+
use_legacy_template #{use_legacy_template_flag}
|
2196
2603
|
}
|
2197
2604
|
|
2198
2605
|
# connection start
|
2199
2606
|
stub_request(:head, "https://logs.google.com:777/es//").
|
2200
2607
|
with(basic_auth: ['john', 'doe']).
|
2201
2608
|
to_return(:status => 200, :body => "", :headers => {})
|
2609
|
+
|
2610
|
+
# test-tag1
|
2611
|
+
# check if template exists
|
2612
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2613
|
+
with(basic_auth: ['john', 'doe']).
|
2614
|
+
to_return(:status => 404, :body => "", :headers => {})
|
2615
|
+
# creation
|
2616
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2617
|
+
with(basic_auth: ['john', 'doe']).
|
2618
|
+
to_return(:status => 200, :body => "", :headers => {})
|
2619
|
+
# creation of index which can rollover
|
2620
|
+
stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-test-tag1-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
|
2621
|
+
with(basic_auth: ['john', 'doe']).
|
2622
|
+
to_return(:status => 200, :body => "", :headers => {})
|
2623
|
+
# check if alias exists
|
2624
|
+
stub_request(:head, "https://logs.google.com:777/es//_alias/mylogs-test-tag1").
|
2625
|
+
with(basic_auth: ['john', 'doe']).
|
2626
|
+
to_return(:status => 404, :body => "", :headers => {})
|
2627
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/mylogs-test-tag1").
|
2628
|
+
with(basic_auth: ['john', 'doe']).
|
2629
|
+
to_return(status: 404, body: "", headers: {})
|
2630
|
+
if use_legacy_template_flag
|
2631
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs-test-tag1").
|
2632
|
+
with(basic_auth: ['john', 'doe'],
|
2633
|
+
body: "{\"order\":8,\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"mylogs-test-tag1\"},\"mappings\":{},\"aliases\":{\"myapp-logs-alias\":{}},\"index_patterns\":\"mylogs-test-tag1-*\"}").
|
2634
|
+
to_return(status: 200, body: "", headers: {})
|
2635
|
+
else
|
2636
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs-test-tag1").
|
2637
|
+
with(basic_auth: ['john', 'doe'],
|
2638
|
+
body: "{\"priority\":108,\"index_patterns\":\"mylogs-test-tag1-*\",\"template\":{\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"mylogs-test-tag1\"},\"mappings\":{},\"aliases\":{\"myapp-logs-alias\":{}}}}").
|
2639
|
+
to_return(status: 200, body: "", headers: {})
|
2640
|
+
end
|
2641
|
+
# put the alias for the index
|
2642
|
+
stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-test-tag1-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/#{alias_endpoint}/mylogs-test-tag1").
|
2643
|
+
with(basic_auth: ['john', 'doe'],
|
2644
|
+
:body => "{\"aliases\":{\"mylogs-test-tag1\":{\"is_write_index\":true}}}").
|
2645
|
+
to_return(:status => 200, :body => "", :headers => {})
|
2646
|
+
stub_request(:get, "https://logs.google.com:777/es//_xpack").
|
2647
|
+
with(basic_auth: ['john', 'doe']).
|
2648
|
+
to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
|
2649
|
+
stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
|
2650
|
+
with(basic_auth: ['john', 'doe']).
|
2651
|
+
to_return(:status => 404, :body => "", :headers => {})
|
2652
|
+
stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
|
2653
|
+
with(basic_auth: ['john', 'doe'],
|
2654
|
+
:body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
|
2655
|
+
to_return(:status => 200, :body => "", :headers => {})
|
2656
|
+
|
2657
|
+
# test-tag2
|
2202
2658
|
# check if template exists
|
2203
2659
|
stub_request(:get, "https://logs.google.com:777/es//_template/myapp_alias_template").
|
2204
2660
|
with(basic_auth: ['john', 'doe']).
|
@@ -2208,24 +2664,31 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2208
2664
|
with(basic_auth: ['john', 'doe']).
|
2209
2665
|
to_return(:status => 200, :body => "", :headers => {})
|
2210
2666
|
# creation of index which can rollover
|
2211
|
-
stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-
|
2667
|
+
stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-test-tag2-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
|
2212
2668
|
with(basic_auth: ['john', 'doe']).
|
2213
2669
|
to_return(:status => 200, :body => "", :headers => {})
|
2214
2670
|
# check if alias exists
|
2215
|
-
stub_request(:head, "https://logs.google.com:777/es//_alias/mylogs-
|
2671
|
+
stub_request(:head, "https://logs.google.com:777/es//_alias/mylogs-test-tag2").
|
2216
2672
|
with(basic_auth: ['john', 'doe']).
|
2217
2673
|
to_return(:status => 404, :body => "", :headers => {})
|
2218
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2674
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/mylogs-test-tag2").
|
2219
2675
|
with(basic_auth: ['john', 'doe']).
|
2220
2676
|
to_return(status: 404, body: "", headers: {})
|
2221
|
-
|
2222
|
-
|
2223
|
-
|
2224
|
-
|
2677
|
+
if use_legacy_template_flag
|
2678
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs-test-tag2").
|
2679
|
+
with(basic_auth: ['john', 'doe'],
|
2680
|
+
body: "{\"order\":8,\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"mylogs-test-tag2\"},\"mappings\":{},\"aliases\":{\"myapp-logs-alias\":{}},\"index_patterns\":\"mylogs-test-tag2-*\"}").
|
2681
|
+
to_return(status: 200, body: "", headers: {})
|
2682
|
+
else
|
2683
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs-test-tag2").
|
2684
|
+
with(basic_auth: ['john', 'doe'],
|
2685
|
+
body: "{\"priority\":108,\"index_patterns\":\"mylogs-test-tag2-*\",\"template\":{\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"mylogs-test-tag2\"},\"mappings\":{},\"aliases\":{\"myapp-logs-alias\":{}}}}").
|
2686
|
+
to_return(status: 200, body: "", headers: {})
|
2687
|
+
end
|
2225
2688
|
# put the alias for the index
|
2226
|
-
stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-
|
2689
|
+
stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-test-tag2-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/#{alias_endpoint}/mylogs-test-tag2").
|
2227
2690
|
with(basic_auth: ['john', 'doe'],
|
2228
|
-
:body => "{\"aliases\":{\"mylogs-
|
2691
|
+
:body => "{\"aliases\":{\"mylogs-test-tag2\":{\"is_write_index\":true}}}").
|
2229
2692
|
to_return(:status => 200, :body => "", :headers => {})
|
2230
2693
|
stub_request(:get, "https://logs.google.com:777/es//_xpack").
|
2231
2694
|
with(basic_auth: ['john', 'doe']).
|
@@ -2241,19 +2704,28 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2241
2704
|
driver(config)
|
2242
2705
|
|
2243
2706
|
elastic_request = stub_elastic("https://logs.google.com:777/es//_bulk")
|
2244
|
-
driver.run(default_tag: '
|
2245
|
-
driver.feed(sample_record)
|
2707
|
+
driver.run(default_tag: 'test') do
|
2708
|
+
driver.feed("test-tag1", event_time, sample_record)
|
2709
|
+
driver.feed("test-tag2", event_time, sample_record)
|
2710
|
+
driver.feed("test-tag1", event_time, sample_record)
|
2711
|
+
driver.feed("test-tag2", event_time, sample_record)
|
2246
2712
|
end
|
2247
|
-
assert_equal('mylogs-
|
2248
|
-
|
2249
|
-
assert_equal ["mylogs-custom-test"], driver.instance.alias_indexes
|
2713
|
+
assert_equal('mylogs-test-tag2', index_cmds.first['index']['_index'])
|
2714
|
+
assert_equal ["mylogs-test-tag1", "mylogs-test-tag2"], driver.instance.alias_indexes
|
2250
2715
|
|
2251
2716
|
assert_requested(elastic_request)
|
2252
2717
|
end
|
2253
2718
|
|
2254
|
-
|
2719
|
+
data("legacy_template" => [true, "_template"],
|
2720
|
+
"new_template" => [false, "_index_template"])
|
2721
|
+
def test_custom_template_with_rollover_index_create_and_custom_ilm(data)
|
2722
|
+
use_legacy_template_flag, endpoint = data
|
2255
2723
|
cwd = File.dirname(__FILE__)
|
2256
|
-
template_file =
|
2724
|
+
template_file = if use_legacy_template_flag
|
2725
|
+
File.join(cwd, 'test_alias_template.json')
|
2726
|
+
else
|
2727
|
+
File.join(cwd, 'test_index_alias_template.json')
|
2728
|
+
end
|
2257
2729
|
|
2258
2730
|
config = %{
|
2259
2731
|
host logs.google.com
|
@@ -2271,6 +2743,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2271
2743
|
ilm_policy_id fluentd-policy
|
2272
2744
|
enable_ilm true
|
2273
2745
|
ilm_policy {"policy":{"phases":{"hot":{"actions":{"rollover":{"max_size":"70gb", "max_age":"30d"}}}}}}
|
2746
|
+
use_legacy_template #{use_legacy_template_flag}
|
2274
2747
|
}
|
2275
2748
|
|
2276
2749
|
# connection start
|
@@ -2278,11 +2751,11 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2278
2751
|
with(basic_auth: ['john', 'doe']).
|
2279
2752
|
to_return(:status => 200, :body => "", :headers => {})
|
2280
2753
|
# check if template exists
|
2281
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2754
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2282
2755
|
with(basic_auth: ['john', 'doe']).
|
2283
2756
|
to_return(:status => 404, :body => "", :headers => {})
|
2284
2757
|
# creation
|
2285
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2758
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2286
2759
|
with(basic_auth: ['john', 'doe']).
|
2287
2760
|
to_return(:status => 200, :body => "", :headers => {})
|
2288
2761
|
# creation of index which can rollover
|
@@ -2293,10 +2766,10 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2293
2766
|
stub_request(:head, "https://logs.google.com:777/es//_alias/mylogs").
|
2294
2767
|
with(basic_auth: ['john', 'doe']).
|
2295
2768
|
to_return(:status => 404, :body => "", :headers => {})
|
2296
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2769
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/mylogs").
|
2297
2770
|
with(basic_auth: ['john', 'doe']).
|
2298
2771
|
to_return(status: 404, body: "", headers: {})
|
2299
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2772
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs").
|
2300
2773
|
with(basic_auth: ['john', 'doe']).
|
2301
2774
|
to_return(status: 200, body: "", headers: {})
|
2302
2775
|
# put the alias for the index
|
@@ -2317,13 +2790,20 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2317
2790
|
|
2318
2791
|
driver(config)
|
2319
2792
|
|
2320
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2793
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/mylogs", times: 1)
|
2321
2794
|
end
|
2322
2795
|
end
|
2323
2796
|
|
2324
|
-
|
2797
|
+
data("legacy_template" => [true, "_template"],
|
2798
|
+
"new_template" => [false, "_index_template"])
|
2799
|
+
def test_template_overwrite(data)
|
2800
|
+
use_legacy_template_flag, endpoint = data
|
2325
2801
|
cwd = File.dirname(__FILE__)
|
2326
|
-
template_file =
|
2802
|
+
template_file = if use_legacy_template_flag
|
2803
|
+
File.join(cwd, 'test_template.json')
|
2804
|
+
else
|
2805
|
+
File.join(cwd, 'test_index_template.json')
|
2806
|
+
end
|
2327
2807
|
|
2328
2808
|
config = %{
|
2329
2809
|
host logs.google.com
|
@@ -2335,6 +2815,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2335
2815
|
template_name logstash
|
2336
2816
|
template_file #{template_file}
|
2337
2817
|
template_overwrite true
|
2818
|
+
use_legacy_template #{use_legacy_template_flag}
|
2338
2819
|
}
|
2339
2820
|
|
2340
2821
|
# connection start
|
@@ -2342,22 +2823,29 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2342
2823
|
with(basic_auth: ['john', 'doe']).
|
2343
2824
|
to_return(:status => 200, :body => "", :headers => {})
|
2344
2825
|
# check if template exists
|
2345
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2826
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
2346
2827
|
with(basic_auth: ['john', 'doe']).
|
2347
2828
|
to_return(:status => 200, :body => "", :headers => {})
|
2348
2829
|
# creation
|
2349
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2830
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
2350
2831
|
with(basic_auth: ['john', 'doe']).
|
2351
2832
|
to_return(:status => 200, :body => "", :headers => {})
|
2352
2833
|
|
2353
2834
|
driver(config)
|
2354
2835
|
|
2355
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2836
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash", times: 1)
|
2356
2837
|
end
|
2357
2838
|
|
2358
|
-
|
2839
|
+
data("legacy_template" => [true, "_template"],
|
2840
|
+
"new_template" => [false, "_index_template"])
|
2841
|
+
def test_custom_template_overwrite(data)
|
2842
|
+
use_legacy_template_flag, endpoint = data
|
2359
2843
|
cwd = File.dirname(__FILE__)
|
2360
|
-
template_file =
|
2844
|
+
template_file = if use_legacy_template_flag
|
2845
|
+
File.join(cwd, 'test_template.json')
|
2846
|
+
else
|
2847
|
+
File.join(cwd, 'test_index_template.json')
|
2848
|
+
end
|
2361
2849
|
|
2362
2850
|
config = %{
|
2363
2851
|
host logs.google.com
|
@@ -2370,6 +2858,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2370
2858
|
template_file #{template_file}
|
2371
2859
|
template_overwrite true
|
2372
2860
|
customize_template {"--appid--": "myapp-logs","--index_prefix--":"mylogs"}
|
2861
|
+
use_legacy_template #{use_legacy_template_flag}
|
2373
2862
|
}
|
2374
2863
|
|
2375
2864
|
# connection start
|
@@ -2377,22 +2866,29 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2377
2866
|
with(basic_auth: ['john', 'doe']).
|
2378
2867
|
to_return(:status => 200, :body => "", :headers => {})
|
2379
2868
|
# check if template exists
|
2380
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2869
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2381
2870
|
with(basic_auth: ['john', 'doe']).
|
2382
2871
|
to_return(:status => 200, :body => "", :headers => {})
|
2383
2872
|
# creation
|
2384
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2873
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2385
2874
|
with(basic_auth: ['john', 'doe']).
|
2386
2875
|
to_return(:status => 200, :body => "", :headers => {})
|
2387
2876
|
|
2388
2877
|
driver(config)
|
2389
2878
|
|
2390
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2879
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template", times: 1)
|
2391
2880
|
end
|
2392
2881
|
|
2393
|
-
|
2882
|
+
data("legacy_template" => [true, "_template"],
|
2883
|
+
"new_template" => [false, "_index_template"])
|
2884
|
+
def test_custom_template_with_rollover_index_overwrite(data)
|
2885
|
+
use_legacy_template_flag, endpoint = data
|
2394
2886
|
cwd = File.dirname(__FILE__)
|
2395
|
-
template_file =
|
2887
|
+
template_file = if use_legacy_template_flag
|
2888
|
+
File.join(cwd, 'test_template.json')
|
2889
|
+
else
|
2890
|
+
File.join(cwd, 'test_index_template.json')
|
2891
|
+
end
|
2396
2892
|
|
2397
2893
|
config = %{
|
2398
2894
|
host logs.google.com
|
@@ -2409,6 +2905,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2409
2905
|
rollover_index true
|
2410
2906
|
index_name mylogs
|
2411
2907
|
application_name myapp
|
2908
|
+
use_legacy_template #{use_legacy_template_flag}
|
2412
2909
|
}
|
2413
2910
|
|
2414
2911
|
# connection start
|
@@ -2416,11 +2913,11 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2416
2913
|
with(basic_auth: ['john', 'doe']).
|
2417
2914
|
to_return(:status => 200, :body => "", :headers => {})
|
2418
2915
|
# check if template exists
|
2419
|
-
stub_request(:get, "https://logs.google.com:777/es
|
2916
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2420
2917
|
with(basic_auth: ['john', 'doe']).
|
2421
2918
|
to_return(:status => 200, :body => "", :headers => {})
|
2422
2919
|
# creation
|
2423
|
-
stub_request(:put, "https://logs.google.com:777/es
|
2920
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template").
|
2424
2921
|
with(basic_auth: ['john', 'doe']).
|
2425
2922
|
to_return(:status => 200, :body => "", :headers => {})
|
2426
2923
|
# creation of index which can rollover
|
@@ -2438,7 +2935,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2438
2935
|
|
2439
2936
|
driver(config)
|
2440
2937
|
|
2441
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2938
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/myapp_alias_template", times: 1)
|
2442
2939
|
end
|
2443
2940
|
|
2444
2941
|
def test_template_create_invalid_filename
|
@@ -2468,9 +2965,16 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2468
2965
|
}
|
2469
2966
|
end
|
2470
2967
|
|
2471
|
-
|
2968
|
+
data("legacy_template" => [true, "_template"],
|
2969
|
+
"new_template" => [false, "_index_template"])
|
2970
|
+
def test_template_create_for_host_placeholder(data)
|
2971
|
+
use_legacy_template_flag, endpoint = data
|
2472
2972
|
cwd = File.dirname(__FILE__)
|
2473
|
-
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
|
2474
2978
|
|
2475
2979
|
config = %{
|
2476
2980
|
host logs-${tag}.google.com
|
@@ -2483,6 +2987,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2483
2987
|
template_file #{template_file}
|
2484
2988
|
verify_es_version_at_startup false
|
2485
2989
|
default_elasticsearch_version 6
|
2990
|
+
use_legacy_template #{use_legacy_template_flag}
|
2486
2991
|
}
|
2487
2992
|
|
2488
2993
|
# connection start
|
@@ -2490,10 +2995,10 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2490
2995
|
with(basic_auth: ['john', 'doe']).
|
2491
2996
|
to_return(:status => 200, :body => "", :headers => {})
|
2492
2997
|
# check if template exists
|
2493
|
-
stub_request(:get, "https://logs-test.google.com:777/es
|
2998
|
+
stub_request(:get, "https://logs-test.google.com:777/es//#{endpoint}/logstash").
|
2494
2999
|
with(basic_auth: ['john', 'doe']).
|
2495
3000
|
to_return(:status => 404, :body => "", :headers => {})
|
2496
|
-
stub_request(:put, "https://logs-test.google.com:777/es
|
3001
|
+
stub_request(:put, "https://logs-test.google.com:777/es//#{endpoint}/logstash").
|
2497
3002
|
with(basic_auth: ['john', 'doe']).
|
2498
3003
|
to_return(status: 200, body: "", headers: {})
|
2499
3004
|
stub_request(:post, "https://logs-test.google.com:777/es//_bulk").
|
@@ -2508,9 +3013,16 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2508
3013
|
end
|
2509
3014
|
end
|
2510
3015
|
|
2511
|
-
|
3016
|
+
data("legacy_template" => [true, "_template"],
|
3017
|
+
"new_template" => [false, "_index_template"])
|
3018
|
+
def test_template_retry_install_fails(data)
|
3019
|
+
use_legacy_template_flag, endpoint = data
|
2512
3020
|
cwd = File.dirname(__FILE__)
|
2513
|
-
template_file =
|
3021
|
+
template_file = if use_legacy_template_flag
|
3022
|
+
File.join(cwd, 'test_template.json')
|
3023
|
+
else
|
3024
|
+
File.join(cwd, 'test_index_template.json')
|
3025
|
+
end
|
2514
3026
|
|
2515
3027
|
config = %{
|
2516
3028
|
host logs.google.com
|
@@ -2522,11 +3034,12 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2522
3034
|
template_name logstash
|
2523
3035
|
template_file #{template_file}
|
2524
3036
|
max_retry_putting_template 3
|
3037
|
+
use_legacy_template #{use_legacy_template_flag}
|
2525
3038
|
}
|
2526
3039
|
|
2527
3040
|
connection_resets = 0
|
2528
3041
|
# check if template exists
|
2529
|
-
stub_request(:get, "https://logs.google.com:778/es
|
3042
|
+
stub_request(:get, "https://logs.google.com:778/es//#{endpoint}/logstash")
|
2530
3043
|
.with(basic_auth: ['john', 'doe']) do |req|
|
2531
3044
|
connection_resets += 1
|
2532
3045
|
raise Faraday::ConnectionFailed, "Test message"
|
@@ -2539,9 +3052,16 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2539
3052
|
assert_equal(4, connection_resets)
|
2540
3053
|
end
|
2541
3054
|
|
2542
|
-
|
3055
|
+
data("legacy_template" => [true, "_template"],
|
3056
|
+
"new_template" => [false, "_index_template"])
|
3057
|
+
def test_template_retry_install_does_not_fail(data)
|
3058
|
+
use_legacy_template_flag, endpoint = data
|
2543
3059
|
cwd = File.dirname(__FILE__)
|
2544
|
-
template_file =
|
3060
|
+
template_file = if use_legacy_template_flag
|
3061
|
+
File.join(cwd, 'test_template.json')
|
3062
|
+
else
|
3063
|
+
File.join(cwd, 'test_index_template.json')
|
3064
|
+
end
|
2545
3065
|
|
2546
3066
|
config = %{
|
2547
3067
|
host logs.google.com
|
@@ -2554,11 +3074,12 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2554
3074
|
template_file #{template_file}
|
2555
3075
|
max_retry_putting_template 3
|
2556
3076
|
fail_on_putting_template_retry_exceed false
|
3077
|
+
use_legacy_template #{use_legacy_template_flag}
|
2557
3078
|
}
|
2558
3079
|
|
2559
3080
|
connection_resets = 0
|
2560
3081
|
# check if template exists
|
2561
|
-
stub_request(:get, "https://logs.google.com:778/es
|
3082
|
+
stub_request(:get, "https://logs.google.com:778/es//#{endpoint}/logstash")
|
2562
3083
|
.with(basic_auth: ['john', 'doe']) do |req|
|
2563
3084
|
connection_resets += 1
|
2564
3085
|
raise Faraday::ConnectionFailed, "Test message"
|
@@ -2569,9 +3090,17 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2569
3090
|
assert_equal(4, connection_resets)
|
2570
3091
|
end
|
2571
3092
|
|
2572
|
-
|
3093
|
+
data("legacy_template" => [true, "_template"],
|
3094
|
+
"new_template" => [false, "_index_template"])
|
3095
|
+
def test_templates_create(data)
|
3096
|
+
use_legacy_template_flag, endpoint = data
|
2573
3097
|
cwd = File.dirname(__FILE__)
|
2574
|
-
template_file =
|
3098
|
+
template_file = if use_legacy_template_flag
|
3099
|
+
File.join(cwd, 'test_template.json')
|
3100
|
+
else
|
3101
|
+
File.join(cwd, 'test_index_template.json')
|
3102
|
+
end
|
3103
|
+
|
2575
3104
|
config = %{
|
2576
3105
|
host logs.google.com
|
2577
3106
|
port 777
|
@@ -2580,43 +3109,52 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2580
3109
|
user john
|
2581
3110
|
password doe
|
2582
3111
|
templates {"logstash1":"#{template_file}", "logstash2":"#{template_file}","logstash3":"#{template_file}" }
|
3112
|
+
use_legacy_template #{use_legacy_template_flag}
|
2583
3113
|
}
|
2584
3114
|
|
2585
3115
|
stub_request(:head, "https://logs.google.com:777/es//").
|
2586
3116
|
with(basic_auth: ['john', 'doe']).
|
2587
3117
|
to_return(:status => 200, :body => "", :headers => {})
|
2588
3118
|
# check if template exists
|
2589
|
-
stub_request(:get, "https://logs.google.com:777/es
|
3119
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash1").
|
2590
3120
|
with(basic_auth: ['john', 'doe']).
|
2591
3121
|
to_return(:status => 404, :body => "", :headers => {})
|
2592
|
-
stub_request(:get, "https://logs.google.com:777/es
|
3122
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash2").
|
2593
3123
|
with(basic_auth: ['john', 'doe']).
|
2594
3124
|
to_return(:status => 404, :body => "", :headers => {})
|
2595
3125
|
|
2596
|
-
stub_request(:get, "https://logs.google.com:777/es
|
3126
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash3").
|
2597
3127
|
with(basic_auth: ['john', 'doe']).
|
2598
3128
|
to_return(:status => 200, :body => "", :headers => {}) #exists
|
2599
3129
|
|
2600
|
-
stub_request(:put, "https://logs.google.com:777/es
|
3130
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash1").
|
2601
3131
|
with(basic_auth: ['john', 'doe']).
|
2602
3132
|
to_return(:status => 200, :body => "", :headers => {})
|
2603
|
-
stub_request(:put, "https://logs.google.com:777/es
|
3133
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash2").
|
2604
3134
|
with(basic_auth: ['john', 'doe']).
|
2605
3135
|
to_return(:status => 200, :body => "", :headers => {})
|
2606
|
-
stub_request(:put, "https://logs.google.com:777/es
|
3136
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash3").
|
2607
3137
|
with(basic_auth: ['john', 'doe']).
|
2608
3138
|
to_return(:status => 200, :body => "", :headers => {})
|
2609
3139
|
|
2610
3140
|
driver(config)
|
2611
3141
|
|
2612
|
-
assert_requested( :put, "https://logs.google.com:777/es
|
2613
|
-
assert_requested( :put, "https://logs.google.com:777/es
|
2614
|
-
assert_not_requested(:put, "https://logs.google.com:777/es
|
3142
|
+
assert_requested( :put, "https://logs.google.com:777/es//#{endpoint}/logstash1", times: 1)
|
3143
|
+
assert_requested( :put, "https://logs.google.com:777/es//#{endpoint}/logstash2", times: 1)
|
3144
|
+
assert_not_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash3") #exists
|
2615
3145
|
end
|
2616
3146
|
|
2617
|
-
|
3147
|
+
data("legacy_template" => [true, "_template"],
|
3148
|
+
"new_template" => [false, "_index_template"])
|
3149
|
+
def test_templates_overwrite(data)
|
3150
|
+
use_legacy_template_flag, endpoint = data
|
2618
3151
|
cwd = File.dirname(__FILE__)
|
2619
|
-
template_file =
|
3152
|
+
template_file = if use_legacy_template_flag
|
3153
|
+
File.join(cwd, 'test_template.json')
|
3154
|
+
else
|
3155
|
+
File.join(cwd, 'test_index_template.json')
|
3156
|
+
end
|
3157
|
+
|
2620
3158
|
config = %{
|
2621
3159
|
host logs.google.com
|
2622
3160
|
port 777
|
@@ -2626,42 +3164,50 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2626
3164
|
password doe
|
2627
3165
|
templates {"logstash1":"#{template_file}", "logstash2":"#{template_file}","logstash3":"#{template_file}" }
|
2628
3166
|
template_overwrite true
|
3167
|
+
use_legacy_template #{use_legacy_template_flag}
|
2629
3168
|
}
|
2630
3169
|
|
2631
3170
|
stub_request(:head, "https://logs.google.com:777/es//").
|
2632
3171
|
with(basic_auth: ['john', 'doe']).
|
2633
3172
|
to_return(:status => 200, :body => "", :headers => {})
|
2634
3173
|
# check if template exists
|
2635
|
-
stub_request(:get, "https://logs.google.com:777/es
|
3174
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash1").
|
2636
3175
|
with(basic_auth: ['john', 'doe']).
|
2637
3176
|
to_return(:status => 200, :body => "", :headers => {})
|
2638
|
-
stub_request(:get, "https://logs.google.com:777/es
|
3177
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash2").
|
2639
3178
|
with(basic_auth: ['john', 'doe']).
|
2640
3179
|
to_return(:status => 200, :body => "", :headers => {})
|
2641
|
-
stub_request(:get, "https://logs.google.com:777/es
|
3180
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash3").
|
2642
3181
|
with(basic_auth: ['john', 'doe']).
|
2643
3182
|
to_return(:status => 200, :body => "", :headers => {}) #exists
|
2644
3183
|
|
2645
|
-
stub_request(:put, "https://logs.google.com:777/es
|
3184
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash1").
|
2646
3185
|
with(basic_auth: ['john', 'doe']).
|
2647
3186
|
to_return(:status => 200, :body => "", :headers => {})
|
2648
|
-
stub_request(:put, "https://logs.google.com:777/es
|
3187
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash2").
|
2649
3188
|
with(basic_auth: ['john', 'doe']).
|
2650
3189
|
to_return(:status => 200, :body => "", :headers => {})
|
2651
|
-
stub_request(:put, "https://logs.google.com:777/es
|
3190
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash3").
|
2652
3191
|
with(basic_auth: ['john', 'doe']).
|
2653
3192
|
to_return(:status => 200, :body => "", :headers => {})
|
2654
3193
|
|
2655
3194
|
driver(config)
|
2656
3195
|
|
2657
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2658
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2659
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
3196
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash1", times: 1)
|
3197
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash2", times: 1)
|
3198
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash3", times: 1)
|
2660
3199
|
end
|
2661
3200
|
|
2662
|
-
|
3201
|
+
data("legacy_template" => [true, "_template"],
|
3202
|
+
"new_template" => [false, "_index_template"])
|
3203
|
+
def test_templates_are_also_used(data)
|
3204
|
+
use_legacy_template_flag, endpoint = data
|
2663
3205
|
cwd = File.dirname(__FILE__)
|
2664
|
-
template_file =
|
3206
|
+
template_file = if use_legacy_template_flag
|
3207
|
+
File.join(cwd, 'test_template.json')
|
3208
|
+
else
|
3209
|
+
File.join(cwd, 'test_index_template.json')
|
3210
|
+
end
|
2665
3211
|
|
2666
3212
|
config = %{
|
2667
3213
|
host logs.google.com
|
@@ -2673,43 +3219,52 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2673
3219
|
template_name logstash
|
2674
3220
|
template_file #{template_file}
|
2675
3221
|
templates {"logstash1":"#{template_file}", "logstash2":"#{template_file}" }
|
3222
|
+
use_legacy_template #{use_legacy_template_flag}
|
2676
3223
|
}
|
2677
3224
|
# connection start
|
2678
3225
|
stub_request(:head, "https://logs.google.com:777/es//").
|
2679
3226
|
with(basic_auth: ['john', 'doe']).
|
2680
3227
|
to_return(:status => 200, :body => "", :headers => {})
|
2681
3228
|
# check if template exists
|
2682
|
-
stub_request(:get, "https://logs.google.com:777/es
|
3229
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
2683
3230
|
with(basic_auth: ['john', 'doe']).
|
2684
3231
|
to_return(:status => 404, :body => "", :headers => {})
|
2685
|
-
stub_request(:get, "https://logs.google.com:777/es
|
3232
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash1").
|
2686
3233
|
with(basic_auth: ['john', 'doe']).
|
2687
3234
|
to_return(:status => 404, :body => "", :headers => {})
|
2688
|
-
stub_request(:get, "https://logs.google.com:777/es
|
3235
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash2").
|
2689
3236
|
with(basic_auth: ['john', 'doe']).
|
2690
3237
|
to_return(:status => 404, :body => "", :headers => {})
|
2691
3238
|
#creation
|
2692
|
-
stub_request(:put, "https://logs.google.com:777/es
|
3239
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash").
|
2693
3240
|
with(basic_auth: ['john', 'doe']).
|
2694
3241
|
to_return(:status => 200, :body => "", :headers => {})
|
2695
|
-
stub_request(:put, "https://logs.google.com:777/es
|
3242
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash1").
|
2696
3243
|
with(basic_auth: ['john', 'doe']).
|
2697
3244
|
to_return(:status => 200, :body => "", :headers => {})
|
2698
|
-
stub_request(:put, "https://logs.google.com:777/es
|
3245
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash2").
|
2699
3246
|
with(basic_auth: ['john', 'doe']).
|
2700
3247
|
to_return(:status => 200, :body => "", :headers => {})
|
2701
3248
|
|
2702
3249
|
driver(config)
|
2703
3250
|
|
2704
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
3251
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash", times: 1)
|
2705
3252
|
|
2706
|
-
|
2707
|
-
|
3253
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash1")
|
3254
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash2")
|
2708
3255
|
end
|
2709
3256
|
|
2710
|
-
|
3257
|
+
data("legacy_template" => [true, "_template"],
|
3258
|
+
"new_template" => [false, "_index_template"])
|
3259
|
+
def test_templates_can_be_partially_created_if_error_occurs(data)
|
3260
|
+
use_legacy_template_flag, endpoint = data
|
2711
3261
|
cwd = File.dirname(__FILE__)
|
2712
|
-
template_file =
|
3262
|
+
template_file = if use_legacy_template_flag
|
3263
|
+
File.join(cwd, 'test_template.json')
|
3264
|
+
else
|
3265
|
+
File.join(cwd, 'test_index_template.json')
|
3266
|
+
end
|
3267
|
+
|
2713
3268
|
config = %{
|
2714
3269
|
host logs.google.com
|
2715
3270
|
port 777
|
@@ -2718,22 +3273,23 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2718
3273
|
user john
|
2719
3274
|
password doe
|
2720
3275
|
templates {"logstash1":"#{template_file}", "logstash2":"/abc" }
|
3276
|
+
use_legacy_template #{use_legacy_template_flag}
|
2721
3277
|
}
|
2722
3278
|
stub_request(:head, "https://logs.google.com:777/es//").
|
2723
3279
|
with(basic_auth: ['john', 'doe']).
|
2724
3280
|
to_return(:status => 200, :body => "", :headers => {})
|
2725
3281
|
# check if template exists
|
2726
|
-
stub_request(:get, "https://logs.google.com:777/es
|
3282
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash1").
|
2727
3283
|
with(basic_auth: ['john', 'doe']).
|
2728
3284
|
to_return(:status => 404, :body => "", :headers => {})
|
2729
|
-
stub_request(:get, "https://logs.google.com:777/es
|
3285
|
+
stub_request(:get, "https://logs.google.com:777/es//#{endpoint}/logstash2").
|
2730
3286
|
with(basic_auth: ['john', 'doe']).
|
2731
3287
|
to_return(:status => 404, :body => "", :headers => {})
|
2732
3288
|
|
2733
|
-
stub_request(:put, "https://logs.google.com:777/es
|
3289
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash1").
|
2734
3290
|
with(basic_auth: ['john', 'doe']).
|
2735
3291
|
to_return(:status => 200, :body => "", :headers => {})
|
2736
|
-
stub_request(:put, "https://logs.google.com:777/es
|
3292
|
+
stub_request(:put, "https://logs.google.com:777/es//#{endpoint}/logstash2").
|
2737
3293
|
with(basic_auth: ['john', 'doe']).
|
2738
3294
|
to_return(:status => 200, :body => "", :headers => {})
|
2739
3295
|
|
@@ -2741,8 +3297,8 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2741
3297
|
driver(config)
|
2742
3298
|
}
|
2743
3299
|
|
2744
|
-
assert_requested(:put, "https://logs.google.com:777/es
|
2745
|
-
assert_not_requested(:put, "https://logs.google.com:777/es
|
3300
|
+
assert_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash1", times: 1)
|
3301
|
+
assert_not_requested(:put, "https://logs.google.com:777/es//#{endpoint}/logstash2")
|
2746
3302
|
end
|
2747
3303
|
|
2748
3304
|
def test_legacy_hosts_list
|
@@ -2910,6 +3466,18 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
2910
3466
|
assert_requested(elastic_request)
|
2911
3467
|
end
|
2912
3468
|
|
3469
|
+
def test_api_key_header
|
3470
|
+
stub_request(:head, "http://localhost:9200/").
|
3471
|
+
to_return(:status => 200, :body => "", :headers => {})
|
3472
|
+
elastic_request = stub_request(:post, "http://localhost:9200/_bulk").
|
3473
|
+
with(headers: {'Authorization'=>'ApiKey dGVzdGF1dGhoZWFkZXI='})
|
3474
|
+
driver.configure(%[api_key testauthheader])
|
3475
|
+
driver.run(default_tag: 'test') do
|
3476
|
+
driver.feed(sample_record)
|
3477
|
+
end
|
3478
|
+
assert_requested(elastic_request)
|
3479
|
+
end
|
3480
|
+
|
2913
3481
|
def test_write_message_with_bad_chunk
|
2914
3482
|
driver.configure("target_index_key bad_value\n@log_level debug\n")
|
2915
3483
|
stub_elastic
|
@@ -3020,6 +3588,39 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
3020
3588
|
assert_requested(request, times: 2)
|
3021
3589
|
end
|
3022
3590
|
|
3591
|
+
def test_writes_with_record_metadata
|
3592
|
+
chunk_id_key = "metadata_key".freeze
|
3593
|
+
driver.configure(Fluent::Config::Element.new(
|
3594
|
+
'ROOT', '', {
|
3595
|
+
'@type' => 'elasticsearch',
|
3596
|
+
}, [
|
3597
|
+
Fluent::Config::Element.new('metadata', '', {
|
3598
|
+
'include_chunk_id' => true,
|
3599
|
+
'chunk_id_key' => chunk_id_key,
|
3600
|
+
}, [])
|
3601
|
+
]
|
3602
|
+
))
|
3603
|
+
stub_request(:post, "http://localhost:9200/_bulk").
|
3604
|
+
with(
|
3605
|
+
body: /{"index":{"_index":"fluentd","_type":"fluentd"}}\n{"age":26,"request_id":"42","parent_id":"parent","routing_id":"routing","#{chunk_id_key}":".*"}\n/) do |req|
|
3606
|
+
@index_cmds = req.body.split("\n").map {|r| JSON.parse(r) }
|
3607
|
+
end
|
3608
|
+
driver.run(default_tag: 'test', shutdown: false) do
|
3609
|
+
driver.feed(sample_record)
|
3610
|
+
end
|
3611
|
+
assert_true index_cmds[1].has_key?(chunk_id_key)
|
3612
|
+
first_chunk_id = index_cmds[1].fetch(chunk_id_key)
|
3613
|
+
|
3614
|
+
driver.run(default_tag: 'test') do
|
3615
|
+
driver.feed(sample_record)
|
3616
|
+
end
|
3617
|
+
assert_true index_cmds[1].has_key?(chunk_id_key)
|
3618
|
+
second_chunk_id = index_cmds[1].fetch(chunk_id_key)
|
3619
|
+
assert do
|
3620
|
+
first_chunk_id != second_chunk_id
|
3621
|
+
end
|
3622
|
+
end
|
3623
|
+
|
3023
3624
|
def test_writes_with_huge_records_but_uncheck
|
3024
3625
|
driver.configure(Fluent::Config::Element.new(
|
3025
3626
|
'ROOT', '', {
|
@@ -3922,7 +4523,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
|
|
3922
4523
|
stub_elastic
|
3923
4524
|
|
3924
4525
|
ts = "2001/02/03 13:14:01,673+02:00"
|
3925
|
-
index = "logstash-#{
|
4526
|
+
index = "logstash-#{Time.now.getutc.strftime("%Y.%m.%d")}"
|
3926
4527
|
|
3927
4528
|
flexmock(driver.instance.router).should_receive(:emit_error_event)
|
3928
4529
|
.with(tag_for_error, Fluent::EventTime, Hash, ArgumentError).once
|