Skip to content

Conversation

JeremyDahlgren
Copy link
Contributor

Addresses a second settings cleanup request comment from #133834, moving the settings merging and creation of a LinkedProjectConfig out of RemoteClusterService and into TransportReloadRemoteClusterCredentialsAction.
This is one step closer to eliminating the Settings based code in RemoteClusterService so it operates on LinkedProjectConfig objects only.

Resolves: ES-12864

Addresses a second settings cleanup request comment from
PR 133834, moving the settings merging and creation of
a LinkedProjectConfig out of RemoteClusterService and into
TransportReloadRemoteClusterCredentialsAction. This is one
step closer to eliminating the Settings based code in
RemoteClusterService so it operates on LinkedProjectConfig
objects only.

Resolves: ES-12864
@JeremyDahlgren JeremyDahlgren added :Distributed Coordination/Network Http and internode communication implementations >refactoring Team:Distributed Coordination Meta label for Distributed Coordination team v9.2.0 labels Sep 25, 2025
Comment on lines -306 to +319
public synchronized void updateRemoteClusterCredentials(Supplier<Settings> settingsSupplier, ActionListener<Void> listener) {
/**
* Rebuilds linked project connections as needed for updated remote cluster credentials.
* @param settingsSupplier A {@link Supplier} for the updated credentials {@link Settings}.
* @param configFunction A function that builds a {@link LinkedProjectConfig} for an alias, static settings, and new settings.
* @param listener An {@link ActionListener} invoked once all connection modifications have been completed.
*/
public synchronized void updateRemoteClusterCredentials(
Supplier<Settings> settingsSupplier,
TriFunction<String, Settings, Settings, LinkedProjectConfig> configFunction,
ActionListener<Void> listener
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not fond of the way this PR turned out. I think I would prefer moving the code in updateRemoteClusterCredentials() into TransportReloadRemoteClusterCredentialsAction, and have TransportReloadRemoteClusterCredentialsAction call RemoteClusterService. maybeRebuildConnectionOnCredentialsChange() with a LinkedProjectConfig as needed. We could add a getter on RemoteClusterService for the RemoteClusterCredentialsManager.

Yang's comment discusses using ClusterSettingsLinkedProjectConfigService, but we aren't aware of or have access to one, or a LinkedProjectConfigService here. I may be misunderstanding what he is suggesting to do here.

@n1v0lg @ywangd - thoughts?

Copy link
Contributor

@n1v0lg n1v0lg Sep 26, 2025

Choose a reason for hiding this comment

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

I haven't wrapped my head around this and what the cleanest approach here would be but in case this is useful:

We can easily expose LinkedProjectConfigService to TransportReloadRemoteClusterCredentialsAction by injecting it during node construction:

final var linkedProjectConfigService = pluginsService.loadSingletonServiceProvider(
    LinkedProjectConfigService.class,
    () -> new ClusterSettingsLinkedProjectConfigService(settings, clusterService.getClusterSettings(), projectResolver)
);

modules.bindToInstance(LinkedProjectConfigService.class, linkedProjectConfigService);

exposes it to all TransportActions:

@Inject
public TransportReloadRemoteClusterCredentialsAction(
    TransportService transportService,
    ClusterService clusterService,
    ActionFilters actionFilters,
    LinkedProjectConfigService linkedProjectConfigService
)

Copy link
Member

Choose a reason for hiding this comment

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

@JeremyDahlgren
My previous comment was indeed a bit vague. It took me a while to remember what I was thinking. 🤦 Sorry for the confusion.

My main point is to remove "settings usage for remote cluster config" as much as possible from RemoteClusterService since we now have the unified LinkedProjectConfig object. Hence I mostly like to see us removing maybeRebuildConnectionOnCredentialsChange from RemoteClusterService or at least it should not take Settings but instead LinkedProjectConfig as input.

For concrete changes:

  1. I think "add a getter on RemoteClusterService for the RemoteClusterCredentialsManager" seems a reasonable near term option. I assume this means we call RemoteClusterCredentialsManager#updateClusterCredentials within the transport action. Conceptually this makes sense since with the unified config object, RemoteClusterService should remove itself from dealing with these lower level updates and in long term, RemoteClusterCredentialsManager might need to be managed independently and injected to places. One thing to note is that this means the process of "updating credentials and rebuilding connection" will be performed in two synchronized blocks instead of one. It feels OK to me since clusterCredentials is updated as a volatile field and should not have any visible intermediate state.
  2. You are right that LinkedProjectConfigService is not accessible in RemoteClusterService. If we go with your suggestion of moving the logic to the transport action, we should be able to keep the code mostly as is exception in a different class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Coordination/Network Http and internode communication implementations >refactoring Team:Distributed Coordination Meta label for Distributed Coordination team v9.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants