-
Notifications
You must be signed in to change notification settings - Fork 167
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 #1311 from lilai23/tag_transmission
流量标签透传插件:优化rocketmq和跨线程日志的性能消耗
- Loading branch information
Showing
10 changed files
with
174 additions
and
20 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
50 changes: 50 additions & 0 deletions
50
...eicloud/sermant/tag/transmission/declarers/mq/rocketmq/RocketmqProducerStartDeclarer.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,50 @@ | ||
/* | ||
* 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.mq.rocketmq; | ||
|
||
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.mq.rocketmq.RocketmqProducerStartInterceptor; | ||
|
||
/** | ||
* RocketMQ流量标签透传的生产者启动时增强声明,支持RocketMQ4.8+ | ||
* | ||
* @author lilai | ||
* @since 2023-09-16 | ||
*/ | ||
public class RocketmqProducerStartDeclarer extends AbstractPluginDeclarer { | ||
/** | ||
* 增强类的全限定名、拦截器、拦截方法 | ||
*/ | ||
private static final String ENHANCE_CLASS = "org.apache.rocketmq.client.producer.MQProducer"; | ||
|
||
private static final String METHOD_NAME = "start"; | ||
|
||
@Override | ||
public ClassMatcher getClassMatcher() { | ||
return ClassMatcher.isExtendedFrom(ENHANCE_CLASS); | ||
} | ||
|
||
@Override | ||
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) { | ||
return new InterceptDeclarer[]{ | ||
InterceptDeclarer.build(MethodMatcher.nameEquals(METHOD_NAME), new RocketmqProducerStartInterceptor()) | ||
}; | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
...d/sermant/tag/transmission/interceptors/mq/rocketmq/RocketmqProducerStartInterceptor.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,41 @@ | ||
/* | ||
* 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.mq.rocketmq; | ||
|
||
import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext; | ||
import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor; | ||
import com.huaweicloud.sermant.tag.transmission.utils.RocketmqProducerMarkUtils; | ||
|
||
/** | ||
* RocketMQ流量标签透传的生产者启动时的拦截器,支持RocketMQ4.8+ | ||
* | ||
* @author lilai | ||
* @since 2023-09-16 | ||
*/ | ||
public class RocketmqProducerStartInterceptor extends AbstractInterceptor { | ||
@Override | ||
public ExecuteContext before(ExecuteContext context) throws Exception { | ||
return context; | ||
} | ||
|
||
@Override | ||
public ExecuteContext after(ExecuteContext context) throws Exception { | ||
// 标记生产者线程,防止进入consumer的拦截点 | ||
RocketmqProducerMarkUtils.setProducerMark(); | ||
return context; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...c/main/java/com/huaweicloud/sermant/tag/transmission/utils/RocketmqProducerMarkUtils.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,49 @@ | ||
/* | ||
* 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.utils; | ||
|
||
/** | ||
* RocketMQ的生产者线程标记工具类 | ||
* | ||
* @author lilai | ||
* @since 2023-09-16 | ||
*/ | ||
public class RocketmqProducerMarkUtils { | ||
/** | ||
* 生产者线程标记 | ||
*/ | ||
private static final ThreadLocal<Boolean> PRODUCER_MARK = new ThreadLocal<>(); | ||
|
||
private RocketmqProducerMarkUtils() { | ||
} | ||
|
||
/** | ||
* 标记当前线程为生产者线程 | ||
*/ | ||
public static void setProducerMark() { | ||
PRODUCER_MARK.set(true); | ||
} | ||
|
||
/** | ||
* 判断是否当前线程是否是生产者线程 | ||
* | ||
* @return 是否是生产者线程 | ||
*/ | ||
public static boolean isProducer() { | ||
return PRODUCER_MARK.get() != null; | ||
} | ||
} |
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