fluent-plugin-elasticsearch 5.0.3 → 5.1.1
Sign up to get free protection for your applications and to get access to all the features.
- 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 +19 -0
- data/README.md +84 -2
- data/fluent-plugin-elasticsearch.gemspec +1 -1
- data/lib/fluent/plugin/elasticsearch_error_handler.rb +13 -2
- data/lib/fluent/plugin/elasticsearch_index_template.rb +13 -1
- data/lib/fluent/plugin/out_elasticsearch.rb +52 -4
- data/lib/fluent/plugin/out_elasticsearch_data_stream.rb +81 -49
- data/test/plugin/test_elasticsearch_error_handler.rb +25 -8
- data/test/plugin/test_elasticsearch_fallback_selector.rb +1 -1
- data/test/plugin/test_elasticsearch_index_lifecycle_management.rb +10 -0
- data/test/plugin/test_in_elasticsearch.rb +12 -0
- data/test/plugin/test_out_elasticsearch.rb +412 -18
- data/test/plugin/test_out_elasticsearch_data_stream.rb +348 -98
- data/test/plugin/test_out_elasticsearch_dynamic.rb +100 -5
- metadata +3 -3
@@ -27,13 +27,18 @@ class TestElasticsearchErrorHandler < Test::Unit::TestCase
|
|
27
27
|
@error_events << {:tag => tag, :time=>time, :record=>record, :error=>e}
|
28
28
|
end
|
29
29
|
|
30
|
-
def process_message(tag, meta, header, time, record, extracted_values)
|
30
|
+
def process_message(tag, meta, header, time, record, affinity_target_indices, extracted_values)
|
31
31
|
return [meta, header, record]
|
32
32
|
end
|
33
33
|
|
34
|
+
def get_affinity_target_indices(chunk)
|
35
|
+
indices = Hash.new
|
36
|
+
indices
|
37
|
+
end
|
38
|
+
|
34
39
|
def append_record_to_messages(op, meta, header, record, msgs)
|
35
40
|
if record.has_key?('raise') && record['raise']
|
36
|
-
raise
|
41
|
+
raise 'process_message'
|
37
42
|
end
|
38
43
|
return true
|
39
44
|
end
|
@@ -302,7 +307,7 @@ class TestElasticsearchErrorHandler < Test::Unit::TestCase
|
|
302
307
|
def test_retry_error
|
303
308
|
records = []
|
304
309
|
error_records = Hash.new(false)
|
305
|
-
error_records.merge!({0=>true, 4=>true
|
310
|
+
error_records.merge!({0=>true, 4=>true})
|
306
311
|
10.times do |i|
|
307
312
|
records << {time: 12345, record: {"message"=>"record #{i}","_id"=>i,"raise"=>error_records[i]}}
|
308
313
|
end
|
@@ -386,6 +391,18 @@ class TestElasticsearchErrorHandler < Test::Unit::TestCase
|
|
386
391
|
"reason":"unrecognized error"
|
387
392
|
}
|
388
393
|
}
|
394
|
+
},
|
395
|
+
{
|
396
|
+
"create" : {
|
397
|
+
"_index" : "foo",
|
398
|
+
"_type" : "bar",
|
399
|
+
"_id" : "9",
|
400
|
+
"status" : 500,
|
401
|
+
"error" : {
|
402
|
+
"type" : "json_parse_exception",
|
403
|
+
"reason":"Invalid UTF-8 start byte 0x92\\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@204fe9c9; line: 1, column: 81]"
|
404
|
+
}
|
405
|
+
}
|
389
406
|
}
|
390
407
|
]
|
391
408
|
}))
|
@@ -400,12 +417,12 @@ class TestElasticsearchErrorHandler < Test::Unit::TestCase
|
|
400
417
|
next unless e.respond_to?(:retry_stream)
|
401
418
|
e.retry_stream.each {|time, record| records << record}
|
402
419
|
end
|
403
|
-
assert_equal 2, records.length
|
404
|
-
assert_equal 2, records[0]['_id']
|
405
|
-
assert_equal 8, records[1]['_id']
|
420
|
+
assert_equal 2, records.length, "Exp. retry_stream to contain records"
|
421
|
+
assert_equal 2, records[0]['_id'], "Exp record with given ID to in retry_stream"
|
422
|
+
assert_equal 8, records[1]['_id'], "Exp record with given ID to in retry_stream"
|
406
423
|
error_ids = @plugin.error_events.collect {|h| h[:record]['_id']}
|
407
|
-
assert_equal
|
408
|
-
assert_equal [5, 6, 7], error_ids
|
424
|
+
assert_equal 4, error_ids.length, "Exp. a certain number of records to be dropped from retry_stream"
|
425
|
+
assert_equal [5, 6, 7, 9], error_ids, "Exp. specific records to be dropped from retry_stream"
|
409
426
|
@plugin.error_events.collect {|h| h[:error]}.each do |e|
|
410
427
|
assert_true e.respond_to?(:backtrace)
|
411
428
|
end
|
@@ -19,7 +19,7 @@ class ElasticsearchFallbackSelectorTest < Test::Unit::TestCase
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def stub_elastic_info(url="http://localhost:9200/", version="6.4.2")
|
22
|
-
body ="{\"version\":{\"number\":\"#{version}\"}}"
|
22
|
+
body ="{\"version\":{\"number\":\"#{version}\", \"build_flavor\":\"default\"},\"tagline\" : \"You Know, for Search\"}"
|
23
23
|
stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json' } })
|
24
24
|
end
|
25
25
|
|
@@ -27,9 +27,15 @@ class TestElasticsearchIndexLifecycleManagement < Test::Unit::TestCase
|
|
27
27
|
CODE
|
28
28
|
end
|
29
29
|
|
30
|
+
def stub_elastic_info(url="http://localhost:9200/", version="7.9.0")
|
31
|
+
body ="{\"version\":{\"number\":\"#{version}\", \"build_flavor\":\"default\"},\"tagline\" : \"You Know, for Search\"}"
|
32
|
+
stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json' } })
|
33
|
+
end
|
34
|
+
|
30
35
|
def test_xpack_info
|
31
36
|
stub_request(:get, "http://localhost:9200/_xpack").
|
32
37
|
to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
|
38
|
+
stub_elastic_info
|
33
39
|
expected = {"features"=>{"ilm"=>{"available"=>true, "enabled"=>true}}}
|
34
40
|
assert_equal(expected, xpack_info)
|
35
41
|
end
|
@@ -37,18 +43,21 @@ class TestElasticsearchIndexLifecycleManagement < Test::Unit::TestCase
|
|
37
43
|
def test_verify_ilm_working
|
38
44
|
stub_request(:get, "http://localhost:9200/_xpack").
|
39
45
|
to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
|
46
|
+
stub_elastic_info
|
40
47
|
assert_nothing_raised { verify_ilm_working }
|
41
48
|
end
|
42
49
|
|
43
50
|
def test_ilm_policy_doesnt_exists
|
44
51
|
stub_request(:get, "http://localhost:9200/_ilm/policy/%7B:policy_id=%3E%22fluentd-policy%22%7D").
|
45
52
|
to_return(:status => 404, :body => "", :headers => {})
|
53
|
+
stub_elastic_info
|
46
54
|
assert_false(ilm_policy_exists?(policy_id: "fluentd-policy"))
|
47
55
|
end
|
48
56
|
|
49
57
|
def test_ilm_policy_exists
|
50
58
|
stub_request(:get, "http://localhost:9200/_ilm/policy/%7B:policy_id=%3E%22fluent-policy%22%7D").
|
51
59
|
to_return(:status => 200, :body => "", :headers => {})
|
60
|
+
stub_elastic_info
|
52
61
|
assert_true(ilm_policy_exists?(policy_id: "fluent-policy"))
|
53
62
|
end
|
54
63
|
|
@@ -59,6 +68,7 @@ class TestElasticsearchIndexLifecycleManagement < Test::Unit::TestCase
|
|
59
68
|
with(:body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}",
|
60
69
|
:headers => {'Content-Type'=>'application/json'}).
|
61
70
|
to_return(:status => 200, :body => "", :headers => {})
|
71
|
+
stub_elastic_info
|
62
72
|
create_ilm_policy("fluent-policy")
|
63
73
|
|
64
74
|
assert_requested(:put, "http://localhost:9200/_ilm/policy/fluent-policy", times: 1)
|
@@ -31,6 +31,11 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
31
31
|
@driver ||= Fluent::Test::Driver::Input.new(Fluent::Plugin::ElasticsearchInput).configure(conf)
|
32
32
|
end
|
33
33
|
|
34
|
+
def stub_elastic_info(url="http://localhost:9200/", version="7.9.0")
|
35
|
+
body ="{\"version\":{\"number\":\"#{version}\", \"build_flavor\":\"default\"},\"tagline\" : \"You Know, for Search\"}"
|
36
|
+
stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json' } })
|
37
|
+
end
|
38
|
+
|
34
39
|
def sample_response(index_name="fluentd")
|
35
40
|
{
|
36
41
|
"took"=>4,
|
@@ -322,6 +327,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
322
327
|
with(body: "{\"sort\":[\"_doc\"]}").
|
323
328
|
to_return(status: 200, body: sample_response.to_s,
|
324
329
|
headers: {'Content-Type' => 'application/json'})
|
330
|
+
stub_elastic_info
|
325
331
|
|
326
332
|
driver(CONFIG)
|
327
333
|
driver.run(expect_emits: 1, timeout: 10)
|
@@ -337,6 +343,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
337
343
|
with(body: "{\"sort\":[\"_doc\"]}").
|
338
344
|
to_return(status: 200, body: sample_response(index_name).to_s,
|
339
345
|
headers: {'Content-Type' => 'application/json'})
|
346
|
+
stub_elastic_info
|
340
347
|
|
341
348
|
driver(CONFIG + %[index_name #{index_name}])
|
342
349
|
driver.run(expect_emits: 1, timeout: 10)
|
@@ -352,6 +359,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
352
359
|
with(body: "{\"sort\":[\"_doc\"]}").
|
353
360
|
to_return(status: 200, body: sample_response(index_name).to_s,
|
354
361
|
headers: {'Content-Type' => 'application/json'})
|
362
|
+
stub_elastic_info
|
355
363
|
|
356
364
|
driver(CONFIG + %[parse_timestamp])
|
357
365
|
driver.run(expect_emits: 1, timeout: 10)
|
@@ -370,6 +378,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
370
378
|
with(body: "{\"sort\":[\"_doc\"]}").
|
371
379
|
to_return(status: 200, body: sample_response(index_name).to_s,
|
372
380
|
headers: {'Content-Type' => 'application/json'})
|
381
|
+
stub_elastic_info
|
373
382
|
|
374
383
|
driver(CONFIG + %[parse_timestamp true
|
375
384
|
timestamp_key_format %Y-%m-%dT%H:%M:%S.%N%z
|
@@ -389,6 +398,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
389
398
|
with(body: "{\"sort\":[\"_doc\"]}").
|
390
399
|
to_return(status: 200, body: sample_response.to_s,
|
391
400
|
headers: {'Content-Type' => 'application/json'})
|
401
|
+
stub_elastic_info
|
392
402
|
|
393
403
|
driver(CONFIG + %[docinfo true])
|
394
404
|
driver.run(expect_emits: 1, timeout: 10)
|
@@ -412,6 +422,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
412
422
|
with(body: "{\"sort\":[\"_doc\"],\"slice\":{\"id\":1,\"max\":2}}").
|
413
423
|
to_return(status: 200, body: sample_response.to_s,
|
414
424
|
headers: {'Content-Type' => 'application/json'})
|
425
|
+
stub_elastic_info
|
415
426
|
|
416
427
|
driver(CONFIG + %[num_slices 2])
|
417
428
|
driver.run(expect_emits: 1, timeout: 10)
|
@@ -434,6 +445,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
434
445
|
body: "{\"scroll_id\":\"WomkoUKG0QPB679Ulo6TqQgh3pIGRUmrl9qXXGK3EeiQh9rbYNasTkspZQcJ01uz\"}") do
|
435
446
|
connection += 1
|
436
447
|
end
|
448
|
+
stub_elastic_info
|
437
449
|
scroll_request.to_return(lambda do |req|
|
438
450
|
if connection <= 1
|
439
451
|
{status: 200, body: sample_scroll_response_2.to_s,
|