Skip to content

Commit

Permalink
Correctly read compatibility mode from cluster settings when it was u…
Browse files Browse the repository at this point in the history
…nset

Signed-off-by: Jugal Chauhan <[email protected]>
  • Loading branch information
jugal-chauhan authored Jan 17, 2025
1 parent a980069 commit 4d369c1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void testRepoRegisterAndSnapshotCreateRequests() throws Exception {
fl -> {
if (Objects.equals(fl.uri(), "/")) {
return new SimpleHttpResponse(ROOT_RESPONSE_HEADERS, ROOT_RESPONSE_ES_7_10_2, "OK", 200);
} else if (Objects.equals(fl.uri(), "/_cluster/settings")) {
} else if (Objects.equals(fl.uri(), "/_cluster/settings?include_defaults=true")) {
return new SimpleHttpResponse(CLUSTER_SETTINGS_COMPATIBILITY_HEADERS, CLUSTER_SETTINGS_COMPATIBILITY_OVERRIDE_DISABLED,
"OK", 200);
}
Expand Down Expand Up @@ -136,7 +136,7 @@ public void testSnapshotCreateWithIndexAllowlist() throws Exception {
fl -> {
if (Objects.equals(fl.uri(), "/")) {
return new SimpleHttpResponse(ROOT_RESPONSE_HEADERS, ROOT_RESPONSE_ES_7_10_2, "OK", 200);
} else if (Objects.equals(fl.uri(), "/_cluster/settings")) {
} else if (Objects.equals(fl.uri(), "/_cluster/settings?include_defaults=true")) {
return new SimpleHttpResponse(CLUSTER_SETTINGS_COMPATIBILITY_HEADERS, CLUSTER_SETTINGS_COMPATIBILITY_OVERRIDE_DISABLED,
"OK", 200);
} else if (fl.uri().equals("/_snapshot/migration_assistant_repo/" + snapshotName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public Version getClusterVersion() {
if (!VersionMatchers.isES_7_10.test(versionFromRootApi)) {
return versionFromRootApi;
}
return client.getAsync("_cluster/settings", null)
return client.getAsync("_cluster/settings?include_defaults=true", null)
.flatMap(this::checkCompatibilityModeFromResponse)
.doOnError(e -> log.error(e.getMessage()))
.retryWhen(OpenSearchClient.CHECK_IF_ITEM_EXISTS_RETRY_STRATEGY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,35 +86,35 @@ void beforeTest() {
@Test
void testGetClusterVersion_ES_7_10() {
setupOkResponse(restClient, "", ROOT_RESPONSE_ES_7_10_2);
setupOkResponse(restClient, "_cluster/settings", CLUSTER_SETTINGS_COMPATIBILITY_OVERRIDE_DISABLED);
setupOkResponse(restClient, "_cluster/settings?include_defaults=true", CLUSTER_SETTINGS_COMPATIBILITY_OVERRIDE_DISABLED);

var version = openSearchClientFactory.getClusterVersion();

assertThat(version, equalTo(Version.fromString("ES 7.10.2")));
verify(restClient).getAsync("", null);
verify(restClient).getAsync("_cluster/settings", null);
verify(restClient).getAsync("_cluster/settings?include_defaults=true", null);
verifyNoMoreInteractions(restClient);
}

@Test
void testGetClusterVersion_OS_CompatibilityModeEnabled() {
when(connectionContext.isAwsSpecificAuthentication()).thenReturn(true);
setupOkResponse(restClient, "", ROOT_RESPONSE_ES_7_10_2);
setupOkResponse(restClient, "_cluster/settings", CLUSTER_SETTINGS_COMPATIBILITY_OVERRIDE_ENABLED);
setupOkResponse(restClient, "_cluster/settings?include_defaults=true", CLUSTER_SETTINGS_COMPATIBILITY_OVERRIDE_ENABLED);
setupOkResponse(restClient, "_nodes/_all/nodes,version?format=json", NODES_RESPONSE_OS_2_13_0);

var version = openSearchClientFactory.getClusterVersion();

assertThat(version, equalTo(Version.fromString("AOS 2.13.0")));
verify(restClient).getAsync("", null);
verify(restClient).getAsync("_cluster/settings", null);
verify(restClient).getAsync("_cluster/settings?include_defaults=true", null);
verify(restClient).getAsync("_nodes/_all/nodes,version?format=json", null);
}

@Test
void testGetClusterVersion_OS_CompatibilityModeDisableEnabled() {
setupOkResponse(restClient, "", ROOT_RESPONSE_OS_1_0_0);
setupOkResponse(restClient, "_cluster/settings", CLUSTER_SETTINGS_COMPATIBILITY_OVERRIDE_DISABLED);
setupOkResponse(restClient, "_cluster/settings?include_defaults=true", CLUSTER_SETTINGS_COMPATIBILITY_OVERRIDE_DISABLED);

var version = openSearchClientFactory.getClusterVersion();

Expand All @@ -129,13 +129,13 @@ void testGetClusterVersion_OS_CompatibilityModeFailure_UseFallback() {
setupOkResponse(restClient, "", ROOT_RESPONSE_ES_7_10_2);

var versionResponse = new HttpResponse(403, "Forbidden", Map.of(), "");
when(restClient.getAsync("_cluster/settings", null)).thenReturn(Mono.just(versionResponse));
when(restClient.getAsync("_cluster/settings?include_defaults=true", null)).thenReturn(Mono.just(versionResponse));

var version = openSearchClientFactory.getClusterVersion();

assertThat(version, equalTo(Version.fromString("ES 7.10.2")));
verify(restClient).getAsync("", null);
verify(restClient).getAsync("_cluster/settings", null);
verify(restClient).getAsync("_cluster/settings?include_defaults=true", null);
verifyNoMoreInteractions(restClient);
}

Expand Down

0 comments on commit 4d369c1

Please sign in to comment.