Skip to content

Commit 66b3e89

Browse files
authored
[ML] enable logging for test failures (#60902) (#60910)
1 parent 2a4fd83 commit 66b3e89

File tree

5 files changed

+98
-0
lines changed

5 files changed

+98
-0
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/inference/trainedmodel/inference/EnsembleInferenceModel.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66

77
package org.elasticsearch.xpack.core.ml.inference.trainedmodel.inference;
88

9+
import org.apache.logging.log4j.LogManager;
10+
import org.apache.logging.log4j.Logger;
911
import org.apache.lucene.util.RamUsageEstimator;
1012
import org.elasticsearch.common.Nullable;
13+
import org.elasticsearch.common.Strings;
1114
import org.elasticsearch.common.collect.Tuple;
1215
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
1316
import org.elasticsearch.common.xcontent.XContentParser;
@@ -25,6 +28,7 @@
2528
import org.elasticsearch.xpack.core.ml.inference.trainedmodel.ensemble.OutputAggregator;
2629
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
2730

31+
import java.util.Arrays;
2832
import java.util.Collections;
2933
import java.util.HashMap;
3034
import java.util.LinkedHashSet;
@@ -49,6 +53,7 @@
4953
public class EnsembleInferenceModel implements InferenceModel {
5054

5155
public static final long SHALLOW_SIZE = RamUsageEstimator.shallowSizeOfInstance(EnsembleInferenceModel.class);
56+
private static final Logger LOGGER = LogManager.getLogger(EnsembleInferenceModel.class);
5257

5358
@SuppressWarnings("unchecked")
5459
private static final ConstructingObjectParser<EnsembleInferenceModel, Void> PARSER = new ConstructingObjectParser<>(
@@ -136,6 +141,8 @@ private InferenceResults innerInfer(double[] features, InferenceConfig config, M
136141
if (preparedForInference == false) {
137142
throw ExceptionsHelper.serverError("model is not prepared for inference");
138143
}
144+
LOGGER.debug("Inference called with feature names [{}]",
145+
featureNames == null ? "<null>" : Strings.arrayToCommaDelimitedString(featureNames));
139146
assert featureNames != null && featureNames.length > 0;
140147
double[][] inferenceResults = new double[this.models.size()][];
141148
double[][] featureInfluence = new double[features.length][];
@@ -237,12 +244,14 @@ public String getName() {
237244

238245
@Override
239246
public void rewriteFeatureIndices(Map<String, Integer> newFeatureIndexMapping) {
247+
LOGGER.debug("rewriting features {}", newFeatureIndexMapping);
240248
if (preparedForInference) {
241249
return;
242250
}
243251
preparedForInference = true;
244252
if (newFeatureIndexMapping == null || newFeatureIndexMapping.isEmpty()) {
245253
Set<String> referencedFeatures = subModelFeatures();
254+
LOGGER.debug("detected submodel feature names {}", referencedFeatures);
246255
int newFeatureIndex = 0;
247256
newFeatureIndexMapping = new HashMap<>();
248257
this.featureNames = new String[referencedFeatures.size()];
@@ -301,4 +310,16 @@ public double[] getClassificationWeights() {
301310
return classificationWeights;
302311
}
303312

313+
@Override
314+
public String toString() {
315+
return "EnsembleInferenceModel{" +
316+
"featureNames=" + Arrays.toString(featureNames) +
317+
", models=" + models +
318+
", outputAggregator=" + outputAggregator +
319+
", targetType=" + targetType +
320+
", classificationLabels=" + classificationLabels +
321+
", classificationWeights=" + Arrays.toString(classificationWeights) +
322+
", preparedForInference=" + preparedForInference +
323+
'}';
324+
}
304325
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/inference/trainedmodel/inference/TreeInferenceModel.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
package org.elasticsearch.xpack.core.ml.inference.trainedmodel.inference;
88

9+
import org.apache.logging.log4j.LogManager;
10+
import org.apache.logging.log4j.Logger;
911
import org.apache.lucene.util.Accountable;
1012
import org.elasticsearch.common.Nullable;
1113
import org.elasticsearch.common.Numbers;
@@ -28,6 +30,7 @@
2830
import org.elasticsearch.xpack.core.ml.job.config.Operator;
2931
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
3032

33+
import java.util.Arrays;
3134
import java.util.Collections;
3235
import java.util.List;
3336
import java.util.Map;
@@ -56,6 +59,7 @@
5659

5760
public class TreeInferenceModel implements InferenceModel {
5861

62+
private static final Logger LOGGER = LogManager.getLogger(TreeInferenceModel.class);
5963
public static final long SHALLOW_SIZE = shallowSizeOfInstance(TreeInferenceModel.class);
6064

6165
@SuppressWarnings("unchecked")
@@ -304,6 +308,7 @@ public String getName() {
304308

305309
@Override
306310
public void rewriteFeatureIndices(Map<String, Integer> newFeatureIndexMapping) {
311+
LOGGER.debug("rewriting features {}", newFeatureIndexMapping);
307312
if (preparedForInference) {
308313
return;
309314
}
@@ -358,6 +363,20 @@ public Node[] getNodes() {
358363
return nodes;
359364
}
360365

366+
@Override
367+
public String toString() {
368+
return "TreeInferenceModel{" +
369+
"nodes=" + Arrays.toString(nodes) +
370+
", featureNames=" + Arrays.toString(featureNames) +
371+
", targetType=" + targetType +
372+
", classificationLabels=" + classificationLabels +
373+
", highOrderCategory=" + highOrderCategory +
374+
", maxDepth=" + maxDepth +
375+
", leafSize=" + leafSize +
376+
", preparedForInference=" + preparedForInference +
377+
'}';
378+
}
379+
361380
private static int getDepth(Node[] nodes, int nodeIndex, int depth) {
362381
Node node = nodes[nodeIndex];
363382
if (node instanceof LeafNode) {
@@ -519,6 +538,19 @@ private static boolean isMissing(double feature) {
519538
public long ramBytesUsed() {
520539
return SHALLOW_SIZE;
521540
}
541+
542+
@Override
543+
public String toString() {
544+
return "InnerNode{" +
545+
"operator=" + operator +
546+
", threshold=" + threshold +
547+
", splitFeature=" + splitFeature +
548+
", defaultLeft=" + defaultLeft +
549+
", leftChild=" + leftChild +
550+
", rightChild=" + rightChild +
551+
", numberSamples=" + numberSamples +
552+
'}';
553+
}
522554
}
523555

524556
public static class LeafNode extends Node {
@@ -544,5 +576,13 @@ long getNumberSamples() {
544576
public double[] getLeafValue() {
545577
return leafValue;
546578
}
579+
580+
@Override
581+
public String toString() {
582+
return "LeafNode{" +
583+
"leafValue=" + Arrays.toString(leafValue) +
584+
", numberSamples=" + numberSamples +
585+
'}';
586+
}
547587
}
548588
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.elasticsearch.action.index.IndexRequest;
1919
import org.elasticsearch.action.search.SearchResponse;
2020
import org.elasticsearch.action.support.WriteRequest;
21+
import org.elasticsearch.common.settings.Settings;
2122
import org.elasticsearch.common.unit.TimeValue;
2223
import org.elasticsearch.common.xcontent.XContentType;
2324
import org.elasticsearch.index.query.QueryBuilder;
@@ -37,6 +38,7 @@
3738
import org.elasticsearch.xpack.core.ml.dataframe.evaluation.classification.Precision;
3839
import org.elasticsearch.xpack.core.ml.dataframe.evaluation.classification.Recall;
3940
import org.junit.After;
41+
import org.junit.Before;
4042

4143
import java.io.IOException;
4244
import java.util.ArrayList;
@@ -85,9 +87,25 @@ public class ClassificationIT extends MlNativeDataFrameAnalyticsIntegTestCase {
8587
private String destIndex;
8688
private boolean analysisUsesExistingDestIndex;
8789

90+
@Before
91+
public void setupLogging() {
92+
client().admin().cluster()
93+
.prepareUpdateSettings()
94+
.setTransientSettings(Settings.builder()
95+
.put("logger.org.elasticsearch.xpack.ml.dataframe.inference", "DEBUG")
96+
.put("logger.org.elasticsearch.xpack.core.ml.inference", "DEBUG"))
97+
.get();
98+
}
99+
88100
@After
89101
public void cleanup() {
90102
cleanUp();
103+
client().admin().cluster()
104+
.prepareUpdateSettings()
105+
.setTransientSettings(Settings.builder()
106+
.putNull("logger.org.elasticsearch.xpack.ml.dataframe.inference")
107+
.putNull("logger.org.elasticsearch.xpack.core.ml.inference"))
108+
.get();
91109
}
92110

93111
public void testSingleNumericFeatureAndMixedTrainingAndNonTrainingRows() throws Exception {

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/inference/InferenceRunner.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public void run(String modelId) {
8585
TestDocsIterator testDocsIterator = new TestDocsIterator(new OriginSettingClient(client, ClientHelper.ML_ORIGIN), config,
8686
extractedFields);
8787
try (LocalModel localModel = localModelPlainActionFuture.actionGet()) {
88+
LOGGER.debug("Loaded inference model [{}]", localModel);
8889
inferTestDocs(localModel, testDocsIterator);
8990
}
9091
} catch (Exception e) {

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/loadingservice/LocalModel.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,22 @@ public long release() {
228228
public void close() {
229229
release();
230230
}
231+
232+
@Override
233+
public String toString() {
234+
return "LocalModel{" +
235+
"trainedModelDefinition=" + trainedModelDefinition +
236+
", modelId='" + modelId + '\'' +
237+
", fieldNames=" + fieldNames +
238+
", defaultFieldMap=" + defaultFieldMap +
239+
", statsAccumulator=" + statsAccumulator +
240+
", trainedModelStatsService=" + trainedModelStatsService +
241+
", persistenceQuotient=" + persistenceQuotient +
242+
", currentInferenceCount=" + currentInferenceCount +
243+
", inferenceConfig=" + inferenceConfig +
244+
", licenseLevel=" + licenseLevel +
245+
", trainedModelCircuitBreaker=" + trainedModelCircuitBreaker +
246+
", referenceCount=" + referenceCount +
247+
'}';
248+
}
231249
}

0 commit comments

Comments
 (0)