|
296 | 296 | expect(subject.logger).to have_received(:debug).with(/Encountered a retryable error/i, anything)
|
297 | 297 | end
|
298 | 298 | end
|
| 299 | + |
| 300 | + context "unexpected bulk response" do |
| 301 | + let(:options) do |
| 302 | + { "hosts" => "127.0.0.1:9999", "index" => "%{foo}", "manage_template" => false } |
| 303 | + end |
| 304 | + |
| 305 | + let(:events) { [ ::LogStash::Event.new("foo" => "bar1"), ::LogStash::Event.new("foo" => "bar2") ] } |
| 306 | + |
| 307 | + let(:bulk_response) do |
| 308 | + # shouldn't really happen but we've seen this happen - here ES returns more items than were sent |
| 309 | + { "took"=>1, "ingest_took"=>9, "errors"=>true, |
| 310 | + "items"=>[{"index"=>{"_index"=>"bar1", "_type"=>"_doc", "_id"=>nil, "status"=>500, |
| 311 | + "error"=>{"type" => "illegal_state_exception", |
| 312 | + "reason" => "pipeline with id [test-ingest] could not be loaded, caused by [ElasticsearchParseException[Error updating pipeline with id [test-ingest]]; nested: ElasticsearchException[java.lang.IllegalArgumentException: no enrich index exists for policy with name [test-metadata1]]; nested: IllegalArgumentException[no enrich index exists for policy with name [test-metadata1]];; ElasticsearchException[java.lang.IllegalArgumentException: no enrich index exists for policy with name [test-metadata1]]; nested: IllegalArgumentException[no enrich index exists for policy with name [test-metadata1]];; java.lang.IllegalArgumentException: no enrich index exists for policy with name [test-metadata1]]" |
| 313 | + } |
| 314 | + } |
| 315 | + }, |
| 316 | + # NOTE: this is an artificial success (usually everything fails with a 500) but even if some doc where |
| 317 | + # to succeed due the unexpected reponse items we can not clearly identify which actions to retry ... |
| 318 | + {"index"=>{"_index"=>"bar2", "_type"=>"_doc", "_id"=>nil, "status"=>201}}, |
| 319 | + {"index"=>{"_index"=>"bar2", "_type"=>"_doc", "_id"=>nil, "status"=>500, |
| 320 | + "error"=>{"type" => "illegal_state_exception", |
| 321 | + "reason" => "pipeline with id [test-ingest] could not be loaded, caused by [ElasticsearchParseException[Error updating pipeline with id [test-ingest]]; nested: ElasticsearchException[java.lang.IllegalArgumentException: no enrich index exists for policy with name [test-metadata1]];" |
| 322 | + } |
| 323 | + } |
| 324 | + }] |
| 325 | + } |
| 326 | + end |
| 327 | + |
| 328 | + before(:each) do |
| 329 | + allow(subject.client).to receive(:bulk_send).with(instance_of(StringIO)) do |stream| |
| 330 | + expect( stream.string ).to include '"foo":"bar1"' |
| 331 | + expect( stream.string ).to include '"foo":"bar2"' |
| 332 | + end.and_return(bulk_response, {"errors"=>false}) # let's make it go away (second call) to not retry indefinitely |
| 333 | + end |
| 334 | + |
| 335 | + it "should retry submit" do |
| 336 | + allow(subject.logger).to receive(:error).with(/Encountered an unexpected error/i, anything) |
| 337 | + allow(subject.client).to receive(:bulk).and_call_original # track count |
| 338 | + |
| 339 | + subject.multi_receive(events) |
| 340 | + |
| 341 | + expect(subject.client).to have_received(:bulk).twice |
| 342 | + end |
| 343 | + |
| 344 | + it "should log specific error message" do |
| 345 | + expect(subject.logger).to receive(:error).with(/Encountered an unexpected error/i, |
| 346 | + hash_including(:error_message => 'Sent 2 documents but Elasticsearch returned 3 responses (likely a bug with _bulk endpoint)')) |
| 347 | + |
| 348 | + subject.multi_receive(events) |
| 349 | + end |
| 350 | + end |
299 | 351 | end
|
300 | 352 |
|
301 | 353 | context "with timeout set" do
|
|
0 commit comments