-
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.
1.支持kafka消费以及生产过程透传 2.支持动态配置
- Loading branch information
Showing
15 changed files
with
627 additions
and
31 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
53 changes: 53 additions & 0 deletions
53
.../java/com/huaweicloud/sermant/tag/transmission/declarers/KafkaConsumerRecordDeclarer.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,53 @@ | ||
/* | ||
* 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.declarers; | ||
|
||
import com.huaweicloud.sermant.core.plugin.agent.declarer.AbstractPluginDeclarer; | ||
import com.huaweicloud.sermant.core.plugin.agent.declarer.InterceptDeclarer; | ||
import com.huaweicloud.sermant.core.plugin.agent.matcher.ClassMatcher; | ||
import com.huaweicloud.sermant.core.plugin.agent.matcher.MethodMatcher; | ||
import com.huaweicloud.sermant.tag.transmission.interceptors.KafkaConsumerRecordInterceptor; | ||
|
||
/** | ||
* kafka获取消息内容的拦截点声明,支持1.x, 2.x, 3.x | ||
* | ||
* @author lilai | ||
* @since 2023-07-18 | ||
*/ | ||
public class KafkaConsumerRecordDeclarer extends AbstractPluginDeclarer { | ||
/** | ||
* 增强类的全限定名 | ||
*/ | ||
private static final String ENHANCE_CLASSES = "org.apache.kafka.clients.consumer.ConsumerRecord"; | ||
|
||
/** | ||
* 拦截类的全限定名 | ||
*/ | ||
private static final String INTERCEPT_CLASS = KafkaConsumerRecordInterceptor.class.getCanonicalName(); | ||
|
||
@Override | ||
public ClassMatcher getClassMatcher() { | ||
return ClassMatcher.nameEquals(ENHANCE_CLASSES); | ||
} | ||
|
||
@Override | ||
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) { | ||
return new InterceptDeclarer[]{ | ||
InterceptDeclarer.build(MethodMatcher.nameEquals("value"), INTERCEPT_CLASS) | ||
}; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...c/main/java/com/huaweicloud/sermant/tag/transmission/declarers/KafkaProviderDeclarer.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,53 @@ | ||
/* | ||
* 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.declarers; | ||
|
||
import com.huaweicloud.sermant.core.plugin.agent.declarer.AbstractPluginDeclarer; | ||
import com.huaweicloud.sermant.core.plugin.agent.declarer.InterceptDeclarer; | ||
import com.huaweicloud.sermant.core.plugin.agent.matcher.ClassMatcher; | ||
import com.huaweicloud.sermant.core.plugin.agent.matcher.MethodMatcher; | ||
import com.huaweicloud.sermant.tag.transmission.interceptors.KafkaProducerInterceptor; | ||
|
||
/** | ||
* kafka生产消息增强拦截点声明,支持1.x, 2.x, 3.x | ||
* | ||
* @author lilai | ||
* @since 2023-07-18 | ||
*/ | ||
public class KafkaProviderDeclarer extends AbstractPluginDeclarer { | ||
/** | ||
* 增强类的全限定名 | ||
*/ | ||
private static final String ENHANCE_CLASSES = "org.apache.kafka.clients.producer.KafkaProducer"; | ||
|
||
/** | ||
* 拦截类的全限定名 | ||
*/ | ||
private static final String INTERCEPT_CLASS = KafkaProducerInterceptor.class.getCanonicalName(); | ||
|
||
@Override | ||
public ClassMatcher getClassMatcher() { | ||
return ClassMatcher.nameEquals(ENHANCE_CLASSES); | ||
} | ||
|
||
@Override | ||
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) { | ||
return new InterceptDeclarer[]{ | ||
InterceptDeclarer.build(MethodMatcher.nameEquals("doSend"), INTERCEPT_CLASS) | ||
}; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...java/com/huaweicloud/sermant/tag/transmission/interceptors/AbstractClientInterceptor.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,77 @@ | ||
/* | ||
* 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.interceptors; | ||
|
||
import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext; | ||
import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor; | ||
import com.huaweicloud.sermant.core.plugin.config.PluginConfigManager; | ||
import com.huaweicloud.sermant.core.utils.MapUtils; | ||
import com.huaweicloud.sermant.core.utils.tag.TrafficTag; | ||
import com.huaweicloud.sermant.core.utils.tag.TrafficUtils; | ||
import com.huaweicloud.sermant.tag.transmission.config.TagTransmissionConfig; | ||
|
||
/** | ||
* 客户端拦截器抽象类,获取当前线程的流量标签并透传至下游进程,适用于http客户端/rpc客户端/消息队列生产者 | ||
* | ||
* @author lilai | ||
* @since 2023-07-18 | ||
*/ | ||
public abstract class AbstractClientInterceptor extends AbstractInterceptor { | ||
protected final TagTransmissionConfig tagTransmissionConfig; | ||
|
||
/** | ||
* 构造器 | ||
*/ | ||
public AbstractClientInterceptor() { | ||
this.tagTransmissionConfig = PluginConfigManager.getPluginConfig(TagTransmissionConfig.class); | ||
} | ||
|
||
@Override | ||
public ExecuteContext before(ExecuteContext context) { | ||
if (!tagTransmissionConfig.isEffect()) { | ||
return context; | ||
} | ||
|
||
TrafficTag trafficTag = TrafficUtils.getTrafficTag(); | ||
if (trafficTag == null || MapUtils.isEmpty(trafficTag.getTag())) { | ||
return context; | ||
} | ||
|
||
return doBefore(context); | ||
} | ||
|
||
@Override | ||
public ExecuteContext after(ExecuteContext context) { | ||
return doAfter(context); | ||
} | ||
|
||
/** | ||
* 前置触发点 | ||
* | ||
* @param context 执行上下文 | ||
* @return 执行上下文 | ||
*/ | ||
protected abstract ExecuteContext doBefore(ExecuteContext context); | ||
|
||
/** | ||
* 后置触发点 | ||
* | ||
* @param context 执行上下文 | ||
* @return 执行上下文 | ||
*/ | ||
protected abstract ExecuteContext doAfter(ExecuteContext context); | ||
} |
68 changes: 68 additions & 0 deletions
68
...java/com/huaweicloud/sermant/tag/transmission/interceptors/AbstractServerInterceptor.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,68 @@ | ||
/* | ||
* 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.interceptors; | ||
|
||
import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext; | ||
import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor; | ||
import com.huaweicloud.sermant.core.plugin.config.PluginConfigManager; | ||
import com.huaweicloud.sermant.tag.transmission.config.TagTransmissionConfig; | ||
|
||
/** | ||
* 服务端拦截器抽象类,获取跨进程的流量标签并在本进程传递,适用于http服务端/rpc服务端/消息队列消费者 | ||
* | ||
* @author lilai | ||
* @since 2023-07-18 | ||
*/ | ||
public abstract class AbstractServerInterceptor extends AbstractInterceptor { | ||
protected final TagTransmissionConfig tagTransmissionConfig; | ||
|
||
/** | ||
* 构造器 | ||
*/ | ||
public AbstractServerInterceptor() { | ||
this.tagTransmissionConfig = PluginConfigManager.getPluginConfig(TagTransmissionConfig.class); | ||
} | ||
|
||
@Override | ||
public ExecuteContext before(ExecuteContext context) { | ||
if (!tagTransmissionConfig.isEffect()) { | ||
return context; | ||
} | ||
return doBefore(context); | ||
} | ||
|
||
@Override | ||
public ExecuteContext after(ExecuteContext context) { | ||
return doAfter(context); | ||
} | ||
|
||
/** | ||
* 前置触发点 | ||
* | ||
* @param context 执行上下文 | ||
* @return 执行上下文 | ||
*/ | ||
protected abstract ExecuteContext doBefore(ExecuteContext context); | ||
|
||
/** | ||
* 后置触发点 | ||
* | ||
* @param context 执行上下文 | ||
* @return 执行上下文 | ||
*/ | ||
protected abstract ExecuteContext doAfter(ExecuteContext context); | ||
} |
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.