Skip to content

Commit c11a3e1

Browse files
committed
Revert "HBASE-26124 Backport HBASE-25373 "Remove HTrace completely in code base and try to make use of OpenTelemetry" to branch-2 (#3529)"
This reverts commit f049301.
1 parent fffdcba commit c11a3e1

File tree

45 files changed

+914
-362
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+914
-362
lines changed

hbase-asyncfs/src/test/java/org/apache/hadoop/hbase/io/asyncfs/AsyncFSTestBase.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919

2020
import java.io.File;
2121
import java.io.IOException;
22+
2223
import org.apache.hadoop.conf.Configuration;
2324
import org.apache.hadoop.fs.Path;
2425
import org.apache.hadoop.hbase.HBaseCommonTestingUtility;
26+
import org.apache.hadoop.hbase.trace.TraceUtil;
2527
import org.apache.hadoop.hdfs.MiniDFSCluster;
2628
import org.slf4j.Logger;
2729
import org.slf4j.LoggerFactory;
@@ -102,6 +104,7 @@ protected static void startMiniDFSCluster(int servers) throws IOException {
102104
org.apache.log4j.Logger.getLogger(org.apache.hadoop.metrics2.impl.MetricsSystemImpl.class)
103105
.setLevel(org.apache.log4j.Level.ERROR);
104106

107+
TraceUtil.initTracer(conf);
105108
CLUSTER = new MiniDFSCluster.Builder(conf).numDataNodes(servers).build();
106109
CLUSTER.waitClusterUp();
107110
}

hbase-client/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@
145145
<artifactId>zookeeper</artifactId>
146146
</dependency>
147147
<dependency>
148-
<groupId>io.opentelemetry</groupId>
149-
<artifactId>opentelemetry-api</artifactId>
148+
<groupId>org.apache.htrace</groupId>
149+
<artifactId>htrace-core4</artifactId>
150150
</dependency>
151151
<dependency>
152152
<groupId>org.jruby.jcodings</groupId>

hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncRequestFutureImpl.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@
4646
import org.apache.hadoop.hbase.client.backoff.ServerStatistics;
4747
import org.apache.hadoop.hbase.client.coprocessor.Batch;
4848
import org.apache.hadoop.hbase.exceptions.ClientExceptionsUtil;
49+
import org.apache.hadoop.hbase.trace.TraceUtil;
4950
import org.apache.hadoop.hbase.util.Bytes;
5051
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
52+
import org.apache.htrace.core.Tracer;
5153
import org.apache.yetus.audience.InterfaceAudience;
5254
import org.slf4j.Logger;
5355
import org.slf4j.LoggerFactory;
@@ -570,9 +572,13 @@ private Collection<? extends Runnable> getNewMultiActionRunnable(ServerName serv
570572
asyncProcess.incTaskCounters(multiAction.getRegions(), server);
571573
SingleServerRequestRunnable runnable = createSingleServerRequest(
572574
multiAction, numAttempt, server, callsInProgress);
575+
Tracer tracer = Tracer.curThreadTracer();
573576

574-
// remove trace for runnable because HBASE-25373 and OpenTelemetry do not cover TraceRunnable
575-
return Collections.singletonList(runnable);
577+
if (tracer == null) {
578+
return Collections.singletonList(runnable);
579+
} else {
580+
return Collections.singletonList(tracer.wrap(runnable, "AsyncProcess.sendMultiAction"));
581+
}
576582
}
577583

