Skip to content
Closed
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
@@ -1,4 +1,4 @@
/**
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
Expand Down Expand Up @@ -42,7 +42,7 @@ public JaegerSpanContext extract(StringBuilder s) {
throw new EmptyTracerStateStringException();
}
String value = s.toString();
if (value != null && !value.equals("")) {
if (!"".equals(value)) {
String[] parts = value.split(":");
if (parts.length != 4) {
if (LOG.isDebugEnabled()) {
Expand All @@ -59,7 +59,7 @@ public JaegerSpanContext extract(StringBuilder s) {
(new BigInteger(parts[3], 16)).byteValue());
} else {
throw new TraceIdOutOfBoundException(
"Trace id [" + traceId + "] length is not withing 1 and 32");
"Trace id [" + traceId + "] length is not within 1 and 32");
}
}
} else {
Expand All @@ -68,13 +68,12 @@ public JaegerSpanContext extract(StringBuilder s) {
}

@Override
public void inject(JaegerSpanContext context,
StringBuilder string) {
public void inject(JaegerSpanContext context, StringBuilder string) {
int intFlag = context.getFlags() & 255;
string.append(
context.getTraceId() + ":" + Long.toHexString(context.getSpanId())
+ ":" + Long.toHexString(context.getParentId()) + ":" + Integer
.toHexString(intFlag));
string.append(context.getTraceId())
.append(":").append(Long.toHexString(context.getSpanId()))
.append(":").append(Long.toHexString(context.getParentId()))
.append(":").append(Integer.toHexString(intFlag));
}

private static long high(String hexString) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
Expand Down Expand Up @@ -41,11 +41,10 @@ private TracingUtil() {

/**
* Initialize the tracing with the given service name.
*
* @param serviceName
*/
public static void initTracing(String serviceName) {
if (!GlobalTracer.isRegistered()) {
public static void initTracing(
String serviceName, org.apache.hadoop.conf.Configuration conf) {
if (!GlobalTracer.isRegistered() && isTracingEnabled(conf)) {
Configuration config = Configuration.fromEnv(serviceName);
JaegerTracer tracer = config.getTracerBuilder()
.registerExtractor(StringCodec.FORMAT, new StringCodec())
Expand All @@ -61,13 +60,7 @@ public static void initTracing(String serviceName) {
* @return encoded tracing context.
*/
public static String exportCurrentSpan() {
if (GlobalTracer.get().activeSpan() != null) {
StringBuilder builder = new StringBuilder();
GlobalTracer.get().inject(GlobalTracer.get().activeSpan().context(),
StringCodec.FORMAT, builder);
return builder.toString();
}
return NULL_SPAN_AS_STRING;
return exportSpan(GlobalTracer.get().activeSpan());
}

/**
Expand All @@ -93,48 +86,51 @@ public static String exportSpan(Span span) {
* @return OpenTracing scope.
*/
public static Scope importAndCreateScope(String name, String encodedParent) {
Tracer.SpanBuilder spanBuilder;
Tracer tracer = GlobalTracer.get();
SpanContext parentSpan = null;
if (encodedParent != null && encodedParent.length() > 0) {
StringBuilder builder = new StringBuilder();
builder.append(encodedParent);
parentSpan = tracer.extract(StringCodec.FORMAT, builder);
return tracer.buildSpan(name)
.asChildOf(extractParent(encodedParent, tracer))
.startActive(true);
}

private static SpanContext extractParent(String parent, Tracer tracer) {
if (!GlobalTracer.isRegistered()) {
return null;
}

if (parentSpan == null) {
spanBuilder = tracer.buildSpan(name);
} else {
spanBuilder =
tracer.buildSpan(name).asChildOf(parentSpan);
if (parent == null || parent.isEmpty()) {
return null;
}
return spanBuilder.startActive(true);

return tracer.extract(StringCodec.FORMAT, new StringBuilder(parent));
}

/**
* Creates a proxy of the implementation and trace all the method calls.
*
* @param delegate the original class instance
* @param interfce the interface which should be implemented by the proxy
* @param itf the interface which should be implemented by the proxy
* @param <T> the type of the interface
* @param conf configuration
*
* @return A new interface which implements interfce but delegate all the
* calls to the delegate and also enables tracing.
*/
public static <T> T createProxy(T delegate, Class<T> interfce,
org.apache.hadoop.conf.Configuration conf) {
boolean isTracingEnabled = conf.getBoolean(
ScmConfigKeys.HDDS_TRACING_ENABLED,
ScmConfigKeys.HDDS_TRACING_ENABLED_DEFAULT);
if (!isTracingEnabled) {
public static <T> T createProxy(
T delegate, Class<T> itf, org.apache.hadoop.conf.Configuration conf) {
if (!isTracingEnabled(conf)) {
return delegate;
}
Class<?> aClass = delegate.getClass();
return (T) Proxy.newProxyInstance(aClass.getClassLoader(),
new Class<?>[] {interfce},
new TraceAllMethod<T>(delegate, interfce.getSimpleName()));
return itf.cast(Proxy.newProxyInstance(aClass.getClassLoader(),
new Class<?>[] {itf},
new TraceAllMethod<>(delegate, itf.getSimpleName())));
}

private static boolean isTracingEnabled(
org.apache.hadoop.conf.Configuration conf) {
return conf.getBoolean(
ScmConfigKeys.HDDS_TRACING_ENABLED,
ScmConfigKeys.HDDS_TRACING_ENABLED_DEFAULT);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void start() {
datanodeDetails.setIpAddress(ip);
TracingUtil.initTracing(
"HddsDatanodeService." + datanodeDetails.getUuidString()
.substring(0, 8));
.substring(0, 8), conf);
LOG.info("HddsDatanodeService host:{} ip:{}", hostname, ip);
// Authenticate Hdds Datanode service if security is enabled
if (OzoneSecurityUtil.isSecurityEnabled(conf)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,12 @@ public class StorageContainerManagerStarter extends GenericCli {
private static final Logger LOG =
LoggerFactory.getLogger(StorageContainerManagerStarter.class);

public static void main(String[] args) throws Exception {
TracingUtil.initTracing("StorageContainerManager");
public static void main(String[] args) {
new StorageContainerManagerStarter(
new StorageContainerManagerStarter.SCMStarterHelper()).run(args);
}

public StorageContainerManagerStarter(SCMStarterInterface receiverObj) {
super();
receiver = receiverObj;
}

Expand Down Expand Up @@ -121,6 +119,7 @@ private void startScm() throws Exception {
*/
private void commonInit() {
conf = createOzoneConfiguration();
TracingUtil.initTracing("StorageContainerManager", conf);

String[] originalArgs = getCmd().getParseResult().originalArgs()
.toArray(new String[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ public class OzoneManagerStarter extends GenericCli {
LoggerFactory.getLogger(OzoneManagerStarter.class);

public static void main(String[] args) throws Exception {
TracingUtil.initTracing("OzoneManager");
new OzoneManagerStarter(
new OzoneManagerStarter.OMStarterHelper()).run(args);
}

public OzoneManagerStarter(OMStarterInterface receiverObj) {
super();
receiver = receiverObj;
}

Expand Down Expand Up @@ -100,6 +98,7 @@ public void initOm()
*/
private void commonInit() {
conf = createOzoneConfiguration();
TracingUtil.initTracing("OzoneManager", conf);

String[] originalArgs = getCmd().getParseResult().originalArgs()
.toArray(new String[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static void main(String[] argv) throws Exception {

@Override
public void execute(String[] argv) {
TracingUtil.initTracing("shell");
TracingUtil.initTracing("shell", createOzoneConfiguration());
try (Scope scope = GlobalTracer.get().buildSpan("main").startActive(true)) {
super.execute(argv);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class S3Shell extends Shell {

@Override
public void execute(String[] argv) {
TracingUtil.initTracing("s3shell");
TracingUtil.initTracing("s3shell", createOzoneConfiguration());
try (Scope scope = GlobalTracer.get().buildSpan("main").startActive(true)) {
super.execute(argv);
}
Expand All @@ -48,9 +48,8 @@ public void execute(String[] argv) {
* Main for the S3Shell Command handling.
*
* @param argv - System Args Strings[]
* @throws Exception
*/
public static void main(String[] argv) throws Exception {
public static void main(String[] argv) {
new S3Shell().run(argv);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.hadoop.hdds.HddsUtils;
import org.apache.hadoop.hdds.cli.GenericCli;
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.tracing.TracingUtil;

import org.slf4j.Logger;
Expand Down Expand Up @@ -57,11 +58,13 @@ public class Freon extends GenericCli {
private boolean httpServer = false;

private FreonHttpServer freonHttpServer;
private OzoneConfiguration conf;

@Override
public void execute(String[] argv) {
HddsUtils.initializeMetrics(createOzoneConfiguration(), "ozone-freon");
TracingUtil.initTracing("freon");
conf = createOzoneConfiguration();
HddsUtils.initializeMetrics(conf, "ozone-freon");
TracingUtil.initTracing("freon", conf);
super.execute(argv);
}

Expand All @@ -78,7 +81,7 @@ public void stopHttpServer() {
public void startHttpServer() {
if (httpServer) {
try {
freonHttpServer = new FreonHttpServer(createOzoneConfiguration());
freonHttpServer = new FreonHttpServer(conf);
freonHttpServer.start();
} catch (IOException e) {
LOG.error("Freon http server can't be started", e);
Expand Down