Skip to content

Commit 3a10c99

Browse files
Use CrossProjectModeDecider in RemoteClusterService
Addresses a TODO in RemoteClusterService by using the CrossProjectModeDecider which handles the details of the settings lookup. This is the class used throughout the codebase now to test if CPS is enabled.
1 parent 8975f24 commit 3a10c99

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

server/src/main/java/org/elasticsearch/transport/RemoteClusterService.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.elasticsearch.core.TimeValue;
3434
import org.elasticsearch.indices.IndicesExpressionGrouper;
3535
import org.elasticsearch.node.ReportingService;
36+
import org.elasticsearch.search.crossproject.CrossProjectModeDecider;
3637

3738
import java.io.Closeable;
3839
import java.io.IOException;
@@ -80,7 +81,7 @@ public boolean isRemoteClusterServerEnabled() {
8081
private final Map<ProjectId, Map<String, RemoteClusterConnection>> remoteClusters;
8182
private final RemoteClusterCredentialsManager remoteClusterCredentialsManager;
8283
private final ProjectResolver projectResolver;
83-
private final boolean crossProjectEnabled;
84+
private final CrossProjectModeDecider crossProjectModeDecider;
8485

8586
RemoteClusterService(Settings settings, TransportService transportService, ProjectResolver projectResolver) {
8687
super(settings);
@@ -97,11 +98,7 @@ public boolean isRemoteClusterServerEnabled() {
9798
if (remoteClusterServerEnabled) {
9899
registerRemoteClusterHandshakeRequestHandler(transportService);
99100
}
100-
/*
101-
* TODO: This is not the right way to check if we're in CPS context and is more of a temporary measure since
102-
* the functionality to do it the right way is not yet ready -- replace this code when it's ready.
103-
*/
104-
this.crossProjectEnabled = settings.getAsBoolean("serverless.cross_project.enabled", false);
101+
this.crossProjectModeDecider = new CrossProjectModeDecider(settings);
105102
// Since this counter may never be incremented we need to force an initial observed value of zero via add(0) so the metric will be
106103
// in the mappings of the indices of the APM data stream, otherwise we will encounter 'not found' errors in dashboards and alerts.
107104
// See observability-dev issue #3042.
@@ -232,15 +229,15 @@ void ensureConnected(String clusterAlias, ActionListener<Void> listener) {
232229
* it returns an empty value where we default/fall back to true.
233230
*/
234231
public Optional<Boolean> isSkipUnavailable(String clusterAlias) {
235-
if (crossProjectEnabled) {
232+
if (crossProjectModeDecider.crossProjectEnabled()) {
236233
return Optional.empty();
237234
} else {
238235
return Optional.of(getRemoteClusterConnection(clusterAlias).isSkipUnavailable());
239236
}
240237
}
241238

242239
public boolean crossProjectEnabled() {
243-
return crossProjectEnabled;
240+
return crossProjectModeDecider.crossProjectEnabled();
244241
}
245242

246243
/**
@@ -368,6 +365,7 @@ public synchronized void updateRemoteCluster(
368365
boolean forceRebuild,
369366
ActionListener<RemoteClusterConnectionStatus> listener
370367
) {
368+
final var crossProjectEnabled = crossProjectModeDecider.crossProjectEnabled();
371369
final var projectId = config.originProjectId();
372370
final var clusterAlias = config.linkedProjectAlias();
373371
final var connectionMap = getConnectionsMapForProject(projectId);

0 commit comments

Comments
 (0)