578584
// group the actions by the amount of delay
@@ -592,10 +598,12 @@ private Collection<? extends Runnable> getNewMultiActionRunnable(ServerName serv
592598
List<Runnable> toReturn = new ArrayList<>(actions.size());
593599
for (DelayingRunner runner : actions.values()) {
594600
asyncProcess.incTaskCounters(runner.getActions().getRegions(), server);
601+
String traceText = "AsyncProcess.sendMultiAction";
595602
Runnable runnable = createSingleServerRequest(runner.getActions(), numAttempt, server, callsInProgress);
596603
// use a delay runner only if we need to sleep for some time
597604
if (runner.getSleepTime() > 0) {
598605
runner.setRunner(runnable);
606+
traceText = "AsyncProcess.clientBackoff.sendMultiAction";
599607
runnable = runner;
600608
if (asyncProcess.connection.getConnectionMetrics() != null) {
601609
asyncProcess.connection.getConnectionMetrics()
@@ -606,7 +614,7 @@ private Collection<? extends Runnable> getNewMultiActionRunnable(ServerName serv
606614
asyncProcess.connection.getConnectionMetrics().incrNormalRunners();
607615
}
608616
}
609-
// remove trace for runnable because HBASE-25373 and OpenTelemetry do not cover TraceRunnable
617+
runnable = TraceUtil.wrap(runnable, traceText);
610618
toReturn.add(runnable);
611619

612620
}

hbase-client/src/main/java/org/apache/hadoop/hbase/client/ResultBoundedCompletionService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.concurrent.TimeUnit;
2727
import java.util.concurrent.TimeoutException;
2828

29+
import org.apache.hadoop.hbase.trace.TraceUtil;
2930
import org.apache.yetus.audience.InterfaceAudience;
3031
import org.slf4j.Logger;
3132
import org.slf4j.LoggerFactory;
@@ -167,8 +168,7 @@ public ResultBoundedCompletionService(
167168

168169
public void submit(RetryingCallable<V> task, int callTimeout, int id) {
169170
QueueingFuture<V> newFuture = new QueueingFuture<>(task, callTimeout, id);
170-
// remove trace for runnable because HBASE-25373 and OpenTelemetry do not cover TraceRunnable
171-
executor.execute(newFuture);
171+
executor.execute(TraceUtil.wrap(newFuture, "ResultBoundedCompletionService.submit"));
172172
tasks[id] = newFuture;
173173
}
174174

hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/BlockingRpcConnection.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
import static org.apache.hadoop.hbase.ipc.IPCUtil.setCancelled;
2525
import static org.apache.hadoop.hbase.ipc.IPCUtil.write;
2626

27-
import io.opentelemetry.api.trace.Span;
28-
import io.opentelemetry.context.Context;
29-
import io.opentelemetry.context.Scope;
3027
import java.io.BufferedInputStream;
3128
import java.io.BufferedOutputStream;
3229
import java.io.DataInputStream;
@@ -65,6 +62,7 @@
6562
import org.apache.hadoop.net.NetUtils;
6663
import org.apache.hadoop.security.UserGroupInformation;
6764
import org.apache.hadoop.util.StringUtils;
65+
import org.apache.htrace.core.TraceScope;
6866
import org.apache.yetus.audience.InterfaceAudience;
6967
import org.slf4j.Logger;
7068
import org.slf4j.LoggerFactory;
@@ -595,12 +593,9 @@ private void negotiateCryptoAes(RPCProtos.CryptoCipherMeta cryptoCipherMeta)
595593
}
596594

597595
private void tracedWriteRequest(Call call) throws IOException {
598-
Span span = TraceUtil.getGlobalTracer().spanBuilder("RpcClientImpl.tracedWriteRequest")
599-
.setParent(Context.current().with(call.span)).startSpan();
600-
try (Scope scope = span.makeCurrent()) {
596+
try (TraceScope ignored = TraceUtil.createTrace("RpcClientImpl.tracedWriteRequest",
597+
call.span)) {
601598
writeRequest(call);
602-
} finally {
603-
span.end();
604599
}
605600
}
606601

hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/Call.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,20 @@
1717
*/
1818
package org.apache.hadoop.hbase.ipc;
1919

20-
import io.opentelemetry.api.trace.Span;
2120
import java.io.IOException;
2221
import java.util.Optional;
2322
import org.apache.commons.lang3.builder.ToStringBuilder;
2423
import org.apache.commons.lang3.builder.ToStringStyle;
2524
import org.apache.hadoop.hbase.CellScanner;
2625
import org.apache.hadoop.hbase.client.MetricsConnection;
2726
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
27+
import org.apache.htrace.core.Span;
28+
import org.apache.htrace.core.Tracer;
2829
import org.apache.yetus.audience.InterfaceAudience;
29-
3030
import org.apache.hbase.thirdparty.com.google.protobuf.Descriptors;
3131
import org.apache.hbase.thirdparty.com.google.protobuf.Message;
3232
import org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback;
3333
import org.apache.hbase.thirdparty.io.netty.util.Timeout;
34-
3534
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
3635

3736
/** A call waiting for a value. */
@@ -74,7 +73,7 @@ protected Call(int id, final Descriptors.MethodDescriptor md, Message param,
7473
this.timeout = timeout;
7574
this.priority = priority;
7675
this.callback = callback;
77-
this.span = Span.current();
76+
this.span = Tracer.getCurrentSpan();
7877
}
7978

8079
/**

hbase-common/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@
192192
</dependency>
193193
<!-- tracing Dependencies -->
194194
<dependency>
195-
<groupId>io.opentelemetry</groupId>
196-
<artifactId>opentelemetry-api</artifactId>
195+
<groupId>org.apache.htrace</groupId>
196+
<artifactId>htrace-core4</artifactId>
197197
</dependency>
198198
<dependency>
199199
<groupId>org.apache.commons</groupId>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.hadoop.hbase.trace;
20+
21+
import org.apache.hadoop.conf.Configuration;
22+
import org.apache.htrace.core.HTraceConfiguration;
23+
import org.apache.yetus.audience.InterfaceAudience;
24+
import org.slf4j.Logger;
25+
import org.slf4j.LoggerFactory;
26+
27+
@InterfaceAudience.Private
28+
public class HBaseHTraceConfiguration extends HTraceConfiguration {
29+
private static final Logger LOG = LoggerFactory.getLogger(HBaseHTraceConfiguration.class);
30+
31+
public static final String KEY_PREFIX = "hbase.htrace.";
32+
33+
private Configuration conf;
34+
35+
private void handleDeprecation(String key) {
36+
String oldKey = "hbase." + key;
37+
String newKey = KEY_PREFIX + key;
38+
String oldValue = conf.get(oldKey);
39+
if (oldValue != null) {
40+
LOG.warn("Warning: using deprecated configuration key " + oldKey +
41+
". Please use " + newKey + " instead.");
42+
String newValue = conf.get(newKey);
43+
if (newValue == null) {
44+
conf.set(newKey, oldValue);
45+
} else {
46+
LOG.warn("Conflicting values for " + newKey + " and " + oldKey +
47+
". Using " + newValue);
48+
}
49+
}
50+
}
51+
52+
public HBaseHTraceConfiguration(Configuration conf) {
53+
this.conf = conf;
54+
handleDeprecation("local-file-span-receiver.path");
55+
handleDeprecation("local-file-span-receiver.capacity");
56+
handleDeprecation("sampler.frequency");
57+
handleDeprecation("sampler.fraction");
58+
handleDeprecation("zipkin.collector-hostname");
59+
handleDeprecation("zipkin.collector-port");
60+
handleDeprecation("zipkin.num-threads");
61+
handleDeprecation("zipkin.traced-service-hostname");
62+
handleDeprecation("zipkin.traced-service-port");
63+
}
64+
65+
@Override
66+
public String get(String key) {
67+
return conf.get(KEY_PREFIX + key);
68+
}
69+
70+
@Override
71+
public String get(String key, String defaultValue) {
72+
return conf.get(KEY_PREFIX + key,defaultValue);
73+
74+
}
75+
76+
@Override
77+
public boolean getBoolean(String key, boolean defaultValue) {
78+
return conf.getBoolean(KEY_PREFIX + key, defaultValue);
79+
}
80+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hbase.trace;
19+
20+
import java.io.IOException;
21+
import java.util.Collection;
22+
import java.util.HashSet;
23+
24+
import org.apache.hadoop.conf.Configuration;
25+
import org.apache.htrace.core.SpanReceiver;
26+
import org.apache.yetus.audience.InterfaceAudience;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
29+
30+
/**
31+
* This class provides functions for reading the names of SpanReceivers from
32+
* hbase-site.xml, adding those SpanReceivers to the Tracer, and closing those
33+
* SpanReceivers when appropriate.
34+
*/
35+
@InterfaceAudience.Private
36+
public class SpanReceiverHost {
37+
public static final String SPAN_RECEIVERS_CONF_KEY = "hbase.trace.spanreceiver.classes";
38+
private static final Logger LOG = LoggerFactory.getLogger(SpanReceiverHost.class);
39+
private Collection<SpanReceiver> receivers;
40+
private Configuration conf;
41+
private boolean closed = false;
42+
43+
private enum SingletonHolder {
44+
INSTANCE;
45+
final transient Object lock = new Object();
46+
transient SpanReceiverHost host = null;
47+
}
48+
49+
public static SpanReceiverHost getInstance(Configuration conf) {
50+
synchronized (SingletonHolder.INSTANCE.lock) {
51+
if (SingletonHolder.INSTANCE.host != null) {
52+
return SingletonHolder.INSTANCE.host;
53+
}
54+
55+
SpanReceiverHost host = new SpanReceiverHost(conf);
56+
host.loadSpanReceivers();
57+
SingletonHolder.INSTANCE.host = host;
58+
return SingletonHolder.INSTANCE.host;
59+
}
60+
61+
}
62+
63+
public static Configuration getConfiguration(){
64+
synchronized (SingletonHolder.INSTANCE.lock) {
65+
if (SingletonHolder.INSTANCE.host == null || SingletonHolder.INSTANCE.host.conf == null) {
66+
return null;
67+
}
68+
69+
return SingletonHolder.INSTANCE.host.conf;
70+
}
71+
}
72+
73+
SpanReceiverHost(Configuration conf) {
74+
receivers = new HashSet<>();
75+
this.conf = conf;
76+
}
77+
78+
/**
79+
* Reads the names of classes specified in the {@code hbase.trace.spanreceiver.classes} property
80+
* and instantiates and registers them with the Tracer.
81+
*/
82+
public void loadSpanReceivers() {
83+
String[] receiverNames = conf.getStrings(SPAN_RECEIVERS_CONF_KEY);
84+
if (receiverNames == null || receiverNames.length == 0) {
85+
return;
86+
}
87+
88+
SpanReceiver.Builder builder = new SpanReceiver.Builder(new HBaseHTraceConfiguration(conf));
89+
for (String className : receiverNames) {
90+
className = className.trim();
91+
92+
SpanReceiver receiver = builder.className(className).build();
93+
if (receiver != null) {
94+
receivers.add(receiver);
95+
LOG.info("SpanReceiver {} was loaded successfully.", className);
96+
}
97+
}
98+
for (SpanReceiver rcvr : receivers) {
99+
TraceUtil.addReceiver(rcvr);
100+
}
101+
}
102+
103+
/**
104+
* Calls close() on all SpanReceivers created by this SpanReceiverHost.
105+
*/
106+
public synchronized void closeReceivers() {
107+
if (closed) {
108+
return;
109+
}
110+
111+
closed = true;
112+
for (SpanReceiver rcvr : receivers) {
113+
try {
114+
rcvr.close();
115+
} catch (IOException e) {
116+
LOG.warn("Unable to close SpanReceiver correctly: " + e.getMessage(), e);
117+
}
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)