use of com.tencent.polaris.api.config.consumer.OutlierDetectionConfig 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());
}
use of com.tencent.polaris.api.config.consumer.OutlierDetectionConfig 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());
}
use of com.tencent.polaris.api.config.consumer.OutlierDetectionConfig 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);
}
}
Aggregations