Skip to content

Commit dbc8d74

Browse files
authored
Make IlmHealthIndicatorService work in multi-project cluster (#129961)
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 1d3cab1 commit dbc8d74

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
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;
17+
import org.elasticsearch.core.NotMultiProjectCapable;
1418
import org.elasticsearch.core.TimeValue;
1519
import org.elasticsearch.health.Diagnosis;
1620
import org.elasticsearch.health.HealthIndicatorDetails;
@@ -210,7 +214,7 @@ public String name() {
210214

211215
@Override
212216
public HealthIndicatorResult calculate(boolean verbose, int maxAffectedResourcesCount, HealthInfo healthInfo) {
213-
final var projectMetadata = clusterService.state().metadata().getProject();
217+
final var projectMetadata = getDefaultILMProject(clusterService.state());
214218
var ilmMetadata = projectMetadata.custom(IndexLifecycleMetadata.TYPE, IndexLifecycleMetadata.EMPTY);
215219
final var currentMode = currentILMMode(projectMetadata);
216220
if (ilmMetadata.getPolicyMetadatas().isEmpty()) {
@@ -341,14 +345,13 @@ static class StagnatingIndicesFinder {
341345
* @return A list containing the ILM managed indices that are stagnated in any ILM action/step.
342346
*/
343347
public List<IndexMetadata> find() {
344-
var metadata = clusterService.state().metadata();
348+
final var project = getDefaultILMProject(clusterService.state());
345349
var now = nowSupplier.getAsLong();
346350

347-
return metadata.getProject()
348-
.indices()
351+
return project.indices()
349352
.values()
350353
.stream()
351-
.filter(metadata.getProject()::isIndexManagedByILM)
354+
.filter(project::isIndexManagedByILM)
352355
.filter(md -> isStagnated(rules, now, md))
353356
.toList();
354357
}
@@ -496,4 +499,13 @@ public boolean test(Long now, IndexMetadata indexMetadata) {
496499
|| (maxRetries != null && failedStepRetryCount != null && failedStepRetryCount > maxRetries));
497500
}
498501
}
502+
503+
/**
504+
* This method solely exists because we are not making ILM properly project-aware and it's not worth the investment of altering this
505+
* health indicator to be project-aware.
506+
*/
507+
@NotMultiProjectCapable
508+
private static ProjectMetadata getDefaultILMProject(ClusterState state) {
509+
return state.metadata().getProject(ProjectId.DEFAULT);
510+
}
499511
}

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
@@ -52,7 +52,6 @@ tasks.named("yamlRestTest").configure {
5252
'^cluster.desired_balance/10_basic/*',
5353
'^cluster.stats/10_basic/snapshot stats reported in get cluster stats',
5454
'^data_stream/40_supported_apis/Verify shard stores api', // uses _shard_stores API
55-
'^health/10_basic/*',
5655
'^indices.get_alias/10_basic/Get alias against closed indices', // Does NOT work with security enabled, see also core-rest-tests-with-security
5756
'^indices.recovery/*/*',
5857
'^indices.resolve_cluster/*/*',

0 commit comments

Comments
 (0)