Skip to content

Commit fb6a176

Browse files
authored
[ML] Add explanation so far to file structure finder exceptions (#38191)
The explanation so far can be invaluable for troubleshooting as incorrect decisions made early on in the structure analysis can result in seemingly crazy decisions or timeouts later on. Relates elastic/kibana#29821
1 parent e49b593 commit fb6a176

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/filestructurefinder/FileStructureFinderManager.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.ibm.icu.text.CharsetDetector;
99
import com.ibm.icu.text.CharsetMatch;
10+
import org.elasticsearch.ElasticsearchException;
1011
import org.elasticsearch.ElasticsearchTimeoutException;
1112
import org.elasticsearch.common.collect.Tuple;
1213
import org.elasticsearch.common.unit.TimeValue;
@@ -148,6 +149,14 @@ public FileStructureFinder findFileStructure(List<String> explanation, int ideal
148149
Math.max(MIN_SAMPLE_LINE_COUNT, idealSampleLineCount), timeoutChecker);
149150

150151
return makeBestStructureFinder(explanation, sampleInfo.v1(), charsetName, sampleInfo.v2(), overrides, timeoutChecker);
152+
} catch (Exception e) {
153+
// Add a dummy exception containing the explanation so far - this can be invaluable for troubleshooting as incorrect
154+
// decisions made early on in the structure analysis can result in seemingly crazy decisions or timeouts later on
155+
if (explanation.isEmpty() == false) {
156+
e.addSuppressed(
157+
new ElasticsearchException(explanation.stream().collect(Collectors.joining("]\n[", "Explanation so far:\n[", "]\n"))));
158+
}
159+
throw e;
151160
}
152161
}
153162

0 commit comments

Comments
 (0)