Search in sources :

Example 46 with FlowRule

use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project JHodgepodge by werwolfGu.

the class FlowQpsDemo method initFlowQpsRule.

private static void initFlowQpsRule() {
    List<FlowRule> rules = new ArrayList<FlowRule>();
    FlowRule rule1 = new FlowRule();
    rule1.setResource(KEY);
    // set limit qps to 20
    rule1.setCount(20);
    rule1.setGrade(RuleConstant.FLOW_GRADE_QPS);
    rule1.setLimitApp("default");
    rules.add(rule1);
    rule1 = new FlowRule();
    rule1.setResource(KEY);
    // set limit qps to 20
    rule1.setCount(10);
    rule1.setGrade(RuleConstant.FLOW_GRADE_QPS);
    rule1.setLimitApp("caller1");
    rules.add(rule1);
    rule1 = new FlowRule();
    rule1.setResource(KEY);
    // set limit qps to 20
    rule1.setCount(20);
    rule1.setGrade(RuleConstant.FLOW_GRADE_QPS);
    rule1.setLimitApp("caller2");
    rules.add(rule1);
    FlowRuleManager.loadRules(rules);
}
Also used : ArrayList(java.util.ArrayList) FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule)

Example 47 with FlowRule

use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project XHuiCloud by sindaZeng.

the class FlowRuleEntity method toRule.

@Override
public FlowRule toRule() {
    FlowRule flowRule = new FlowRule();
    flowRule.setCount(this.count);
    flowRule.setGrade(this.grade);
    flowRule.setResource(this.resource);
    flowRule.setLimitApp(this.limitApp);
    flowRule.setRefResource(this.refResource);
    flowRule.setStrategy(this.strategy);
    if (this.controlBehavior != null) {
        flowRule.setControlBehavior(controlBehavior);
    }
    if (this.warmUpPeriodSec != null) {
        flowRule.setWarmUpPeriodSec(warmUpPeriodSec);
    }
    if (this.maxQueueingTimeMs != null) {
        flowRule.setMaxQueueingTimeMs(maxQueueingTimeMs);
    }
    flowRule.setClusterMode(clusterMode);
    flowRule.setClusterConfig(clusterConfig);
    return flowRule;
}
Also used : FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule)

Example 48 with FlowRule

use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project study-by-myself by Howinfun.

the class AbstractSentinelRulesListener method reloadSentinelRules.

public void reloadSentinelRules(List<SentinelFlowRule> flowRuleList, List<SentinelDegradeRule> degradeRuleList) {
    final List<FlowRule> flowRules = new ArrayList<>();
    final List<DegradeRule> degradeRules = new ArrayList<>();
    // 处理流控规则
    flowRuleList.forEach(sentinelFlowRule -> {
        FlowRule flowRule = new FlowRule();
        BeanUtils.copyProperties(sentinelFlowRule, flowRule);
        flowRules.add(flowRule);
    });
    // 处理熔断规则
    degradeRuleList.forEach(sentinelDegradeRule -> {
        DegradeRule degradeRule = new DegradeRule();
        BeanUtils.copyProperties(sentinelDegradeRule, degradeRule);
        degradeRules.add(degradeRule);
    });
    FlowRuleManager.loadRules(flowRules);
    DegradeRuleManager.loadRules(degradeRules);
}
Also used : ArrayList(java.util.ArrayList) SentinelFlowRule(com.github.howinfun.sentinel.pojo.SentinelFlowRule) FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule) SentinelDegradeRule(com.github.howinfun.sentinel.pojo.SentinelDegradeRule) DegradeRule(com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule)

Example 49 with FlowRule

use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project RuoYi-Cloud-Plus by JavaLionLi.

the class FlowRuleEntity method toRule.

@Override
public FlowRule toRule() {
    FlowRule flowRule = new FlowRule();
    flowRule.setCount(this.count);
    flowRule.setGrade(this.grade);
    flowRule.setResource(this.resource);
    flowRule.setLimitApp(this.limitApp);
    flowRule.setRefResource(this.refResource);
    flowRule.setStrategy(this.strategy);
    if (this.controlBehavior != null) {
        flowRule.setControlBehavior(controlBehavior);
    }
    if (this.warmUpPeriodSec != null) {
        flowRule.setWarmUpPeriodSec(warmUpPeriodSec);
    }
    if (this.maxQueueingTimeMs != null) {
        flowRule.setMaxQueueingTimeMs(maxQueueingTimeMs);
    }
    flowRule.setClusterMode(clusterMode);
    flowRule.setClusterConfig(clusterConfig);
    return flowRule;
}
Also used : FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule)

Example 50 with FlowRule

use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project Sermant by huaweicloud.

the class RateLimitingRuleConverter method convertToSentinelRule.

@Override
public List<FlowRule> convertToSentinelRule(RateLimitingRule resilienceRule) {
    final FlowRule flowRule = new FlowRule();
    // 转换为rate/s, sentinel当前只能以1S为单位进行统计, 因此此处做一定请求比例转换
    final BigDecimal divide = BigDecimal.valueOf(resilienceRule.getRate() * CommonConst.RATE_DIV_POINT).divide(BigDecimal.valueOf(resilienceRule.getParsedLimitRefreshPeriod()), RoundingMode.CEILING);
    flowRule.setCount(divide.doubleValue());
    flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS);
    flowRule.setResource(resilienceRule.getName());
    return Collections.singletonList(flowRule);
}
Also used : FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule) BigDecimal(java.math.BigDecimal)

Aggregations

FlowRule (com.alibaba.csp.sentinel.slots.block.flow.FlowRule)113 ArrayList (java.util.ArrayList)31 Test (org.junit.Test)31 ClusterNode (com.alibaba.csp.sentinel.node.ClusterNode)22 List (java.util.List)17 TokenResult (com.alibaba.csp.sentinel.cluster.TokenResult)11 DegradeRule (com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule)9 BlockException (com.alibaba.csp.sentinel.slots.block.BlockException)6 Test (org.junit.jupiter.api.Test)6 ClusterFlowConfig (com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig)5 TypeReference (com.alibaba.fastjson.TypeReference)5 QuarkusUnitTest (io.quarkus.test.QuarkusUnitTest)5 Before (org.junit.Before)5 ParamFlowRule (com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule)4 ClusterMetric (com.alibaba.csp.sentinel.cluster.flow.statistic.metric.ClusterMetric)3 FlowRuleManager (com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager)3 AbstractTimeBasedTest (com.alibaba.csp.sentinel.test.AbstractTimeBasedTest)3 RateLimitDescriptor (io.envoyproxy.envoy.extensions.common.ratelimit.v3.RateLimitDescriptor)3 RateLimitResponse (io.envoyproxy.envoy.service.ratelimit.v3.RateLimitResponse)3 IOException (java.io.IOException)3