HADOOP-12183. Annotate the HTrace span created by FsShell with the command-line arguments passed by the user (Masatake Iwasaki via Colin P. McCabe)

(cherry picked from commit 454da959c7)
This commit is contained in:
Colin Patrick Mccabe 2015-07-31 14:59:42 -07:00
parent 07a042aa3c
commit 7d68f17731
3 changed files with 17 additions and 1 deletions

View File

@ -228,6 +228,10 @@ Release 2.8.0 - UNRELEASED
HADOOP-11807. add a lint mode to releasedocmaker (ramtin via aw) HADOOP-11807. add a lint mode to releasedocmaker (ramtin via aw)
HADOOP-12183. Annotate the HTrace span created by FsShell with the
command-line arguments passed by the user (Masatake Iwasaki via Colin P.
McCabe)
OPTIMIZATIONS OPTIMIZATIONS
HADOOP-11785. Reduce the number of listStatus operation in distcp HADOOP-11785. Reduce the number of listStatus operation in distcp

View File

@ -35,6 +35,7 @@
import org.apache.hadoop.tracing.SpanReceiverHost; import org.apache.hadoop.tracing.SpanReceiverHost;
import org.apache.hadoop.tools.TableListing; import org.apache.hadoop.tools.TableListing;
import org.apache.hadoop.tracing.TraceUtils; import org.apache.hadoop.tracing.TraceUtils;
import org.apache.hadoop.util.StringUtils;
import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner; import org.apache.hadoop.util.ToolRunner;
import org.apache.htrace.Sampler; import org.apache.htrace.Sampler;
@ -298,6 +299,13 @@ public int run(String argv[]) throws Exception {
throw new UnknownCommandException(); throw new UnknownCommandException();
} }
TraceScope scope = Trace.startSpan(instance.getCommandName(), traceSampler); TraceScope scope = Trace.startSpan(instance.getCommandName(), traceSampler);
if (scope.getSpan() != null) {
String args = StringUtils.join(" ", argv);
if (args.length() > 2048) {
args = args.substring(0, 2048);
}
scope.getSpan().addKVAnnotation("args", args);
}
try { try {
exitCode = instance.run(Arrays.copyOfRange(argv, 1, argv.length)); exitCode = instance.run(Arrays.copyOfRange(argv, 1, argv.length));
} finally { } finally {

View File

@ -24,6 +24,7 @@
import org.apache.hadoop.util.ToolRunner; import org.apache.hadoop.util.ToolRunner;
import org.apache.htrace.SamplerBuilder; import org.apache.htrace.SamplerBuilder;
import org.apache.htrace.impl.AlwaysSampler; import org.apache.htrace.impl.AlwaysSampler;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
public class TestFsShell { public class TestFsShell {
@ -57,10 +58,13 @@ public void testTracing() throws Throwable {
FsShell shell = new FsShell(conf); FsShell shell = new FsShell(conf);
int res; int res;
try { try {
res = ToolRunner.run(shell, new String[]{"-help"}); res = ToolRunner.run(shell, new String[]{"-help", "ls", "cat"});
} finally { } finally {
shell.close(); shell.close();
} }
SetSpanReceiver.assertSpanNamesFound(new String[]{"help"}); SetSpanReceiver.assertSpanNamesFound(new String[]{"help"});
Assert.assertEquals("-help ls cat",
SetSpanReceiver.getMap()
.get("help").get(0).getKVAnnotations().get("args"));
} }
} }