-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add LinkedProjectConfigService
with ClusterSettings
implementation
#133834
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
JeremyDahlgren
merged 17 commits into
elastic:main
from
JeremyDahlgren:es-12730-linked-proj-cfg-svc-cluster-settings
Sep 9, 2025
Merged
Changes from 4 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
616359b
Add LinkedProjectConfigService with ClusterSettings implementation
JeremyDahlgren 2cc57b4
Merge branch 'main' into es-12730-linked-proj-cfg-svc-cluster-settings
JeremyDahlgren 033fbbb
Add test for ClusterSettings impl, add javadoc
JeremyDahlgren 26615d9
[CI] Auto commit changes from spotless
bc41d9a
Merge branch 'main' into es-12730-linked-proj-cfg-svc-cluster-settings
JeremyDahlgren ef7621a
Merge branch 'main' into es-12730-linked-proj-cfg-svc-cluster-settings
JeremyDahlgren 1dfc156
Merge branch 'main' into es-12730-linked-proj-cfg-svc-cluster-settings
JeremyDahlgren b24de49
Eliminate using LinkedProjectConfigService in RemoteClusterAware
JeremyDahlgren b5d40ff
Add FixForMultiProject annotations in ClusterSettingsLinkedProjectCon…
JeremyDahlgren d461715
Move LinkedProjectConfigService.NOOP to test code
JeremyDahlgren 0450941
Rename loadAllLinkedProjectConfigs() to getInitialLinkedProjectConfigs()
JeremyDahlgren 20861a3
Remove redundant legacy alias check
JeremyDahlgren 716d6b6
Add optional support for registering ClusterSettings update consumers
JeremyDahlgren d38a203
Merge branch 'main' into es-12730-linked-proj-cfg-svc-cluster-settings
JeremyDahlgren af28735
RemoteClusterAware implements LinkedProjectConfigListener
JeremyDahlgren e32fa12
Merge branch 'main' into es-12730-linked-proj-cfg-svc-cluster-settings
JeremyDahlgren 68fa0fd
Remove conditional creation of linkedProjectConfigService
JeremyDahlgren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
server/src/main/java/org/elasticsearch/transport/AbstractLinkedProjectConfigService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.transport; | ||
|
||
import org.elasticsearch.cluster.metadata.ProjectId; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
|
||
/** | ||
* Abstract base class for {@link LinkedProjectConfigService} implementations. | ||
* Provides common functionality for managing a list of registered listeners and notifying them of updates. | ||
*/ | ||
public abstract class AbstractLinkedProjectConfigService implements LinkedProjectConfigService { | ||
private final List<LinkedProjectConfigListener> listeners = new CopyOnWriteArrayList<>(); | ||
|
||
@Override | ||
public void register(LinkedProjectConfigListener listener) { | ||
listeners.add(listener); | ||
} | ||
|
||
protected void handleUpdate(LinkedProjectConfig config) { | ||
listeners.forEach(listener -> listener.updateLinkedProject(config)); | ||
} | ||
|
||
protected void handleSkipUnavailableChanged( | ||
ProjectId originProjectId, | ||
ProjectId linkedProjectId, | ||
String linkedProjectAlias, | ||
boolean skipUnavailable | ||
) { | ||
listeners.forEach( | ||
listener -> listener.skipUnavailableChanged(originProjectId, linkedProjectId, linkedProjectAlias, skipUnavailable) | ||
); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
.../src/main/java/org/elasticsearch/transport/ClusterSettingsLinkedProjectConfigService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.transport; | ||
|
||
import org.elasticsearch.cluster.metadata.ProjectId; | ||
import org.elasticsearch.cluster.project.ProjectResolver; | ||
import org.elasticsearch.common.settings.ClusterSettings; | ||
import org.elasticsearch.common.settings.Setting; | ||
import org.elasticsearch.common.settings.Settings; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
/** | ||
* A {@link LinkedProjectConfigService} implementation that listens for {@link ClusterSettings} changes, | ||
* creating {@link LinkedProjectConfig}s from the relevant settings and notifying registered listeners of updates. | ||
*/ | ||
public class ClusterSettingsLinkedProjectConfigService extends AbstractLinkedProjectConfigService { | ||
private final Settings settings; | ||
private final ProjectResolver projectResolver; | ||
|
||
@SuppressWarnings("this-escape") | ||
public ClusterSettingsLinkedProjectConfigService(Settings settings, ClusterSettings clusterSettings, ProjectResolver projectResolver) { | ||
this.settings = settings; | ||
this.projectResolver = projectResolver; | ||
List<Setting.AffixSetting<?>> remoteClusterSettings = List.of( | ||
RemoteClusterSettings.REMOTE_CLUSTER_COMPRESS, | ||
RemoteClusterSettings.REMOTE_CLUSTER_PING_SCHEDULE, | ||
RemoteClusterSettings.REMOTE_CONNECTION_MODE, | ||
RemoteClusterSettings.SniffConnectionStrategySettings.REMOTE_CLUSTERS_PROXY, | ||
RemoteClusterSettings.SniffConnectionStrategySettings.REMOTE_CLUSTER_SEEDS, | ||
RemoteClusterSettings.SniffConnectionStrategySettings.REMOTE_NODE_CONNECTIONS, | ||
RemoteClusterSettings.ProxyConnectionStrategySettings.PROXY_ADDRESS, | ||
RemoteClusterSettings.ProxyConnectionStrategySettings.REMOTE_SOCKET_CONNECTIONS, | ||
RemoteClusterSettings.ProxyConnectionStrategySettings.SERVER_NAME | ||
); | ||
clusterSettings.addAffixGroupUpdateConsumer(remoteClusterSettings, this::settingsChangedCallback); | ||
clusterSettings.addAffixUpdateConsumer( | ||
RemoteClusterSettings.REMOTE_CLUSTER_SKIP_UNAVAILABLE, | ||
this::skipUnavailableChangedCallback, | ||
(alias, value) -> {} | ||
); | ||
} | ||
|
||
@Override | ||
public Collection<LinkedProjectConfig> loadAllLinkedProjectConfigs() { | ||
return RemoteClusterSettings.getRemoteClusters(settings) | ||
.stream() | ||
.map(alias -> RemoteClusterSettings.toConfig(projectResolver.getProjectId(), ProjectId.DEFAULT, alias, settings)) | ||
.toList(); | ||
} | ||
|
||
private void settingsChangedCallback(String clusterAlias, Settings newSettings) { | ||
final var mergedSettings = Settings.builder().put(settings, false).put(newSettings, false).build(); | ||
final var config = RemoteClusterSettings.toConfig(projectResolver.getProjectId(), ProjectId.DEFAULT, clusterAlias, mergedSettings); | ||
handleUpdate(config); | ||
} | ||
|
||
private void skipUnavailableChangedCallback(String clusterAlias, Boolean skipUnavailable) { | ||
handleSkipUnavailableChanged(projectResolver.getProjectId(), ProjectId.DEFAULT, clusterAlias, skipUnavailable); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
server/src/main/java/org/elasticsearch/transport/LinkedProjectConfigService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.transport; | ||
|
||
import org.elasticsearch.cluster.metadata.ProjectId; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
/** | ||
* Service for registering {@link LinkedProjectConfigListener}s to be notified of changes to linked project configurations. | ||
*/ | ||
public interface LinkedProjectConfigService { | ||
|
||
/** | ||
* Listener interface for receiving updates about linked project configurations. | ||
* Implementations must not throw from any of the interface methods. | ||
*/ | ||
interface LinkedProjectConfigListener { | ||
/** | ||
* Called when a linked project configuration has been added or updated. | ||
* | ||
* @param config The updated {@link LinkedProjectConfig}. | ||
*/ | ||
void updateLinkedProject(LinkedProjectConfig config); | ||
|
||
/** | ||
* Called when the boolean skip_unavailable setting has changed for a linked project configuration. | ||
* Note that skip_unavailable may not be supported in all contexts where linked projects are used. | ||
* | ||
* @param originProjectId The {@link ProjectId} of the owning project that has the linked project configuration. | ||
* @param linkedProjectId The {@link ProjectId} of the linked project. | ||
* @param linkedProjectAlias The alias used for the linked project. | ||
* @param skipUnavailable The new value of the skip_unavailable setting. | ||
*/ | ||
default void skipUnavailableChanged( | ||
ProjectId originProjectId, | ||
ProjectId linkedProjectId, | ||
String linkedProjectAlias, | ||
boolean skipUnavailable | ||
) {} | ||
} | ||
|
||
/** | ||
* Registers a {@link LinkedProjectConfigListener} to receive updates about linked project configurations. | ||
* | ||
* @param listener The listener to register. | ||
*/ | ||
void register(LinkedProjectConfigListener listener); | ||
|
||
/** | ||
* Loads all existing linked project configurations for all origin projects. | ||
* | ||
* @return A collection of all existing {@link LinkedProjectConfig}s. | ||
*/ | ||
Collection<LinkedProjectConfig> loadAllLinkedProjectConfigs(); | ||
JeremyDahlgren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
/** | ||
* A no-op stub implementation of {@link LinkedProjectConfigService} intended for use in test scenarios where linked project | ||
* configuration updates are not needed. | ||
*/ | ||
LinkedProjectConfigService NOOP = new LinkedProjectConfigService() { | ||
ywangd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
@Override | ||
public void register(LinkedProjectConfigListener listener) {} | ||
|
||
@Override | ||
public Collection<LinkedProjectConfig> loadAllLinkedProjectConfigs() { | ||
return Collections.emptyList(); | ||
} | ||
}; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.