Skip to content

Commit

Permalink
Remove redundant entry in Web servlet CommonFilter and update entry c…
Browse files Browse the repository at this point in the history
…lassification

Signed-off-by: Eric Zhao <[email protected]>
  • Loading branch information
sczyh30 committed Nov 6, 2019
1 parent 800f6b9 commit d38d548
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.EntryType;
import com.alibaba.csp.sentinel.ResourceTypeConstants;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.Tracer;
import com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser;
Expand Down Expand Up @@ -79,7 +80,6 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
throws IOException, ServletException {
HttpServletRequest sRequest = (HttpServletRequest) request;
Entry urlEntry = null;
Entry httpMethodUrlEntry = null;

try {
String target = FilterUtil.filterTarget(sRequest);
Expand All @@ -98,11 +98,13 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
String origin = parseOrigin(sRequest);
String contextName = webContextUnify ? WebServletConfig.WEB_SERVLET_CONTEXT_NAME : target;
ContextUtil.enter(contextName, origin);
urlEntry = SphU.entry(target, EntryType.IN);
// Add method specification if necessary

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);
Expand All @@ -112,12 +114,8 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
WebCallbackManager.getUrlBlockHandler().blocked(sRequest, sResponse, e);
} catch (IOException | ServletException | RuntimeException e2) {
Tracer.traceEntry(e2, urlEntry);
Tracer.traceEntry(e2, httpMethodUrlEntry);
throw e2;
} finally {
if (httpMethodUrlEntry != null) {
httpMethodUrlEntry.exit();
}
if (urlEntry != null) {
urlEntry.exit();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
import javax.servlet.http.HttpServletResponse;

import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.ResourceTypeConstants;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.Tracer;
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.util.FilterUtil;
import com.alibaba.csp.sentinel.context.ContextUtil;
import com.alibaba.csp.sentinel.slots.block.BlockException;

Expand All @@ -57,7 +57,7 @@ public void doFilter(ServletRequest request, ServletResponse response,
Entry entry = null;
try {
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);
} catch (BlockException e) {
HttpServletResponse sResponse = (HttpServletResponse)response;
Expand Down

0 comments on commit d38d548

Please sign in to comment.