falcon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From venkat...@apache.org
Subject [4/4] git commit: FALCON-834 Propagate request id in the response to help trace and debug failures in merlin. Contributed by Venkatesh Seetharam
Date Mon, 27 Oct 2014 03:55:43 GMT
FALCON-834 Propagate request id in the response to help trace and debug failures in merlin.
Contributed by Venkatesh Seetharam


Project: http://git-wip-us.apache.org/repos/asf/incubator-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-falcon/commit/bf959ea9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-falcon/tree/bf959ea9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-falcon/diff/bf959ea9

Branch: refs/heads/master
Commit: bf959ea9fa78da7ea5e652295f833473123e8fd8
Parents: 03d3531
Author: Venkatesh Seetharam <venkatesh@apache.org>
Authored: Sun Oct 26 20:35:13 2014 -0700
Committer: Venkatesh Seetharam <venkatesh@apache.org>
Committed: Sun Oct 26 20:35:13 2014 -0700

----------------------------------------------------------------------
 CHANGES.txt                                          |  3 +++
 .../apache/falcon/security/FalconAuditFilter.java    | 15 ++++++++++++++-
 .../falcon/security/FalconAuthenticationFilter.java  |  4 ----
 3 files changed, 17 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/bf959ea9/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 9261af3..6259566 100755
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -37,6 +37,9 @@ Trunk (Unreleased)
    FALCON-263 API to get workflow parameters. (pavan kumar kolamuri via Shwetha GS)
 
   IMPROVEMENTS
+   FALCON-834 Propagate request id in the response to help trace and debug
+   failures in merlin (Venkatesh Seetharam)
+
    FALCON-828 Add hadoop version info as part of falcon admin version API
    (Venkatesh Seetharam)
 

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/bf959ea9/prism/src/main/java/org/apache/falcon/security/FalconAuditFilter.java
----------------------------------------------------------------------
diff --git a/prism/src/main/java/org/apache/falcon/security/FalconAuditFilter.java b/prism/src/main/java/org/apache/falcon/security/FalconAuditFilter.java
index 21e28b3..9a9b400 100644
--- a/prism/src/main/java/org/apache/falcon/security/FalconAuditFilter.java
+++ b/prism/src/main/java/org/apache/falcon/security/FalconAuditFilter.java
@@ -21,6 +21,7 @@ package org.apache.falcon.security;
 import org.apache.falcon.aspect.GenericAlert;
 import org.apache.falcon.entity.v0.SchemaHelper;
 import org.apache.falcon.util.Servlets;
+import org.apache.log4j.NDC;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -31,16 +32,21 @@ import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.util.Date;
+import java.util.UUID;
 
 /**
- * This records audit information as part of the filter after processing the request.
+ * This records audit information as part of the filter after processing the request
+ * and also introduces a UUID into request and response for tracing requests in logs.
  */
 public class FalconAuditFilter implements Filter {
 
     private static final Logger LOG = LoggerFactory.getLogger(FalconAuditFilter.class);
 
+    public static final String REQUEST_ID = "requestId";
+
     @Override
     public void init(FilterConfig filterConfig) throws ServletException {
         LOG.info("FalconAuditFilter initialization started");
@@ -51,11 +57,18 @@ public class FalconAuditFilter implements Filter {
                          ServletResponse response,
                          FilterChain filterChain) throws IOException, ServletException {
         final String requestTimeISO9601 = SchemaHelper.formatDateUTC(new Date());
+        // generate a unique id and shove it into NDC
+        final String requestId = UUID.randomUUID().toString();
+        NDC.push(requestId);
 
         try {
             filterChain.doFilter(request, response);
         } finally {
             recordAudit((HttpServletRequest) request, requestTimeISO9601);
+
+            // put the request id into the response so users can trace logs for this request
+            ((HttpServletResponse) response).setHeader(REQUEST_ID, requestId);
+            NDC.pop();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/bf959ea9/prism/src/main/java/org/apache/falcon/security/FalconAuthenticationFilter.java
----------------------------------------------------------------------
diff --git a/prism/src/main/java/org/apache/falcon/security/FalconAuthenticationFilter.java
b/prism/src/main/java/org/apache/falcon/security/FalconAuthenticationFilter.java
index 4edde75..fa30f0e 100644
--- a/prism/src/main/java/org/apache/falcon/security/FalconAuthenticationFilter.java
+++ b/prism/src/main/java/org/apache/falcon/security/FalconAuthenticationFilter.java
@@ -42,7 +42,6 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
-import java.util.UUID;
 
 /**
  * This enforces authentication as part of the filter before processing the request.
@@ -177,9 +176,7 @@ public class FalconAuthenticationFilter
                                 "User can't be a superuser:" + BLACK_LISTED_USERS_KEY);
                     } else {
                         try {
-                            String requestId = UUID.randomUUID().toString();
                             NDC.push(user + ":" + httpRequest.getMethod() + "/" + httpRequest.getPathInfo());
-                            NDC.push(requestId);
                             CurrentUser.authenticate(user);
                             LOG.info("Request from user: {}, URL={}", user,
                                     Servlets.getRequestURI(httpRequest));
@@ -187,7 +184,6 @@ public class FalconAuthenticationFilter
                             filterChain.doFilter(servletRequest, servletResponse);
                         } finally {
                             NDC.pop();
-                            NDC.pop();
                         }
                     }
                 }


Mime
View raw message