From 434bb0a554e6bf81f3ce43c9335a596d793a50a6 Mon Sep 17 00:00:00 2001 From: gmarouli Date: Fri, 31 Oct 2025 09:00:12 +0200 Subject: [PATCH 1/6] Fix: ILMDownsampleDisruptionIT.testILMDownsampleRollingRestart --- muted-tests.yml | 3 --- .../downsample/ILMDownsampleDisruptionIT.java | 23 +++++++++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/muted-tests.yml b/muted-tests.yml index 05235d19eba24..e339bdd519881 100644 --- a/muted-tests.yml +++ b/muted-tests.yml @@ -510,9 +510,6 @@ tests: - class: org.elasticsearch.xpack.security.CoreWithSecurityClientYamlTestSuiteIT method: test {yaml=indices.validate_query/20_query_string/validate_query with query_string parameters} issue: https://github.com/elastic/elasticsearch/issues/137391 -- class: org.elasticsearch.xpack.downsample.ILMDownsampleDisruptionIT - method: testILMDownsampleRollingRestart - issue: https://github.com/elastic/elasticsearch/issues/136585 # Examples: # diff --git a/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java b/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java index c31d537379f35..f107e7db2c8ac 100644 --- a/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java +++ b/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java @@ -25,15 +25,19 @@ import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.InternalTestCluster; -import org.elasticsearch.test.junit.annotations.TestIssueLogging; import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentFactory; import org.elasticsearch.xpack.aggregatemetric.AggregateMetricMapperPlugin; import org.elasticsearch.xpack.ccr.Ccr; import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin; +import org.elasticsearch.xpack.core.ilm.ExplainLifecycleRequest; +import org.elasticsearch.xpack.core.ilm.ExplainLifecycleResponse; +import org.elasticsearch.xpack.core.ilm.IndexLifecycleExplainResponse; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.Phase; +import org.elasticsearch.xpack.core.ilm.PhaseCompleteStep; +import org.elasticsearch.xpack.core.ilm.action.ExplainLifecycleAction; import org.elasticsearch.xpack.core.ilm.action.ILMActions; import org.elasticsearch.xpack.core.ilm.action.PutLifecycleRequest; import org.elasticsearch.xpack.ilm.IndexLifecycle; @@ -57,6 +61,7 @@ import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.xpack.core.rollup.ConfigTestHelpers.randomInterval; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.notNullValue; @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, numClientNodes = 4) public class ILMDownsampleDisruptionIT extends DownsamplingIntegTestCase { @@ -130,10 +135,6 @@ public void setup(final String sourceIndex, int numOfShards, int numOfReplicas, assertAcked(client().execute(ILMActions.PUT, putLifecycleRequest).actionGet()); } - @TestIssueLogging( - value = "org.elasticsearch.cluster.service.MasterService:TRACE", - issueUrl = "https://github.com/elastic/elasticsearch/issues/136585" - ) public void testILMDownsampleRollingRestart() throws Exception { final InternalTestCluster cluster = internalCluster(); cluster.startMasterOnlyNodes(1); @@ -172,6 +173,18 @@ public void testILMDownsampleRollingRestart() throws Exception { startDownsampleTaskViaIlm(sourceIndex, targetIndex); assertBusy(() -> assertTargetIndex(cluster, targetIndex, indexedDocs)); ensureGreen(targetIndex); + // We assert that ILM to successfully completed the phase + assertBusy(() -> { + ExplainLifecycleResponse explainLifecycleResponse = safeGet( + client().execute( + ExplainLifecycleAction.INSTANCE, + new ExplainLifecycleRequest(TimeValue.THIRTY_SECONDS).indices(targetIndex) + ) + ); + IndexLifecycleExplainResponse ilmExplain = explainLifecycleResponse.getIndexResponses().get(targetIndex); + assertThat(ilmExplain, notNullValue()); + assertThat(ilmExplain.getStep(), equalTo(PhaseCompleteStep.NAME)); + }, 60, TimeUnit.SECONDS); } private void startDownsampleTaskViaIlm(String sourceIndex, String targetIndex) throws Exception { From ebd8b9e0824eb39896cba55248670351ce231696 Mon Sep 17 00:00:00 2001 From: gmarouli Date: Fri, 31 Oct 2025 11:14:10 +0200 Subject: [PATCH 2/6] Use a `addTemporaryStateListener` to reduce the wait time. --- .../downsample/ILMDownsampleDisruptionIT.java | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java b/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java index f107e7db2c8ac..0c69300985089 100644 --- a/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java +++ b/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java @@ -14,6 +14,7 @@ import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest; import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest; import org.elasticsearch.action.downsample.DownsampleConfig; +import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.core.TimeValue; @@ -23,6 +24,7 @@ import org.elasticsearch.index.query.MatchAllQueryBuilder; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; +import org.elasticsearch.test.ClusterServiceUtils; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.InternalTestCluster; import org.elasticsearch.xcontent.XContentBuilder; @@ -30,14 +32,10 @@ import org.elasticsearch.xpack.aggregatemetric.AggregateMetricMapperPlugin; import org.elasticsearch.xpack.ccr.Ccr; import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin; -import org.elasticsearch.xpack.core.ilm.ExplainLifecycleRequest; -import org.elasticsearch.xpack.core.ilm.ExplainLifecycleResponse; -import org.elasticsearch.xpack.core.ilm.IndexLifecycleExplainResponse; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.Phase; import org.elasticsearch.xpack.core.ilm.PhaseCompleteStep; -import org.elasticsearch.xpack.core.ilm.action.ExplainLifecycleAction; import org.elasticsearch.xpack.core.ilm.action.ILMActions; import org.elasticsearch.xpack.core.ilm.action.PutLifecycleRequest; import org.elasticsearch.xpack.ilm.IndexLifecycle; @@ -52,7 +50,9 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; import static org.elasticsearch.core.Strings.format; @@ -173,18 +173,14 @@ public void testILMDownsampleRollingRestart() throws Exception { startDownsampleTaskViaIlm(sourceIndex, targetIndex); assertBusy(() -> assertTargetIndex(cluster, targetIndex, indexedDocs)); ensureGreen(targetIndex); - // We assert that ILM to successfully completed the phase - assertBusy(() -> { - ExplainLifecycleResponse explainLifecycleResponse = safeGet( - client().execute( - ExplainLifecycleAction.INSTANCE, - new ExplainLifecycleRequest(TimeValue.THIRTY_SECONDS).indices(targetIndex) - ) - ); - IndexLifecycleExplainResponse ilmExplain = explainLifecycleResponse.getIndexResponses().get(targetIndex); - assertThat(ilmExplain, notNullValue()); - assertThat(ilmExplain.getStep(), equalTo(PhaseCompleteStep.NAME)); - }, 60, TimeUnit.SECONDS); + // We assert that ILM successfully completed the phase + logger.info("Waiting for ILM to complete the phase for index [{}]", targetIndex); + ClusterServiceUtils.addTemporaryStateListener(clusterState -> { + IndexMetadata indexMetadata = getIndexMetadataByIndexName(clusterState, targetIndex); + // We expect a single project available in this cluster + return indexMetadata.getLifecycleExecutionState() != null + && Objects.equals(indexMetadata.getLifecycleExecutionState().step(), PhaseCompleteStep.NAME); + }); } private void startDownsampleTaskViaIlm(String sourceIndex, String targetIndex) throws Exception { @@ -233,4 +229,19 @@ private void assertTargetIndex(final InternalTestCluster cluster, final String t } ); } + + /** + * We assume the index exists and its index name is unique. + * @return the index metadata found in any project that contains an index with this name. + */ + private IndexMetadata getIndexMetadataByIndexName(ClusterState clusterState, String indexName) { + AtomicReference indexMetadata = new AtomicReference<>(); + clusterState.forEachProject(projectState -> { + if (projectState.metadata().hasIndex(indexName)) { + indexMetadata.set(projectState.metadata().index(indexName)); + } + }); + assertThat(indexMetadata.get(), notNullValue()); + return indexMetadata.get(); + } } From 432f2c5737a854818a7962c7af10bcdb23766b67 Mon Sep 17 00:00:00 2001 From: gmarouli Date: Fri, 31 Oct 2025 11:38:02 +0200 Subject: [PATCH 3/6] Remove project aware code --- .../downsample/ILMDownsampleDisruptionIT.java | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java b/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java index 0c69300985089..fbdadf31cae63 100644 --- a/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java +++ b/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java @@ -176,8 +176,7 @@ public void testILMDownsampleRollingRestart() throws Exception { // We assert that ILM successfully completed the phase logger.info("Waiting for ILM to complete the phase for index [{}]", targetIndex); ClusterServiceUtils.addTemporaryStateListener(clusterState -> { - IndexMetadata indexMetadata = getIndexMetadataByIndexName(clusterState, targetIndex); - // We expect a single project available in this cluster + IndexMetadata indexMetadata = clusterState.metadata().getProject().index(targetIndex); return indexMetadata.getLifecycleExecutionState() != null && Objects.equals(indexMetadata.getLifecycleExecutionState().step(), PhaseCompleteStep.NAME); }); @@ -229,19 +228,4 @@ private void assertTargetIndex(final InternalTestCluster cluster, final String t } ); } - - /** - * We assume the index exists and its index name is unique. - * @return the index metadata found in any project that contains an index with this name. - */ - private IndexMetadata getIndexMetadataByIndexName(ClusterState clusterState, String indexName) { - AtomicReference indexMetadata = new AtomicReference<>(); - clusterState.forEachProject(projectState -> { - if (projectState.metadata().hasIndex(indexName)) { - indexMetadata.set(projectState.metadata().index(indexName)); - } - }); - assertThat(indexMetadata.get(), notNullValue()); - return indexMetadata.get(); - } } From 40372365d7584bd8f81411420afefefd5290d05b Mon Sep 17 00:00:00 2001 From: elasticsearchmachine Date: Fri, 31 Oct 2025 09:44:53 +0000 Subject: [PATCH 4/6] [CI] Auto commit changes from spotless --- .../xpack/downsample/ILMDownsampleDisruptionIT.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java b/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java index fbdadf31cae63..8ae7602c06c86 100644 --- a/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java +++ b/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java @@ -14,7 +14,6 @@ import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest; import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest; import org.elasticsearch.action.downsample.DownsampleConfig; -import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.core.TimeValue; @@ -52,7 +51,6 @@ import java.util.Map; import java.util.Objects; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; import static org.elasticsearch.core.Strings.format; @@ -61,7 +59,6 @@ import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.xpack.core.rollup.ConfigTestHelpers.randomInterval; import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.notNullValue; @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, numClientNodes = 4) public class ILMDownsampleDisruptionIT extends DownsamplingIntegTestCase { From 5bbc396c751d5d7034c5008535a832cc7d63da8e Mon Sep 17 00:00:00 2001 From: gmarouli Date: Fri, 31 Oct 2025 11:53:47 +0200 Subject: [PATCH 5/6] Actually wait for the listener to complete :) --- .../xpack/downsample/ILMDownsampleDisruptionIT.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java b/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java index 8ae7602c06c86..bacd4b646b602 100644 --- a/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java +++ b/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java @@ -23,7 +23,6 @@ import org.elasticsearch.index.query.MatchAllQueryBuilder; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; -import org.elasticsearch.test.ClusterServiceUtils; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.InternalTestCluster; import org.elasticsearch.xcontent.XContentBuilder; @@ -172,7 +171,7 @@ public void testILMDownsampleRollingRestart() throws Exception { ensureGreen(targetIndex); // We assert that ILM successfully completed the phase logger.info("Waiting for ILM to complete the phase for index [{}]", targetIndex); - ClusterServiceUtils.addTemporaryStateListener(clusterState -> { + awaitClusterState(clusterState -> { IndexMetadata indexMetadata = clusterState.metadata().getProject().index(targetIndex); return indexMetadata.getLifecycleExecutionState() != null && Objects.equals(indexMetadata.getLifecycleExecutionState().step(), PhaseCompleteStep.NAME); From 5b8e5035524fac290e359e03e2c6911d7b64215a Mon Sep 17 00:00:00 2001 From: Mary Gouseti Date: Fri, 31 Oct 2025 12:40:00 +0200 Subject: [PATCH 6/6] Update x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java Co-authored-by: David Turner --- .../xpack/downsample/ILMDownsampleDisruptionIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java b/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java index bacd4b646b602..770c43b9a57d6 100644 --- a/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java +++ b/x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/ILMDownsampleDisruptionIT.java @@ -169,7 +169,7 @@ public void testILMDownsampleRollingRestart() throws Exception { startDownsampleTaskViaIlm(sourceIndex, targetIndex); assertBusy(() -> assertTargetIndex(cluster, targetIndex, indexedDocs)); ensureGreen(targetIndex); - // We assert that ILM successfully completed the phase + // We wait for ILM to successfully complete the phase logger.info("Waiting for ILM to complete the phase for index [{}]", targetIndex); awaitClusterState(clusterState -> { IndexMetadata indexMetadata = clusterState.metadata().getProject().index(targetIndex);