Skip to content

Commit e7b8757

Browse files
authored
[ML] make InferenceIngestIT more lenient when checking cache miss counts (#65774) (#65815)
Looking over the failure history, it is always the cache miss count that is off. This is mostly ok as all the failures had indicated that there were indeed cache failures and every one of them were fence-post errors. Opting to make the cache miss count check lenient as other stats checked verify consistency. closes #61564
1 parent 4d8bba3 commit e7b8757

File tree

2 files changed

+34
-31
lines changed
  • x-pack/plugin/ml
    • qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration
    • src/main/java/org/elasticsearch/xpack/ml/inference/loadingservice

2 files changed

+34
-31
lines changed

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

+26-23
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@
1010
import org.elasticsearch.client.RequestOptions;
1111
import org.elasticsearch.client.Response;
1212
import org.elasticsearch.client.ResponseException;
13+
import org.elasticsearch.client.ml.GetTrainedModelsStatsResponse;
14+
import org.elasticsearch.client.ml.inference.TrainedModelStats;
1315
import org.elasticsearch.common.bytes.BytesReference;
1416
import org.elasticsearch.common.settings.Settings;
1517
import org.elasticsearch.common.util.concurrent.ThreadContext;
1618
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
1719
import org.elasticsearch.common.xcontent.XContentBuilder;
1820
import org.elasticsearch.common.xcontent.XContentFactory;
1921
import org.elasticsearch.common.xcontent.XContentHelper;
22+
import org.elasticsearch.common.xcontent.XContentParser;
2023
import org.elasticsearch.common.xcontent.XContentType;
24+
import org.elasticsearch.common.xcontent.json.JsonXContent;
2125
import org.elasticsearch.index.query.QueryBuilder;
2226
import org.elasticsearch.index.query.QueryBuilders;
2327
import org.elasticsearch.test.ExternalTestCluster;
@@ -38,6 +42,11 @@
3842
import java.util.concurrent.TimeUnit;
3943

4044
import static org.hamcrest.CoreMatchers.containsString;
45+
import static org.hamcrest.CoreMatchers.notNullValue;
46+
import static org.hamcrest.Matchers.equalTo;
47+
import static org.hamcrest.Matchers.greaterThan;
48+
import static org.hamcrest.Matchers.hasSize;
49+
import static org.hamcrest.Matchers.is;
4150

4251
/**
4352
* This is a {@link ESRestTestCase} because the cleanup code in {@link ExternalTestCluster#ensureEstimatedStats()} causes problems
@@ -134,15 +143,8 @@ public void testPathologicalPipelineCreationAndDeletion() throws Exception {
134143
assertThat(EntityUtils.toString(searchResponse.getEntity()), containsString("\"value\":10"));
135144
assertBusy(() -> {
136145
try {
137-
Response statsResponse = client().performRequest(new Request("GET",
138-
"_ml/trained_models/" + classificationModelId + "/_stats"));
139-
String response = EntityUtils.toString(statsResponse.getEntity());
140-
assertThat(response, containsString("\"inference_count\":10"));
141-
assertThat(response, containsString("\"cache_miss_count\":30"));
142-
statsResponse = client().performRequest(new Request("GET", "_ml/trained_models/" + regressionModelId + "/_stats"));
143-
response = EntityUtils.toString(statsResponse.getEntity());
144-
assertThat(response, containsString("\"inference_count\":10"));
145-
assertThat(response, containsString("\"cache_miss_count\":30"));
146+
assertStatsWithCacheMisses(classificationModelId, 10L);
147+
assertStatsWithCacheMisses(regressionModelId, 10L);
146148
} catch (ResponseException ex) {
147149
//this could just mean shard failures.
148150
fail(ex.getMessage());
@@ -190,27 +192,28 @@ public void testPipelineIngest() throws Exception {
190192

191193
assertBusy(() -> {
192194
try {
193-
Response statsResponse = client().performRequest(new Request("GET",
194-
"_ml/trained_models/" + classificationModelId + "/_stats"));
195-
String response = EntityUtils.toString(statsResponse.getEntity());
196-
assertThat(response, containsString("\"inference_count\":10"));
197-
assertThat(response, containsString("\"cache_miss_count\":3"));
198-
statsResponse = client().performRequest(new Request("GET", "_ml/trained_models/" + regressionModelId + "/_stats"));
199-
response = EntityUtils.toString(statsResponse.getEntity());
200-
assertThat(response, containsString("\"inference_count\":15"));
201-
assertThat(response, containsString("\"cache_miss_count\":3"));
202-
// can get both
203-
statsResponse = client().performRequest(new Request("GET", "_ml/trained_models/_stats"));
204-
String entityString = EntityUtils.toString(statsResponse.getEntity());
205-
assertThat(entityString, containsString("\"inference_count\":15"));
206-
assertThat(entityString, containsString("\"inference_count\":10"));
195+
assertStatsWithCacheMisses(classificationModelId, 10L);
196+
assertStatsWithCacheMisses(regressionModelId, 15L);
207197
} catch (ResponseException ex) {
208198
//this could just mean shard failures.
209199
fail(ex.getMessage());
210200
}
211201
}, 30, TimeUnit.SECONDS);
212202
}
213203

204+
public void assertStatsWithCacheMisses(String modelId, long inferenceCount) throws IOException {
205+
Response statsResponse = client().performRequest(new Request("GET",
206+
"_ml/trained_models/" + modelId + "/_stats"));
207+
try (XContentParser parser = createParser(JsonXContent.jsonXContent, statsResponse.getEntity().getContent())) {
208+
GetTrainedModelsStatsResponse response = GetTrainedModelsStatsResponse.fromXContent(parser);
209+
assertThat(response.getTrainedModelStats(), hasSize(1));
210+
TrainedModelStats trainedModelStats = response.getTrainedModelStats().get(0);
211+
assertThat(trainedModelStats.getInferenceStats(), is(notNullValue()));
212+
assertThat(trainedModelStats.getInferenceStats().getInferenceCount(), equalTo(inferenceCount));
213+
assertThat(trainedModelStats.getInferenceStats().getCacheMissCount(), greaterThan(0L));
214+
}
215+
}
216+
214217
public void testSimulate() throws IOException {
215218
String classificationModelId = "test_classification_simulate";
216219
putModel(classificationModelId, CLASSIFICATION_CONFIG);

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ public class LocalModel implements Closeable {
5858
private final AtomicLong referenceCount;
5959

6060
LocalModel(String modelId,
61-
String nodeId,
62-
InferenceDefinition trainedModelDefinition,
63-
TrainedModelInput input,
64-
Map<String, String> defaultFieldMap,
65-
InferenceConfig modelInferenceConfig,
66-
License.OperationMode licenseLevel,
67-
TrainedModelStatsService trainedModelStatsService,
68-
CircuitBreaker trainedModelCircuitBreaker) {
61+
String nodeId,
62+
InferenceDefinition trainedModelDefinition,
63+
TrainedModelInput input,
64+
Map<String, String> defaultFieldMap,
65+
InferenceConfig modelInferenceConfig,
66+
License.OperationMode licenseLevel,
67+
TrainedModelStatsService trainedModelStatsService,
68+
CircuitBreaker trainedModelCircuitBreaker) {
6969
this.trainedModelDefinition = trainedModelDefinition;
7070
this.modelId = modelId;
7171
this.fieldNames = new HashSet<>(input.getFieldNames());

0 commit comments

Comments
 (0)