Skip to content

Make IlmHealthIndicatorService work in multi-project cluster #129961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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<IndexMetadata> 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();
}
Expand Down Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to get your new 'not MP compatible' annotation?

I assume that adding an assertion runs into the same problems that we have in the other cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I just added the annotation.

I assume that adding an assertion runs into the same problems that we have in the other cases?

Adding the assertion would lead to similar problems. Since this is not a cluster state listener, the impact is far less, but we still call the health report here. Even though it's just one test/test suite, I'm still not very comfortable with the idea of trying to modify the big XPackRestIT or this test (we could retrieve a specific indicator rather than the full health report). The former is a larger effort and the latter reduces test coverage IMO.

return state.metadata().getProject(ProjectId.DEFAULT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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/*/*',
Expand Down