Search in sources :

Example 1 with CircuitBreakerConfig

use of com.tencent.polaris.api.config.consumer.CircuitBreakerConfig in project polaris-java by polarismesh.

the class ConsecutiveCircuitBreaker method init.

@Override
public void init(InitContext ctx) throws PolarisException {
    CircuitBreakerConfig circuitBreakerConfig = ctx.getConfig().getConsumer().getCircuitBreaker();
    OutlierDetectionConfig outlierDetection = ctx.getConfig().getConsumer().getOutlierDetection();
    HalfOpenConfig halfOpenConfig = new HalfOpenConfig(circuitBreakerConfig, outlierDetection);
    Config cfg = circuitBreakerConfig.getPluginConfig(getName(), Config.class);
    if (cfg == null) {
        throw new PolarisException(ErrorCode.INVALID_CONFIG, String.format("plugin %s config is missing", getName()));
    }
    ConfigSet<Config> configSet = new ConfigSet<>(StatusDimension.Level.SERVICE, false, halfOpenConfig, cfg);
    configGroup = new ConfigGroup<>(configSet);
    stateMachine = new StateMachineImpl(configGroup, id, this);
    flowControlParam = new DefaultFlowControlParam(ctx.getConfig().getGlobal().getAPI());
}
Also used : PolarisException(com.tencent.polaris.api.exception.PolarisException) OutlierDetectionConfig(com.tencent.polaris.api.config.consumer.OutlierDetectionConfig) DefaultFlowControlParam(com.tencent.polaris.client.flow.DefaultFlowControlParam) HalfOpenConfig(com.tencent.polaris.plugins.circuitbreaker.common.HalfOpenConfig) 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) CircuitBreakerConfig(com.tencent.polaris.api.config.consumer.CircuitBreakerConfig) ConfigSet(com.tencent.polaris.plugins.circuitbreaker.common.ConfigSet)

Example 2 with CircuitBreakerConfig

use of com.tencent.polaris.api.config.consumer.CircuitBreakerConfig in project polaris-java by polarismesh.

the class DefaultCircuitBreakAPI method subInit.

@Override
protected void subInit() {
    CircuitBreakerConfig cbConfig = sdkContext.getConfig().getConsumer().getCircuitBreaker();
    if (!cbConfig.isEnable()) {
        return;
    }
    List<ServiceCallResultListener> serviceCallResultListeners = ServiceCallResultListener.getServiceCallResultListeners(sdkContext);
    for (ServiceCallResultListener listener : serviceCallResultListeners) {
        if (listener instanceof ServiceCallResultChecker) {
            checker = (ServiceCallResultChecker) listener;
            break;
        }
    }
}
Also used : ServiceCallResultListener(com.tencent.polaris.client.api.ServiceCallResultListener) CircuitBreakerConfig(com.tencent.polaris.api.config.consumer.CircuitBreakerConfig)

Example 3 with CircuitBreakerConfig

use of com.tencent.polaris.api.config.consumer.CircuitBreakerConfig in project polaris-java by polarismesh.

the class ErrRateCircuitBreaker method init.

@Override
public void init(InitContext ctx) throws PolarisException {
    CircuitBreakerConfig circuitBreakerConfig = ctx.getConfig().getConsumer().getCircuitBreaker();
    OutlierDetectionConfig outlierDetection = ctx.getConfig().getConsumer().getOutlierDetection();
    metricWindowMs = circuitBreakerConfig.getCheckPeriod();
    HalfOpenConfig halfOpenConfig = new HalfOpenConfig(circuitBreakerConfig, outlierDetection);
    Config cfg = circuitBreakerConfig.getPluginConfig(getName(), Config.class);
    if (cfg == null) {
        throw new PolarisException(ErrorCode.INVALID_CONFIG, String.format("plugin %s config is missing", getName()));
    }
    ConfigSet<Config> configSet = new ConfigSet<>(StatusDimension.Level.SERVICE, false, halfOpenConfig, cfg);
    create = new Function<Integer, Object>() {

        @Override
        public Object apply(Integer integer) {
            return new ErrRateCounter(metricWindowName, configSet.getPlugConfig(), getBucketIntervalMs());
        }
    };
    configGroup = new ConfigGroup<>(configSet);
    stateMachine = new StateMachineImpl(configGroup, id, this, metricWindowMs);
    flowControlParam = new DefaultFlowControlParam(ctx.getConfig().getGlobal().getAPI());
}
Also used : OutlierDetectionConfig(com.tencent.polaris.api.config.consumer.OutlierDetectionConfig) HalfOpenConfig(com.tencent.polaris.plugins.circuitbreaker.common.HalfOpenConfig) OutlierDetectionConfig(com.tencent.polaris.api.config.consumer.OutlierDetectionConfig) RecoverConfig(com.tencent.polaris.client.pb.CircuitBreakerProto.RecoverConfig) CircuitBreakerConfig(com.tencent.polaris.api.config.consumer.CircuitBreakerConfig) ErrRateConfig(com.tencent.polaris.client.pb.CircuitBreakerProto.CbPolicy.ErrRateConfig) HalfOpenConfig(com.tencent.polaris.plugins.circuitbreaker.common.HalfOpenConfig) PolarisException(com.tencent.polaris.api.exception.PolarisException) DefaultFlowControlParam(com.tencent.polaris.client.flow.DefaultFlowControlParam) CircuitBreakerConfig(com.tencent.polaris.api.config.consumer.CircuitBreakerConfig) ConfigSet(com.tencent.polaris.plugins.circuitbreaker.common.ConfigSet)

