Merge pull request #197 from fangjian0423/master

calculate exception ratio and count in Sentinel RestTemplate
pull/201/head
xiaojing 6 years ago committed by GitHub
commit 9258223c8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -33,6 +33,7 @@ import org.springframework.util.ClassUtils;
import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.Tracer;
import com.alibaba.csp.sentinel.context.ContextUtil;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
@ -61,24 +62,38 @@ public class SentinelProtectInterceptor implements ClientHttpRequestInterceptor
String hostResource = uri.getScheme() + "://" + uri.getHost()
+ (uri.getPort() == -1 ? "" : ":" + uri.getPort());
String hostWithPathResource = hostResource + uri.getPath();
boolean entryWithPath = true;
if (hostResource.equals(hostWithPathResource)) {
entryWithPath = false;
}
Entry hostEntry = null, hostWithPathEntry = null;
ClientHttpResponse response;
try {
ContextUtil.enter(hostWithPathResource);
hostWithPathEntry = SphU.entry(hostWithPathResource);
if (entryWithPath) {
hostWithPathEntry = SphU.entry(hostWithPathResource);
}
hostEntry = SphU.entry(hostResource);
response = execution.execute(request, body);
}
catch (BlockException e) {
try {
return handleBlockException(request, body, execution, e);
catch (Throwable e) {
if (!BlockException.isBlockException(e)) {
Tracer.trace(e);
throw new IllegalStateException(e);
}
catch (Exception ex) {
if (ex instanceof IllegalStateException) {
throw (IllegalStateException) ex;
else {
try {
return handleBlockException(request, body, execution,
(BlockException) e);
}
catch (Exception ex) {
if (ex instanceof IllegalStateException) {
throw (IllegalStateException) ex;
}
throw new IllegalStateException(
"sentinel handle BlockException error: " + ex.getMessage(),
ex);
}
throw new IllegalStateException(
"sentinel handle BlockException error: " + ex.getMessage(), ex);
}
}
finally {

Loading…
Cancel
Save