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

Elasticsearch: Fix startup check for 8.3 and above #5521

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ public ElasticsearchContainer(final DockerImageName dockerImageName) {
this.isAtLeastMajorVersion8 =
new ComparableVersion(dockerImageName.getVersionPart()).isGreaterThanOrEqualTo("8.0.0");
// regex that
// matches 8.3 JSON logging with started message and some follow up content within the message field
// matches 8.0 JSON logging with no whitespace between message field and content
// matches 7.x JSON logging with whitespace between message field and content
// matches 6.x text logging with node name in brackets and just a 'started' message till the end of the line
String regex = ".*(\"message\":\\s?\"started\".*|] started\n$)";
String regex = ".*(\"message\":\\s?\"started[\\s?|\"].*|] started\n$)";
setWaitStrategy(new LogMessageWaitStrategy().withRegEx(regex));
if (isAtLeastMajorVersion8) {
withPassword(ELASTICSEARCH_DEFAULT_PASSWORD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,20 @@ public void elasticsearchVersion() throws IOException {
}
}

@Test
public void elasticsearchVersion83() throws IOException {
try (
ElasticsearchContainer container = new ElasticsearchContainer(
"docker.elastic.co/elasticsearch/elasticsearch:8.3.0"
)
) {
container.start();
Response response = getClient(container).performRequest(new Request("GET", "/"));
assertThat(response.getStatusLine().getStatusCode(), is(200));
assertThat(EntityUtils.toString(response.getEntity()), containsString("8.3.0"));
}
}

@Test
public void elasticsearchOssImage() throws IOException {
try (
Expand Down Expand Up @@ -406,10 +420,15 @@ private RestClient getClient(ElasticsearchContainer container) {
new UsernamePasswordCredentials(ELASTICSEARCH_USERNAME, ELASTICSEARCH_PASSWORD)
);

String protocol = container.caCertAsBytes().isPresent() ? "https://" : "http://";

client =
RestClient
.builder(HttpHost.create(container.getHttpHostAddress()))
.builder(HttpHost.create(protocol + container.getHttpHostAddress()))
.setHttpClientConfigCallback(httpClientBuilder -> {
if (container.caCertAsBytes().isPresent()) {
httpClientBuilder.setSSLContext(container.createSslContextFromCa());
}
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
})
.build();
Expand Down