Search in sources :

Example 6 with Rule

use of com.tencent.polaris.client.pb.RateLimitProto.Rule in project polaris-java by polarismesh.

the class QuotaFlow method lookupRateLimitWindow.

private RateLimitWindow lookupRateLimitWindow(CommonQuotaRequest request) throws PolarisException {
    // 1.获取限流规则
    ResourcesResponse resourcesResponse = BaseFlow.syncGetResources(rateLimitExtension.getExtensions(), false, request, request.getFlowControlParam());
    ServiceRule serviceRule = resourcesResponse.getServiceRule(request.getSvcEventKey());
    // 2.进行规则匹配
    Rule rule = lookupRule(serviceRule, request.getLabels());
    if (null == rule) {
        return null;
    }
    request.setTargetRule(rule);
    // 3.获取已有的限流窗口
    ServiceKey serviceKey = request.getSvcEventKey().getServiceKey();
    String labelsStr = formatLabelsToStr(request);
    RateLimitWindowSet rateLimitWindowSet = getRateLimitWindowSet(serviceKey);
    RateLimitWindow rateLimitWindow = rateLimitWindowSet.getRateLimitWindow(rule, labelsStr);
    if (null != rateLimitWindow) {
        return rateLimitWindow;
    }
    // 3.创建限流窗口
    return rateLimitWindowSet.addRateLimitWindow(request, labelsStr);
}
Also used : ServiceRule(com.tencent.polaris.api.pojo.ServiceRule) ServiceKey(com.tencent.polaris.api.pojo.ServiceKey) Rule(com.tencent.polaris.client.pb.RateLimitProto.Rule) ServiceRule(com.tencent.polaris.api.pojo.ServiceRule) MatchString(com.tencent.polaris.client.pb.ModelProto.MatchString) ResourcesResponse(com.tencent.polaris.client.flow.ResourcesResponse)

Aggregations

Rule (com.tencent.polaris.client.pb.RateLimitProto.Rule)6 ServiceRule (com.tencent.polaris.api.pojo.ServiceRule)4 MatchString (com.tencent.polaris.client.pb.ModelProto.MatchString)4 RateLimit (com.tencent.polaris.client.pb.RateLimitProto.RateLimit)3 HashMap (java.util.HashMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ServiceKey (com.tencent.polaris.api.pojo.ServiceKey)1 ResourcesResponse (com.tencent.polaris.client.flow.ResourcesResponse)1 DiscoverResponse (com.tencent.polaris.client.pb.ResponseProto.DiscoverResponse)1 ServiceRuleByProto (com.tencent.polaris.client.pojo.ServiceRuleByProto)1 Function (java.util.function.Function)1