Browse Source

HADOOP-18077. ProfileOutputServlet unable to proceed due to NPE (#3875)

Viraj Jasani 3 years ago
parent
commit
93294f0329

+ 4 - 2
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java

@@ -772,10 +772,11 @@ public final class HttpServer2 implements FilterContainer {
 
     addDefaultServlets();
     addPrometheusServlet(conf);
-    addAsyncProfilerServlet(contexts);
+    addAsyncProfilerServlet(contexts, conf);
   }
 
-  private void addAsyncProfilerServlet(ContextHandlerCollection contexts) throws IOException {
+  private void addAsyncProfilerServlet(ContextHandlerCollection contexts, Configuration conf)
+      throws IOException {
     final String asyncProfilerHome = ProfileServlet.getAsyncProfilerHome();
     if (asyncProfilerHome != null && !asyncProfilerHome.trim().isEmpty()) {
       addServlet("prof", "/prof", ProfileServlet.class);
@@ -787,6 +788,7 @@ public final class HttpServer2 implements FilterContainer {
       genCtx.addServlet(ProfileOutputServlet.class, "/*");
       genCtx.setResourceBase(tmpDir.toAbsolutePath().toString());
       genCtx.setDisplayName("prof-output-hadoop");
+      setContextAttributes(genCtx, conf);
     } else {
       addServlet("prof", "/prof", ProfilerDisabledServlet.class);
       LOG.info("ASYNC_PROFILER_HOME environment variable and async.profiler.home system property "

+ 7 - 1
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/ProfilerDisabledServlet.java

@@ -36,9 +36,15 @@ public class ProfilerDisabledServlet extends HttpServlet {
       throws IOException {
     resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
     ProfileServlet.setResponseHeader(resp);
+    // TODO : Replace github.com link with
+    //  https://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/
+    //  AsyncProfilerServlet.html once Async profiler changes are released
+    //  in 3.x (3.4.0 as of today).
     resp.getWriter().write("The profiler servlet was disabled at startup.\n\n"
         + "Please ensure the prerequisites for the Profiler Servlet have been installed and the\n"
-        + "environment is properly configured.");
+        + "environment is properly configured. \n\n"
+        + "For more details, please refer to: https://github.com/apache/hadoop/blob/trunk/"
+        + "hadoop-common-project/hadoop-common/src/site/markdown/AsyncProfilerServlet.md");
   }
 
 }