Browse Source

Remove redundant entry in Web servlet CommonFilter and update entry classification

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
master
Eric Zhao 5 years ago
parent
commit
d38d5484ef
2 changed files with 9 additions and 11 deletions
  1. +7
    -9
      sentinel-adapter/sentinel-web-servlet/src/main/java/com/alibaba/csp/sentinel/adapter/servlet/CommonFilter.java
  2. +2
    -2
      sentinel-adapter/sentinel-web-servlet/src/main/java/com/alibaba/csp/sentinel/adapter/servlet/CommonTotalFilter.java

+ 7
- 9
sentinel-adapter/sentinel-web-servlet/src/main/java/com/alibaba/csp/sentinel/adapter/servlet/CommonFilter.java View File

@@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletResponse;


import com.alibaba.csp.sentinel.Entry; import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.EntryType; import com.alibaba.csp.sentinel.EntryType;
import com.alibaba.csp.sentinel.ResourceTypeConstants;
import com.alibaba.csp.sentinel.SphU; import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.Tracer; import com.alibaba.csp.sentinel.Tracer;
import com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser; import com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser;
@@ -79,7 +80,6 @@ public class CommonFilter implements Filter {
throws IOException, ServletException { throws IOException, ServletException {
HttpServletRequest sRequest = (HttpServletRequest) request; HttpServletRequest sRequest = (HttpServletRequest) request;
Entry urlEntry = null; Entry urlEntry = null;
Entry httpMethodUrlEntry = null;


try { try {
String target = FilterUtil.filterTarget(sRequest); String target = FilterUtil.filterTarget(sRequest);
@@ -98,11 +98,13 @@ public class CommonFilter implements Filter {
String origin = parseOrigin(sRequest); String origin = parseOrigin(sRequest);
String contextName = webContextUnify ? WebServletConfig.WEB_SERVLET_CONTEXT_NAME : target; String contextName = webContextUnify ? WebServletConfig.WEB_SERVLET_CONTEXT_NAME : target;
ContextUtil.enter(contextName, origin); ContextUtil.enter(contextName, origin);
urlEntry = SphU.entry(target, EntryType.IN);
// Add method specification if necessary

if (httpMethodSpecify) { if (httpMethodSpecify) {
httpMethodUrlEntry = SphU.entry(sRequest.getMethod().toUpperCase() + COLON + target,
EntryType.IN);
// Add HTTP method prefix if necessary.
String pathWithHttpMethod = sRequest.getMethod().toUpperCase() + COLON + target;
urlEntry = SphU.entry(pathWithHttpMethod, ResourceTypeConstants.COMMON_WEB, EntryType.IN);
} else {
urlEntry = SphU.entry(target, ResourceTypeConstants.COMMON_WEB, EntryType.IN);
} }
} }
chain.doFilter(request, response); chain.doFilter(request, response);
@@ -112,12 +114,8 @@ public class CommonFilter implements Filter {
WebCallbackManager.getUrlBlockHandler().blocked(sRequest, sResponse, e); WebCallbackManager.getUrlBlockHandler().blocked(sRequest, sResponse, e);
} catch (IOException | ServletException | RuntimeException e2) { } catch (IOException | ServletException | RuntimeException e2) {
Tracer.traceEntry(e2, urlEntry); Tracer.traceEntry(e2, urlEntry);
Tracer.traceEntry(e2, httpMethodUrlEntry);
throw e2; throw e2;
} finally { } finally {
if (httpMethodUrlEntry != null) {
httpMethodUrlEntry.exit();
}
if (urlEntry != null) { if (urlEntry != null) {
urlEntry.exit(); urlEntry.exit();
} }


+ 2
- 2
sentinel-adapter/sentinel-web-servlet/src/main/java/com/alibaba/csp/sentinel/adapter/servlet/CommonTotalFilter.java View File

@@ -27,11 +27,11 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;


import com.alibaba.csp.sentinel.Entry; import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.ResourceTypeConstants;
import com.alibaba.csp.sentinel.SphU; import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.Tracer; import com.alibaba.csp.sentinel.Tracer;
import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager; import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager;
import com.alibaba.csp.sentinel.adapter.servlet.config.WebServletConfig; import com.alibaba.csp.sentinel.adapter.servlet.config.WebServletConfig;
import com.alibaba.csp.sentinel.adapter.servlet.util.FilterUtil;
import com.alibaba.csp.sentinel.context.ContextUtil; import com.alibaba.csp.sentinel.context.ContextUtil;
import com.alibaba.csp.sentinel.slots.block.BlockException; import com.alibaba.csp.sentinel.slots.block.BlockException;


@@ -57,7 +57,7 @@ public class CommonTotalFilter implements Filter {
Entry entry = null; Entry entry = null;
try { try {
ContextUtil.enter(WebServletConfig.WEB_SERVLET_CONTEXT_NAME); ContextUtil.enter(WebServletConfig.WEB_SERVLET_CONTEXT_NAME);
entry = SphU.entry(TOTAL_URL_REQUEST);
entry = SphU.entry(TOTAL_URL_REQUEST, ResourceTypeConstants.COMMON_WEB);
chain.doFilter(request, response); chain.doFilter(request, response);
} catch (BlockException e) { } catch (BlockException e) {
HttpServletResponse sResponse = (HttpServletResponse)response; HttpServletResponse sResponse = (HttpServletResponse)response;


Loading…
Cancel
Save