Skip to content
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.
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 @@ -5,7 +5,7 @@

package io.opentelemetry.javaagent.instrumentation.elasticsearch.rest;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.instrumentation.elasticsearch.rest.common.v5_0.internal.ElasticsearchEndpointDefinition;
import io.opentelemetry.javaagent.instrumentation.elasticsearch.apiclient.ElasticsearchEndpointMap;
Expand All @@ -20,7 +20,7 @@
import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;

public class ElasticsearchEndpointMapTest {
class ElasticsearchEndpointMapTest {

private static final Set<String> SEARCH_ENDPOINTS =
new HashSet<>(
Expand Down Expand Up @@ -57,16 +57,17 @@ private static List<String> getPathParts(String route) {
}

@Test
public void testIsSearchEndpoint() {
void testIsSearchEndpoint() {
for (ElasticsearchEndpointDefinition esEndpointDefinition :
ElasticsearchEndpointMap.getAllEndpoints()) {
String endpointId = esEndpointDefinition.getEndpointName();
assertEquals(SEARCH_ENDPOINTS.contains(endpointId), esEndpointDefinition.isSearchEndpoint());
assertThat(SEARCH_ENDPOINTS.contains(endpointId))
.isEqualTo(esEndpointDefinition.isSearchEndpoint());
}
}

@Test
public void testProcessPathParts() {
void testProcessPathParts() {
for (ElasticsearchEndpointDefinition esEndpointDefinition :
ElasticsearchEndpointMap.getAllEndpoints()) {
for (String route :
Expand All @@ -81,44 +82,45 @@ public void testProcessPathParts() {
Map<String, String> expectedMap = new HashMap<>();
pathParts.forEach(part -> expectedMap.put(part, part));

assertEquals(expectedMap, observedParams);
assertThat(expectedMap).isEqualTo(observedParams);
}
}
}

@Test
public void testSearchEndpoint() {
void testSearchEndpoint() {
ElasticsearchEndpointDefinition esEndpoint = ElasticsearchEndpointMap.get("search");
Map<String, String> observedParams = new HashMap<>();
esEndpoint.processPathParts(
"/test-index-1,test-index-2/_search", (k, v) -> observedParams.put(k, v));

assertEquals("test-index-1,test-index-2", observedParams.get("index"));
assertThat(observedParams.get("index")).isEqualTo("test-index-1,test-index-2");
}

@Test
public void testBuildRegexPattern() {
void testBuildRegexPattern() {
Pattern pattern =
ElasticsearchEndpointDefinition.EndpointPattern.buildRegexPattern(
"/_nodes/{node_id}/shutdown");
assertEquals("^/_nodes/(?<node0id>[^/]+)/shutdown$", pattern.pattern());
assertThat(pattern.pattern()).isEqualTo("^/_nodes/(?<node0id>[^/]+)/shutdown$");

pattern =
ElasticsearchEndpointDefinition.EndpointPattern.buildRegexPattern(
"/_snapshot/{repository}/{snapshot}/_mount");
assertEquals("^/_snapshot/(?<repository>[^/]+)/(?<snapshot>[^/]+)/_mount$", pattern.pattern());
assertThat(pattern.pattern())
.isEqualTo("^/_snapshot/(?<repository>[^/]+)/(?<snapshot>[^/]+)/_mount$");

pattern =
ElasticsearchEndpointDefinition.EndpointPattern.buildRegexPattern(
"/_security/profile/_suggest");
assertEquals("^/_security/profile/_suggest$", pattern.pattern());
assertThat(pattern.pattern()).isEqualTo("^/_security/profile/_suggest$");

pattern =
ElasticsearchEndpointDefinition.EndpointPattern.buildRegexPattern(
"/_application/search_application/{name}");
assertEquals("^/_application/search_application/(?<name>[^/]+)$", pattern.pattern());
assertThat(pattern.pattern()).isEqualTo("^/_application/search_application/(?<name>[^/]+)$");

pattern = ElasticsearchEndpointDefinition.EndpointPattern.buildRegexPattern("/");
assertEquals("^/$", pattern.pattern());
assertThat(pattern.pattern()).isEqualTo("^/$");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_ELASTICSEARCH_PATH_PARTS;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_OPERATION;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM;
import static org.assertj.core.api.Assertions.assertThat;

import co.elastic.clients.elasticsearch.ElasticsearchAsyncClient;
import co.elastic.clients.elasticsearch.ElasticsearchClient;
Expand All @@ -33,7 +34,6 @@
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down Expand Up @@ -82,9 +82,9 @@ static void cleanUp() {
}

@Test
public void elasticsearchStatus() throws IOException {
void elasticsearchStatus() throws IOException {
InfoResponse response = client.info();
Assertions.assertEquals(response.version().number(), "7.17.2");
assertThat(response.version().number()).isEqualTo("7.17.2");

testing.waitAndAssertTraces(
trace ->
Expand Down Expand Up @@ -114,7 +114,7 @@ public void elasticsearchStatus() throws IOException {
}

@Test
public void elasticsearchIndex() throws IOException {
void elasticsearchIndex() throws IOException {
client.index(
r ->
r.id("test-id")
Expand Down Expand Up @@ -157,7 +157,7 @@ public void elasticsearchIndex() throws IOException {
}

@Test
public void elasticsearchStatusAsync() throws Exception {
void elasticsearchStatusAsync() throws Exception {
CountDownLatch countDownLatch = new CountDownLatch(1);
AsyncRequest request = new AsyncRequest();

Expand All @@ -177,7 +177,7 @@ public void elasticsearchStatusAsync() throws Exception {
//noinspection ResultOfMethodCallIgnored
countDownLatch.await(10, TimeUnit.SECONDS);

Assertions.assertEquals(request.getResponse().version().number(), "7.17.2");
assertThat(request.getResponse().version().number()).isEqualTo("7.17.2");

testing.waitAndAssertTraces(
trace ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static io.opentelemetry.semconv.ServerAttributes.SERVER_PORT;
import static io.opentelemetry.semconv.UrlAttributes.URL_FULL;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM;
import static org.assertj.core.api.Assertions.assertThat;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.opentelemetry.api.trace.SpanKind;
Expand All @@ -27,7 +28,6 @@
import org.elasticsearch.client.ResponseListener;
import org.elasticsearch.client.RestClient;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down Expand Up @@ -89,36 +89,32 @@ void elasticsearchStatus() throws IOException {
Map result = objectMapper.readValue(response.getEntity().getContent(), Map.class);

// usually this test reports green status, but sometimes it is yellow
Assertions.assertTrue(
"green".equals(result.get("status")) || "yellow".equals(result.get("status")));
assertThat(result.get("status")).isIn("green", "yellow");

testing.waitAndAssertTraces(
trace -> {
trace.hasSpansSatisfyingExactly(
span -> {
span.hasName("GET")
.hasKind(SpanKind.CLIENT)
.hasNoParent()
.hasAttributesSatisfyingExactly(
equalTo(maybeStable(DB_SYSTEM), "elasticsearch"),
equalTo(HTTP_REQUEST_METHOD, "GET"),
equalTo(SERVER_ADDRESS, httpHost.getHostName()),
equalTo(SERVER_PORT, httpHost.getPort()),
equalTo(URL_FULL, httpHost.toURI() + "/_cluster/health"));
},
span -> {
span.hasName("GET")
.hasKind(SpanKind.CLIENT)
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(
equalTo(SERVER_ADDRESS, httpHost.getHostName()),
equalTo(SERVER_PORT, httpHost.getPort()),
equalTo(HTTP_REQUEST_METHOD, "GET"),
equalTo(NETWORK_PROTOCOL_VERSION, "1.1"),
equalTo(URL_FULL, httpHost.toURI() + "/_cluster/health"),
equalTo(HTTP_RESPONSE_STATUS_CODE, 200));
});
});
trace ->
trace.hasSpansSatisfyingExactly(
span ->
span.hasName("GET")
.hasKind(SpanKind.CLIENT)
.hasNoParent()
.hasAttributesSatisfyingExactly(
equalTo(maybeStable(DB_SYSTEM), "elasticsearch"),
equalTo(HTTP_REQUEST_METHOD, "GET"),
equalTo(SERVER_ADDRESS, httpHost.getHostName()),
equalTo(SERVER_PORT, httpHost.getPort()),
equalTo(URL_FULL, httpHost.toURI() + "/_cluster/health")),
span ->
span.hasName("GET")
.hasKind(SpanKind.CLIENT)
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(
equalTo(SERVER_ADDRESS, httpHost.getHostName()),
equalTo(SERVER_PORT, httpHost.getPort()),
equalTo(HTTP_REQUEST_METHOD, "GET"),
equalTo(NETWORK_PROTOCOL_VERSION, "1.1"),
equalTo(URL_FULL, httpHost.toURI() + "/_cluster/health"),
equalTo(HTTP_RESPONSE_STATUS_CODE, 200))));
}

@Test
Expand Down Expand Up @@ -151,52 +147,44 @@ public void onFailure(Exception e) {
};

testing.runWithSpan(
"parent",
() -> {
client.performRequestAsync("GET", "_cluster/health", responseListener);
});
"parent", () -> client.performRequestAsync("GET", "_cluster/health", responseListener));
countDownLatch.await();
if (exception[0] != null) {
throw exception[0];
}
Map result = objectMapper.readValue(requestResponse[0].getEntity().getContent(), Map.class);

// usually this test reports green status, but sometimes it is yellow
Assertions.assertTrue(
"green".equals(result.get("status")) || "yellow".equals(result.get("status")));
assertThat(result.get("status")).isIn("green", "yellow");

testing.waitAndAssertTraces(
trace -> {
trace.hasSpansSatisfyingExactly(
span -> {
span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent();
},
span -> {
span.hasName("GET")
.hasKind(SpanKind.CLIENT)
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(
equalTo(maybeStable(DB_SYSTEM), "elasticsearch"),
equalTo(HTTP_REQUEST_METHOD, "GET"),
equalTo(SERVER_ADDRESS, httpHost.getHostName()),
equalTo(SERVER_PORT, httpHost.getPort()),
equalTo(URL_FULL, httpHost.toURI() + "/_cluster/health"));
},
span -> {
span.hasName("GET")
.hasKind(SpanKind.CLIENT)
.hasParent(trace.getSpan(1))
.hasAttributesSatisfyingExactly(
equalTo(SERVER_ADDRESS, httpHost.getHostName()),
equalTo(SERVER_PORT, httpHost.getPort()),
equalTo(HTTP_REQUEST_METHOD, "GET"),
equalTo(NETWORK_PROTOCOL_VERSION, "1.1"),
equalTo(URL_FULL, httpHost.toURI() + "/_cluster/health"),
equalTo(HTTP_RESPONSE_STATUS_CODE, 200));
},
span -> {
span.hasName("callback").hasKind(SpanKind.INTERNAL).hasParent(trace.getSpan(0));
});
});
trace ->
trace.hasSpansSatisfyingExactly(
span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(),
span ->
span.hasName("GET")
.hasKind(SpanKind.CLIENT)
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(
equalTo(maybeStable(DB_SYSTEM), "elasticsearch"),
equalTo(HTTP_REQUEST_METHOD, "GET"),
equalTo(SERVER_ADDRESS, httpHost.getHostName()),
equalTo(SERVER_PORT, httpHost.getPort()),
equalTo(URL_FULL, httpHost.toURI() + "/_cluster/health")),
span ->
span.hasName("GET")
.hasKind(SpanKind.CLIENT)
.hasParent(trace.getSpan(1))
.hasAttributesSatisfyingExactly(
equalTo(SERVER_ADDRESS, httpHost.getHostName()),
equalTo(SERVER_PORT, httpHost.getPort()),
equalTo(HTTP_REQUEST_METHOD, "GET"),
equalTo(NETWORK_PROTOCOL_VERSION, "1.1"),
equalTo(URL_FULL, httpHost.toURI() + "/_cluster/health"),
equalTo(HTTP_RESPONSE_STATUS_CODE, 200)),
span ->
span.hasName("callback")
.hasKind(SpanKind.INTERNAL)
.hasParent(trace.getSpan(0))));
}
}
Loading
Loading