|
@@ -8,7 +8,6 @@ package org.elasticsearch.xpack.dataframe.integration;
|
|
|
|
|
|
import org.apache.http.entity.ContentType;
|
|
|
import org.apache.http.entity.StringEntity;
|
|
|
-import org.apache.lucene.util.LuceneTestCase;
|
|
|
import org.elasticsearch.client.Request;
|
|
|
import org.elasticsearch.client.ResponseException;
|
|
|
import org.elasticsearch.common.Strings;
|
|
@@ -17,6 +16,7 @@ import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
|
|
import org.elasticsearch.rest.RestStatus;
|
|
|
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformTaskState;
|
|
|
import org.junit.After;
|
|
|
+import org.junit.Before;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.List;
|
|
@@ -27,13 +27,21 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
|
|
import static org.hamcrest.CoreMatchers.is;
|
|
|
import static org.hamcrest.CoreMatchers.nullValue;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
-import static org.hamcrest.Matchers.greaterThan;
|
|
|
+import static org.hamcrest.Matchers.oneOf;
|
|
|
|
|
|
-@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/pull/44583")
|
|
|
public class DataFrameTaskFailedStateIT extends DataFrameRestTestCase {
|
|
|
|
|
|
private static final String TRANSFORM_ID = "failure_pivot_1";
|
|
|
|
|
|
+ @Before
|
|
|
+ public void setClusterSettings() throws IOException {
|
|
|
+ // Make sure we never retry on failure to speed up the test
|
|
|
+ Request addFailureRetrySetting = new Request("PUT", "/_cluster/settings");
|
|
|
+ addFailureRetrySetting.setJsonEntity(
|
|
|
+ "{\"persistent\": {\"xpack.data_frame.num_transform_failure_retries\": \"" + 0 + "\"}}");
|
|
|
+ client().performRequest(addFailureRetrySetting);
|
|
|
+ }
|
|
|
+
|
|
|
@After
|
|
|
public void cleanUpPotentiallyFailedTransform() throws Exception {
|
|
|
// If the tests failed in the middle, we should force stop it. This prevents other transform tests from failing due
|
|
@@ -43,14 +51,14 @@ public class DataFrameTaskFailedStateIT extends DataFrameRestTestCase {
|
|
|
}
|
|
|
|
|
|
public void testForceStopFailedTransform() throws Exception {
|
|
|
- createReviewsIndex();
|
|
|
+ createReviewsIndex(REVIEWS_INDEX_NAME, 10);
|
|
|
String dataFrameIndex = "failure_pivot_reviews";
|
|
|
createDestinationIndexWithBadMapping(dataFrameIndex);
|
|
|
- createPivotReviewsTransform(TRANSFORM_ID, dataFrameIndex, null);
|
|
|
+ createContinuousPivotReviewsTransform(TRANSFORM_ID, dataFrameIndex, null);
|
|
|
startDataframeTransform(TRANSFORM_ID, false);
|
|
|
awaitState(TRANSFORM_ID, DataFrameTransformTaskState.FAILED);
|
|
|
Map<?, ?> fullState = getDataFrameState(TRANSFORM_ID);
|
|
|
- final String failureReason = "task encountered more than 10 failures; latest failure: " +
|
|
|
+ final String failureReason = "task encountered more than 0 failures; latest failure: " +
|
|
|
"Bulk index experienced failures. See the logs of the node running the transform for details.";
|
|
|
// Verify we have failed for the expected reason
|
|
|
assertThat(XContentMapValues.extractValue("state.reason", fullState),
|
|
@@ -69,21 +77,20 @@ public class DataFrameTaskFailedStateIT extends DataFrameRestTestCase {
|
|
|
|
|
|
awaitState(TRANSFORM_ID, DataFrameTransformTaskState.STOPPED);
|
|
|
fullState = getDataFrameState(TRANSFORM_ID);
|
|
|
- // Verify we have failed for the expected reason
|
|
|
assertThat(XContentMapValues.extractValue("state.reason", fullState),
|
|
|
is(nullValue()));
|
|
|
}
|
|
|
|
|
|
|
|
|
public void testForceStartFailedTransform() throws Exception {
|
|
|
- createReviewsIndex();
|
|
|
+ createReviewsIndex(REVIEWS_INDEX_NAME, 10);
|
|
|
String dataFrameIndex = "failure_pivot_reviews";
|
|
|
createDestinationIndexWithBadMapping(dataFrameIndex);
|
|
|
- createPivotReviewsTransform(TRANSFORM_ID, dataFrameIndex, null);
|
|
|
+ createContinuousPivotReviewsTransform(TRANSFORM_ID, dataFrameIndex, null);
|
|
|
startDataframeTransform(TRANSFORM_ID, false);
|
|
|
awaitState(TRANSFORM_ID, DataFrameTransformTaskState.FAILED);
|
|
|
Map<?, ?> fullState = getDataFrameState(TRANSFORM_ID);
|
|
|
- final String failureReason = "task encountered more than 10 failures; latest failure: " +
|
|
|
+ final String failureReason = "task encountered more than 0 failures; latest failure: " +
|
|
|
"Bulk index experienced failures. See the logs of the node running the transform for details.";
|
|
|
// Verify we have failed for the expected reason
|
|
|
assertThat(XContentMapValues.extractValue("state.reason", fullState),
|
|
@@ -101,23 +108,15 @@ public class DataFrameTaskFailedStateIT extends DataFrameRestTestCase {
|
|
|
deleteIndex(dataFrameIndex);
|
|
|
// Force start the data frame to indicate failure correction
|
|
|
startDataframeTransform(TRANSFORM_ID, true);
|
|
|
- // Wait for data to be indexed appropriately and refresh for search
|
|
|
- waitForDataFrameCheckpoint(TRANSFORM_ID);
|
|
|
- refreshIndex(dataFrameIndex);
|
|
|
|
|
|
// Verify that we have started and that our reason is cleared
|
|
|
fullState = getDataFrameState(TRANSFORM_ID);
|
|
|
assertThat(XContentMapValues.extractValue("state.reason", fullState), is(nullValue()));
|
|
|
assertThat(XContentMapValues.extractValue("state.task_state", fullState), equalTo("started"));
|
|
|
- assertThat(XContentMapValues.extractValue("state.indexer_state", fullState), equalTo("started"));
|
|
|
- assertThat((int)XContentMapValues.extractValue("stats.index_failures", fullState), greaterThan(0));
|
|
|
-
|
|
|
- // get and check some users to verify we restarted
|
|
|
- assertOnePivotValue(dataFrameIndex + "/_search?q=reviewer:user_0", 3.776978417);
|
|
|
- assertOnePivotValue(dataFrameIndex + "/_search?q=reviewer:user_5", 3.72);
|
|
|
- assertOnePivotValue(dataFrameIndex + "/_search?q=reviewer:user_11", 3.846153846);
|
|
|
- assertOnePivotValue(dataFrameIndex + "/_search?q=reviewer:user_20", 3.769230769);
|
|
|
- assertOnePivotValue(dataFrameIndex + "/_search?q=reviewer:user_26", 3.918918918);
|
|
|
+ assertThat(XContentMapValues.extractValue("state.indexer_state", fullState), is(oneOf("started", "indexing")));
|
|
|
+ assertThat(XContentMapValues.extractValue("stats.index_failures", fullState), equalTo(1));
|
|
|
+
|
|
|
+ stopDataFrameTransform(TRANSFORM_ID, true);
|
|
|
}
|
|
|
|
|
|
private void awaitState(String transformId, DataFrameTransformTaskState state) throws Exception {
|