use of com.tencent.polaris.plugins.circuitbreaker.common.ConfigSet in project polaris-java by polarismesh.
the class ErrRateCircuitBreaker 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);
ErrRateCounter errRateCounter = (ErrRateCounter) pluginValue;
SliceWindow metricWindow = errRateCounter.getSliceWindow(statusDimension);
metricWindow.addGauge((bucket -> {
bucket.addMetric(Dimension.keyRequestCount.ordinal(), 1);
if (gauge.getRetStatus() == RetStatus.RetFail) {
return bucket.addMetric(Dimension.keyFailCount.ordinal(), 1);
}
return bucket.getMetric(Dimension.keyFailCount.ordinal());
}));
} 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;
}
use of com.tencent.polaris.plugins.circuitbreaker.common.ConfigSet 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.plugins.circuitbreaker.common.ConfigSet 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());
}
Aggregations