HADOOP-12175. FsShell must load SpanReceierHost to support tracing (Masatake Iwasaki via Colin P. McCabe)

(cherry picked from commit 69b095730b)
This commit is contained in:
Colin Patrick Mccabe 2015-07-28 12:49:38 -07:00
parent 2ec008eb38
commit 5875935669
4 changed files with 38 additions and 2 deletions

View File

@ -526,6 +526,9 @@ Release 2.8.0 - UNRELEASED
HADOOP-12245. References to misspelled REMAINING_QUATA in HADOOP-12245. References to misspelled REMAINING_QUATA in
FileSystemShell.md. (Gabor Liptak via aajisaka) FileSystemShell.md. (Gabor Liptak via aajisaka)
HADOOP-12175. FsShell must load SpanReceierHost to support tracing
(Masatake Iwasaki via Colin P. McCabe)
Release 2.7.2 - UNRELEASED Release 2.7.2 - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -32,6 +32,7 @@ import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.shell.Command; import org.apache.hadoop.fs.shell.Command;
import org.apache.hadoop.fs.shell.CommandFactory; import org.apache.hadoop.fs.shell.CommandFactory;
import org.apache.hadoop.fs.shell.FsCommand; import org.apache.hadoop.fs.shell.FsCommand;
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.Tool; import org.apache.hadoop.util.Tool;
@ -57,6 +58,9 @@ public class FsShell extends Configured implements Tool {
private final String usagePrefix = private final String usagePrefix =
"Usage: hadoop fs [generic options]"; "Usage: hadoop fs [generic options]";
private SpanReceiverHost spanReceiverHost;
static final String SEHLL_HTRACE_PREFIX = "dfs.shell.htrace.";
/** /**
* Default ctor with no configuration. Be sure to invoke * Default ctor with no configuration. Be sure to invoke
* {@link #setConf(Configuration)} with a valid configuration prior * {@link #setConf(Configuration)} with a valid configuration prior
@ -97,6 +101,8 @@ public class FsShell extends Configured implements Tool {
commandFactory.addObject(new Usage(), "-usage"); commandFactory.addObject(new Usage(), "-usage");
registerCommands(commandFactory); registerCommands(commandFactory);
} }
this.spanReceiverHost =
SpanReceiverHost.get(getConf(), SEHLL_HTRACE_PREFIX);
} }
protected void registerCommands(CommandFactory factory) { protected void registerCommands(CommandFactory factory) {
@ -279,7 +285,7 @@ public class FsShell extends Configured implements Tool {
// initialize FsShell // initialize FsShell
init(); init();
traceSampler = new SamplerBuilder(TraceUtils. traceSampler = new SamplerBuilder(TraceUtils.
wrapHadoopConf("dfs.shell.htrace.", getConf())).build(); wrapHadoopConf(SEHLL_HTRACE_PREFIX, getConf())).build();
int exitCode = -1; int exitCode = -1;
if (argv.length < 1) { if (argv.length < 1) {
printUsage(System.err); printUsage(System.err);
@ -335,6 +341,9 @@ public class FsShell extends Configured implements Tool {
fs.close(); fs.close();
fs = null; fs = null;
} }
if (this.spanReceiverHost != null) {
this.spanReceiverHost.closeReceivers();
}
} }
/** /**

View File

@ -18,6 +18,12 @@
package org.apache.hadoop.fs; package org.apache.hadoop.fs;
import junit.framework.AssertionFailedError; import junit.framework.AssertionFailedError;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.tracing.SetSpanReceiver;
import org.apache.hadoop.tracing.SpanReceiverHost;
import org.apache.hadoop.util.ToolRunner;
import org.apache.htrace.SamplerBuilder;
import org.apache.htrace.impl.AlwaysSampler;
import org.junit.Test; import org.junit.Test;
public class TestFsShell { public class TestFsShell {
@ -39,4 +45,22 @@ public class TestFsShell {
} }
} }
@Test
public void testTracing() throws Throwable {
Configuration conf = new Configuration();
String prefix = FsShell.SEHLL_HTRACE_PREFIX;
conf.set(prefix + SpanReceiverHost.SPAN_RECEIVERS_CONF_SUFFIX,
SetSpanReceiver.class.getName());
conf.set(prefix + SamplerBuilder.SAMPLER_CONF_KEY,
AlwaysSampler.class.getName());
conf.setQuietMode(false);
FsShell shell = new FsShell(conf);
int res;
try {
res = ToolRunner.run(shell, new String[]{"-help"});
} finally {
shell.close();
}
SetSpanReceiver.assertSpanNamesFound(new String[]{"help"});
}
} }

View File

@ -86,7 +86,7 @@ public class SetSpanReceiver implements SpanReceiver {
} }
} }
static void assertSpanNamesFound(final String[] expectedSpanNames) { public static void assertSpanNamesFound(final String[] expectedSpanNames) {
try { try {
GenericTestUtils.waitFor(new Supplier<Boolean>() { GenericTestUtils.waitFor(new Supplier<Boolean>() {
@Override @Override