From d468806f43bdabee326d4a80e9a29ed03c3ac853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=99=9F=20Wu=20Sheng?= Date: Tue, 31 May 2022 10:46:53 +0800 Subject: [PATCH] Remove duplicate ServiceComb plugin codes. (#189) Follow https://github.com/apache/skywalking-java/pull/127#issuecomment-1140764345 --- .../apm-sdk-plugin/servicecomb-plugin/pom.xml | 1 - .../pom.xml | 46 ------ .../ProducerOperationHandlerInterceptor.java | 75 ---------- .../v1/TransportClientHandlerInterceptor.java | 96 ------------- ...oducerOperationHandlerInstrumentation.java | 73 ---------- ...TransportClientHandlerInstrumentation.java | 72 ---------- .../src/main/resources/skywalking-plugin.def | 18 --- ...oducerOperationHandlerInterceptorTest.java | 133 ------------------ ...TransportClientHandlerInterceptorTest.java | 128 ----------------- .../service-agent/java-agent/Plugin-list.md | 1 - 10 files changed, 643 deletions(-) delete mode 100644 apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/pom.xml delete mode 100644 apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/ProducerOperationHandlerInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/TransportClientHandlerInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/define/ProducerOperationHandlerInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/define/TransportClientHandlerInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/resources/skywalking-plugin.def delete mode 100644 apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/v1/ProducerOperationHandlerInterceptorTest.java delete mode 100644 apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/v1/TransportClientHandlerInterceptorTest.java diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/pom.xml index f00e39166..5a493258f 100644 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/pom.xml @@ -28,7 +28,6 @@ servicecomb-plugin - servicecomb-java-chassis-1.x-plugin servicecomb-java-chassis-2.x-plugin pom diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/pom.xml deleted file mode 100644 index c89ddfe4e..000000000 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - servicecomb-plugin - org.apache.skywalking - 8.11.0-SNAPSHOT - - 4.0.0 - - apm-servicecomb-java-chassis-1.x-plugin - jar - - servicecomb-java-chassis-1.x-plugin - http://maven.apache.org - - - 1.0.0-m1 - - - - - org.apache.servicecomb - java-chassis-core - ${java-chassis-core.version} - provided - - - diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/ProducerOperationHandlerInterceptor.java b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/ProducerOperationHandlerInterceptor.java deleted file mode 100644 index c9e0a2399..000000000 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/ProducerOperationHandlerInterceptor.java +++ /dev/null @@ -1,75 +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.v1; - -import java.lang.reflect.Method; -import org.apache.servicecomb.core.Invocation; -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; - -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 { - Invocation invocation = (Invocation) allArguments[0]; - AbstractSpan span = ContextManager.activeSpan(); - int statusCode = invocation.getStatus().getStatusCode(); - if (statusCode >= 400) { - span.errorOccurred(); - Tags.HTTP_RESPONSE_STATUS_CODE.set(span, statusCode); - } - ContextManager.stopSpan(); - return ret; - } - - @Override - public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - AbstractSpan span = ContextManager.activeSpan(); - span.log(t); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/TransportClientHandlerInterceptor.java b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/TransportClientHandlerInterceptor.java deleted file mode 100644 index 9debb8b92..000000000 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/TransportClientHandlerInterceptor.java +++ /dev/null @@ -1,96 +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.v1; - -import java.lang.reflect.Method; -import java.net.URI; -import org.apache.servicecomb.core.Invocation; -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; - -public class TransportClientHandlerInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - Invocation invocation = (Invocation) allArguments[0]; - if (!checkRegisterStatus(invocation)) { - return; - } - URI uri = new URI(invocation.getEndpoint().toString()); - String peer = uri.getHost() + ":" + uri.getPort(); - String operationName = invocation.getMicroserviceQualifiedName(); - final ContextCarrier contextCarrier = new ContextCarrier(); - AbstractSpan span = ContextManager.createExitSpan(operationName, 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 { - Invocation invocation = (Invocation) allArguments[0]; - if (!checkRegisterStatus(invocation)) { - return ret; - } - AbstractSpan span = ContextManager.activeSpan(); - int statusCode = invocation.getStatus().getStatusCode(); - if (statusCode >= 400) { - span.errorOccurred(); - Tags.HTTP_RESPONSE_STATUS_CODE.set(span, statusCode); - } - ContextManager.stopSpan(); - return ret; - } - - @Override - public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - Invocation invocation = (Invocation) allArguments[0]; - if (!checkRegisterStatus(invocation)) { - return; - } - AbstractSpan span = ContextManager.activeSpan(); - span.log(t); - } - - /** - * Serviecomb chassis Consumers and providers need to register at the service center. If the consumer is not - * registered then return false. - */ - private Boolean checkRegisterStatus(Invocation invocation) { - return null != invocation.getOperationMeta() && null != invocation.getEndpoint(); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/define/ProducerOperationHandlerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/define/ProducerOperationHandlerInstrumentation.java deleted file mode 100644 index d29980978..000000000 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/define/ProducerOperationHandlerInstrumentation.java +++ /dev/null @@ -1,73 +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.v1.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} represents that skywalking intercept {@link - * org.apache.servicecomb.core.handler.impl.ProducerOperationHandler#handle(org.apache.servicecomb.core.Invocation, - * org.apache.servicecomb.swagger.invocation.AsyncResponse)} by using ProducerOperationHandlerInterceptor - */ -public class ProducerOperationHandlerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "org.apache.servicecomb.core.handler.impl.ProducerOperationHandler"; - - private static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.servicecomb.v1.ProducerOperationHandlerInterceptor"; - - @Override - protected ClassMatch enhanceClass() { - return NameMatch.byName(ENHANCE_CLASS); - } - - @Override - public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override - public 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-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/define/TransportClientHandlerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/define/TransportClientHandlerInstrumentation.java deleted file mode 100644 index 490014899..000000000 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/define/TransportClientHandlerInstrumentation.java +++ /dev/null @@ -1,72 +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.v1.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 TransportClientHandlerInstrumentation} represents that skywalking intercept {@link - * org.apache.servicecomb.core.handler.impl.TransportClientHandler} by using linkTransportClientHandlerInterceptor - */ -public class TransportClientHandlerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "org.apache.servicecomb.core.handler.impl.TransportClientHandler"; - - private static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.servicecomb.v1.TransportClientHandlerInterceptor"; - - @Override - protected ClassMatch enhanceClass() { - return NameMatch.byName(ENHANCE_CLASS); - } - - @Override - public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override - public 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-1.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/resources/skywalking-plugin.def deleted file mode 100644 index 845541dc1..000000000 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/resources/skywalking-plugin.def +++ /dev/null @@ -1,18 +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. - -servicecomb-1.x=org.apache.skywalking.apm.plugin.servicecomb.v1.define.ProducerOperationHandlerInstrumentation -servicecomb-1.x=org.apache.skywalking.apm.plugin.servicecomb.v1.define.TransportClientHandlerInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/v1/ProducerOperationHandlerInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/v1/ProducerOperationHandlerInterceptorTest.java deleted file mode 100644 index 4e1b29530..000000000 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/v1/ProducerOperationHandlerInterceptorTest.java +++ /dev/null @@ -1,133 +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.v1; - -import java.lang.reflect.Method; -import java.util.List; -import javax.ws.rs.core.Response; -import org.apache.servicecomb.core.Endpoint; -import org.apache.servicecomb.core.Invocation; -import org.apache.servicecomb.core.definition.OperationMeta; -import org.apache.servicecomb.core.definition.SchemaMeta; -import org.apache.servicecomb.swagger.invocation.InvocationType; -import org.apache.servicecomb.swagger.invocation.SwaggerInvocation; -import org.apache.skywalking.apm.agent.core.boot.ServiceManager; -import org.apache.skywalking.apm.agent.core.conf.Config; -import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.apache.skywalking.apm.agent.core.context.util.TagValuePair; -import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; -import org.apache.skywalking.apm.agent.test.helper.SpanHelper; -import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; -import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class ProducerOperationHandlerInterceptorTest { - - @Rule - public AgentServiceRule agentServiceRule = new AgentServiceRule(); - @Mock - Response.StatusType statusType; - @SegmentStoragePoint - private SegmentStorage segmentStorage; - private ProducerOperationHandlerInterceptor invocationInterceptor; - @Mock - private OperationMeta operationMeta; - @Mock - private EnhancedInstance enhancedInstance; - @Mock - private Invocation invocation; - @Mock - private Endpoint endpoint; - @Mock - private Method method; - @Mock - private SwaggerInvocation swagger; - private Object[] allArguments; - private Class[] argumentsType; - private Object[] swaggerArguments; - - @Mock - private SchemaMeta schemaMeta; - - @Before - public void setUp() throws Exception { - ServiceManager.INSTANCE.boot(); - invocationInterceptor = new ProducerOperationHandlerInterceptor(); - PowerMockito.mock(Invocation.class); - when(operationMeta.getSchemaMeta()).thenReturn(schemaMeta); - when(endpoint.getAddress()).thenReturn("0.0.0.0:7777"); - when(invocation.getEndpoint()).thenReturn(endpoint); - when(invocation.getMicroserviceQualifiedName()).thenReturn("productorTest"); - when(operationMeta.getOperationPath()).thenReturn("/bmi"); - when(invocation.getOperationMeta()).thenReturn(operationMeta); - when(invocation.getStatus()).thenReturn(statusType); - when(statusType.getStatusCode()).thenReturn(200); - when(method.getName()).thenReturn("producer"); - when(invocation.getInvocationType()).thenReturn(InvocationType.PRODUCER); - Config.Agent.SERVICE_NAME = "serviceComnTestCases-APP"; - - allArguments = new Object[] {invocation}; - argumentsType = new Class[] {}; - swaggerArguments = new Class[] {}; - - } - - @Test - public void testConsumer() throws Throwable { - - invocationInterceptor.beforeMethod(enhancedInstance, method, allArguments, argumentsType, null); - invocationInterceptor.afterMethod(enhancedInstance, method, 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(invocation, times(3)).getContext(); - } - - private void assertCombSpan(AbstractTracingSpan span) { - assertThat(span.getOperationName(), is("productorTest")); - assertThat(SpanHelper.getComponentId(span), is(28)); - List tags = SpanHelper.getTags(span); - assertThat(tags.get(0).getValue(), is("/bmi")); - assertThat(span.isEntry(), is(true)); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/v1/TransportClientHandlerInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/v1/TransportClientHandlerInterceptorTest.java deleted file mode 100644 index 0095d0246..000000000 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/v1/TransportClientHandlerInterceptorTest.java +++ /dev/null @@ -1,128 +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.v1; - -import java.util.List; -import javax.ws.rs.core.Response; -import org.apache.servicecomb.core.Endpoint; -import org.apache.servicecomb.core.Invocation; -import org.apache.servicecomb.core.definition.OperationMeta; -import org.apache.servicecomb.core.definition.SchemaMeta; -import org.apache.servicecomb.core.provider.consumer.ReferenceConfig; -import org.apache.servicecomb.swagger.invocation.InvocationType; -import org.apache.servicecomb.swagger.invocation.SwaggerInvocation; -import org.apache.skywalking.apm.agent.core.boot.ServiceManager; -import org.apache.skywalking.apm.agent.core.conf.Config; -import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.apache.skywalking.apm.agent.core.context.util.TagValuePair; -import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; -import org.apache.skywalking.apm.agent.test.helper.SpanHelper; -import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; -import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; -import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class TransportClientHandlerInterceptorTest { - - @Rule - public AgentServiceRule agentServiceRule = new AgentServiceRule(); - @Mock - Response.StatusType statusType; - @Mock - ReferenceConfig referenceConfig; - @SegmentStoragePoint - private SegmentStorage segmentStorage; - private TransportClientHandlerInterceptor nextInterceptor; - @Mock - private OperationMeta operationMeta; - @Mock - private EnhancedInstance enhancedInstance; - @Mock - private Invocation invocation; - @Mock - private Endpoint endpoint; - @Mock - private SwaggerInvocation swagger; - private Object[] allArguments; - private Class[] argumentsType; - private Object[] swaggerArguments; - - @Mock - private SchemaMeta schemaMeta; - - @Before - public void setUp() throws Exception { - ServiceManager.INSTANCE.boot(); - nextInterceptor = new TransportClientHandlerInterceptor(); - PowerMockito.mock(Invocation.class); - when(operationMeta.getSchemaMeta()).thenReturn(schemaMeta); - when(endpoint.toString()).thenReturn("/bmi"); - when(invocation.getEndpoint()).thenReturn(endpoint); - when(invocation.getMicroserviceQualifiedName()).thenReturn("consumerTest"); - when(operationMeta.getOperationPath()).thenReturn("/bmi"); - when(invocation.getOperationMeta()).thenReturn(operationMeta); - when(invocation.getStatus()).thenReturn(statusType); - when(statusType.getStatusCode()).thenReturn(200); - when(invocation.getInvocationType()).thenReturn(InvocationType.CONSUMER); - Config.Agent.SERVICE_NAME = "serviceComnTestCases-APP"; - - allArguments = new Object[] {invocation}; - argumentsType = new Class[] {}; - swaggerArguments = new Class[] {}; - } - - @Test - public void testConsumer() throws Throwable { - nextInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null); - 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(invocation, times(3)).getContext(); - } - - private void assertCombSpan(AbstractTracingSpan span) { - assertThat(span.getOperationName(), is("consumerTest")); - assertThat(SpanHelper.getComponentId(span), is(28)); - List tags = SpanHelper.getTags(span); - assertThat(tags.get(0).getValue(), is("/bmi")); - assertThat(span.isExit(), is(true)); - } - -} diff --git a/docs/en/setup/service-agent/java-agent/Plugin-list.md b/docs/en/setup/service-agent/java-agent/Plugin-list.md index 770b0fe72..d5d04c2dd 100644 --- a/docs/en/setup/service-agent/java-agent/Plugin-list.md +++ b/docs/en/setup/service-agent/java-agent/Plugin-list.md @@ -77,7 +77,6 @@ - rocketMQ-3.x - rocketMQ-4.x - sentinel-1.x -- servicecomb-1.x - servicecomb-2.x - sharding-sphere-3.x - sharding-sphere-4.0.0