From 116373bde21c9e7c9d9b4cc0933ae8c910a21de2 Mon Sep 17 00:00:00 2001 From: David Roberts Date: Mon, 4 Feb 2019 14:32:35 +0000 Subject: [PATCH] [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 --- .../filestructurefinder/FileStructureFinderManager.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/filestructurefinder/FileStructureFinderManager.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/filestructurefinder/FileStructureFinderManager.java index 935af8d35ed75..5332f18e9f05a 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/filestructurefinder/FileStructureFinderManager.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/filestructurefinder/FileStructureFinderManager.java @@ -7,6 +7,7 @@ import com.ibm.icu.text.CharsetDetector; import com.ibm.icu.text.CharsetMatch; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchTimeoutException; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.unit.TimeValue; @@ -148,6 +149,14 @@ public FileStructureFinder findFileStructure(List explanation, int ideal Math.max(MIN_SAMPLE_LINE_COUNT, idealSampleLineCount), timeoutChecker); return makeBestStructureFinder(explanation, sampleInfo.v1(), charsetName, sampleInfo.v2(), overrides, timeoutChecker); + } catch (Exception e) { + // Add a dummy exception containing the explanation so far - this 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 + if (explanation.isEmpty() == false) { + e.addSuppressed( + new ElasticsearchException(explanation.stream().collect(Collectors.joining("]\n[", "Explanation so far:\n[", "]\n")))); + } + throw e; } }