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);
}
Aggregations