Skip to content
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

Fix double trailing slash in getClusterVersion #1001

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected OpenSearchClient(RestClient client, FailedRequestsLogger failedRequest
}

public Version getClusterVersion() {
return client.getAsync("/", null)
return client.getAsync("", null)
Copy link
Member

Choose a reason for hiding this comment

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

Interesting. So we were doing something like curls -X GET https://<hostname>:9200//, and the double slash was accepted for self-host versions of OpenSearch, but not the managed version? That makes sense to me given all the processing they do.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it was accepted on everything but 2.15 managed.

.flatMap(resp -> {
try {
return Mono.just(versionFromResponse(resp));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.junit.jupiter.api.Test;

import org.opensearch.migrations.Version;
import org.opensearch.migrations.bulkload.common.DocumentReindexer.BulkDocSection;
import org.opensearch.migrations.bulkload.common.http.HttpResponse;
import org.opensearch.migrations.bulkload.http.BulkRequestGenerator;
Expand All @@ -33,6 +34,7 @@
import static org.opensearch.migrations.bulkload.http.BulkRequestGenerator.itemEntryFailure;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -124,6 +126,30 @@ void testCreateIndex_errorOnCreation_notRetriedOnBadRequest() {
assertThat(exception.getMessage(), containsString("illegal_argument_exception"));
}

@Test
void testGetClusterVersion() {
var restClient = mock(RestClient.class);
var failedRequestLogger = mock(FailedRequestsLogger.class);
var openSearchClient = new OpenSearchClient(restClient, failedRequestLogger);

var versionJson = "{\"version\": {\"number\": \"7.10.2\"}}";
var successResponse = new HttpResponse(200, "OK", Map.of(), versionJson);

ArgumentCaptor<String> pathCaptor = ArgumentCaptor.forClass(String.class);

when(restClient.getAsync(pathCaptor.capture(), any()))
.thenReturn(Mono.just(successResponse));

Version version = openSearchClient.getClusterVersion();

assertThat(version, equalTo(Version.fromString("ES 7.10.2")));

String capturedPath = pathCaptor.getValue();
assertThat(capturedPath, equalTo(""));

verify(restClient, times(1)).getAsync(anyString(), any());
}

@Test
void testBulkRequest_succeedAfterRetries() {
var docId1 = "tt1979320";
Expand Down
Loading