未验证 提交 cd029df3 编写于 作者: L Lu Jiajing 提交者: GitHub

Chore: polish methods naming for Spring Kafka (#7320)

上级 a6afcac8
...@@ -32,6 +32,7 @@ Release Notes. ...@@ -32,6 +32,7 @@ Release Notes.
* Support `guava-cache` plugin. * Support `guava-cache` plugin.
* Enhance the compatibility of `mysql-8.x-plugin` plugin. * Enhance the compatibility of `mysql-8.x-plugin` plugin.
* Support Kafka SASL login module. * Support Kafka SASL login module.
* Chore: polish methods naming for `Spring-Kafka` plugins.
#### OAP-Backend #### OAP-Backend
......
...@@ -22,11 +22,11 @@ import org.apache.skywalking.apm.agent.core.context.ContextManager; ...@@ -22,11 +22,11 @@ import org.apache.skywalking.apm.agent.core.context.ContextManager;
public class InterceptorMethod { public class InterceptorMethod {
public static void beforeMethod(String operationName) { public static void beginKafkaPollAndInvokeIteration(String operationName) {
ContextManager.getRuntimeContext().put(Constants.KAFKA_FLAG, new KafkaContext(operationName)); ContextManager.getRuntimeContext().put(Constants.KAFKA_FLAG, new KafkaContext(operationName));
} }
public static Object afterMethod(Object ret) { public static Object endKafkaPollAndInvokeIteration(Object ret) {
KafkaContext context = (KafkaContext) ContextManager.getRuntimeContext().get(Constants.KAFKA_FLAG); KafkaContext context = (KafkaContext) ContextManager.getRuntimeContext().get(Constants.KAFKA_FLAG);
if (context == null) { if (context == null) {
return ret; return ret;
......
...@@ -33,7 +33,7 @@ public class PostRunMethodInterceptor implements InstanceMethodsAroundIntercepto ...@@ -33,7 +33,7 @@ public class PostRunMethodInterceptor implements InstanceMethodsAroundIntercepto
@Override @Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable { public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
return InterceptorMethod.afterMethod(ret); return InterceptorMethod.endKafkaPollAndInvokeIteration(ret);
} }
@Override @Override
......
...@@ -26,20 +26,30 @@ import org.apache.skywalking.apm.plugin.kafka.define.InterceptorMethod; ...@@ -26,20 +26,30 @@ import org.apache.skywalking.apm.plugin.kafka.define.InterceptorMethod;
import java.lang.reflect.Method; import java.lang.reflect.Method;
/**
* The interceptor intends to be imposed on the method `processSeeks` in the ListenerConsumer class
* defined in {@link org.springframework.kafka.listener.KafkaMessageListenerContainer}
*/
public class ProcessSeeksMethodInterceptor implements InstanceMethodsAroundInterceptor { public class ProcessSeeksMethodInterceptor implements InstanceMethodsAroundInterceptor {
private static final String OPERATION_NAME = "/spring-kafka" + Constants.KAFKA_POLL_AND_INVOKE_OPERATION_NAME; private static final String OPERATION_NAME = "/spring-kafka" + Constants.KAFKA_POLL_AND_INVOKE_OPERATION_NAME;
/**
* The `beforeMethod` is called before `processSeeks`, which can be used to mark the end of the last iteration.
*/
@Override @Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable { MethodInterceptResult result) throws Throwable {
InterceptorMethod.afterMethod(null); InterceptorMethod.endKafkaPollAndInvokeIteration(null);
} }
/**
* The `afterMethod` is called after `processSeeks`, where the new PollAndInvoke iteration starts
*/
@Override @Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable { Object ret) throws Throwable {
InterceptorMethod.beforeMethod(OPERATION_NAME); InterceptorMethod.beginKafkaPollAndInvokeIteration(OPERATION_NAME);
return ret; return ret;
} }
......
...@@ -33,13 +33,13 @@ public class PollAndInvokeMethodInterceptor implements InstanceMethodsAroundInte ...@@ -33,13 +33,13 @@ public class PollAndInvokeMethodInterceptor implements InstanceMethodsAroundInte
@Override @Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable { MethodInterceptResult result) throws Throwable {
InterceptorMethod.beforeMethod(OPERATION_NAME); InterceptorMethod.beginKafkaPollAndInvokeIteration(OPERATION_NAME);
} }
@Override @Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable { Object ret) throws Throwable {
return InterceptorMethod.afterMethod(ret); return InterceptorMethod.endKafkaPollAndInvokeIteration(ret);
} }
@Override @Override
......
...@@ -33,13 +33,13 @@ public class KafkaOnMessageAnnotationMethodInterceptor implements InstanceMethod ...@@ -33,13 +33,13 @@ public class KafkaOnMessageAnnotationMethodInterceptor implements InstanceMethod
@Override @Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable { MethodInterceptResult result) throws Throwable {
InterceptorMethod.beforeMethod(OPERATION_NAME); InterceptorMethod.beginKafkaPollAndInvokeIteration(OPERATION_NAME);
} }
@Override @Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable { Object ret) throws Throwable {
return InterceptorMethod.afterMethod(ret); return InterceptorMethod.endKafkaPollAndInvokeIteration(ret);
} }
@Override @Override
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册