diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/pom.xml index ff52581b04948b2762211481e1ea2358c7f717c9..cee6c694f0398c9069bdb3462deb7b4fc3e3e04c 100644 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/pom.xml @@ -41,6 +41,12 @@ 0.5.0 test + + io.servicecomb + common-rest + 0.5.0 + provided + io.swagger swagger-core diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/NextInterceptor.java b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/NextInterceptor.java deleted file mode 100644 index 2abc0d7aa7a3ba266a7bf7ea1ae3c5407df68e7e..0000000000000000000000000000000000000000 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/NextInterceptor.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.servicecomb; - -import io.servicecomb.core.Invocation; -import io.servicecomb.swagger.invocation.InvocationType; -import io.servicecomb.swagger.invocation.SwaggerInvocation; -import io.servicecomb.swagger.invocation.context.InvocationContext; -import java.lang.reflect.Method; -import java.net.URI; -import javax.ws.rs.core.Response.StatusType; -import org.apache.skywalking.apm.agent.core.context.CarrierItem; -import org.apache.skywalking.apm.agent.core.context.ContextCarrier; -import org.apache.skywalking.apm.agent.core.context.ContextManager; -import org.apache.skywalking.apm.agent.core.context.tag.Tags; -import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; - -/** - * {@link NextInterceptor} define how to enhance class {@link Invocation#next(io.servicecomb.swagger.invocation.AsyncResponse)}. - * - * @author lytscu - */ -public class NextInterceptor implements InstanceMethodsAroundInterceptor { - static final ThreadLocal DEEP = new ThreadLocal() { - @Override - protected Integer initialValue() { - Integer deepindex = 0; - return deepindex; - } - }; - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - SwaggerInvocation swagger = (SwaggerInvocation)objInst; - InvocationType type = swagger.getInvocationType(); - Invocation invocation = (Invocation)objInst; - AbstractSpan span; - boolean isConsumer = type.equals(InvocationType.CONSUMER); - if (isConsumer) { - Integer count = (Integer)DEEP.get(); - try { - //When count = 2, you can get the peer - if (count == 2) { - URI uri = new URI(invocation.getEndpoint().toString()); - String peer = uri.getHost() + ":" + uri.getPort(); - final ContextCarrier contextCarrier = new ContextCarrier(); - span = ContextManager.createExitSpan(invocation.getMicroserviceQualifiedName(), contextCarrier, peer); - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - invocation.getContext().put(next.getHeadKey(), next.getHeadValue()); - } - String url = invocation.getOperationMeta().getOperationPath(); - Tags.URL.set(span, url); - span.setComponent(ComponentsDefine.SERVICECOMB); - SpanLayer.asRPCFramework(span); - } - } finally { - count++; - DEEP.set(count); - } - } - } - - @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Object ret) throws Throwable { - SwaggerInvocation swagger = (SwaggerInvocation)objInst; - InvocationType type = swagger.getInvocationType(); - boolean isConsumer = type.equals(InvocationType.CONSUMER); - if (isConsumer) { - Integer count = (Integer)DEEP.get(); - try { - if (count == 1) { - AbstractSpan span = ContextManager.activeSpan(); - StatusType statusType = ((InvocationContext)objInst).getStatus(); - int statusCode = statusType.getStatusCode(); - if (statusCode >= 400) { - span.errorOccurred(); - Tags.STATUS_CODE.set(span, Integer.toString(statusCode)); - } - ContextManager.stopSpan(); - } - } finally { - count--; - DEEP.set(count); - } - } - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - AbstractSpan span = ContextManager.activeSpan(); - span.errorOccurred(); - span.log(t); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/ProducerOperationHandlerInterceptor.java b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/ProducerOperationHandlerInterceptor.java new file mode 100644 index 0000000000000000000000000000000000000000..52046eae650e593ca726a17a8c5cf246dc9ba648 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/ProducerOperationHandlerInterceptor.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.servicecomb; + +import io.servicecomb.core.Invocation; +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +/** + * {org.apache.skywalking.apm.plugin.servicecomb.} define how to enhance class {@link Invocation#getHandlerContext()}. + * + * @author lytscu + */ +public class ProducerOperationHandlerInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + Invocation invocation = (Invocation)allArguments[0]; + ContextCarrier contextCarrier = new ContextCarrier(); + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + next.setHeadValue(invocation.getContext().get(next.getHeadKey())); + } + String operationName = invocation.getMicroserviceQualifiedName(); + AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier); + String url = invocation.getOperationMeta().getOperationPath(); + Tags.URL.set(span, url); + span.setComponent(ComponentsDefine.SERVICECOMB); + SpanLayer.asRPCFramework(span); + } + + @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + AbstractSpan span = ContextManager.activeSpan(); + span.errorOccurred(); + span.log(t); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/InvocationInterceptor.java b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/TransportClientHandlerInterceptor.java similarity index 54% rename from apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/InvocationInterceptor.java rename to apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/TransportClientHandlerInterceptor.java index e76a4e0c47b469a11ea25551bba239f25d80a39e..2eec6411612e9ce4555c692a2e37eef71aeffa85 100644 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/InvocationInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/TransportClientHandlerInterceptor.java @@ -19,11 +19,8 @@ package org.apache.skywalking.apm.plugin.servicecomb; import io.servicecomb.core.Invocation; -import io.servicecomb.swagger.invocation.InvocationType; -import io.servicecomb.swagger.invocation.SwaggerInvocation; -import io.servicecomb.swagger.invocation.context.InvocationContext; import java.lang.reflect.Method; -import javax.ws.rs.core.Response.StatusType; +import java.net.URI; import org.apache.skywalking.apm.agent.core.context.CarrierItem; import org.apache.skywalking.apm.agent.core.context.ContextCarrier; import org.apache.skywalking.apm.agent.core.context.ContextManager; @@ -36,52 +33,42 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInt import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; /** - * {@link InvocationInterceptor} define how to enhance class {@link Invocation#getHandlerContext()}. + * {@link TransportClientHandlerInterceptor} define how to enhance class {@link Invocation#next(io.servicecomb.swagger.invocation.AsyncResponse)}. * * @author lytscu */ -public class InvocationInterceptor implements InstanceMethodsAroundInterceptor { +public class TransportClientHandlerInterceptor implements InstanceMethodsAroundInterceptor { @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - SwaggerInvocation swagger = (SwaggerInvocation)objInst; - InvocationType type = swagger.getInvocationType(); - Invocation invocation = (Invocation)objInst; - AbstractSpan span; - boolean isConsumer = type.equals(InvocationType.CONSUMER); - if (!isConsumer) { - - ContextCarrier contextCarrier = new ContextCarrier(); - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - next.setHeadValue(invocation.getContext().get(next.getHeadKey())); - } - String operationName = invocation.getMicroserviceQualifiedName(); - span = ContextManager.createEntrySpan(operationName, contextCarrier); - String url = invocation.getOperationMeta().getOperationPath(); - Tags.URL.set(span, url); - span.setComponent(ComponentsDefine.SERVICECOMB); - SpanLayer.asRPCFramework(span); + Invocation invocation = (Invocation)allArguments[0]; + URI uri = new URI(invocation.getEndpoint().toString()); + String peer = uri.getHost() + ":" + uri.getPort(); + final ContextCarrier contextCarrier = new ContextCarrier(); + AbstractSpan span = ContextManager.createExitSpan(invocation.getMicroserviceQualifiedName(), contextCarrier, peer); + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + invocation.getContext().put(next.getHeadKey(), next.getHeadValue()); } + String url = invocation.getOperationMeta().getOperationPath(); + Tags.URL.set(span, url); + span.setComponent(ComponentsDefine.SERVICECOMB); + SpanLayer.asRPCFramework(span); } @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Object ret) throws Throwable { - SwaggerInvocation swagger = (SwaggerInvocation)objInst; - InvocationType type = swagger.getInvocationType(); - boolean isConsumer = type.equals(InvocationType.CONSUMER); - if (!isConsumer) { - AbstractSpan span = ContextManager.activeSpan(); - StatusType statusType = ((InvocationContext)objInst).getStatus(); - int statusCode = statusType.getStatusCode(); - if (statusCode >= 400) { - span.errorOccurred(); - Tags.STATUS_CODE.set(span, Integer.toString(statusCode)); - } - ContextManager.stopSpan(); + Invocation invocation = (Invocation)allArguments[0]; + AbstractSpan span = ContextManager.activeSpan(); + int statusCode = invocation.getStatus().getStatusCode(); + if (statusCode >= 400) { + span.errorOccurred(); + Tags.STATUS_CODE.set(span, Integer.toString(statusCode)); } + ContextManager.stopSpan(); + return ret; } diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/define/ProducerOperationHandlerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/define/ProducerOperationHandlerInstrumentation.java new file mode 100644 index 0000000000000000000000000000000000000000..e160b8d42a7daeefae070bef4ca525e540820015 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/define/ProducerOperationHandlerInstrumentation.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.servicecomb.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link ProducerOperationHandlerInstrumentation} presents that skywalking intercept {@link + * ProducerOperationHandler#handle (io.servicecomb.core.Invocation, io.servicecomb.swagger.invocation.AsyncResponse)#}by + * using {@link ProducerOperationHandlerInterceptor} + * + * @author lytscu + */ +public class ProducerOperationHandlerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "io.servicecomb.core.handler.impl.ProducerOperationHandler"; + + private static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.servicecomb.ProducerOperationHandlerInterceptor"; + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("handle"); + } + + @Override + public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/define/InvocationInstrumentation.java b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/define/TransportClientHandlerInstrumentation.java similarity index 64% rename from apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/define/InvocationInstrumentation.java rename to apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/define/TransportClientHandlerInstrumentation.java index 347e6647cc76de4a3cc329a40008a70d604d8d67..2c644fe692f9b350474157a830782e8de4f47a23 100644 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/define/InvocationInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/define/TransportClientHandlerInstrumentation.java @@ -18,7 +18,7 @@ package org.apache.skywalking.apm.plugin.servicecomb.define; -import io.servicecomb.core.Invocation; +import io.servicecomb.core.handler.impl.TransportClientHandler; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; @@ -26,23 +26,20 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsIn import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; -import org.apache.skywalking.apm.plugin.servicecomb.InvocationInterceptor; import static net.bytebuddy.matcher.ElementMatchers.named; /** - * {@link InvocationInstrumentation} presents that skywalking intercept {@link io.servicecomb.core.Invocation#getHandlerContext}by - * using {@link InvocationInterceptor}, and {@link Invocation#next by using {@link NextInterceptor}, + * {@link TransportClientHandlerInstrumentation} presents that skywalking intercept {@link TransportClientHandler}by + * using {@linkTransportClientHandlerInterceptor } * * @author lytscu */ -public class InvocationInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { +public class TransportClientHandlerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - private static final String ENHANCE_CLASS = "io.servicecomb.core.Invocation"; + private static final String ENHANCE_CLASS = "io.servicecomb.core.handler.impl.TransportClientHandler"; - private static final String PRODUCER_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.servicecomb.InvocationInterceptor"; - - private static final String CONSUMER_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.servicecomb.NextInterceptor"; + private static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.servicecomb.TransportClientHandlerInterceptor"; @Override protected ClassMatch enhanceClass() { @@ -60,33 +57,18 @@ public class InvocationInstrumentation extends ClassInstanceMethodsEnhancePlugin new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named("getHandlerContext"); + return named("handle"); } @Override public String getMethodsInterceptor() { - return PRODUCER_INTERCEPT_CLASS; + return INTERCEPT_CLASS; } @Override public boolean isOverrideArgs() { return false; } }, - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("next"); - } - - @Override - public String getMethodsInterceptor() { - return CONSUMER_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - } }; } } diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/resources/skywalking-plugin.def index 2b17f4d6aa5f7941b1ac26edb22f0b0b75a1c346..950da2df718f26ca1dc98892fc73d557538ffd68 100644 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/resources/skywalking-plugin.def @@ -1 +1,2 @@ -servicecomb-0.x=org.apache.skywalking.apm.plugin.servicecomb.define.InvocationInstrumentation +servicecomb-0.x=org.apache.skywalking.apm.plugin.servicecomb.define.ProducerOperationHandlerInstrumentation +servicecomb-0.x=org.apache.skywalking.apm.plugin.servicecomb.define.TransportClientHandlerInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/InvocationInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/ProducerOperationHandlerInterceptorTest.java similarity index 78% rename from apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/InvocationInterceptorTest.java rename to apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/ProducerOperationHandlerInterceptorTest.java index 711012d761dafe9da0137c3469b7c989a856e1d5..fe26ca3c64dbd4ad9fa2788fa453581acb0c9571 100644 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/InvocationInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/ProducerOperationHandlerInterceptorTest.java @@ -22,7 +22,6 @@ import io.servicecomb.core.Endpoint; import io.servicecomb.core.Invocation; import io.servicecomb.core.definition.OperationMeta; import io.servicecomb.core.definition.SchemaMeta; -import io.servicecomb.core.provider.consumer.ReferenceConfig; import io.servicecomb.swagger.invocation.InvocationType; import io.servicecomb.swagger.invocation.SwaggerInvocation; import java.util.List; @@ -57,30 +56,23 @@ import static org.mockito.Mockito.when; @RunWith(PowerMockRunner.class) @PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class InvocationInterceptorTest { - - @SegmentStoragePoint - private SegmentStorage segmentStorage; +public class ProducerOperationHandlerInterceptorTest { @Rule public AgentServiceRule agentServiceRule = new AgentServiceRule(); - - private InvocationInterceptor invocationInterceptor; @Mock - private OperationMeta operationMeta; - + Response.StatusType statusType; + @SegmentStoragePoint + private SegmentStorage segmentStorage; + private ProducerOperationHandlerInterceptor invocationInterceptor; @Mock - private MockInvocation enhancedInstance; - + private OperationMeta operationMeta; @Mock - private Endpoint endpoint; - + private EnhancedInstance enhancedInstance; @Mock - Response.StatusType statusType; - + private Invocation invocation; @Mock - ReferenceConfig referenceConfig; - + private Endpoint endpoint; @Mock private SwaggerInvocation swagger; private Object[] allArguments; @@ -93,20 +85,20 @@ public class InvocationInterceptorTest { @Before public void setUp() throws Exception { ServiceManager.INSTANCE.boot(); - invocationInterceptor = new InvocationInterceptor(); + invocationInterceptor = new ProducerOperationHandlerInterceptor(); PowerMockito.mock(Invocation.class); when(operationMeta.getSchemaMeta()).thenReturn(schemaMeta); when(endpoint.getAddress()).thenReturn("0.0.0.0:7777"); - when(enhancedInstance.getEndpoint()).thenReturn(endpoint); - when(enhancedInstance.getMicroserviceQualifiedName()).thenReturn("productorTest"); + when(invocation.getEndpoint()).thenReturn(endpoint); + when(invocation.getMicroserviceQualifiedName()).thenReturn("productorTest"); when(operationMeta.getOperationPath()).thenReturn("/bmi"); - when(enhancedInstance.getOperationMeta()).thenReturn(operationMeta); - when(enhancedInstance.getStatus()).thenReturn(statusType); + when(invocation.getOperationMeta()).thenReturn(operationMeta); + when(invocation.getStatus()).thenReturn(statusType); when(statusType.getStatusCode()).thenReturn(200); - when(enhancedInstance.getInvocationType()).thenReturn(InvocationType.PRODUCER); + when(invocation.getInvocationType()).thenReturn(InvocationType.PRODUCER); Config.Agent.APPLICATION_CODE = "serviceComnTestCases-APP"; - allArguments = new Object[] {}; + allArguments = new Object[] {invocation,}; argumentsType = new Class[] {}; swaggerArguments = new Class[] {}; } @@ -122,7 +114,7 @@ public class InvocationInterceptorTest { List spans = SegmentHelper.getSpans(traceSegment); assertCombSpan(spans.get(0)); - verify(enhancedInstance, times(1)).getContext(); + verify(invocation, times(1)).getContext(); } private void assertCombSpan(AbstractTracingSpan span) { @@ -133,18 +125,4 @@ public class InvocationInterceptorTest { assertThat(span.isEntry(), is(true)); } - private class MockInvocation extends Invocation implements EnhancedInstance { - public MockInvocation(ReferenceConfig referenceConfig, OperationMeta operationMeta, Object[] swaggerArguments) { - super(referenceConfig, operationMeta, swaggerArguments); - } - - @Override public Object getSkyWalkingDynamicField() { - return null; - } - - @Override public void setSkyWalkingDynamicField(Object value) { - - } - - } } diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/NextInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/TransportClientHandlerInterceptorTest.java similarity index 78% rename from apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/NextInterceptorTest.java rename to apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/TransportClientHandlerInterceptorTest.java index 5f566c137a01e3aba5493f2687474273e9361c84..f3126575129b62cfe6bb95fe44e8001cfb2d8a2a 100644 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/NextInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/TransportClientHandlerInterceptorTest.java @@ -49,7 +49,6 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import static org.apache.skywalking.apm.plugin.servicecomb.NextInterceptor.DEEP; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.times; @@ -58,30 +57,25 @@ import static org.mockito.Mockito.when; @RunWith(PowerMockRunner.class) @PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class NextInterceptorTest { - - @SegmentStoragePoint - private SegmentStorage segmentStorage; +public class TransportClientHandlerInterceptorTest { @Rule public AgentServiceRule agentServiceRule = new AgentServiceRule(); - - private NextInterceptor nextInterceptor; @Mock - private OperationMeta operationMeta; - + Response.StatusType statusType; @Mock - private MockInvocation enhancedInstance; - + ReferenceConfig referenceConfig; + @SegmentStoragePoint + private SegmentStorage segmentStorage; + private TransportClientHandlerInterceptor nextInterceptor; @Mock - private Endpoint endpoint; - + private OperationMeta operationMeta; @Mock - Response.StatusType statusType; - + private EnhancedInstance enhancedInstance; @Mock - ReferenceConfig referenceConfig; - + private Invocation invocation; + @Mock + private Endpoint endpoint; @Mock private SwaggerInvocation swagger; private Object[] allArguments; @@ -94,39 +88,33 @@ public class NextInterceptorTest { @Before public void setUp() throws Exception { ServiceManager.INSTANCE.boot(); - nextInterceptor = new NextInterceptor(); + nextInterceptor = new TransportClientHandlerInterceptor(); PowerMockito.mock(Invocation.class); when(operationMeta.getSchemaMeta()).thenReturn(schemaMeta); when(endpoint.getAddress()).thenReturn("0.0.0.0:7777"); - when(enhancedInstance.getEndpoint()).thenReturn(endpoint); - when(enhancedInstance.getMicroserviceQualifiedName()).thenReturn("consumerTest"); + when(invocation.getEndpoint()).thenReturn(endpoint); + when(invocation.getMicroserviceQualifiedName()).thenReturn("consumerTest"); when(operationMeta.getOperationPath()).thenReturn("/bmi"); - when(enhancedInstance.getOperationMeta()).thenReturn(operationMeta); - when(enhancedInstance.getStatus()).thenReturn(statusType); + when(invocation.getOperationMeta()).thenReturn(operationMeta); + when(invocation.getStatus()).thenReturn(statusType); when(statusType.getStatusCode()).thenReturn(200); - when(enhancedInstance.getInvocationType()).thenReturn(InvocationType.CONSUMER); + when(invocation.getInvocationType()).thenReturn(InvocationType.CONSUMER); Config.Agent.APPLICATION_CODE = "serviceComnTestCases-APP"; - allArguments = new Object[] {}; + allArguments = new Object[] {invocation,}; argumentsType = new Class[] {}; swaggerArguments = new Class[] {}; } @Test public void testConsumer() throws Throwable { - Integer count = 2; - DEEP.set(count); nextInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null); - count = 1; - DEEP.set(count); nextInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentsType, null); - Assert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); assertCombSpan(spans.get(0)); - verify(enhancedInstance, times(1)).getContext(); + verify(invocation, times(1)).getContext(); } private void assertCombSpan(AbstractTracingSpan span) { @@ -137,18 +125,4 @@ public class NextInterceptorTest { assertThat(span.isExit(), is(true)); } - private class MockInvocation extends Invocation implements EnhancedInstance { - public MockInvocation(ReferenceConfig referenceConfig, OperationMeta operationMeta, Object[] swaggerArguments) { - super(referenceConfig, operationMeta, swaggerArguments); - } - - @Override public Object getSkyWalkingDynamicField() { - return null; - } - - @Override public void setSkyWalkingDynamicField(Object value) { - - } - - } }