Search in sources :

Example 1 with ClusterFlowConfig

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;
}
Also used : ClusterFlowConfig(com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig)

Example 2 with ClusterFlowConfig

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;
}
Also used : ClusterFlowConfig(com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig)

Example 3 with ClusterFlowConfig

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;
}
Also used : ClusterFlowConfig(com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig)

Example 4 with ClusterFlowConfig

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));
}
Also used : FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule) ClusterFlowConfig(com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig)

Example 5 with ClusterFlowConfig

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);
}
Also used : ClusterMetric(com.alibaba.csp.sentinel.cluster.flow.statistic.metric.ClusterMetric) FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule) ClusterFlowConfig(com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig)

Aggregations

ClusterFlowConfig (com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig)10 FlowRule (com.alibaba.csp.sentinel.slots.block.flow.FlowRule)5 ClusterMetric (com.alibaba.csp.sentinel.cluster.flow.statistic.metric.ClusterMetric)2 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1