Search in sources :

Example 6 with InstanceByProto

use of com.tencent.polaris.client.pojo.InstanceByProto in project polaris-java by polarismesh.

the class ConsecutiveCircuitBreaker method stat.

@Override
public boolean stat(InstanceGauge gauge) {
    InstanceByProto instance = ChangeStateUtils.getInstance(gauge, localRegistry);
    if (null == instance) {
        return false;
    }
    InstanceLocalValue instanceLocalValue = instance.getInstanceLocalValue();
    if (null == instanceLocalValue) {
        return false;
    }
    ConfigSet<Config> configSet = CircuitBreakUtils.getConfigSet(gauge, this);
    StatusDimension statusDimension = ChangeStateUtils.buildStatusDimension(gauge, configSet.getLevel());
    if (CircuitBreakUtils.instanceClose(instance, statusDimension)) {
        Object pluginValue = instanceLocalValue.getPluginValue(id, create);
        ConsecutiveCounter consecutiveCounter = (ConsecutiveCounter) pluginValue;
        RetStatus retStatus = gauge.getRetStatus();
        int failCount;
        if (retStatus == RetStatus.RetFail) {
            failCount = consecutiveCounter.onFail(statusDimension);
        } else {
            consecutiveCounter.resetCounter(statusDimension);
            failCount = 0;
        }
        return failCount == configSet.getPlugConfig().getContinuousErrorThreshold();
    } else if (CircuitBreakUtils.instanceHalfOpen(instance, statusDimension)) {
        // 半开计数器
        Object pluginValue = instanceLocalValue.getPluginValue(id, create);
        HalfOpenCounter consecutiveCounter = (HalfOpenCounter) pluginValue;
        RetStatus retStatus = gauge.getRetStatus();
        return consecutiveCounter.triggerHalfOpenConversion(statusDimension, retStatus, configSet.getHalfOpenConfig());
    }
    return false;
}
Also used : InstanceByProto(com.tencent.polaris.client.pojo.InstanceByProto) RetStatus(com.tencent.polaris.api.pojo.RetStatus) ConsecutiveErrConfig(com.tencent.polaris.client.pb.CircuitBreakerProto.CbPolicy.ConsecutiveErrConfig) OutlierDetectionConfig(com.tencent.polaris.api.config.consumer.OutlierDetectionConfig) RecoverConfig(com.tencent.polaris.client.pb.CircuitBreakerProto.RecoverConfig) CircuitBreakerConfig(com.tencent.polaris.api.config.consumer.CircuitBreakerConfig) HalfOpenConfig(com.tencent.polaris.plugins.circuitbreaker.common.HalfOpenConfig) InstanceLocalValue(com.tencent.polaris.api.pojo.InstanceLocalValue) StatusDimension(com.tencent.polaris.api.pojo.StatusDimension) HalfOpenCounter(com.tencent.polaris.plugins.circuitbreaker.common.HalfOpenCounter)

Aggregations

InstanceByProto (com.tencent.polaris.client.pojo.InstanceByProto)6 InstanceLocalValue (com.tencent.polaris.api.pojo.InstanceLocalValue)4 CircuitBreakerConfig (com.tencent.polaris.api.config.consumer.CircuitBreakerConfig)2 OutlierDetectionConfig (com.tencent.polaris.api.config.consumer.OutlierDetectionConfig)2 Instance (com.tencent.polaris.api.pojo.Instance)2 RetStatus (com.tencent.polaris.api.pojo.RetStatus)2 ServiceEventKey (com.tencent.polaris.api.pojo.ServiceEventKey)2 StatusDimension (com.tencent.polaris.api.pojo.StatusDimension)2 RecoverConfig (com.tencent.polaris.client.pb.CircuitBreakerProto.RecoverConfig)2 HalfOpenConfig (com.tencent.polaris.plugins.circuitbreaker.common.HalfOpenConfig)2 HalfOpenCounter (com.tencent.polaris.plugins.circuitbreaker.common.HalfOpenCounter)2 DefaultPlugins (com.tencent.polaris.api.config.plugin.DefaultPlugins)1 PluginConfigProvider (com.tencent.polaris.api.config.plugin.PluginConfigProvider)1 Verifier (com.tencent.polaris.api.config.verify.Verifier)1 Destroyable (com.tencent.polaris.api.control.Destroyable)1 ErrorCode (com.tencent.polaris.api.exception.ErrorCode)1 PolarisException (com.tencent.polaris.api.exception.PolarisException)1 PluginType (com.tencent.polaris.api.plugin.PluginType)1 CircuitBreakResult (com.tencent.polaris.api.plugin.circuitbreaker.CircuitBreakResult)1 CircuitBreaker (com.tencent.polaris.api.plugin.circuitbreaker.CircuitBreaker)1