-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Transform] improve irrecoverable error detection - part 2 (#52003)
base error handling on rest status instead of listing individual exception types relates to #51820
- Loading branch information
Hendrik Muhs
committed
Feb 12, 2020
1 parent
3f151d1
commit 5d35eaa
Showing
3 changed files
with
240 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
.../src/test/java/org/elasticsearch/xpack/transform/utils/ExceptionRootCauseFinderTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.transform.utils; | ||
|
||
import org.elasticsearch.ElasticsearchSecurityException; | ||
import org.elasticsearch.ResourceNotFoundException; | ||
import org.elasticsearch.action.DocWriteRequest.OpType; | ||
import org.elasticsearch.action.bulk.BulkItemResponse; | ||
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; | ||
import org.elasticsearch.index.mapper.MapperParsingException; | ||
import org.elasticsearch.index.shard.ShardId; | ||
import org.elasticsearch.index.translog.TranslogException; | ||
import org.elasticsearch.rest.RestStatus; | ||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ExceptionRootCauseFinderTests extends ESTestCase { | ||
public void testFetFirstIrrecoverableExceptionFromBulkResponses() { | ||
Map<Integer, BulkItemResponse> bulkItemResponses = new HashMap<>(); | ||
|
||
int id = 1; | ||
// 1 | ||
bulkItemResponses.put( | ||
id, | ||
new BulkItemResponse( | ||
id++, | ||
OpType.INDEX, | ||
new BulkItemResponse.Failure("the_index", "type", "id", new MapperParsingException("mapper parsing error")) | ||
) | ||
); | ||
// 2 | ||
bulkItemResponses.put( | ||
id, | ||
new BulkItemResponse( | ||
id++, | ||
OpType.INDEX, | ||
new BulkItemResponse.Failure("the_index", "type", "id", new ResourceNotFoundException("resource not found error")) | ||
) | ||
); | ||
// 3 | ||
bulkItemResponses.put( | ||
id, | ||
new BulkItemResponse( | ||
id++, | ||
OpType.INDEX, | ||
new BulkItemResponse.Failure("the_index", "type", "id", new IllegalArgumentException("illegal argument error")) | ||
) | ||
); | ||
// 4 not irrecoverable | ||
bulkItemResponses.put( | ||
id, | ||
new BulkItemResponse( | ||
id++, | ||
OpType.INDEX, | ||
new BulkItemResponse.Failure("the_index", "type", "id", new EsRejectedExecutionException("es rejected execution")) | ||
) | ||
); | ||
// 5 not irrecoverable | ||
bulkItemResponses.put( | ||
id, | ||
new BulkItemResponse( | ||
id++, | ||
OpType.INDEX, | ||
new BulkItemResponse.Failure( | ||
"the_index", | ||
"type", | ||
"id", | ||
new TranslogException(new ShardId("the_index", "uid", 0), "translog error") | ||
) | ||
) | ||
); | ||
// 6 | ||
bulkItemResponses.put( | ||
id, | ||
new BulkItemResponse( | ||
id++, | ||
OpType.INDEX, | ||
new BulkItemResponse.Failure( | ||
"the_index", | ||
"type", | ||
"id", | ||
new ElasticsearchSecurityException("Authentication required", RestStatus.UNAUTHORIZED) | ||
) | ||
) | ||
); | ||
// 7 | ||
bulkItemResponses.put( | ||
id, | ||
new BulkItemResponse( | ||
id++, | ||
OpType.INDEX, | ||
new BulkItemResponse.Failure( | ||
"the_index", | ||
"type", | ||
"id", | ||
new ElasticsearchSecurityException("current license is non-compliant for [transform]", RestStatus.FORBIDDEN) | ||
) | ||
) | ||
); | ||
// 8 not irrecoverable | ||
bulkItemResponses.put( | ||
id, | ||
new BulkItemResponse( | ||
id++, | ||
OpType.INDEX, | ||
new BulkItemResponse.Failure( | ||
"the_index", | ||
"type", | ||
"id", | ||
new ElasticsearchSecurityException("overloaded, to many requests", RestStatus.TOO_MANY_REQUESTS) | ||
) | ||
) | ||
); | ||
// 9 not irrecoverable | ||
bulkItemResponses.put( | ||
id, | ||
new BulkItemResponse( | ||
id++, | ||
OpType.INDEX, | ||
new BulkItemResponse.Failure( | ||
"the_index", | ||
"type", | ||
"id", | ||
new ElasticsearchSecurityException("internal error", RestStatus.INTERNAL_SERVER_ERROR) | ||
) | ||
) | ||
); | ||
|
||
assertFirstException(bulkItemResponses.values(), MapperParsingException.class, "mapper parsing error"); | ||
bulkItemResponses.remove(1); | ||
assertFirstException(bulkItemResponses.values(), ResourceNotFoundException.class, "resource not found error"); | ||
bulkItemResponses.remove(2); | ||
assertFirstException(bulkItemResponses.values(), IllegalArgumentException.class, "illegal argument error"); | ||
bulkItemResponses.remove(3); | ||
assertFirstException(bulkItemResponses.values(), ElasticsearchSecurityException.class, "Authentication required"); | ||
bulkItemResponses.remove(6); | ||
assertFirstException( | ||
bulkItemResponses.values(), | ||
ElasticsearchSecurityException.class, | ||
"current license is non-compliant for [transform]" | ||
); | ||
bulkItemResponses.remove(7); | ||
|
||
assertNull(ExceptionRootCauseFinder.getFirstIrrecoverableExceptionFromBulkResponses(bulkItemResponses.values())); | ||
} | ||
|
||
private static void assertFirstException(Collection<BulkItemResponse> bulkItemResponses, Class<?> expectedClass, String message) { | ||
Throwable t = ExceptionRootCauseFinder.getFirstIrrecoverableExceptionFromBulkResponses(bulkItemResponses); | ||
assertNotNull(t); | ||
assertEquals(t.getClass(), expectedClass); | ||
assertEquals(t.getMessage(), message); | ||
} | ||
} |