Skip to content

Commit

Permalink
fix:修复code review中的问题描述
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntaojun committed Dec 15, 2023
1 parent 2f3a9f4 commit 021f595
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
package com.tencent.polaris.api.utils;


import com.tencent.polaris.logging.LoggerFactory;
import com.tencent.polaris.specification.api.v1.model.ModelProto.MatchString;
import com.tencent.polaris.specification.api.v1.model.ModelProto.MatchString.MatchStringType;
import org.slf4j.Logger;

import java.util.Collections;
import java.util.Map;
Expand All @@ -28,6 +30,8 @@

public class RuleUtils {

private static final Logger LOG = LoggerFactory.getLogger(RuleUtils.class);

public static final String MATCH_ALL = "*";

private static final Function<String, Pattern> DEFAULT_REGEX_PATTERN = new Function<String, Pattern>() {
Expand Down Expand Up @@ -106,16 +110,20 @@ private static boolean matchStringValue(MatchStringType matchType, String actual
return true;
}
case RANGE: {
// 区间范围判断 [a, b], a <= matchV <= b
String[] tokens = matchValue.split("~");
if (tokens.length != 2) {
return false;
}
try {
// 区间范围中的左端值
long left = Long.parseLong(tokens[0]);
// 区间范围中的右端值
long right = Long.parseLong(tokens[1]);
long matchV = Long.parseLong(actualValue);
return matchV >= left && matchV <= right;
} catch (NumberFormatException ignore) {
LOG.error("[RuleUtils] matchValue is not a number in RANGE match type, return false");
return false;
}
}
Expand Down Expand Up @@ -209,7 +217,9 @@ private static boolean matchValueByValueType(boolean isMatchSource, String ruleM
// 当匹配的是source,记录请求的 K V
multiEnvRouterParamMap.put(ruleMetaKey, destMetaValue);
} else {
// 当匹配的是dest, 并且如果是参数类型, 则需要根据 dest 的 value 获取到流量标签里面对应 key 的真实 value
// 当匹配的是 dest 方向时,ruleMetaKey 为 dest 标签的 key,destMetaValue 为实例标签的 value, 流量标签的变量值信息都在 multiEnvRouterParamMap 中
// 例如, source 标签为 <source-key,source-value>, dest 标签则为 <instance-metadata-key, source-key>
// 因此,在参数场景下,需要根据 dest 中的标签的 value 值信息,反向去查询 source 对应标签的 value
if (!multiEnvRouterParamMap.containsKey(ruleMetaValue.getValue().getValue())) {
allMetaMatched = false;
} else {
Expand Down

This file was deleted.

0 comments on commit 021f595

Please sign in to comment.