use of com.tencent.polaris.client.pb.ModelProto.MatchString.MatchStringType in project polaris-java by polarismesh.
the class QuotaFlow method matchLabels.
private boolean matchLabels(String ruleLabelKey, MatchString ruleLabelMatch, Map<String, String> labels) {
// 设置了MatchAllValue,相当于这个规则就无效了
if (RuleUtils.isMatchAllValue(ruleLabelMatch)) {
return true;
}
if (MapUtils.isEmpty(labels)) {
return false;
}
// 集成的路由规则不包含这个key,就不匹配
if (!labels.containsKey(ruleLabelKey)) {
return false;
}
String labelValue = labels.get(ruleLabelKey);
FlowCache flowCache = rateLimitExtension.getExtensions().getFlowCache();
MatchStringType matchType = ruleLabelMatch.getType();
String matchValue = ruleLabelMatch.getValue().getValue();
if (matchType == MatchStringType.REGEX) {
// 正则表达式匹配
Pattern pattern = flowCache.loadOrStoreCompiledRegex(matchValue);
return pattern.matcher(labelValue).find();
}
return StringUtils.equals(labelValue, matchValue);
}
Aggregations