Example 4 with CircuitBreakerConfig

use of com.tencent.polaris.api.config.consumer.CircuitBreakerConfig in project polaris-java by polarismesh.

the class ServiceCallResultChecker method init.

@Override
public synchronized void init(SDKContext sdkContext) {
    if (!state.compareAndSet(0, 1)) {
        return;
    }
    extensions = sdkContext.getExtensions();
    CircuitBreakerConfig cbConfig = sdkContext.getConfig().getConsumer().getCircuitBreaker();
    if (cbConfig.isEnable()) {
        priorityTaskScheduler = new PriorityTaskScheduler();
        cbTaskExecutors = Executors.newSingleThreadScheduledExecutor();
        CheckServicesCircuitBreak checker = new CheckServicesCircuitBreak(sdkContext.getExtensions(), priorityTaskScheduler);
        long checkPeriodMs = cbConfig.getCheckPeriod();
        cbTaskExecutors.scheduleAtFixedRate(checker, checkPeriodMs, checkPeriodMs / 2, TimeUnit.MILLISECONDS);
    }
    OutlierDetectionConfig outlierDetection = sdkContext.getConfig().getConsumer().getOutlierDetection();
    if (outlierDetection.getWhen() != When.never) {
        detectTaskExecutors = Executors.newSingleThreadScheduledExecutor();
        long checkPeriodMs = outlierDetection.getCheckPeriod();
        detectTask = new InstancesDetectTask(extensions);
        detectTaskExecutors.scheduleAtFixedRate(detectTask, checkPeriodMs, checkPeriodMs, TimeUnit.MILLISECONDS);
    }
}
Also used : OutlierDetectionConfig(com.tencent.polaris.api.config.consumer.OutlierDetectionConfig) InstancesDetectTask(com.tencent.polaris.circuitbreak.client.task.InstancesDetectTask) PriorityTaskScheduler(com.tencent.polaris.circuitbreak.client.task.PriorityTaskScheduler) CircuitBreakerConfig(com.tencent.polaris.api.config.consumer.CircuitBreakerConfig)

Aggregations

CircuitBreakerConfig (com.tencent.polaris.api.config.consumer.CircuitBreakerConfig)4 OutlierDetectionConfig (com.tencent.polaris.api.config.consumer.OutlierDetectionConfig)3 PolarisException (com.tencent.polaris.api.exception.PolarisException)2 DefaultFlowControlParam (com.tencent.polaris.client.flow.DefaultFlowControlParam)2 RecoverConfig (com.tencent.polaris.client.pb.CircuitBreakerProto.RecoverConfig)2 ConfigSet (com.tencent.polaris.plugins.circuitbreaker.common.ConfigSet)2 HalfOpenConfig (com.tencent.polaris.plugins.circuitbreaker.common.HalfOpenConfig)2 InstancesDetectTask (com.tencent.polaris.circuitbreak.client.task.InstancesDetectTask)1 PriorityTaskScheduler (com.tencent.polaris.circuitbreak.client.task.PriorityTaskScheduler)1 ServiceCallResultListener (com.tencent.polaris.client.api.ServiceCallResultListener)1 ConsecutiveErrConfig (com.tencent.polaris.client.pb.CircuitBreakerProto.CbPolicy.ConsecutiveErrConfig)1 ErrRateConfig (com.tencent.polaris.client.pb.CircuitBreakerProto.CbPolicy.ErrRateConfig)1