-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1297 from lilai23/tag_transmission
流量标签透传特性:支持标签键的前缀后缀匹配方式
- Loading branch information
Showing
28 changed files
with
418 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...ain/java/com/huaweicloud/sermant/tag/transmission/config/strategy/ExactMatchStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.huaweicloud.sermant.tag.transmission.config.strategy; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* 精确匹配策略 | ||
* | ||
* @author lilai | ||
* @since 2023-09-07 | ||
*/ | ||
public class ExactMatchStrategy implements MatchStrategy { | ||
@Override | ||
public boolean isMatch(String key, List<String> keyConfigs) { | ||
return keyConfigs.stream().anyMatch(key::equals); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...src/main/java/com/huaweicloud/sermant/tag/transmission/config/strategy/MatchStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.huaweicloud.sermant.tag.transmission.config.strategy; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* 需要透传的key的匹配策略接口 | ||
* | ||
* @author lilai | ||
* @since 2023-09-07 | ||
*/ | ||
public interface MatchStrategy { | ||
/** | ||
* 请求中或线程变量中的key是否匹配配置中要透传的规则 | ||
* | ||
* @param key 被匹配的键 | ||
* @param keyConfigs key的匹配配置 | ||
* @return 匹配结果 | ||
*/ | ||
boolean isMatch(String key, List<String> keyConfigs); | ||
} |
32 changes: 32 additions & 0 deletions
32
...in/java/com/huaweicloud/sermant/tag/transmission/config/strategy/PrefixMatchStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.huaweicloud.sermant.tag.transmission.config.strategy; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* 前缀匹配策略 | ||
* | ||
* @author lilai | ||
* @since 2023-09-07 | ||
*/ | ||
public class PrefixMatchStrategy implements MatchStrategy { | ||
@Override | ||
public boolean isMatch(String key, List<String> keyConfigs) { | ||
return keyConfigs.stream().anyMatch(key::startsWith); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...in/java/com/huaweicloud/sermant/tag/transmission/config/strategy/SuffixMatchStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.huaweicloud.sermant.tag.transmission.config.strategy; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* 后缀匹配策略 | ||
* | ||
* @author lilai | ||
* @since 2023-09-07 | ||
*/ | ||
public class SuffixMatchStrategy implements MatchStrategy { | ||
@Override | ||
public boolean isMatch(String key, List<String> keyConfigs) { | ||
return keyConfigs.stream().anyMatch(key::endsWith); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...src/main/java/com/huaweicloud/sermant/tag/transmission/config/strategy/TagKeyMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.huaweicloud.sermant.tag.transmission.config.strategy; | ||
|
||
import com.huaweicloud.sermant.core.plugin.config.PluginConfigManager; | ||
import com.huaweicloud.sermant.tag.transmission.config.TagTransmissionConfig; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* 流量标签是否需要透传的匹配器 | ||
* | ||
* @author lilai | ||
* @since 2023-09-07 | ||
*/ | ||
public class TagKeyMatcher { | ||
private static final Map<String, MatchStrategy> STRATEGY_MAP = new HashMap<>(); | ||
|
||
private static final TagTransmissionConfig CONFIG = PluginConfigManager.getPluginConfig( | ||
TagTransmissionConfig.class); | ||
|
||
private static final String EXACT_RULE_KEY = "exact"; | ||
|
||
private static final String PREFIX_RULE_KEY = "prefix"; | ||
|
||
private static final String SUFFIX_RULE_KEY = "suffix"; | ||
|
||
static { | ||
STRATEGY_MAP.put(EXACT_RULE_KEY, new ExactMatchStrategy()); | ||
STRATEGY_MAP.put(PREFIX_RULE_KEY, new PrefixMatchStrategy()); | ||
STRATEGY_MAP.put(SUFFIX_RULE_KEY, new SuffixMatchStrategy()); | ||
} | ||
|
||
private TagKeyMatcher() { | ||
} | ||
|
||
/** | ||
* 是否匹配配置中需要透传的key的规则 | ||
* | ||
* @param key 被匹配的key | ||
* @return 匹配结果 | ||
*/ | ||
public static boolean isMatch(String key) { | ||
for (String rule : CONFIG.getMatchRule().keySet()) { | ||
MatchStrategy matchStrategy = STRATEGY_MAP.get(rule); | ||
if (matchStrategy.isMatch(key, CONFIG.getMatchRule().get(rule))) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.