|
@@ -11,11 +11,15 @@ package org.elasticsearch.action.bulk;
|
|
|
import org.elasticsearch.ElasticsearchException;
|
|
|
import org.elasticsearch.action.DocWriteRequest;
|
|
|
import org.elasticsearch.action.index.IndexRequest;
|
|
|
+import org.elasticsearch.ingest.CompoundProcessor;
|
|
|
import org.elasticsearch.test.ESTestCase;
|
|
|
import org.elasticsearch.transport.RemoteTransportException;
|
|
|
import org.elasticsearch.xcontent.ObjectPath;
|
|
|
import org.elasticsearch.xcontent.json.JsonXContent;
|
|
|
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
import static org.hamcrest.CoreMatchers.containsString;
|
|
|
import static org.hamcrest.CoreMatchers.equalTo;
|
|
|
import static org.hamcrest.CoreMatchers.is;
|
|
@@ -24,14 +28,36 @@ import static org.hamcrest.CoreMatchers.startsWith;
|
|
|
|
|
|
public class FailureStoreDocumentConverterTests extends ESTestCase {
|
|
|
|
|
|
- public void testFailureStoreDocumentConverstion() throws Exception {
|
|
|
+ public void testFailureStoreDocumentConversion() throws Exception {
|
|
|
IndexRequest source = new IndexRequest("original_index").routing("fake_routing")
|
|
|
.id("1")
|
|
|
.source(JsonXContent.contentBuilder().startObject().field("key", "value").endObject());
|
|
|
|
|
|
// The exception will be wrapped for the test to make sure the converter correctly unwraps it
|
|
|
- Exception exception = new ElasticsearchException("Test exception please ignore");
|
|
|
- exception = new RemoteTransportException("Test exception wrapper, please ignore", exception);
|
|
|
+ ElasticsearchException exception = new ElasticsearchException("Test exception please ignore");
|
|
|
+ ElasticsearchException ingestException = exception;
|
|
|
+ if (randomBoolean()) {
|
|
|
+ ingestException = new ElasticsearchException("Test suppressed exception, please ignore");
|
|
|
+ exception.addSuppressed(ingestException);
|
|
|
+ }
|
|
|
+ boolean withPipelineOrigin = randomBoolean();
|
|
|
+ if (withPipelineOrigin) {
|
|
|
+ ingestException.addHeader(
|
|
|
+ CompoundProcessor.PIPELINE_ORIGIN_EXCEPTION_HEADER,
|
|
|
+ Arrays.asList("some-failing-pipeline", "some-pipeline")
|
|
|
+ );
|
|
|
+ }
|
|
|
+ boolean withProcessorTag = randomBoolean();
|
|
|
+ if (withProcessorTag) {
|
|
|
+ ingestException.addHeader(CompoundProcessor.PROCESSOR_TAG_EXCEPTION_HEADER, "foo-tag");
|
|
|
+ }
|
|
|
+ boolean withProcessorType = randomBoolean();
|
|
|
+ if (withProcessorType) {
|
|
|
+ ingestException.addHeader(CompoundProcessor.PROCESSOR_TYPE_EXCEPTION_HEADER, "bar-type");
|
|
|
+ }
|
|
|
+ if (randomBoolean()) {
|
|
|
+ exception = new RemoteTransportException("Test exception wrapper, please ignore", exception);
|
|
|
+ }
|
|
|
|
|
|
String targetIndexName = "rerouted_index";
|
|
|
long testTime = 1702357200000L; // 2023-12-12T05:00:00.000Z
|
|
@@ -68,7 +94,23 @@ public class FailureStoreDocumentConverterTests extends ESTestCase {
|
|
|
);
|
|
|
assertThat(
|
|
|
ObjectPath.eval("error.stack_trace", convertedRequest.sourceAsMap()),
|
|
|
- containsString("at org.elasticsearch.action.bulk.FailureStoreDocumentConverterTests.testFailureStoreDocumentConverstion")
|
|
|
+ containsString("at org.elasticsearch.action.bulk.FailureStoreDocumentConverterTests.testFailureStoreDocumentConversion")
|
|
|
+ );
|
|
|
+ assertThat(
|
|
|
+ ObjectPath.eval("error.pipeline_trace", convertedRequest.sourceAsMap()),
|
|
|
+ is(equalTo(withPipelineOrigin ? List.of("some-pipeline", "some-failing-pipeline") : null))
|
|
|
+ );
|
|
|
+ assertThat(
|
|
|
+ ObjectPath.eval("error.pipeline", convertedRequest.sourceAsMap()),
|
|
|
+ is(equalTo(withPipelineOrigin ? "some-failing-pipeline" : null))
|
|
|
+ );
|
|
|
+ assertThat(
|
|
|
+ ObjectPath.eval("error.processor_tag", convertedRequest.sourceAsMap()),
|
|
|
+ is(equalTo(withProcessorTag ? "foo-tag" : null))
|
|
|
+ );
|
|
|
+ assertThat(
|
|
|
+ ObjectPath.eval("error.processor_type", convertedRequest.sourceAsMap()),
|
|
|
+ is(equalTo(withProcessorType ? "bar-type" : null))
|
|
|
);
|
|
|
|
|
|
assertThat(convertedRequest.isWriteToFailureStore(), is(true));
|