Skip to content

Commit 2474276

Browse files
[ML] Fix DFA explain API timeout when source index is missing (#50176)
This commit fixes a bug that caused the data frame analytics _explain API to time out in a multi-node setup when the source index was missing. When we try to create the extracted fields detector, we check the index settings. If the index is missing that responds with a failure that could be wrapped as a remote exception. While we unwrapped correctly to check if the cause was an `IndexNotFoundException`, we then proceeded to cast the original exception instead of the cause.
1 parent b0c249f commit 2474276

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/ExplainDataFrameAnalyticsIT.java

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package org.elasticsearch.xpack.ml.integration;
77

8+
import org.elasticsearch.ResourceNotFoundException;
89
import org.elasticsearch.action.bulk.BulkRequestBuilder;
910
import org.elasticsearch.action.bulk.BulkResponse;
1011
import org.elasticsearch.action.index.IndexRequest;
@@ -14,14 +15,26 @@
1415
import org.elasticsearch.xpack.core.ml.dataframe.DataFrameAnalyticsConfig;
1516
import org.elasticsearch.xpack.core.ml.dataframe.DataFrameAnalyticsSource;
1617
import org.elasticsearch.xpack.core.ml.dataframe.analyses.Classification;
18+
import org.elasticsearch.xpack.core.ml.dataframe.analyses.OutlierDetection;
1719
import org.elasticsearch.xpack.core.ml.utils.QueryProvider;
1820

1921
import java.io.IOException;
2022

23+
import static org.hamcrest.Matchers.equalTo;
2124
import static org.hamcrest.Matchers.lessThanOrEqualTo;
2225

2326
public class ExplainDataFrameAnalyticsIT extends MlNativeDataFrameAnalyticsIntegTestCase {
2427

28+
public void testExplain_GivenMissingSourceIndex() {
29+
DataFrameAnalyticsConfig config = new DataFrameAnalyticsConfig.Builder()
30+
.setSource(new DataFrameAnalyticsSource(new String[] {"missing_index"}, null, null))
31+
.setAnalysis(new OutlierDetection.Builder().build())
32+
.buildForExplain();
33+
34+
ResourceNotFoundException e = expectThrows(ResourceNotFoundException.class, () -> explainDataFrame(config));
35+
assertThat(e.getMessage(), equalTo("cannot retrieve data because index [missing_index] does not exist"));
36+
}
37+
2538
public void testSourceQueryIsApplied() throws IOException {
2639
// To test the source query is applied when we extract data,
2740
// we set up a job where we have a query which excludes all but one document.

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/extractor/ExtractedFieldsDetectorFactory.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,10 @@ private void getDocValueFieldsLimit(String[] index, ActionListener<Integer> docV
171171
docValueFieldsLimitListener.onResponse(minDocValueFieldsLimit);
172172
},
173173
e -> {
174-
if (ExceptionsHelper.unwrapCause(e) instanceof IndexNotFoundException) {
174+
Throwable cause = ExceptionsHelper.unwrapCause(e);
175+
if (cause instanceof IndexNotFoundException) {
175176
docValueFieldsLimitListener.onFailure(new ResourceNotFoundException("cannot retrieve data because index "
176-
+ ((IndexNotFoundException) e).getIndex() + " does not exist"));
177+
+ ((IndexNotFoundException) cause).getIndex() + " does not exist"));
177178
} else {
178179
docValueFieldsLimitListener.onFailure(e);
179180
}

0 commit comments

Comments
 (0)