Skip to content

Commit d34c563

Browse files
authored
[ML] Avoid the .ml-stats index in post test cleanup (#116476)
Fixes ml yaml rest tests failing in the post clean up with a search_phase_execution_exception against the .ml-stats index. The fix is to use another method to find reference ingest pipelines avoid the call to _ml/trained_models/_stats
1 parent f121e09 commit d34c563

File tree

2 files changed

+21
-74
lines changed

2 files changed

+21
-74
lines changed

muted-tests.yml

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ tests:
1717
- class: org.elasticsearch.smoketest.WatcherYamlRestIT
1818
method: test {p0=watcher/usage/10_basic/Test watcher usage stats output}
1919
issue: https://github.com/elastic/elasticsearch/issues/112189
20-
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
21-
method: test {p0=ml/inference_processor/Test create processor with missing mandatory fields}
22-
issue: https://github.com/elastic/elasticsearch/issues/112191
2320
- class: org.elasticsearch.xpack.esql.action.ManyShardsIT
2421
method: testRejection
2522
issue: https://github.com/elastic/elasticsearch/issues/112406
@@ -142,9 +139,6 @@ tests:
142139
- class: org.elasticsearch.search.SearchServiceTests
143140
method: testParseSourceValidation
144141
issue: https://github.com/elastic/elasticsearch/issues/115936
145-
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
146-
method: test {p0=ml/inference_crud/Test delete given model referenced by pipeline}
147-
issue: https://github.com/elastic/elasticsearch/issues/115970
148142
- class: org.elasticsearch.index.reindex.ReindexNodeShutdownIT
149143
method: testReindexWithShutdown
150144
issue: https://github.com/elastic/elasticsearch/issues/115996
@@ -168,48 +162,27 @@ tests:
168162
- class: org.elasticsearch.xpack.ml.integration.DatafeedJobsRestIT
169163
method: testLookbackWithIndicesOptions
170164
issue: https://github.com/elastic/elasticsearch/issues/116127
171-
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
172-
method: test {p0=ml/inference_crud/Test delete given model with alias referenced by pipeline}
173-
issue: https://github.com/elastic/elasticsearch/issues/116133
174165
- class: org.elasticsearch.xpack.esql.qa.multi_node.EsqlSpecIT
175166
method: test {categorize.Categorize SYNC}
176167
issue: https://github.com/elastic/elasticsearch/issues/113054
177168
- class: org.elasticsearch.xpack.esql.qa.multi_node.EsqlSpecIT
178169
method: test {categorize.Categorize ASYNC}
179170
issue: https://github.com/elastic/elasticsearch/issues/113055
180-
- class: org.elasticsearch.xpack.inference.InferenceRestIT
181-
method: test {p0=inference/40_semantic_text_query/Query a field that uses the default ELSER 2 endpoint}
182-
issue: https://github.com/elastic/elasticsearch/issues/114376
183-
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
184-
method: test {p0=ml/inference_crud/Test force delete given model with alias referenced by pipeline}
185-
issue: https://github.com/elastic/elasticsearch/issues/116136
186171
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
187172
method: test {p0=transform/transforms_start_stop/Test start already started transform}
188173
issue: https://github.com/elastic/elasticsearch/issues/98802
189174
- class: org.elasticsearch.action.search.SearchPhaseControllerTests
190175
method: testProgressListener
191176
issue: https://github.com/elastic/elasticsearch/issues/116149
192-
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
193-
method: test {p0=ml/forecast/Test forecast unknown job}
194-
issue: https://github.com/elastic/elasticsearch/issues/116150
195177
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
196178
method: test {p0=terms_enum/10_basic/Test security}
197179
issue: https://github.com/elastic/elasticsearch/issues/116178
198180
- class: org.elasticsearch.search.basic.SearchWithRandomDisconnectsIT
199181
method: testSearchWithRandomDisconnects
200182
issue: https://github.com/elastic/elasticsearch/issues/116175
201-
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
202-
method: test {p0=ml/start_stop_datafeed/Test start datafeed given index pattern with no matching indices}
203-
issue: https://github.com/elastic/elasticsearch/issues/116220
204183
- class: org.elasticsearch.search.basic.SearchWhileRelocatingIT
205184
method: testSearchAndRelocateConcurrentlyRandomReplicas
206185
issue: https://github.com/elastic/elasticsearch/issues/116145
207-
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
208-
method: test {p0=ml/filter_crud/Test update filter}
209-
issue: https://github.com/elastic/elasticsearch/issues/116271
210-
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
211-
method: test {p0=ml/get_datafeeds/Test explicit get all datafeeds}
212-
issue: https://github.com/elastic/elasticsearch/issues/116284
213186
- class: org.elasticsearch.xpack.deprecation.DeprecationHttpIT
214187
method: testDeprecatedSettingsReturnWarnings
215188
issue: https://github.com/elastic/elasticsearch/issues/108628
@@ -231,24 +204,9 @@ tests:
231204
- class: org.elasticsearch.threadpool.SimpleThreadPoolIT
232205
method: testThreadPoolMetrics
233206
issue: https://github.com/elastic/elasticsearch/issues/108320
234-
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
235-
method: test {p0=ml/jobs_crud/Test put job deprecated bucket span}
236-
issue: https://github.com/elastic/elasticsearch/issues/116419
237-
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
238-
method: test {p0=ml/explain_data_frame_analytics/Test both job id and body}
239-
issue: https://github.com/elastic/elasticsearch/issues/116433
240-
- class: org.elasticsearch.smoketest.MlWithSecurityIT
241-
method: test {yaml=ml/inference_crud/Test force delete given model with alias referenced by pipeline}
242-
issue: https://github.com/elastic/elasticsearch/issues/116443
243207
- class: org.elasticsearch.xpack.downsample.ILMDownsampleDisruptionIT
244208
method: testILMDownsampleRollingRestart
245209
issue: https://github.com/elastic/elasticsearch/issues/114233
246-
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
247-
method: test {p0=ml/data_frame_analytics_crud/Test put config with unknown field in outlier detection analysis}
248-
issue: https://github.com/elastic/elasticsearch/issues/116458
249-
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
250-
method: test {p0=ml/evaluate_data_frame/Test outlier_detection with query}
251-
issue: https://github.com/elastic/elasticsearch/issues/116484
252210
- class: org.elasticsearch.xpack.kql.query.KqlQueryBuilderTests
253211
issue: https://github.com/elastic/elasticsearch/issues/116487
254212
- class: org.elasticsearch.reservedstate.service.FileSettingsServiceTests
@@ -263,12 +221,6 @@ tests:
263221
- class: org.elasticsearch.xpack.logsdb.qa.StandardVersusLogsIndexModeRandomDataDynamicMappingChallengeRestIT
264222
method: testMatchAllQuery
265223
issue: https://github.com/elastic/elasticsearch/issues/116536
266-
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
267-
method: test {p0=ml/inference_crud/Test force delete given model referenced by pipeline}
268-
issue: https://github.com/elastic/elasticsearch/issues/116555
269-
- class: org.elasticsearch.smoketest.MlWithSecurityIT
270-
method: test {yaml=ml/data_frame_analytics_crud/Test delete given stopped config}
271-
issue: https://github.com/elastic/elasticsearch/issues/116608
272224
- class: org.elasticsearch.xpack.esql.ccq.MultiClusterSpecIT
273225
method: test {categorize.Categorize}
274226
issue: https://github.com/elastic/elasticsearch/issues/116434
@@ -284,9 +236,6 @@ tests:
284236
- class: org.elasticsearch.packaging.test.BootstrapCheckTests
285237
method: test20RunWithBootstrapChecks
286238
issue: https://github.com/elastic/elasticsearch/issues/116620
287-
- class: org.elasticsearch.smoketest.MlWithSecurityIT
288-
method: test {yaml=ml/inference_crud/Test force delete given model referenced by pipeline}
289-
issue: https://github.com/elastic/elasticsearch/issues/116624
290239
- class: org.elasticsearch.packaging.test.DockerTests
291240
method: test011SecurityEnabledStatus
292241
issue: https://github.com/elastic/elasticsearch/issues/116628

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/integration/MlRestTestStateCleaner.java

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
import org.elasticsearch.client.Request;
1111
import org.elasticsearch.client.Response;
1212
import org.elasticsearch.client.RestClient;
13-
import org.elasticsearch.common.xcontent.support.XContentMapValues;
1413
import org.elasticsearch.test.rest.ESRestTestCase;
1514

1615
import java.io.IOException;
16+
import java.util.HashSet;
1717
import java.util.List;
1818
import java.util.Map;
19-
import java.util.Set;
20-
import java.util.stream.Collectors;
19+
20+
import static org.hamcrest.MatcherAssert.assertThat;
21+
import static org.hamcrest.Matchers.hasSize;
2122

2223
public class MlRestTestStateCleaner {
2324

@@ -30,37 +31,34 @@ public MlRestTestStateCleaner(Logger logger, RestClient adminClient) {
3031
}
3132

3233
public void resetFeatures() throws IOException {
33-
waitForMlStatsIndexToInitialize();
34-
deleteAllTrainedModelIngestPipelines();
34+
deletePipelinesWithInferenceProcessors();
3535
// This resets all features, not just ML, but they should have been getting reset between tests anyway so it shouldn't matter
3636
adminClient.performRequest(new Request("POST", "/_features/_reset"));
3737
}
3838

3939
@SuppressWarnings("unchecked")
40-
private void deleteAllTrainedModelIngestPipelines() throws IOException {
41-
final Request getAllTrainedModelStats = new Request("GET", "/_ml/trained_models/_stats");
42-
getAllTrainedModelStats.addParameter("size", "10000");
43-
final Response trainedModelsStatsResponse = adminClient.performRequest(getAllTrainedModelStats);
40+
private void deletePipelinesWithInferenceProcessors() throws IOException {
41+
final Response pipelinesResponse = adminClient.performRequest(new Request("GET", "/_ingest/pipeline"));
42+
final Map<String, Object> pipelines = ESRestTestCase.entityAsMap(pipelinesResponse);
43+
44+
var pipelinesWithInferenceProcessors = new HashSet<String>();
45+
for (var entry : pipelines.entrySet()) {
46+
var pipelineDef = (Map<String, Object>) entry.getValue(); // each top level object is a separate pipeline
47+
var processors = (List<Map<String, Object>>) pipelineDef.get("processors");
48+
for (var processor : processors) {
49+
assertThat(processor.entrySet(), hasSize(1));
50+
if ("inference".equals(processor.keySet().iterator().next())) {
51+
pipelinesWithInferenceProcessors.add(entry.getKey());
52+
}
53+
}
54+
}
4455

45-
final List<Map<String, Object>> pipelines = (List<Map<String, Object>>) XContentMapValues.extractValue(
46-
"trained_model_stats.ingest.pipelines",
47-
ESRestTestCase.entityAsMap(trainedModelsStatsResponse)
48-
);
49-
Set<String> pipelineIds = pipelines.stream().flatMap(m -> m.keySet().stream()).collect(Collectors.toSet());
50-
for (String pipelineId : pipelineIds) {
56+
for (String pipelineId : pipelinesWithInferenceProcessors) {
5157
try {
5258
adminClient.performRequest(new Request("DELETE", "/_ingest/pipeline/" + pipelineId));
5359
} catch (Exception ex) {
5460
logger.warn(() -> "failed to delete pipeline [" + pipelineId + "]", ex);
5561
}
5662
}
5763
}
58-
59-
private void waitForMlStatsIndexToInitialize() throws IOException {
60-
ESRestTestCase.ensureHealth(adminClient, ".ml-stats-*", (request) -> {
61-
request.addParameter("wait_for_no_initializing_shards", "true");
62-
request.addParameter("level", "shards");
63-
request.addParameter("timeout", "30s");
64-
});
65-
}
6664
}

0 commit comments

Comments
 (0)