Skip to content

Make IndexTemplateRegistry project-aware #126986

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 10 commits into from
Apr 24, 2025

Conversation

nielsbauman
Copy link
Contributor

Ensures the IndexTemplatesRegistry installs resources in every project in the cluster.

ES-10055

Ensures the `IndexTemplatesRegistry` installs resources in every project
in the cluster.

ES-10055
@nielsbauman nielsbauman added >non-issue :Data Management/Indices APIs APIs to create and manage indices and templates Team:Data Management Meta label for data/management team v9.1.0 labels Apr 17, 2025
@nielsbauman nielsbauman requested a review from a team April 17, 2025 10:23
@nielsbauman nielsbauman requested review from a team as code owners April 17, 2025 10:23
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-data-management (Team:Data Management)

Copy link
Contributor

@consulthys consulthys left a comment

Choose a reason for hiding this comment

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

MonitoringTemplateRegistry changes LGT Stack Monitoring

@@ -573,30 +594,28 @@ public void onFailure(Exception e) {
},
(req, listener) -> client.execute(TransportPutComposableIndexTemplateAction.TYPE, req, listener)
);
});
};
projectResolver.executeOnProject(projectMetadata.id(), () -> executor.execute(runnable));
Copy link
Member

Choose a reason for hiding this comment

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

A thought: We use this pattern a few times — I think I can see five instances in this class. I wonder whether an overload of ProjectResolver.executeOnProject which takes an additional Executor argument would be a good idea? Then executor.execute(() -> ...) could be replaced by projectResolver.executeOnProject(projectMetadata.id(), executor, () -> ...). It would remove one level of nested lambdas from this code, which might be a bit more readable.

I guess one thing that slightly muddies the water is that this overload would probably want to take a plain Runnable rather than a CheckedRunnable<E>.

I'm not sure about this, what do you think?

Copy link
Contributor Author

@nielsbauman nielsbauman Apr 23, 2025

Choose a reason for hiding this comment

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

Hmm yeah I also thought about this for some time. We also have ProjectResolver#projectClient:

/**
* Returns a client that executes every request in the context of the given project.
*/
default Client projectClient(Client baseClient, ProjectId projectId) {
// We only take the shortcut when the given project ID matches the "current" project ID. If it doesn't, we'll let #executeOnProject
// take care of error handling.
if (supportsMultipleProjects() == false && projectId.equals(getProjectId())) {
return baseClient;
}
return new FilterClient(baseClient) {
@Override
protected <Request extends ActionRequest, Response extends ActionResponse> void doExecute(
ActionType<Response> action,
Request request,
ActionListener<Response> listener
) {
executeOnProject(projectId, () -> super.doExecute(action, request, listener));
}
};
}

which would be a good fit here, except that it creates a new client on every invocation, which feels very wasteful in this class, as there will be a lot of invocations - we created that method as a starting point with the plan to probably improve it sometime later.

I think I'll switch to use that method as it won't have any impact on stateful/single-project clusters. On MP clusters, it will make a difference, but it's more of an optimization - which is not the top priority right now.

Edit: done in 0889dc9

throws Exception {
assertBusy(() -> {
if (expectedTimes > 0) {
assertThat(calledTimesMap.size(), equalTo(event.state().metadata().projects().size()));
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Can we make a stronger assertion, that calledTimesMap.keySet() should contain exactly the IDs from event.state().metadata().projects()?

As well as being a stronger assertion, I think this would make it easier to see what this method is doing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! Done in 4efb382

@nielsbauman nielsbauman enabled auto-merge (squash) April 24, 2025 08:03
@nielsbauman nielsbauman merged commit ff1c9b7 into elastic:main Apr 24, 2025
18 checks passed
@nielsbauman nielsbauman deleted the mp-index-template-registry branch April 24, 2025 10:22
nielsbauman added a commit that referenced this pull request May 3, 2025
nielsbauman added a commit that referenced this pull request May 3, 2025
nielsbauman added a commit to nielsbauman/elasticsearch that referenced this pull request May 5, 2025
After the `IndexTemplateRegistry` was made project-aware in elastic#126986,
we were seeing timeouts of the MP version of the x-pack YAML test suite.
The original version has a timeout of 60 minutes but the MP-version
still had a timeout of 30 minutes. We've gotten away with that
difference because there are still tests on the blacklist for the MP
version, but now that we're making more and more features project-aware,
we need to align the timeout.
nielsbauman added a commit to nielsbauman/elasticsearch that referenced this pull request May 5, 2025
After the `IndexTemplateRegistry` was made project-aware in elastic#126986,
we were seeing timeouts of the MP version of the x-pack YAML test suite.
The original version has a timeout of 60 minutes but the MP-version
still had a timeout of 30 minutes. We've gotten away with that
difference because there are still tests on the blacklist for the MP
version, but now that we're making more and more features project-aware,
we need to align the timeout.

Fixes elastic#127433
nielsbauman added a commit that referenced this pull request May 6, 2025
After the `IndexTemplateRegistry` was made project-aware in #126986,
we were seeing timeouts of the MP version of the x-pack YAML test suite.
The original version has a timeout of 60 minutes but the MP-version
still had a timeout of 30 minutes. We've gotten away with that
difference because there are still tests on the blacklist for the MP
version, but now that we're making more and more features project-aware,
we need to align the timeout.

Fixes #127433
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Data Management/Indices APIs APIs to create and manage indices and templates >non-issue Team:Data Management Meta label for data/management team v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants