-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Consolidate settings consumers for RemoteClusterService
#135722
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 15 commits into
elastic:main
from
JeremyDahlgren:es-12860-refactor-skip-unavailable-updates
Oct 9, 2025
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5251826
Consolidate settings consumers for RemoteClusterService
JeremyDahlgren 23d3ec6
Merge branch 'main' into es-12860-refactor-skip-unavailable-updates
JeremyDahlgren be18795
Merge branch 'main' into es-12860-refactor-skip-unavailable-updates
JeremyDahlgren ae572d6
Add UPDATED response, adjust logic per code review
JeremyDahlgren 79ebe33
Merge branch 'main' into es-12860-refactor-skip-unavailable-updates
JeremyDahlgren 71646cd
Merge branch 'main' into es-12860-refactor-skip-unavailable-updates
JeremyDahlgren 69a272c
Merge branch 'main' into es-12860-refactor-skip-unavailable-updates
JeremyDahlgren 491f669
Merge branch 'main' into es-12860-refactor-skip-unavailable-updates
JeremyDahlgren 77400bc
Merge branch 'main' into es-12860-refactor-skip-unavailable-updates
JeremyDahlgren 80d0d0e
enhance test to check if connection object is same instance
JeremyDahlgren 1650973
Merge branch 'main' into es-12860-refactor-skip-unavailable-updates
JeremyDahlgren 13dab04
Merge branch 'main' into es-12860-refactor-skip-unavailable-updates
JeremyDahlgren 617f3b6
Merge branch 'main' into es-12860-refactor-skip-unavailable-updates
JeremyDahlgren f976d88
Merge branch 'main' into es-12860-refactor-skip-unavailable-updates
JeremyDahlgren d795a86
Merge branch 'main' into es-12860-refactor-skip-unavailable-updates
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ | |
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import java.util.function.BiFunction; | ||
import java.util.function.Consumer; | ||
|
||
import static org.elasticsearch.test.MockLog.assertThatLogger; | ||
import static org.elasticsearch.test.NodeRoles.masterOnlyNode; | ||
|
@@ -112,6 +113,10 @@ private MockTransportService startTransport( | |
return RemoteClusterConnectionTests.startTransport(id, knownNodes, version, transportVersion, threadPool, settings); | ||
} | ||
|
||
private MockTransportService startTransport(final String id) { | ||
return startTransport(id, List.of(), VersionInformation.CURRENT, TransportVersion.current(), Settings.EMPTY); | ||
} | ||
|
||
public void testSettingsAreRegistered() { | ||
assertTrue(ClusterSettings.BUILT_IN_CLUSTER_SETTINGS.contains(RemoteClusterSettings.REMOTE_CLUSTER_SKIP_UNAVAILABLE)); | ||
assertTrue(ClusterSettings.BUILT_IN_CLUSTER_SETTINGS.contains(RemoteClusterSettings.REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING)); | ||
|
@@ -1877,6 +1882,61 @@ public void testLogsConnectionResult() throws IOException { | |
} | ||
} | ||
|
||
public void testSetSkipUnavailable() throws IOException { | ||
final var skipUnavailableProperty = RemoteClusterSettings.REMOTE_CLUSTER_SKIP_UNAVAILABLE.getConcreteSettingForNamespace("remote") | ||
.getKey(); | ||
final var seedNodeProperty = SniffConnectionStrategySettings.REMOTE_CLUSTER_SEEDS.getConcreteSettingForNamespace("remote").getKey(); | ||
final var clusterSettings = ClusterSettings.createBuiltInClusterSettings(); | ||
|
||
try ( | ||
var remote1Transport = startTransport("remote1"); | ||
var remote2Transport = startTransport("remote2"); | ||
var local = startTransport("local"); | ||
var remoteClusterService = createRemoteClusterService(Settings.EMPTY, clusterSettings, local) | ||
) { | ||
linkedProjectConfigService.register(remoteClusterService); | ||
|
||
record SkipUnavailableTestConfig( | ||
boolean skipUnavailable, | ||
MockTransportService seedNodeTransportService, | ||
boolean isNewConnection, | ||
boolean rebuildExpected | ||
) {} | ||
|
||
final Consumer<SkipUnavailableTestConfig> applySettingsAndVerify = (cfg) -> { | ||
final var currentConnection = cfg.isNewConnection ? null : remoteClusterService.getRemoteClusterConnection("remote"); | ||
clusterSettings.applySettings( | ||
Settings.builder() | ||
.put(skipUnavailableProperty, cfg.skipUnavailable) | ||
.put(seedNodeProperty, cfg.seedNodeTransportService.getLocalNode().getAddress().toString()) | ||
.build() | ||
); | ||
assertTrue(isRemoteClusterRegistered(remoteClusterService, "remote")); | ||
assertEquals(cfg.skipUnavailable, remoteClusterService.isSkipUnavailable("remote").orElseThrow()); | ||
if (cfg.rebuildExpected) { | ||
assertNotSame(currentConnection, remoteClusterService.getRemoteClusterConnection("remote")); | ||
} else if (cfg.isNewConnection == false) { | ||
assertSame(currentConnection, remoteClusterService.getRemoteClusterConnection("remote")); | ||
} | ||
}; | ||
|
||
// Apply the initial settings and verify the new connection is built. | ||
var skipUnavailable = randomBoolean(); | ||
applySettingsAndVerify.accept(new SkipUnavailableTestConfig(skipUnavailable, remote1Transport, true, true)); | ||
|
||
// Change skip_unavailable value, but not seed node, connection should not be rebuilt, but skip_unavailable should be modified. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be great to somehow assert that the connection is the same instance, i.e. no rebuilding. |
||
skipUnavailable = skipUnavailable == false; | ||
applySettingsAndVerify.accept(new SkipUnavailableTestConfig(skipUnavailable, remote1Transport, false, false)); | ||
|
||
// Change the seed node but not skip_unavailable, connection should be rebuilt and skip_unavailable should stay the same. | ||
applySettingsAndVerify.accept(new SkipUnavailableTestConfig(skipUnavailable, remote2Transport, false, true)); | ||
|
||
// Change skip_unavailable value and the seed node, connection should be rebuilt and skip_unavailable should also be modified. | ||
skipUnavailable = skipUnavailable == false; | ||
applySettingsAndVerify.accept(new SkipUnavailableTestConfig(skipUnavailable, remote1Transport, false, true)); | ||
} | ||
} | ||
|
||
@FixForMultiProject(description = "Refactor to add the linked project ID associated with the alias.") | ||
private LinkedProjectConfig buildLinkedProjectConfig(String alias, Settings staticSettings, Settings newSettings) { | ||
final var mergedSettings = Settings.builder().put(staticSettings, false).put(newSettings, false).build(); | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a little odd that we report
UNCHANGED
whenskipUnavailable
changes. It might be useful to add a new enum such asUPDATED
for updating properties on existing connection.