diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IlmHealthIndicatorService.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IlmHealthIndicatorService.java index 21c9999a7bd88..affda6a95e6e7 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IlmHealthIndicatorService.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IlmHealthIndicatorService.java @@ -7,10 +7,14 @@ package org.elasticsearch.xpack.ilm; +import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; +import org.elasticsearch.cluster.metadata.ProjectId; +import org.elasticsearch.cluster.metadata.ProjectMetadata; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.core.NotMultiProjectCapable; import org.elasticsearch.core.TimeValue; import org.elasticsearch.health.Diagnosis; import org.elasticsearch.health.HealthIndicatorDetails; @@ -210,7 +214,7 @@ public String name() { @Override public HealthIndicatorResult calculate(boolean verbose, int maxAffectedResourcesCount, HealthInfo healthInfo) { - final var projectMetadata = clusterService.state().metadata().getProject(); + final var projectMetadata = getDefaultILMProject(clusterService.state()); var ilmMetadata = projectMetadata.custom(IndexLifecycleMetadata.TYPE, IndexLifecycleMetadata.EMPTY); final var currentMode = currentILMMode(projectMetadata); if (ilmMetadata.getPolicyMetadatas().isEmpty()) { @@ -341,14 +345,13 @@ static class StagnatingIndicesFinder { * @return A list containing the ILM managed indices that are stagnated in any ILM action/step. */ public List find() { - var metadata = clusterService.state().metadata(); + final var project = getDefaultILMProject(clusterService.state()); var now = nowSupplier.getAsLong(); - return metadata.getProject() - .indices() + return project.indices() .values() .stream() - .filter(metadata.getProject()::isIndexManagedByILM) + .filter(project::isIndexManagedByILM) .filter(md -> isStagnated(rules, now, md)) .toList(); } @@ -496,4 +499,13 @@ public boolean test(Long now, IndexMetadata indexMetadata) { || (maxRetries != null && failedStepRetryCount != null && failedStepRetryCount > maxRetries)); } } + + /** + * This method solely exists because we are not making ILM properly project-aware and it's not worth the investment of altering this + * health indicator to be project-aware. + */ + @NotMultiProjectCapable + private static ProjectMetadata getDefaultILMProject(ClusterState state) { + return state.metadata().getProject(ProjectId.DEFAULT); + } } diff --git a/x-pack/qa/multi-project/core-rest-tests-with-multiple-projects/build.gradle b/x-pack/qa/multi-project/core-rest-tests-with-multiple-projects/build.gradle index f064c97ff296e..2d33cccb00bee 100644 --- a/x-pack/qa/multi-project/core-rest-tests-with-multiple-projects/build.gradle +++ b/x-pack/qa/multi-project/core-rest-tests-with-multiple-projects/build.gradle @@ -52,7 +52,6 @@ tasks.named("yamlRestTest").configure { '^cluster.desired_balance/10_basic/*', '^cluster.stats/10_basic/snapshot stats reported in get cluster stats', '^data_stream/40_supported_apis/Verify shard stores api', // uses _shard_stores API - '^health/10_basic/*', '^indices.get_alias/10_basic/Get alias against closed indices', // Does NOT work with security enabled, see also core-rest-tests-with-security '^indices.recovery/*/*', '^indices.resolve_cluster/*/*',