From d0a53e3f297cc7060782f94e02c86c10d6114af7 Mon Sep 17 00:00:00 2001
From: "Tak Lon (Stephen) Wu"
Date: Mon, 23 Aug 2021 08:52:07 -0700
Subject: [PATCH] HBASE-26133 Backport HBASE-25591 "Upgrade opentelemetry to
0.17.1" to branch-2 (#3608)
10/17 commits of HBASE-22120, original commit f6ff519dd0c7fe0e3ae3c175eefee27a26a065a4
Co-authored-by: Duo Zhang
Signed-off-by: Duo Zhang
Signed-off-by: Peter Somogyi
---
.../hbase/client/TestAsyncTableTracing.java | 6 ++---
hbase-common/pom.xml | 4 +++
.../apache/hadoop/hbase/trace/TraceUtil.java | 25 ++++++++++---------
.../hbase/mttr/IntegrationTestMTTR.java | 3 +--
.../hadoop/hbase/ipc/ServerRpcConnection.java | 4 +--
.../hadoop/hbase/ipc/AbstractTestIPC.java | 14 +++++------
.../regionserver/TestHRegionTracing.java | 15 +++++------
pom.xml | 18 ++++++-------
8 files changed, 44 insertions(+), 45 deletions(-)
diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableTracing.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableTracing.java
index 07cdf0e5383..a3ad9df1154 100644
--- a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableTracing.java
+++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableTracing.java
@@ -24,7 +24,7 @@ import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
-import io.opentelemetry.api.trace.Span.Kind;
+import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.sdk.testing.junit4.OpenTelemetryRule;
import io.opentelemetry.sdk.trace.data.SpanData;
@@ -222,7 +222,7 @@ public class TestAsyncTableTracing {
Waiter.waitFor(CONF, 1000,
() -> traceRule.getSpans().stream()
.anyMatch(span -> span.getName().equals("AsyncTable." + methodName) &&
- span.getKind() == Kind.INTERNAL && span.hasEnded()));
+ span.getKind() == SpanKind.INTERNAL && span.hasEnded()));
SpanData data = traceRule.getSpans().stream()
.filter(s -> s.getName().equals("AsyncTable." + methodName)).findFirst().get();
assertEquals(StatusCode.OK, data.getStatus().getStatusCode());
@@ -409,7 +409,7 @@ public class TestAsyncTableTracing {
Waiter.waitFor(CONF, 1000,
() -> traceRule.getSpans().stream()
.anyMatch(span -> span.getName().equals("AsyncConnection.close") &&
- span.getKind() == Kind.INTERNAL && span.hasEnded()));
+ span.getKind() == SpanKind.INTERNAL && span.hasEnded()));
SpanData data = traceRule.getSpans().stream()
.filter(s -> s.getName().equals("AsyncConnection.close")).findFirst().get();
assertEquals(StatusCode.OK, data.getStatus().getStatusCode());
diff --git a/hbase-common/pom.xml b/hbase-common/pom.xml
index 62661b80f6b..2212fd14a41 100644
--- a/hbase-common/pom.xml
+++ b/hbase-common/pom.xml
@@ -195,6 +195,10 @@
io.opentelemetry
opentelemetry-api
+
+ io.opentelemetry
+ opentelemetry-semconv
+
org.apache.commons
commons-crypto
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/trace/TraceUtil.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/trace/TraceUtil.java
index 2a6b6b6588f..43c2e048686 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/trace/TraceUtil.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/trace/TraceUtil.java
@@ -20,12 +20,12 @@ package org.apache.hadoop.hbase.trace;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.trace.Span;
-import io.opentelemetry.api.trace.Span.Kind;
+import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.api.trace.Tracer;
-import io.opentelemetry.api.trace.attributes.SemanticAttributes;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
+import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@@ -72,14 +72,14 @@ public final class TraceUtil {
}
/**
- * Create a {@link Kind#INTERNAL} span.
+ * Create a {@link SpanKind#INTERNAL} span.
*/
public static Span createSpan(String name) {
- return createSpan(name, Kind.INTERNAL);
+ return createSpan(name, SpanKind.INTERNAL);
}
/**
- * Create a {@link Kind#INTERNAL} span and set table related attributes.
+ * Create a {@link SpanKind#INTERNAL} span and set table related attributes.
*/
public static Span createTableSpan(String spanName, TableName tableName) {
return createSpan(spanName).setAttribute(NAMESPACE_KEY, tableName.getNamespaceAsString())
@@ -88,28 +88,29 @@ public final class TraceUtil {
/**
* Create a span with the given {@code kind}. Notice that, OpenTelemetry only expects one
- * {@link Kind#CLIENT} span and one {@link Kind#SERVER} span for a traced request, so use this
- * with caution when you want to create spans with kind other than {@link Kind#INTERNAL}.
+ * {@link SpanKind#CLIENT} span and one {@link SpanKind#SERVER} span for a traced request, so use
+ * this with caution when you want to create spans with kind other than {@link SpanKind#INTERNAL}.
*/
- private static Span createSpan(String name, Kind kind) {
+ private static Span createSpan(String name, SpanKind kind) {
return getGlobalTracer().spanBuilder(name).setSpanKind(kind).startSpan();
}
/**
* Create a span which parent is from remote, i.e, passed through rpc.
*
- * We will set the kind of the returned span to {@link Kind#SERVER}, as this should be the top
+ * We will set the kind of the returned span to {@link SpanKind#SERVER}, as this should be the top
* most span at server side.
*/
public static Span createRemoteSpan(String name, Context ctx) {
- return getGlobalTracer().spanBuilder(name).setParent(ctx).setSpanKind(Kind.SERVER).startSpan();
+ return getGlobalTracer().spanBuilder(name).setParent(ctx).setSpanKind(SpanKind.SERVER)
+ .startSpan();
}
/**
- * Create a span with {@link Kind#CLIENT}.
+ * Create a span with {@link SpanKind#CLIENT}.
*/
public static Span createClientSpan(String name) {
- return createSpan(name, Kind.CLIENT);
+ return createSpan(name, SpanKind.CLIENT);
}
/**
diff --git a/hbase-it/src/test/java/org/apache/hadoop/hbase/mttr/IntegrationTestMTTR.java b/hbase-it/src/test/java/org/apache/hadoop/hbase/mttr/IntegrationTestMTTR.java
index 5e390d28bcf..13e0f0ae888 100644
--- a/hbase-it/src/test/java/org/apache/hadoop/hbase/mttr/IntegrationTestMTTR.java
+++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/mttr/IntegrationTestMTTR.java
@@ -54,7 +54,6 @@ import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.RetriesExhaustedException;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table;
-import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.coprocessor.CoprocessorException;
import org.apache.hadoop.hbase.filter.KeyOnlyFilter;
@@ -377,7 +376,7 @@ public class IntegrationTestMTTR {
public void addResult(long time, Span span) {
stats.addValue(TimeUnit.MILLISECONDS.convert(time, TimeUnit.NANOSECONDS));
if (TimeUnit.SECONDS.convert(time, TimeUnit.NANOSECONDS) >= 1) {
- traces.add(span.getSpanContext().getTraceIdAsHexString());
+ traces.add(span.getSpanContext().getTraceId());
}
}
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/ServerRpcConnection.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/ServerRpcConnection.java
index 823005b2c52..208ec8ba8f1 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/ServerRpcConnection.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/ServerRpcConnection.java
@@ -23,7 +23,7 @@ import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
-import io.opentelemetry.context.propagation.TextMapPropagator;
+import io.opentelemetry.context.propagation.TextMapGetter;
import java.io.ByteArrayInputStream;
import java.io.Closeable;
import java.io.DataOutputStream;
@@ -615,7 +615,7 @@ abstract class ServerRpcConnection implements Closeable {
ProtobufUtil.mergeFrom(builder, cis, headerSize);
RequestHeader header = (RequestHeader) builder.build();
offset += headerSize;
- TextMapPropagator.Getter getter = new TextMapPropagator.Getter() {
+ TextMapGetter getter = new TextMapGetter() {
@Override
public Iterable keys(RPCTInfo carrier) {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/AbstractTestIPC.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/AbstractTestIPC.java
index c4951b29f98..ce753430b33 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/AbstractTestIPC.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/AbstractTestIPC.java
@@ -34,7 +34,7 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.internal.verification.VerificationModeFactory.times;
-import io.opentelemetry.api.trace.Span.Kind;
+import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.sdk.testing.junit4.OpenTelemetryRule;
import io.opentelemetry.sdk.trace.data.SpanData;
@@ -457,7 +457,7 @@ public abstract class AbstractTestIPC {
}
private void assertRpcAttribute(SpanData data, String methodName, InetSocketAddress addr,
- Kind kind) {
+ SpanKind kind) {
assertEquals(SERVICE.getDescriptorForType().getName(),
data.getAttributes().get(TraceUtil.RPC_SERVICE_KEY));
assertEquals(methodName, data.getAttributes().get(TraceUtil.RPC_METHOD_KEY));
@@ -471,7 +471,7 @@ public abstract class AbstractTestIPC {
private void assertRemoteSpan() {
SpanData data = waitSpan("RpcServer.process");
assertTrue(data.getParentSpanContext().isRemote());
- assertEquals(Kind.SERVER, data.getKind());
+ assertEquals(SpanKind.SERVER, data.getKind());
}
@Test
@@ -484,8 +484,8 @@ public abstract class AbstractTestIPC {
BlockingInterface stub = newBlockingStub(client, rpcServer.getListenerAddress());
stub.pause(null, PauseRequestProto.newBuilder().setMs(100).build());
assertRpcAttribute(waitSpan("RpcClient.callMethod"), "pause", rpcServer.getListenerAddress(),
- Kind.CLIENT);
- assertRpcAttribute(waitSpan("RpcServer.callMethod"), "pause", null, Kind.INTERNAL);
+ SpanKind.CLIENT);
+ assertRpcAttribute(waitSpan("RpcServer.callMethod"), "pause", null, SpanKind.INTERNAL);
assertRemoteSpan();
assertSameTraceId();
for (SpanData data : traceRule.getSpans()) {
@@ -499,8 +499,8 @@ public abstract class AbstractTestIPC {
assertThrows(ServiceException.class,
() -> stub.error(null, EmptyRequestProto.getDefaultInstance()));
assertRpcAttribute(waitSpan("RpcClient.callMethod"), "error", rpcServer.getListenerAddress(),
- Kind.CLIENT);
- assertRpcAttribute(waitSpan("RpcServer.callMethod"), "error", null, Kind.INTERNAL);
+ SpanKind.CLIENT);
+ assertRpcAttribute(waitSpan("RpcServer.callMethod"), "error", null, SpanKind.INTERNAL);
assertRemoteSpan();
assertSameTraceId();
for (SpanData data : traceRule.getSpans()) {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionTracing.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionTracing.java
index 3a772a28059..17c3eb4f03a 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionTracing.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionTracing.java
@@ -23,6 +23,7 @@ import io.opentelemetry.sdk.testing.junit4.OpenTelemetryRule;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName;
@@ -48,7 +49,6 @@ import org.apache.hadoop.hbase.wal.WAL;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
@@ -79,18 +79,12 @@ public class TestHRegionTracing {
@Rule
public final TableNameTestRule tableNameRule = new TableNameTestRule();
- private static WAL WAL;
+ private WAL wal;
private HRegion region;
- @BeforeClass
- public static void setUpBeforeClass() throws IOException {
- WAL = HBaseTestingUtility.createWal(UTIL.getConfiguration(), UTIL.getDataTestDir(), null);
- }
-
@AfterClass
public static void tearDownAfterClass() throws IOException {
- Closeables.close(WAL, true);
UTIL.cleanupTestDir();
}
@@ -102,7 +96,9 @@ public class TestHRegionTracing {
RegionInfo info = RegionInfoBuilder.newBuilder(tableName).build();
ChunkCreator.initialize(MemStoreLAB.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null,
MemStoreLAB.INDEX_CHUNK_SIZE_PERCENTAGE_DEFAULT);
- region = HRegion.createHRegion(info, UTIL.getDataTestDir(), UTIL.getConfiguration(), desc, WAL);
+ wal = HBaseTestingUtility.createWal(UTIL.getConfiguration(),
+ new Path(UTIL.getDataTestDir(), tableName.getNameAsString()), null);
+ region = HRegion.createHRegion(info, UTIL.getDataTestDir(), UTIL.getConfiguration(), desc, wal);
region = UTIL.createLocalHRegion(info, desc);
}
@@ -111,6 +107,7 @@ public class TestHRegionTracing {
if (region != null) {
region.close();
}
+ Closeables.close(wal, true);
}
private void assertSpan(String spanName) {
diff --git a/pom.xml b/pom.xml
index 9fcf86b648a..6f04e4deaeb 100755
--- a/pom.xml
+++ b/pom.xml
@@ -1483,7 +1483,8 @@
9.2.13.0
4.13
1.3
- 0.13.1
+ 0.17.1
+ 0.17.0
1.2.17
2.28.2
@@ -2176,23 +2177,20 @@
io.opentelemetry
- opentelemetry-api
+ opentelemetry-bom
${opentelemetry.version}
+ pom
+ import
io.opentelemetry
- opentelemetry-sdk
- ${opentelemetry.version}
-
-
- io.opentelemetry
- opentelemetry-sdk-testing
- ${opentelemetry.version}
+ opentelemetry-semconv
+ ${opentelemetry.version}-alpha
io.opentelemetry.javaagent
opentelemetry-javaagent
- ${opentelemetry.version}
+ ${opentelemetry-javaagent.version}
all