Skip to content

Commit 17d7577

Browse files
committed
Make IlmHealthIndicatorService work in multi-project cluster
This does _not_ make the health indicator project-aware, it merely avoids exceptions in case there are multiple projects in the cluster. The health indicator would require significant refactoring to be made project-aware, which is not worth it since ILM will not be running in a multi-project context (i.e. serverless).
1 parent 0e23624 commit 17d7577

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IlmHealthIndicatorService.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
package org.elasticsearch.xpack.ilm;
99

10+
import org.elasticsearch.cluster.ClusterState;
1011
import org.elasticsearch.cluster.metadata.IndexMetadata;
12+
import org.elasticsearch.cluster.metadata.ProjectId;
13+
import org.elasticsearch.cluster.metadata.ProjectMetadata;
1114
import org.elasticsearch.cluster.service.ClusterService;
1215
import org.elasticsearch.common.settings.Setting;
1316
import org.elasticsearch.common.settings.Settings;
@@ -210,7 +213,7 @@ public String name() {
210213

211214
@Override
212215
public HealthIndicatorResult calculate(boolean verbose, int maxAffectedResourcesCount, HealthInfo healthInfo) {
213-
final var projectMetadata = clusterService.state().metadata().getProject();
216+
final var projectMetadata = getDefaultILMProject(clusterService.state());
214217
var ilmMetadata = projectMetadata.custom(IndexLifecycleMetadata.TYPE, IndexLifecycleMetadata.EMPTY);
215218
final var currentMode = currentILMMode(projectMetadata);
216219
if (ilmMetadata.getPolicyMetadatas().isEmpty()) {
@@ -341,14 +344,13 @@ static class StagnatingIndicesFinder {
341344
* @return A list containing the ILM managed indices that are stagnated in any ILM action/step.
342345
*/
343346
public List<IndexMetadata> find() {
344-
var metadata = clusterService.state().metadata();
347+
final var project = getDefaultILMProject(clusterService.state());
345348
var now = nowSupplier.getAsLong();
346349

347-
return metadata.getProject()
348-
.indices()
350+
return project.indices()
349351
.values()
350352
.stream()
351-
.filter(metadata.getProject()::isIndexManagedByILM)
353+
.filter(project::isIndexManagedByILM)
352354
.filter(md -> isStagnated(rules, now, md))
353355
.toList();
354356
}
@@ -496,4 +498,12 @@ public boolean test(Long now, IndexMetadata indexMetadata) {
496498
|| (maxRetries != null && failedStepRetryCount != null && failedStepRetryCount > maxRetries));
497499
}
498500
}
501+
502+
/**
503+
* This method solely exists because we are not making ILM properly project-aware and it's not worth the investment of altering this
504+
* health indicator to be project-aware.
505+
*/
506+
private static ProjectMetadata getDefaultILMProject(ClusterState state) {
507+
return state.metadata().getProject(ProjectId.DEFAULT);
508+
}
499509
}

x-pack/qa/multi-project/core-rest-tests-with-multiple-projects/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ tasks.named("yamlRestTest").configure {
5050
'^cat.snapshots/*/*',
5151
'^cluster.desired_balance/10_basic/*',
5252
'^data_stream/40_supported_apis/Verify shard stores api', // uses _shard_stores API
53-
'^health/10_basic/*',
5453
'^indices.get_alias/10_basic/Get alias against closed indices', // Does NOT work with security enabled, see also core-rest-tests-with-security
5554
'^indices.recovery/*/*',
5655
'^indices.resolve_cluster/*/*',

0 commit comments

Comments
 (0)