-
Notifications
You must be signed in to change notification settings - Fork 164
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 #1251 from lilai23/tag_trans
【feature】流量标签透传特性:支持httpclient4.x
- Loading branch information
Showing
17 changed files
with
531 additions
and
4 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
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
40 changes: 40 additions & 0 deletions
40
...mant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/utils/CollectionUtils.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,40 @@ | ||
/* | ||
* 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 C¬ONDITIONS 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.core.utils; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* 集合工具类 | ||
* | ||
* @author lilai | ||
* @since 2023-07-17 | ||
*/ | ||
public class CollectionUtils { | ||
private CollectionUtils() { | ||
} | ||
|
||
/** | ||
* 判断集合是否为null或没有元素 | ||
* | ||
* @param collection 集合 | ||
* @return 是否为空 | ||
*/ | ||
public static boolean isEmpty(Collection<?> collection) { | ||
return collection == null || collection.isEmpty(); | ||
} | ||
} |
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
55 changes: 55 additions & 0 deletions
55
...rmant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/utils/tag/TrafficTag.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,55 @@ | ||
/* | ||
* 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 C¬ONDITIONS 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.core.utils.tag; | ||
|
||
import com.huaweicloud.sermant.core.utils.MapUtils; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* 流量标签 | ||
* | ||
* @author lilai | ||
* @since 2023-07-17 | ||
*/ | ||
public class TrafficTag { | ||
private final Map<String, List<String>> tag; | ||
|
||
/** | ||
* 构造方法 | ||
* | ||
* @param tag 流量标签 http请求的header/dubbo请求的attachment/消息队列header或properties | ||
*/ | ||
public TrafficTag(Map<String, List<String>> tag) { | ||
this.tag = MapUtils.isEmpty(tag) ? new HashMap<>() : tag; | ||
} | ||
|
||
public Map<String, List<String>> getTag() { | ||
return tag; | ||
} | ||
|
||
/** | ||
* 更新流量标签 | ||
* | ||
* @param map 流量标签 | ||
*/ | ||
public void updateTag(Map<String, List<String>> map) { | ||
this.tag.putAll(map); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
...ant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/utils/tag/TrafficUtils.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,80 @@ | ||
/* | ||
* 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 C¬ONDITIONS 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.core.utils.tag; | ||
|
||
import com.huaweicloud.sermant.core.utils.MapUtils; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* 流量中包含的请求信息 | ||
* | ||
* @author lilai | ||
* @since 2023-07-17 | ||
*/ | ||
public class TrafficUtils { | ||
private static final ThreadLocal<TrafficTag> TAG = new ThreadLocal<>(); | ||
|
||
private TrafficUtils() { | ||
} | ||
|
||
/** | ||
* 获取线程中的流量标签 | ||
* | ||
* @return 流量标签 | ||
*/ | ||
public static TrafficTag getTrafficTag() { | ||
return TAG.get(); | ||
} | ||
|
||
/** | ||
* 更新线程中的流量标签 | ||
* | ||
* @param tag 流量标签map | ||
*/ | ||
public static void updateTrafficTag(Map<String, List<String>> tag) { | ||
if (MapUtils.isEmpty(tag)) { | ||
return; | ||
} | ||
TrafficTag trafficTag = TAG.get(); | ||
if (trafficTag == null) { | ||
TAG.set(new TrafficTag(tag)); | ||
return; | ||
} | ||
trafficTag.updateTag(tag); | ||
} | ||
|
||
/** | ||
* 重设线程中的流量标签 | ||
* | ||
* @param trafficTag 流量标签 | ||
*/ | ||
public static void setTrafficTag(TrafficTag trafficTag) { | ||
if (trafficTag == null) { | ||
return; | ||
} | ||
TAG.set(trafficTag); | ||
} | ||
|
||
/** | ||
* 删除线程变量 | ||
*/ | ||
public static void removeTrafficTag() { | ||
TAG.remove(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
tag.transmission.plugin: | ||
enabled: true | ||
tagKeys: [id,name] |
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,50 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>sermant-plugins</artifactId> | ||
<groupId>com.huaweicloud.sermant</groupId> | ||
<version>1.0.0</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>sermant-tag-transmission</artifactId> | ||
<packaging>pom</packaging> | ||
|
||
<modules> | ||
<module>tag-transmission-plugin</module> | ||
</modules> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
<sermant.basedir>${pom.basedir}/../../..</sermant.basedir> | ||
<package.plugin.name>tag-transmission</package.plugin.name> | ||
</properties> | ||
|
||
<profiles> | ||
<profile> | ||
<id>agent</id> | ||
<activation> | ||
<activeByDefault>true</activeByDefault> | ||
</activation> | ||
<modules> | ||
<module>tag-transmission-plugin</module> | ||
</modules> | ||
</profile> | ||
<profile> | ||
<id>test</id> | ||
<modules> | ||
<module>tag-transmission-plugin</module> | ||
</modules> | ||
</profile> | ||
<profile> | ||
<id>release</id> | ||
<modules> | ||
<module>tag-transmission-plugin</module> | ||
</modules> | ||
</profile> | ||
</profiles> | ||
|
||
</project> |
50 changes: 50 additions & 0 deletions
50
sermant-plugins/sermant-tag-transmission/tag-transmission-plugin/pom.xml
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,50 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>sermant-tag-transmission</artifactId> | ||
<groupId>com.huaweicloud.sermant</groupId> | ||
<version>1.0.0</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>tag-transmission-plugin</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
<config.skip.flag>false</config.skip.flag> | ||
<package.plugin.type>plugin</package.plugin.type> | ||
<apache-httpclient.version>4.3</apache-httpclient.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.huaweicloud.sermant</groupId> | ||
<artifactId>sermant-agentcore-core</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.huaweicloud.sermant</groupId> | ||
<artifactId>sermant-common</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
<version>${apache-httpclient.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
Oops, something went wrong.