use of com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig in project Sentinel by alibaba.
the class InMemFlowRuleStore method preProcess.
@Override
protected FlowRuleEntity preProcess(FlowRuleEntity entity) {
if (entity != null && entity.isClusterMode()) {
ClusterFlowConfig config = entity.getClusterConfig();
if (config == null) {
config = new ClusterFlowConfig();
entity.setClusterConfig(config);
}
// Set cluster rule id.
config.setFlowId(entity.getId());
}
return entity;
}
use of com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig in project spring-boot-student by wyh-spring-ecosystem-student.
the class InMemFlowRuleStore method preProcess.
@Override
protected FlowRuleEntity preProcess(FlowRuleEntity entity) {
if (entity != null && entity.isClusterMode()) {
ClusterFlowConfig config = entity.getClusterConfig();
if (config == null) {
config = new ClusterFlowConfig();
entity.setClusterConfig(config);
}
// Set cluster rule id.
config.setFlowId(entity.getId());
}
return entity;
}
use of com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig in project XHuiCloud by sindaZeng.
the class InMemFlowRuleStore method preProcess.
@Override
protected FlowRuleEntity preProcess(FlowRuleEntity entity) {
if (entity != null && entity.isClusterMode()) {
ClusterFlowConfig config = entity.getClusterConfig();
if (config == null) {
config = new ClusterFlowConfig();
entity.setClusterConfig(config);
}
// Set cluster rule id.
config.setFlowId(entity.getId());
}
return entity;
}
use of com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig in project Sentinel by alibaba.
the class EnvoySentinelRuleConverter method toSentinelFlowRule.
public static FlowRule toSentinelFlowRule(String domain, EnvoyRlsRule.ResourceDescriptor descriptor) {
// One descriptor could have only one rule.
String identifier = generateKey(domain, descriptor);
long flowId = generateFlowId(identifier);
return new FlowRule(identifier).setCount(descriptor.getCount()).setClusterMode(true).setClusterConfig(new ClusterFlowConfig().setFlowId(flowId).setThresholdType(ClusterRuleConstant.FLOW_THRESHOLD_GLOBAL).setSampleCount(1).setFallbackToLocalWhenFail(false));
}
use of com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig in project Sentinel by alibaba.
the class ClusterFlowCheckerTest method testAcquireClusterTokenOccupyPass.
// @Test
public void testAcquireClusterTokenOccupyPass() {
long flowId = 98765L;
final int threshold = 5;
FlowRule clusterRule = new FlowRule("abc").setCount(threshold).setClusterMode(true).setClusterConfig(new ClusterFlowConfig().setFlowId(flowId).setThresholdType(ClusterRuleConstant.FLOW_THRESHOLD_GLOBAL));
int sampleCount = 5;
int intervalInMs = 1000;
int bucketLength = intervalInMs / sampleCount;
ClusterMetric metric = new ClusterMetric(sampleCount, intervalInMs);
ClusterMetricStatistics.putMetric(flowId, metric);
System.out.println(System.currentTimeMillis());
assertResultPass(tryAcquire(clusterRule, false));
assertResultPass(tryAcquire(clusterRule, false));
sleep(bucketLength);
assertResultPass(tryAcquire(clusterRule, false));
sleep(bucketLength);
assertResultPass(tryAcquire(clusterRule, true));
assertResultPass(tryAcquire(clusterRule, false));
assertResultBlock(tryAcquire(clusterRule, true));
sleep(bucketLength);
assertResultBlock(tryAcquire(clusterRule, false));
assertResultBlock(tryAcquire(clusterRule, false));
sleep(bucketLength);
assertResultBlock(tryAcquire(clusterRule, false));
assertResultWait(tryAcquire(clusterRule, true), bucketLength);
assertResultBlock(tryAcquire(clusterRule, false));
sleep(bucketLength);
assertResultPass(tryAcquire(clusterRule, false));
ClusterMetricStatistics.removeMetric(flowId);
}
Aggregations