Skip to content

Commit e1ea73d

Browse files
otelbot[bot]trask
andauthored
Code review sweep (run 25139405527) (#18424)
Co-authored-by: otelbot <197425009+otelbot@users.noreply.github.com> Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
1 parent 9e058b9 commit e1ea73d

9 files changed

Lines changed: 31 additions & 44 deletions

File tree

instrumentation/elasticsearch/elasticsearch-rest-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v5_0/ElasticsearchRest5Test.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import com.fasterxml.jackson.databind.ObjectMapper;
2626
import io.opentelemetry.api.trace.SpanKind;
27+
import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension;
2728
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
2829
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
2930
import java.io.IOException;
@@ -33,7 +34,6 @@
3334
import org.elasticsearch.client.Response;
3435
import org.elasticsearch.client.ResponseListener;
3536
import org.elasticsearch.client.RestClient;
36-
import org.junit.jupiter.api.AfterAll;
3737
import org.junit.jupiter.api.BeforeAll;
3838
import org.junit.jupiter.api.Test;
3939
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -45,6 +45,8 @@ class ElasticsearchRest5Test {
4545
@RegisterExtension
4646
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
4747

48+
@RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension.create();
49+
4850
static ElasticsearchContainer elasticsearch;
4951

5052
static HttpHost httpHost;
@@ -69,6 +71,7 @@ static void setup() {
6971
"ES_JAVA_OPTS",
7072
"-Xmx256m -Xms256m -Dlog4j2.disableJmx=true -Dlog4j2.disable.jmx=true -XX:-UseContainerSupport");
7173
elasticsearch.start();
74+
cleanup.deferAfterAll(elasticsearch::stop);
7275

7376
httpHost = HttpHost.create(elasticsearch.getHttpHostAddress());
7477
client =
@@ -80,16 +83,11 @@ static void setup() {
8083
.setConnectTimeout(Integer.MAX_VALUE)
8184
.setSocketTimeout(Integer.MAX_VALUE))
8285
.build();
86+
cleanup.deferAfterAll(client);
8387

8488
objectMapper = new ObjectMapper();
8589
}
8690

87-
@AfterAll
88-
static void cleanUp() throws IOException {
89-
client.close();
90-
elasticsearch.stop();
91-
}
92-
9391
@Test
9492
void elasticsearchStatus() throws IOException {
9593
Response response = client.performRequest("GET", "_cluster/health");

instrumentation/elasticsearch/elasticsearch-rest-6.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v6_4/ElasticsearchRest6Test.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM;
1919
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM_NAME;
2020
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DbSystemNameIncubatingValues.ELASTICSEARCH;
21+
import static java.util.concurrent.TimeUnit.SECONDS;
2122
import static org.assertj.core.api.Assertions.assertThat;
2223

2324
import com.fasterxml.jackson.core.type.TypeReference;
2425
import com.fasterxml.jackson.databind.ObjectMapper;
2526
import io.opentelemetry.api.trace.SpanKind;
27+
import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension;
2628
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
2729
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
2830
import java.io.IOException;
@@ -32,7 +34,6 @@
3234
import org.elasticsearch.client.Response;
3335
import org.elasticsearch.client.ResponseListener;
3436
import org.elasticsearch.client.RestClient;
35-
import org.junit.jupiter.api.AfterAll;
3637
import org.junit.jupiter.api.BeforeAll;
3738
import org.junit.jupiter.api.Test;
3839
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -43,6 +44,8 @@ class ElasticsearchRest6Test {
4344
@RegisterExtension
4445
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
4546

47+
@RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension.create();
48+
4649
static ElasticsearchContainer elasticsearch;
4750

4851
static HttpHost httpHost;
@@ -60,6 +63,7 @@ static void setUp() {
6063
"ES_JAVA_OPTS",
6164
"-Xmx256m -Xms256m -Dlog4j2.disableJmx=true -Dlog4j2.disable.jmx=true -XX:-UseContainerSupport");
6265
elasticsearch.start();
66+
cleanup.deferAfterAll(elasticsearch::stop);
6367

6468
httpHost = HttpHost.create(elasticsearch.getHttpHostAddress());
6569
client =
@@ -71,16 +75,11 @@ static void setUp() {
7175
.setConnectTimeout(Integer.MAX_VALUE)
7276
.setSocketTimeout(Integer.MAX_VALUE))
7377
.build();
78+
cleanup.deferAfterAll(client);
7479

7580
objectMapper = new ObjectMapper();
7681
}
7782

78-
@AfterAll
79-
static void cleanUp() throws IOException {
80-
client.close();
81-
elasticsearch.stop();
82-
}
83-
8483
@Test
8584
void elasticsearchStatus() throws IOException {
8685
Response response = client.performRequest("GET", "_cluster/health");
@@ -153,7 +152,7 @@ public void onFailure(Exception e) {
153152
};
154153
testing.runWithSpan(
155154
"parent", () -> client.performRequestAsync("GET", "_cluster/health", responseListener));
156-
countDownLatch.await();
155+
assertThat(countDownLatch.await(10, SECONDS)).isTrue();
157156

158157
if (exception[0] != null) {
159158
throw exception[0];

instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v7_0/ElasticsearchRest7Singletons.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ public class ElasticsearchRest7Singletons {
1919
ElasticsearchRestJavaagentInstrumenterFactory.create(
2020
"io.opentelemetry.elasticsearch-rest-7.0");
2121

22+
public static final VirtualField<Request, ElasticsearchEndpointDefinition> ENDPOINT_DEFINITION =
23+
VirtualField.find(Request.class, ElasticsearchEndpointDefinition.class);
24+
2225
public static Instrumenter<ElasticsearchRestRequest, Response> instrumenter() {
2326
return instrumenter;
2427
}
2528

26-
public static final VirtualField<Request, ElasticsearchEndpointDefinition> ENDPOINT_DEFINITION =
27-
VirtualField.find(Request.class, ElasticsearchEndpointDefinition.class);
28-
2929
private ElasticsearchRest7Singletons() {}
3030
}

instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v7_0/ElasticsearchRest7Test.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import com.fasterxml.jackson.databind.ObjectMapper;
2626
import io.opentelemetry.api.trace.SpanKind;
27+
import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension;
2728
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
2829
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
2930
import java.io.IOException;
@@ -34,7 +35,6 @@
3435
import org.elasticsearch.client.Response;
3536
import org.elasticsearch.client.ResponseListener;
3637
import org.elasticsearch.client.RestClient;
37-
import org.junit.jupiter.api.AfterAll;
3838
import org.junit.jupiter.api.BeforeAll;
3939
import org.junit.jupiter.api.Test;
4040
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -45,6 +45,8 @@ class ElasticsearchRest7Test {
4545
@RegisterExtension
4646
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
4747

48+
@RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension.create();
49+
4850
static ElasticsearchContainer elasticsearch;
4951

5052
static HttpHost httpHost;
@@ -57,6 +59,7 @@ class ElasticsearchRest7Test {
5759
static void setUp() {
5860
elasticsearch =
5961
new ElasticsearchContainer("docker.elastic.co/elasticsearch/elasticsearch-oss:7.10.2");
62+
cleanup.deferAfterAll(elasticsearch::stop);
6063
// limit memory usage
6164
elasticsearch.withEnv(
6265
"ES_JAVA_OPTS",
@@ -73,18 +76,13 @@ static void setUp() {
7376
.setConnectTimeout(Integer.MAX_VALUE)
7477
.setSocketTimeout(Integer.MAX_VALUE))
7578
.build();
79+
cleanup.deferAfterAll(client);
7680

7781
objectMapper = new ObjectMapper();
7882
}
7983

80-
@AfterAll
81-
static void cleanUp() throws IOException {
82-
client.close();
83-
elasticsearch.stop();
84-
}
85-
8684
@Test
87-
void elasticsearchStatus() throws Exception {
85+
void elasticsearchStatus() throws IOException {
8886
Response response = client.performRequest(new Request("GET", "_cluster/health"));
8987
Map<?, ?> result = objectMapper.readValue(response.getEntity().getContent(), Map.class);
9088

@@ -132,7 +130,6 @@ void elasticsearchStatusAsync() throws Exception {
132130
new ResponseListener() {
133131
@Override
134132
public void onSuccess(Response response) {
135-
136133
runWithSpan(
137134
"callback",
138135
() -> {

instrumentation/elasticsearch/elasticsearch-rest-7.0/library/src/main/java/io/opentelemetry/instrumentation/elasticsearch/rest/v7_0/RestClientWrapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.List;
1919
import java.util.function.Function;
2020
import java.util.function.Supplier;
21+
import javax.annotation.Nullable;
2122
import net.bytebuddy.ByteBuddy;
2223
import net.bytebuddy.description.modifier.Visibility;
2324
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
@@ -132,6 +133,7 @@ private static Field getProxyField(Class<?> clazz, String fieldName) {
132133
}
133134

134135
@SuppressWarnings("unchecked") // casting reflection result
136+
@Nullable
135137
private static Instrumenter<ElasticsearchRestRequest, Response> getInstrumenter(Object proxy)
136138
throws IllegalAccessException {
137139
Supplier<Instrumenter<ElasticsearchRestRequest, Response>> supplier =

instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_0/Elasticsearch5TransportAttributesGetter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public String getNetworkPeerAddress(
2222
return null;
2323
}
2424

25-
@Nullable
2625
@Override
26+
@Nullable
2727
public Integer getNetworkPeerPort(
2828
ElasticTransportRequest request, @Nullable ActionResponse response) {
2929
if (response != null && response.remoteAddress() != null) {

instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_0/Elasticsearch5NodeClientTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.elasticsearch.node.Node;
1818
import org.elasticsearch.node.internal.InternalSettingsPreparer;
1919
import org.elasticsearch.transport.Netty3Plugin;
20-
import org.junit.jupiter.api.AfterAll;
2120
import org.junit.jupiter.api.BeforeAll;
2221
import org.junit.jupiter.api.Test;
2322
import org.junit.jupiter.api.io.TempDir;
@@ -49,6 +48,7 @@ static void setUp(@TempDir File esWorkingDir) {
4948
new Node(
5049
new Environment(InternalSettingsPreparer.prepareSettings(settings)),
5150
singletonList(Netty3Plugin.class)) {};
51+
cleanup.deferAfterAll(testNode);
5252
startNode(testNode);
5353

5454
client = testNode.client();
@@ -69,11 +69,6 @@ static void setUp(@TempDir File esWorkingDir) {
6969
testing.clearData();
7070
}
7171

72-
@AfterAll
73-
static void cleanUp() throws Exception {
74-
testNode.close();
75-
}
76-
7772
@Override
7873
protected Client client() {
7974
return client;

instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_0/Elasticsearch5TransportClientTest.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.elasticsearch.transport.Netty3Plugin;
2121
import org.elasticsearch.transport.TransportService;
2222
import org.elasticsearch.transport.client.PreBuiltTransportClient;
23-
import org.junit.jupiter.api.AfterAll;
2423
import org.junit.jupiter.api.BeforeAll;
2524
import org.junit.jupiter.api.io.TempDir;
2625
import org.slf4j.Logger;
@@ -50,6 +49,7 @@ static void setUp(@TempDir File esWorkingDir) {
5049
new Node(
5150
new Environment(InternalSettingsPreparer.prepareSettings(settings)),
5251
singletonList(Netty3Plugin.class)) {};
52+
cleanup.deferAfterAll(testNode);
5353
startNode(testNode);
5454

5555
tcpPublishAddress =
@@ -63,6 +63,7 @@ static void setUp(@TempDir File esWorkingDir) {
6363
.put("thread_pool.listener.size", 1)
6464
.put(CLUSTER_NAME_SETTING.getKey(), clusterName)
6565
.build());
66+
cleanup.deferAfterAll(client);
6667
client.addTransportAddress(tcpPublishAddress);
6768
testing.runWithSpan(
6869
"setup",
@@ -81,11 +82,6 @@ static void setUp(@TempDir File esWorkingDir) {
8182
testing.clearData();
8283
}
8384

84-
@AfterAll
85-
static void cleanUp() throws Exception {
86-
testNode.close();
87-
}
88-
8985
@Override
9086
protected TransportClient client() {
9187
return client;

instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_3/springdata/ElasticsearchSpringTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
package io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.v5_3.springdata;
77

88
abstract class ElasticsearchSpringTest {
9-
protected static final String EXPERIMENTAL_FLAG =
10-
"otel.instrumentation.elasticsearch.experimental-span-attributes";
9+
private static final boolean EXPERIMENTAL_ATTRIBUTES =
10+
Boolean.getBoolean("otel.instrumentation.elasticsearch.experimental-span-attributes");
1111

1212
protected static String experimental(String value) {
13-
if (!Boolean.getBoolean(EXPERIMENTAL_FLAG)) {
13+
if (!EXPERIMENTAL_ATTRIBUTES) {
1414
return null;
1515
}
1616
return value;
1717
}
1818

1919
protected static Long experimental(long value) {
20-
if (!Boolean.getBoolean(EXPERIMENTAL_FLAG)) {
20+
if (!EXPERIMENTAL_ATTRIBUTES) {
2121
return null;
2222
}
2323
return value;

0 commit comments

Comments
 (0)