fix:熔断监控上报补充code

pull/924/head
chuntaojun 3 years ago
parent b2081651e9
commit ae7f186c92

@ -27,8 +27,12 @@ import com.tencent.polaris.api.rpc.ServiceCallResult;
import com.tencent.polaris.circuitbreak.client.exception.CallAbortedException;
import com.tencent.polaris.discovery.client.api.DefaultConsumerAPI;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Assert;
import java.util.Objects;
/**
* PolarisCircuitBreakerUtils.
*
@ -36,6 +40,8 @@ import org.springframework.util.Assert;
*/
public final class PolarisCircuitBreakerUtils {
private static final Logger LOG = LoggerFactory.getLogger(PolarisCircuitBreakerUtils.class);
private PolarisCircuitBreakerUtils() {
}
@ -61,20 +67,28 @@ public final class PolarisCircuitBreakerUtils {
public static void reportStatus(ConsumerAPI consumerAPI,
PolarisCircuitBreakerConfigBuilder.PolarisCircuitBreakerConfiguration conf, CallAbortedException e) {
ServiceCallResult result = new ServiceCallResult();
result.setMethod(conf.getMethod());
result.setNamespace(conf.getNamespace());
result.setService(conf.getService());
result.setRuleName(e.getRuleName());
result.setRetStatus(RetStatus.RetReject);
result.setCallerService(new ServiceKey(conf.getSourceNamespace(), conf.getSourceService()));
try {
ServiceCallResult result = new ServiceCallResult();
result.setMethod(conf.getMethod());
result.setNamespace(conf.getNamespace());
result.setService(conf.getService());
result.setRuleName(e.getRuleName());
result.setRetStatus(RetStatus.RetReject);
result.setCallerService(new ServiceKey(conf.getSourceNamespace(), conf.getSourceService()));
String callerIp = ((DefaultConsumerAPI) consumerAPI).getSDKContext().getConfig().getGlobal().getAPI().getBindIP();
if (StringUtils.isNotBlank(callerIp)) {
result.setCallerIp(callerIp);
}
if (Objects.nonNull(e.getFallbackInfo())) {
result.setRetCode(e.getFallbackInfo().getCode());
}
consumerAPI.updateServiceCallResult(result);
String callerIp = ((DefaultConsumerAPI) consumerAPI).getSDKContext().getConfig().getGlobal().getAPI().getBindIP();
if (StringUtils.isNotBlank(callerIp)) {
result.setCallerIp(callerIp);
}
consumerAPI.updateServiceCallResult(result);
} catch (Throwable ex) {
LOG.error("[CircuitBreaker]");
}
}
}

@ -5,7 +5,7 @@ spring:
name: polaris-circuitbreaker-callee-service
cloud:
polaris:
address: grpc://183.47.111.80:8091
address: grpc://127.0.0.1:8091
namespace: default
enabled: true
stat:

@ -5,7 +5,7 @@ spring:
name: polaris-circuitbreaker-callee-service
cloud:
polaris:
address: grpc://183.47.111.80:8091
address: grpc://127.0.0.1:8091
namespace: default
enabled: true
stat:

@ -5,7 +5,7 @@ spring:
name: polaris-circuitbreaker-feign-example
cloud:
polaris:
address: grpc://183.47.111.80:8091
address: grpc://127.0.0.1:8091
namespace: default
enabled: true
loadbalancer:

@ -16,7 +16,7 @@ spring:
feature-env:
enabled: true
polaris:
address: grpc://183.47.111.80:8091
address: grpc://127.0.0.1:8091
namespace: default
enabled: true
gateway:

@ -5,7 +5,7 @@ spring:
name: polaris-circuitbreaker-resttemplate-example
cloud:
polaris:
address: grpc://183.47.111.80:8091
address: grpc://127.0.0.1:8091
namespace: default
enabled: true
loadbalancer:

@ -5,7 +5,7 @@ spring:
name: polaris-circuitbreaker-webclient-example
cloud:
polaris:
address: grpc://183.47.111.80:8091
address: grpc://127.0.0.1:8091
namespace: default
enabled: true
loadbalancer:

Loading…
Cancel
Save