From 1b499f0dc06d2387710607ef9d7c99b98b62b6d6 Mon Sep 17 00:00:00 2001 From: lytscu Date: Mon, 22 Jan 2018 15:56:25 +0800 Subject: [PATCH 01/14] Add [Agent] ServiceComb Plugin #437 --- .../trace/component/ComponentsDefine.java | 5 +- apm-sniffer/apm-sdk-plugin/pom.xml | 1 + .../servicecomb-java-chassis-plugin/pom.xml | 81 +++++++++ .../servicecomb/InvocationInterceptor.java | 95 +++++++++++ .../plugin/servicecomb/NextInterceptor.java | 117 +++++++++++++ .../define/InvocationInstrumentation.java | 92 +++++++++++ .../src/main/resources/skywalking-plugin.def | 1 + .../InvocationInterceptorTest.java | 150 +++++++++++++++++ .../servicecomb/NextInterceptorTest.java | 154 ++++++++++++++++++ 9 files changed, 695 insertions(+), 1 deletion(-) create mode 100644 apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/pom.xml create mode 100644 apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/InvocationInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/NextInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/define/InvocationInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/main/resources/skywalking-plugin.def create mode 100644 apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/InvocationInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/NextInterceptorTest.java diff --git a/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java b/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java index b23f30cf3..3cfa01799 100644 --- a/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java +++ b/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java @@ -78,6 +78,8 @@ public class ComponentsDefine { public static final OfficialComponent HTTP_ASYNC_CLIENT = new OfficialComponent(26, "httpasyncclient"); + public static final OfficialComponent SERVICECOMB = new OfficialComponent(27, "ServiceComb"); + private static ComponentsDefine INSTANCE = new ComponentsDefine(); private String[] components; @@ -87,7 +89,7 @@ public class ComponentsDefine { } public ComponentsDefine() { - components = new String[27]; + components = new String[28]; addComponent(TOMCAT); addComponent(HTTPCLIENT); addComponent(DUBBO); @@ -114,6 +116,7 @@ public class ComponentsDefine { addComponent(ELASTIC_JOB); addComponent(ROCKET_MQ); addComponent(HTTP_ASYNC_CLIENT); + addComponent(SERVICECOMB); } private void addComponent(OfficialComponent component) { diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml index 4b81d1d8c..2717502fa 100644 --- a/apm-sniffer/apm-sdk-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/pom.xml @@ -53,6 +53,7 @@ elastic-job-2.x-plugin mongodb-2.x-plugin httpasyncclient-4.x-plugin + servicecomb-java-chassis-plugin pom diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/pom.xml new file mode 100644 index 000000000..afd9a3031 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/pom.xml @@ -0,0 +1,81 @@ + + + + apm-sdk-plugin + org.apache.skywalking + 5.0.0-alpha + + 4.0.0 + + apm-servicecomb-java-chassis-plugin + jar + + servicecomb-java-chassis-plugin + http://maven.apache.org + + + + + io.servicecomb + java-chassis-core + 0.5.0 + provided + + + io.servicecomb + swagger-invocation-core + 0.5.0 + provided + + + io.servicecomb + foundation-common + 0.5.0 + test + + + io.servicecomb + service-registry + 0.5.0 + test + + + io.swagger + swagger-core + 1.5.17 + test + + + org.slf4j + log4j-over-slf4j + 1.7.25 + test + + + javax.ws.rs + jsr311-api + 1.1.1 + + + + + + + org.apache.maven.plugins + maven-source-plugin + + + + attach-sources + none + + jar + + + + + + + \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/InvocationInterceptor.java b/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/InvocationInterceptor.java new file mode 100644 index 000000000..4e2c4e7e9 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/InvocationInterceptor.java @@ -0,0 +1,95 @@ +/* + * 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 java.lang.reflect.Method; +import javax.ws.rs.core.Response.StatusType; +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 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 InvocationInterceptor} define how to enhance class {@link Invocation#getHandlerChain()}. + * + * @author lytscu + */ +public class InvocationInterceptor 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.getOperationName(); + 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 { + 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(); + } + 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-java-chassis-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/NextInterceptor.java b/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/NextInterceptor.java new file mode 100644 index 000000000..e169ec24f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/NextInterceptor.java @@ -0,0 +1,117 @@ +/* + * 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 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 { + if (count == 2) { + String peer = invocation.getEndpoint().getAddress().toString(); + final ContextCarrier contextCarrier = new ContextCarrier(); + span = ContextManager.createExitSpan(invocation.getOperationName(), 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-java-chassis-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/define/InvocationInstrumentation.java b/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/define/InvocationInstrumentation.java new file mode 100644 index 000000000..a173161cb --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/define/InvocationInstrumentation.java @@ -0,0 +1,92 @@ +/* + * 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 io.servicecomb.core.Invocation; +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 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#next(AsyncResponse)}by + * using {@link InvocationInterceptor}, and {@link Invocation#getHandlerChain() by using {@link NextInterceptor}, + * + * @author lytscu + */ +public class InvocationInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "io.servicecomb.core.Invocation"; + + 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"; + + @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("getHandlerChain"); + } + + @Override + public String getMethodsInterceptor() { + return PRODUCER_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-java-chassis-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/main/resources/skywalking-plugin.def new file mode 100644 index 000000000..89240686e --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/main/resources/skywalking-plugin.def @@ -0,0 +1 @@ +servicecomb-0.6=org.apache.skywalking.apm.plugin.servicecomb.define.InvocationInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/InvocationInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/InvocationInterceptorTest.java new file mode 100644 index 000000000..c06dde790 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/InvocationInterceptorTest.java @@ -0,0 +1,150 @@ +/* + * 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.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; +import javax.ws.rs.core.Response; +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.KeyValuePair; +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 InvocationInterceptorTest { + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule agentServiceRule = new AgentServiceRule(); + + private InvocationInterceptor invocationInterceptor; + @Mock + private OperationMeta operationMeta; + + @Mock + private MockInvocation enhancedInstance; + + @Mock + private Endpoint endpoint; + + @Mock + Response.StatusType statusType; + + @Mock + ReferenceConfig referenceConfig; + + @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 InvocationInterceptor(); + 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.getOperationName()).thenReturn("productorTest"); + when(operationMeta.getOperationPath()).thenReturn("/bmi"); + when(enhancedInstance.getOperationMeta()).thenReturn(operationMeta); + when(enhancedInstance.getStatus()).thenReturn(statusType); + when(statusType.getStatusCode()).thenReturn(200); + when(enhancedInstance.getInvocationType()).thenReturn(InvocationType.PRODUCER); + Config.Agent.APPLICATION_CODE = "serviceComnTestCases-APP"; + + allArguments = new Object[] {}; + argumentsType = new Class[] {}; + swaggerArguments = new Class[] {}; + } + + @Test + public void testConsumer() throws Throwable { + + invocationInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null); + invocationInterceptor.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(); + } + + private void assertCombSpan(AbstractTracingSpan span) { + assertThat(span.getOperationName(), is("productorTest")); + assertThat(SpanHelper.getComponentId(span), is(27)); + List tags = SpanHelper.getTags(span); + assertThat(tags.get(0).getValue(), is("/bmi")); + 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-java-chassis-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/NextInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/NextInterceptorTest.java new file mode 100644 index 000000000..9c3576246 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/NextInterceptorTest.java @@ -0,0 +1,154 @@ +/* + * 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.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; +import javax.ws.rs.core.Response; +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.KeyValuePair; +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.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; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class NextInterceptorTest { + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule agentServiceRule = new AgentServiceRule(); + + private NextInterceptor nextInterceptor; + @Mock + private OperationMeta operationMeta; + + @Mock + private MockInvocation enhancedInstance; + + @Mock + private Endpoint endpoint; + + @Mock + Response.StatusType statusType; + + @Mock + ReferenceConfig referenceConfig; + + @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 NextInterceptor(); + 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.getOperationName()).thenReturn("consumerTest"); + when(operationMeta.getOperationPath()).thenReturn("/bmi"); + when(enhancedInstance.getOperationMeta()).thenReturn(operationMeta); + when(enhancedInstance.getStatus()).thenReturn(statusType); + when(statusType.getStatusCode()).thenReturn(200); + when(enhancedInstance.getInvocationType()).thenReturn(InvocationType.CONSUMER); + Config.Agent.APPLICATION_CODE = "serviceComnTestCases-APP"; + + allArguments = new Object[] {}; + 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(); + } + + private void assertCombSpan(AbstractTracingSpan span) { + assertThat(span.getOperationName(), is("consumerTest")); + assertThat(SpanHelper.getComponentId(span), is(27)); + List tags = SpanHelper.getTags(span); + assertThat(tags.get(0).getValue(), is("/bmi")); + 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) { + + } + + } +} From d2a3a2814fc74152d2bc2da30970b46f17bf28b6 Mon Sep 17 00:00:00 2001 From: lytscu Date: Thu, 25 Jan 2018 09:40:28 +0800 Subject: [PATCH 02/14] Modify catalog --- apm-sniffer/apm-sdk-plugin/pom.xml | 2 +- .../apm-sdk-plugin/servicecomb-plugin/pom.xml | 26 +++++++++++++++++++ .../pom.xml | 6 ++--- .../servicecomb/InvocationInterceptor.java | 8 +++--- .../plugin/servicecomb/NextInterceptor.java | 4 ++- .../define/InvocationInstrumentation.java | 4 +-- .../src/main/resources/skywalking-plugin.def | 0 .../InvocationInterceptorTest.java | 0 .../servicecomb/NextInterceptorTest.java | 0 9 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 apm-sniffer/apm-sdk-plugin/servicecomb-plugin/pom.xml rename apm-sniffer/apm-sdk-plugin/{servicecomb-java-chassis-plugin => servicecomb-plugin/servicecomb-java-chassis-0.x-plugin}/pom.xml (93%) rename apm-sniffer/apm-sdk-plugin/{servicecomb-java-chassis-plugin => servicecomb-plugin/servicecomb-java-chassis-0.x-plugin}/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/InvocationInterceptor.java (97%) rename apm-sniffer/apm-sdk-plugin/{servicecomb-java-chassis-plugin => servicecomb-plugin/servicecomb-java-chassis-0.x-plugin}/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/NextInterceptor.java (96%) rename apm-sniffer/apm-sdk-plugin/{servicecomb-java-chassis-plugin => servicecomb-plugin/servicecomb-java-chassis-0.x-plugin}/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/define/InvocationInstrumentation.java (98%) rename apm-sniffer/apm-sdk-plugin/{servicecomb-java-chassis-plugin => servicecomb-plugin/servicecomb-java-chassis-0.x-plugin}/src/main/resources/skywalking-plugin.def (100%) rename apm-sniffer/apm-sdk-plugin/{servicecomb-java-chassis-plugin => servicecomb-plugin/servicecomb-java-chassis-0.x-plugin}/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/InvocationInterceptorTest.java (100%) rename apm-sniffer/apm-sdk-plugin/{servicecomb-java-chassis-plugin => servicecomb-plugin/servicecomb-java-chassis-0.x-plugin}/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/NextInterceptorTest.java (100%) diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml index 2717502fa..dc492895d 100644 --- a/apm-sniffer/apm-sdk-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/pom.xml @@ -53,7 +53,7 @@ elastic-job-2.x-plugin mongodb-2.x-plugin httpasyncclient-4.x-plugin - servicecomb-java-chassis-plugin + servicecomb-plugin pom diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/pom.xml new file mode 100644 index 000000000..1668c7020 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/pom.xml @@ -0,0 +1,26 @@ + + + + apm-sdk-plugin + org.apache.skywalking + 5.0.0-alpha + + 4.0.0 + + servicecomb-plugin + + + servicecomb-java-chassis-0.x-plugin + + pom + + apm-sdk-plugin + http://maven.apache.org + + + UTF-8 + /.. + + \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/pom.xml similarity index 93% rename from apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/pom.xml rename to apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/pom.xml index afd9a3031..ff52581b0 100644 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/pom.xml @@ -3,16 +3,16 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - apm-sdk-plugin + servicecomb-plugin org.apache.skywalking 5.0.0-alpha 4.0.0 - apm-servicecomb-java-chassis-plugin + apm-servicecomb-java-chassis-0.x-plugin jar - servicecomb-java-chassis-plugin + servicecomb-java-chassis-0.x-plugin http://maven.apache.org diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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/InvocationInterceptor.java similarity index 97% rename from apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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/InvocationInterceptor.java index 4e2c4e7e9..ba0e73788 100644 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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/InvocationInterceptor.java @@ -18,12 +18,12 @@ 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 io.servicecomb.core.Invocation; -import io.servicecomb.swagger.invocation.InvocationType; -import io.servicecomb.swagger.invocation.SwaggerInvocation; -import io.servicecomb.swagger.invocation.context.InvocationContext; 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; diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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 similarity index 96% rename from apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/NextInterceptor.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/NextInterceptor.java index e169ec24f..d68231954 100644 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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 @@ -23,6 +23,7 @@ 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; @@ -61,7 +62,8 @@ public class NextInterceptor implements InstanceMethodsAroundInterceptor { Integer count = (Integer)DEEP.get(); try { if (count == 2) { - String peer = invocation.getEndpoint().getAddress().toString(); + URI uri = new URI(invocation.getEndpoint().toString()); + String peer = uri.getHost() + ":" + uri.getPort(); final ContextCarrier contextCarrier = new ContextCarrier(); span = ContextManager.createExitSpan(invocation.getOperationName(), contextCarrier, peer); CarrierItem next = contextCarrier.items(); diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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/InvocationInstrumentation.java similarity index 98% rename from apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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/InvocationInstrumentation.java index a173161cb..44dbc83fb 100644 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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/InvocationInstrumentation.java @@ -18,9 +18,9 @@ package org.apache.skywalking.apm.plugin.servicecomb.define; +import io.servicecomb.core.Invocation; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; -import io.servicecomb.core.Invocation; 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; @@ -60,7 +60,7 @@ public class InvocationInstrumentation extends ClassInstanceMethodsEnhancePlugin new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named("getHandlerChain"); + return named("getHandlerContext"); } @Override diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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 similarity index 100% rename from apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/main/resources/skywalking-plugin.def rename to apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/resources/skywalking-plugin.def diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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/InvocationInterceptorTest.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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/InvocationInterceptorTest.java diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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/NextInterceptorTest.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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/NextInterceptorTest.java From 9ff209373e720d9d0de3458587d22b1fdacbbdfd Mon Sep 17 00:00:00 2001 From: cyberdak Date: Tue, 23 Jan 2018 16:36:13 +0800 Subject: [PATCH 03/14] fix collector/start.sh tip. "Web" to "Collector" --- apm-collector/apm-collector-boot/bin/collectorService.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apm-collector/apm-collector-boot/bin/collectorService.sh b/apm-collector/apm-collector-boot/bin/collectorService.sh index 5eb45b307..dbb7774b2 100644 --- a/apm-collector/apm-collector-boot/bin/collectorService.sh +++ b/apm-collector/apm-collector-boot/bin/collectorService.sh @@ -27,8 +27,8 @@ eval exec "\"$_RUNJAVA\" ${JAVA_OPTS} ${COLLECTOR_OPTIONS} -classpath $CLASSPATH if [ $? -eq 0 ]; then sleep 1 - echo "Skywalking Web started successfully!" + echo "Skywalking Collector started successfully!" else - echo "Skywalking Web started failure!" + echo "Skywalking Collector started failure!" exit 1 fi From 94dcf96e1ff088342bf345f8fe53d872cea445f4 Mon Sep 17 00:00:00 2001 From: lytscu Date: Thu, 25 Jan 2018 09:40:28 +0800 Subject: [PATCH 04/14] Modify catalog --- apm-sniffer/apm-sdk-plugin/pom.xml | 2 +- .../apm-sdk-plugin/servicecomb-plugin/pom.xml | 26 +++++++++++++++++++ .../pom.xml | 6 ++--- .../servicecomb/InvocationInterceptor.java | 10 +++---- .../plugin/servicecomb/NextInterceptor.java | 5 +++- .../define/InvocationInstrumentation.java | 8 +++--- .../src/main/resources/skywalking-plugin.def | 0 .../InvocationInterceptorTest.java | 0 .../servicecomb/NextInterceptorTest.java | 0 9 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 apm-sniffer/apm-sdk-plugin/servicecomb-plugin/pom.xml rename apm-sniffer/apm-sdk-plugin/{servicecomb-java-chassis-plugin => servicecomb-plugin/servicecomb-java-chassis-0.x-plugin}/pom.xml (93%) rename apm-sniffer/apm-sdk-plugin/{servicecomb-java-chassis-plugin => servicecomb-plugin/servicecomb-java-chassis-0.x-plugin}/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/InvocationInterceptor.java (96%) rename apm-sniffer/apm-sdk-plugin/{servicecomb-java-chassis-plugin => servicecomb-plugin/servicecomb-java-chassis-0.x-plugin}/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/NextInterceptor.java (95%) rename apm-sniffer/apm-sdk-plugin/{servicecomb-java-chassis-plugin => servicecomb-plugin/servicecomb-java-chassis-0.x-plugin}/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/define/InvocationInstrumentation.java (93%) rename apm-sniffer/apm-sdk-plugin/{servicecomb-java-chassis-plugin => servicecomb-plugin/servicecomb-java-chassis-0.x-plugin}/src/main/resources/skywalking-plugin.def (100%) rename apm-sniffer/apm-sdk-plugin/{servicecomb-java-chassis-plugin => servicecomb-plugin/servicecomb-java-chassis-0.x-plugin}/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/InvocationInterceptorTest.java (100%) rename apm-sniffer/apm-sdk-plugin/{servicecomb-java-chassis-plugin => servicecomb-plugin/servicecomb-java-chassis-0.x-plugin}/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/NextInterceptorTest.java (100%) diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml index 2717502fa..dc492895d 100644 --- a/apm-sniffer/apm-sdk-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/pom.xml @@ -53,7 +53,7 @@ elastic-job-2.x-plugin mongodb-2.x-plugin httpasyncclient-4.x-plugin - servicecomb-java-chassis-plugin + servicecomb-plugin pom diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/pom.xml new file mode 100644 index 000000000..1668c7020 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/pom.xml @@ -0,0 +1,26 @@ + + + + apm-sdk-plugin + org.apache.skywalking + 5.0.0-alpha + + 4.0.0 + + servicecomb-plugin + + + servicecomb-java-chassis-0.x-plugin + + pom + + apm-sdk-plugin + http://maven.apache.org + + + UTF-8 + /.. + + \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/pom.xml similarity index 93% rename from apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/pom.xml rename to apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/pom.xml index afd9a3031..ff52581b0 100644 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/pom.xml @@ -3,16 +3,16 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - apm-sdk-plugin + servicecomb-plugin org.apache.skywalking 5.0.0-alpha 4.0.0 - apm-servicecomb-java-chassis-plugin + apm-servicecomb-java-chassis-0.x-plugin jar - servicecomb-java-chassis-plugin + servicecomb-java-chassis-0.x-plugin http://maven.apache.org diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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/InvocationInterceptor.java similarity index 96% rename from apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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/InvocationInterceptor.java index 4e2c4e7e9..d27ad3555 100644 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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/InvocationInterceptor.java @@ -18,12 +18,12 @@ 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 io.servicecomb.core.Invocation; -import io.servicecomb.swagger.invocation.InvocationType; -import io.servicecomb.swagger.invocation.SwaggerInvocation; -import io.servicecomb.swagger.invocation.context.InvocationContext; 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,7 +36,7 @@ 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#getHandlerChain()}. + * {@link InvocationInterceptor} define how to enhance class {@link Invocation#getHandlerContext()}. * * @author lytscu */ diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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 similarity index 95% rename from apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/NextInterceptor.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/NextInterceptor.java index e169ec24f..24a7ee3da 100644 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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 @@ -23,6 +23,7 @@ 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; @@ -60,8 +61,10 @@ public class NextInterceptor implements InstanceMethodsAroundInterceptor { if (isConsumer) { Integer count = (Integer)DEEP.get(); try { + //When count = 2, you can get the peer if (count == 2) { - String peer = invocation.getEndpoint().getAddress().toString(); + URI uri = new URI(invocation.getEndpoint().toString()); + String peer = uri.getHost() + ":" + uri.getPort(); final ContextCarrier contextCarrier = new ContextCarrier(); span = ContextManager.createExitSpan(invocation.getOperationName(), contextCarrier, peer); CarrierItem next = contextCarrier.items(); diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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/InvocationInstrumentation.java similarity index 93% rename from apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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/InvocationInstrumentation.java index a173161cb..347e6647c 100644 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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/InvocationInstrumentation.java @@ -18,9 +18,9 @@ package org.apache.skywalking.apm.plugin.servicecomb.define; +import io.servicecomb.core.Invocation; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; -import io.servicecomb.core.Invocation; 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; @@ -31,8 +31,8 @@ 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#next(AsyncResponse)}by - * using {@link InvocationInterceptor}, and {@link Invocation#getHandlerChain() by using {@link NextInterceptor}, + * {@link InvocationInstrumentation} presents that skywalking intercept {@link io.servicecomb.core.Invocation#getHandlerContext}by + * using {@link InvocationInterceptor}, and {@link Invocation#next by using {@link NextInterceptor}, * * @author lytscu */ @@ -60,7 +60,7 @@ public class InvocationInstrumentation extends ClassInstanceMethodsEnhancePlugin new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named("getHandlerChain"); + return named("getHandlerContext"); } @Override diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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 similarity index 100% rename from apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-plugin/src/main/resources/skywalking-plugin.def rename to apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/resources/skywalking-plugin.def diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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/InvocationInterceptorTest.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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/InvocationInterceptorTest.java diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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/NextInterceptorTest.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/servicecomb-java-chassis-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/NextInterceptorTest.java From 5e8bc0090e77e1f320a41fa9998b5c1e454276a7 Mon Sep 17 00:00:00 2001 From: lytscu Date: Fri, 26 Jan 2018 10:07:16 +0800 Subject: [PATCH 05/14] Modify operationName to invocation.getInvocationQualifiedName --- .../apm/plugin/servicecomb/InvocationInterceptor.java | 2 +- .../skywalking/apm/plugin/servicecomb/NextInterceptor.java | 2 +- .../src/main/resources/skywalking-plugin.def | 2 +- .../apm/plugin/servicecomb/InvocationInterceptorTest.java | 2 +- .../skywalking/apm/plugin/servicecomb/NextInterceptorTest.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) 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/InvocationInterceptor.java index d27ad3555..5a76896d2 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/InvocationInterceptor.java @@ -58,7 +58,7 @@ public class InvocationInterceptor implements InstanceMethodsAroundInterceptor { next = next.next(); next.setHeadValue(invocation.getContext().get(next.getHeadKey())); } - String operationName = invocation.getOperationName(); + String operationName = invocation.getInvocationQualifiedName(); span = ContextManager.createEntrySpan(operationName, contextCarrier); String url = invocation.getOperationMeta().getOperationPath(); Tags.URL.set(span, url); 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 index 24a7ee3da..bde064c99 100644 --- 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 @@ -66,7 +66,7 @@ public class NextInterceptor implements InstanceMethodsAroundInterceptor { URI uri = new URI(invocation.getEndpoint().toString()); String peer = uri.getHost() + ":" + uri.getPort(); final ContextCarrier contextCarrier = new ContextCarrier(); - span = ContextManager.createExitSpan(invocation.getOperationName(), contextCarrier, peer); + span = ContextManager.createExitSpan(invocation.getInvocationQualifiedName(), contextCarrier, peer); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); 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 89240686e..2b17f4d6a 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 @@ -servicecomb-0.6=org.apache.skywalking.apm.plugin.servicecomb.define.InvocationInstrumentation +servicecomb-0.x=org.apache.skywalking.apm.plugin.servicecomb.define.InvocationInstrumentation 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/InvocationInterceptorTest.java index c06dde790..f93eea237 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/InvocationInterceptorTest.java @@ -98,7 +98,7 @@ public class InvocationInterceptorTest { when(operationMeta.getSchemaMeta()).thenReturn(schemaMeta); when(endpoint.getAddress()).thenReturn("0.0.0.0:7777"); when(enhancedInstance.getEndpoint()).thenReturn(endpoint); - when(enhancedInstance.getOperationName()).thenReturn("productorTest"); + when(enhancedInstance.getInvocationQualifiedName()).thenReturn("productorTest"); when(operationMeta.getOperationPath()).thenReturn("/bmi"); when(enhancedInstance.getOperationMeta()).thenReturn(operationMeta); when(enhancedInstance.getStatus()).thenReturn(statusType); 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/NextInterceptorTest.java index 9c3576246..80af9f20b 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/NextInterceptorTest.java @@ -99,7 +99,7 @@ public class NextInterceptorTest { when(operationMeta.getSchemaMeta()).thenReturn(schemaMeta); when(endpoint.getAddress()).thenReturn("0.0.0.0:7777"); when(enhancedInstance.getEndpoint()).thenReturn(endpoint); - when(enhancedInstance.getOperationName()).thenReturn("consumerTest"); + when(enhancedInstance.getInvocationQualifiedName()).thenReturn("consumerTest"); when(operationMeta.getOperationPath()).thenReturn("/bmi"); when(enhancedInstance.getOperationMeta()).thenReturn(operationMeta); when(enhancedInstance.getStatus()).thenReturn(statusType); From 1a8fb0f181a737df7fe8e6fbaf6f63f3379e7012 Mon Sep 17 00:00:00 2001 From: lytscu Date: Mon, 29 Jan 2018 20:08:29 +0800 Subject: [PATCH 06/14] Modify operationName to invocation.getMicroserviceQualifiedName() --- .../apm/plugin/servicecomb/InvocationInterceptor.java | 2 +- .../skywalking/apm/plugin/servicecomb/NextInterceptor.java | 2 +- .../apm/plugin/servicecomb/InvocationInterceptorTest.java | 2 +- .../skywalking/apm/plugin/servicecomb/NextInterceptorTest.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) 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/InvocationInterceptor.java index 5a76896d2..e76a4e0c4 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/InvocationInterceptor.java @@ -58,7 +58,7 @@ public class InvocationInterceptor implements InstanceMethodsAroundInterceptor { next = next.next(); next.setHeadValue(invocation.getContext().get(next.getHeadKey())); } - String operationName = invocation.getInvocationQualifiedName(); + String operationName = invocation.getMicroserviceQualifiedName(); span = ContextManager.createEntrySpan(operationName, contextCarrier); String url = invocation.getOperationMeta().getOperationPath(); Tags.URL.set(span, url); 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 index bde064c99..2abc0d7aa 100644 --- 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 @@ -66,7 +66,7 @@ public class NextInterceptor implements InstanceMethodsAroundInterceptor { URI uri = new URI(invocation.getEndpoint().toString()); String peer = uri.getHost() + ":" + uri.getPort(); final ContextCarrier contextCarrier = new ContextCarrier(); - span = ContextManager.createExitSpan(invocation.getInvocationQualifiedName(), contextCarrier, peer); + span = ContextManager.createExitSpan(invocation.getMicroserviceQualifiedName(), contextCarrier, peer); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); 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/InvocationInterceptorTest.java index f93eea237..32c64efbf 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/InvocationInterceptorTest.java @@ -98,7 +98,7 @@ public class InvocationInterceptorTest { when(operationMeta.getSchemaMeta()).thenReturn(schemaMeta); when(endpoint.getAddress()).thenReturn("0.0.0.0:7777"); when(enhancedInstance.getEndpoint()).thenReturn(endpoint); - when(enhancedInstance.getInvocationQualifiedName()).thenReturn("productorTest"); + when(enhancedInstance.getMicroserviceQualifiedName()).thenReturn("productorTest"); when(operationMeta.getOperationPath()).thenReturn("/bmi"); when(enhancedInstance.getOperationMeta()).thenReturn(operationMeta); when(enhancedInstance.getStatus()).thenReturn(statusType); 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/NextInterceptorTest.java index 80af9f20b..e0b012838 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/NextInterceptorTest.java @@ -99,7 +99,7 @@ public class NextInterceptorTest { when(operationMeta.getSchemaMeta()).thenReturn(schemaMeta); when(endpoint.getAddress()).thenReturn("0.0.0.0:7777"); when(enhancedInstance.getEndpoint()).thenReturn(endpoint); - when(enhancedInstance.getInvocationQualifiedName()).thenReturn("consumerTest"); + when(enhancedInstance.getMicroserviceQualifiedName()).thenReturn("consumerTest"); when(operationMeta.getOperationPath()).thenReturn("/bmi"); when(enhancedInstance.getOperationMeta()).thenReturn(operationMeta); when(enhancedInstance.getStatus()).thenReturn(statusType); From 48f8fceebed8109e9f95dafd6f96d9c129eeaa3e Mon Sep 17 00:00:00 2001 From: lytscu Date: Tue, 30 Jan 2018 10:38:05 +0800 Subject: [PATCH 07/14] Modify ComponentId =28 --- .../apm/plugin/servicecomb/InvocationInterceptorTest.java | 2 +- .../skywalking/apm/plugin/servicecomb/NextInterceptorTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/InvocationInterceptorTest.java index 32c64efbf..711012d76 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/InvocationInterceptorTest.java @@ -127,7 +127,7 @@ public class InvocationInterceptorTest { private void assertCombSpan(AbstractTracingSpan span) { assertThat(span.getOperationName(), is("productorTest")); - assertThat(SpanHelper.getComponentId(span), is(27)); + 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-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/NextInterceptorTest.java index e0b012838..5f566c137 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/NextInterceptorTest.java @@ -131,7 +131,7 @@ public class NextInterceptorTest { private void assertCombSpan(AbstractTracingSpan span) { assertThat(span.getOperationName(), is("consumerTest")); - assertThat(SpanHelper.getComponentId(span), is(27)); + assertThat(SpanHelper.getComponentId(span), is(28)); List tags = SpanHelper.getTags(span); assertThat(tags.get(0).getValue(), is("/bmi")); assertThat(span.isExit(), is(true)); From 5fce5dcd0e276266622d48b8afccc464735e272c Mon Sep 17 00:00:00 2001 From: lytscu Date: Mon, 5 Feb 2018 20:54:07 +0800 Subject: [PATCH 08/14] Update servicecomb-java-chassis-0.x-plugin --- .../pom.xml | 6 + .../plugin/servicecomb/NextInterceptor.java | 120 ------------------ .../ProducerOperationHandlerInterceptor.java | 72 +++++++++++ ...=> TransportClientHandlerInterceptor.java} | 61 ++++----- ...oducerOperationHandlerInstrumentation.java | 74 +++++++++++ ...ransportClientHandlerInstrumentation.java} | 34 ++--- .../src/main/resources/skywalking-plugin.def | 3 +- ...ducerOperationHandlerInterceptorTest.java} | 60 +++------ ...ransportClientHandlerInterceptorTest.java} | 66 +++------- 9 files changed, 225 insertions(+), 271 deletions(-) delete mode 100644 apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/NextInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/ProducerOperationHandlerInterceptor.java rename apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/{InvocationInterceptor.java => TransportClientHandlerInterceptor.java} (54%) create mode 100644 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 rename 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 => TransportClientHandlerInstrumentation.java} (64%) rename apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/{InvocationInterceptorTest.java => ProducerOperationHandlerInterceptorTest.java} (78%) rename apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/{NextInterceptorTest.java => TransportClientHandlerInterceptorTest.java} (78%) 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 ff52581b0..cee6c694f 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 2abc0d7aa..000000000 --- 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 000000000..52046eae6 --- /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 e76a4e0c4..2eec64116 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 000000000..e160b8d42 --- /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 347e6647c..2c644fe69 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 2b17f4d6a..950da2df7 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 711012d76..fe26ca3c6 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; - - @Mock - private MockInvocation enhancedInstance; - - @Mock - private Endpoint endpoint; - @Mock Response.StatusType statusType; - + @SegmentStoragePoint + private SegmentStorage segmentStorage; + private ProducerOperationHandlerInterceptor invocationInterceptor; @Mock - ReferenceConfig referenceConfig; - + private OperationMeta operationMeta; + @Mock + private EnhancedInstance enhancedInstance; + @Mock + private Invocation invocation; + @Mock + 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 5f566c137..f31265751 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; - - @Mock - private MockInvocation enhancedInstance; - - @Mock - private Endpoint endpoint; - @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; @@ -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) { - - } - - } } From b5ec187e9cf6b83ce8af286cfcdc6469b10049a2 Mon Sep 17 00:00:00 2001 From: lytscu Date: Fri, 9 Feb 2018 17:19:15 +0800 Subject: [PATCH 09/14] Update servicecomb-java-chassis-0.x-plugin/pom.xml --- .../pom.xml | 41 ------------------- 1 file changed, 41 deletions(-) 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 cee6c694f..bdac6da88 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 @@ -23,47 +23,6 @@ 0.5.0 provided - - io.servicecomb - swagger-invocation-core - 0.5.0 - provided - - - io.servicecomb - foundation-common - 0.5.0 - test - - - io.servicecomb - service-registry - 0.5.0 - test - - - io.servicecomb - common-rest - 0.5.0 - provided - - - io.swagger - swagger-core - 1.5.17 - test - - - org.slf4j - log4j-over-slf4j - 1.7.25 - test - - - javax.ws.rs - jsr311-api - 1.1.1 - From 2e95e7fff23e94f7fa65efd578f07134a28de420 Mon Sep 17 00:00:00 2001 From: lytscu Date: Sun, 11 Feb 2018 14:57:42 +0800 Subject: [PATCH 10/14] Update exception status --- .../ProducerOperationHandlerInterceptor.java | 16 ++++++++++++++-- .../TransportClientHandlerInterceptor.java | 6 +++++- 2 files changed, 19 insertions(+), 3 deletions(-) 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 index 52046eae6..ca1ed82ae 100644 --- 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 @@ -48,16 +48,28 @@ public class ProducerOperationHandlerInterceptor implements InstanceMethodsAroun next = next.next(); next.setHeadValue(invocation.getContext().get(next.getHeadKey())); } + if (null == invocation.getOperationMeta()) { + return; + } String operationName = invocation.getMicroserviceQualifiedName(); AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier); - String url = invocation.getOperationMeta().getOperationPath(); - Tags.URL.set(span, url); + if (null != invocation.getOperationMeta() && null != invocation.getOperationMeta().getOperationPath()) { + 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.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/TransportClientHandlerInterceptor.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 index 2eec64116..cfb08a0d0 100644 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/TransportClientHandlerInterceptor.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 @@ -43,10 +43,14 @@ public class TransportClientHandlerInterceptor implements InstanceMethodsAroundI public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { Invocation invocation = (Invocation)allArguments[0]; + if (null == invocation.getOperationMeta() || null == invocation.getEndpoint()) { + 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(invocation.getMicroserviceQualifiedName(), contextCarrier, peer); + AbstractSpan span = ContextManager.createExitSpan(operationName, contextCarrier, peer); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); From 61f8d3ee505ffc9a3f9041163e58ee624c4dcc20 Mon Sep 17 00:00:00 2001 From: lytscu Date: Sun, 11 Feb 2018 15:32:48 +0800 Subject: [PATCH 11/14] Update afterMethod exception status --- .../servicecomb/ProducerOperationHandlerInterceptor.java | 9 +++++---- .../servicecomb/TransportClientHandlerInterceptor.java | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) 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 index ca1ed82ae..c83a6b5b0 100644 --- 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 @@ -53,10 +53,8 @@ public class ProducerOperationHandlerInterceptor implements InstanceMethodsAroun } String operationName = invocation.getMicroserviceQualifiedName(); AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier); - if (null != invocation.getOperationMeta() && null != invocation.getOperationMeta().getOperationPath()) { - String url = invocation.getOperationMeta().getOperationPath(); - Tags.URL.set(span, url); - } + String url = invocation.getOperationMeta().getOperationPath(); + Tags.URL.set(span, url); span.setComponent(ComponentsDefine.SERVICECOMB); SpanLayer.asRPCFramework(span); } @@ -64,6 +62,9 @@ public class ProducerOperationHandlerInterceptor implements InstanceMethodsAroun @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Object ret) throws Throwable { Invocation invocation = (Invocation)allArguments[0]; + if (null == invocation.getOperationMeta()) { + return ret; + } AbstractSpan span = ContextManager.activeSpan(); int statusCode = invocation.getStatus().getStatusCode(); if (statusCode >= 400) { 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/TransportClientHandlerInterceptor.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 index cfb08a0d0..83db86060 100644 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/TransportClientHandlerInterceptor.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 @@ -65,6 +65,9 @@ public class TransportClientHandlerInterceptor implements InstanceMethodsAroundI @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Object ret) throws Throwable { Invocation invocation = (Invocation)allArguments[0]; + if (null == invocation.getOperationMeta() || null == invocation.getEndpoint()) { + return ret; + } AbstractSpan span = ContextManager.activeSpan(); int statusCode = invocation.getStatus().getStatusCode(); if (statusCode >= 400) { From 098251c2e6eae1e64744c04a8fb0ed7108964bcb Mon Sep 17 00:00:00 2001 From: lytscu Date: Mon, 12 Feb 2018 12:57:50 +0800 Subject: [PATCH 12/14] Update consumer register --- .../ProducerOperationHandlerInterceptor.java | 9 +++---- .../TransportClientHandlerInterceptor.java | 27 +++++++++++++++---- ...oducerOperationHandlerInterceptorTest.java | 9 +++++-- 3 files changed, 32 insertions(+), 13 deletions(-) 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 index c83a6b5b0..56ce3a2ce 100644 --- 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 @@ -48,10 +48,10 @@ public class ProducerOperationHandlerInterceptor implements InstanceMethodsAroun next = next.next(); next.setHeadValue(invocation.getContext().get(next.getHeadKey())); } - if (null == invocation.getOperationMeta()) { - return; + String operationName = "servicecomb/chassis" + method.getName(); + if (null != invocation.getOperationMeta()) { + operationName = invocation.getMicroserviceQualifiedName(); } - String operationName = invocation.getMicroserviceQualifiedName(); AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier); String url = invocation.getOperationMeta().getOperationPath(); Tags.URL.set(span, url); @@ -62,9 +62,6 @@ public class ProducerOperationHandlerInterceptor implements InstanceMethodsAroun @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Object ret) throws Throwable { Invocation invocation = (Invocation)allArguments[0]; - if (null == invocation.getOperationMeta()) { - return ret; - } AbstractSpan span = ContextManager.activeSpan(); int statusCode = invocation.getStatus().getStatusCode(); if (statusCode >= 400) { 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/TransportClientHandlerInterceptor.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 index 83db86060..10f39a814 100644 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/TransportClientHandlerInterceptor.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 @@ -21,6 +21,7 @@ package org.apache.skywalking.apm.plugin.servicecomb; import io.servicecomb.core.Invocation; import java.lang.reflect.Method; import java.net.URI; +import java.net.URISyntaxException; 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; @@ -43,11 +44,10 @@ public class TransportClientHandlerInterceptor implements InstanceMethodsAroundI public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { Invocation invocation = (Invocation)allArguments[0]; - if (null == invocation.getOperationMeta() || null == invocation.getEndpoint()) { + String peer = AsserRegister(invocation); + if (null == peer) { 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); @@ -65,7 +65,8 @@ public class TransportClientHandlerInterceptor implements InstanceMethodsAroundI @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Object ret) throws Throwable { Invocation invocation = (Invocation)allArguments[0]; - if (null == invocation.getOperationMeta() || null == invocation.getEndpoint()) { + String peer = AsserRegister(invocation); + if (null == peer) { return ret; } AbstractSpan span = ContextManager.activeSpan(); @@ -75,15 +76,31 @@ public class TransportClientHandlerInterceptor implements InstanceMethodsAroundI Tags.STATUS_CODE.set(span, Integer.toString(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 (null == invocation.getOperationMeta() || null == invocation.getEndpoint()) { + return; + } AbstractSpan span = ContextManager.activeSpan(); span.errorOccurred(); span.log(t); } + /** + * Serviecomb chissis Consumers and providers need to register at the service center. If the consumer is not + * registered then return + */ + private String AsserRegister(Invocation invocation) throws URISyntaxException { + if (null == invocation.getOperationMeta() || null == invocation.getEndpoint()) { + return null; + } + URI uri = new URI(invocation.getEndpoint().toString()); + String peer = uri.getHost() + ":" + uri.getPort(); + return peer; + } + } 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/ProducerOperationHandlerInterceptorTest.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 index fe26ca3c6..f97d9e8e4 100644 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/ProducerOperationHandlerInterceptorTest.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 @@ -24,6 +24,7 @@ import io.servicecomb.core.definition.OperationMeta; import io.servicecomb.core.definition.SchemaMeta; import io.servicecomb.swagger.invocation.InvocationType; import io.servicecomb.swagger.invocation.SwaggerInvocation; +import java.lang.reflect.Method; import java.util.List; import javax.ws.rs.core.Response; import org.apache.skywalking.apm.agent.core.boot.ServiceManager; @@ -74,6 +75,8 @@ public class ProducerOperationHandlerInterceptorTest { @Mock private Endpoint endpoint; @Mock + private Method method; + @Mock private SwaggerInvocation swagger; private Object[] allArguments; private Class[] argumentsType; @@ -95,19 +98,21 @@ public class ProducerOperationHandlerInterceptorTest { 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.APPLICATION_CODE = "serviceComnTestCases-APP"; allArguments = new Object[] {invocation,}; argumentsType = new Class[] {}; swaggerArguments = new Class[] {}; + } @Test public void testConsumer() throws Throwable { - invocationInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null); - invocationInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentsType, null); + 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); From 3eeacb1ae6fc6c8fe06fe2f898fdb65287c23e24 Mon Sep 17 00:00:00 2001 From: lytscu Date: Mon, 12 Feb 2018 15:23:44 +0800 Subject: [PATCH 13/14] Update comments --- .../ProducerOperationHandlerInterceptor.java | 8 +++--- .../TransportClientHandlerInterceptor.java | 26 +++++++++---------- ...oducerOperationHandlerInstrumentation.java | 4 +-- ...TransportClientHandlerInstrumentation.java | 2 +- 4 files changed, 18 insertions(+), 22 deletions(-) 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 index 56ce3a2ce..4c0e97840 100644 --- 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 @@ -32,7 +32,8 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInt import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; /** - * {org.apache.skywalking.apm.plugin.servicecomb.} define how to enhance class {@link Invocation#getHandlerContext()}. + * {org.apache.skywalking.apm.plugin.servicecomb.ProducerOperationHandlerInterceptor} define how to enhance class {@link + * ProducerOperationHandler#handle(io.servicecomb.core.Invocation, io.servicecomb.swagger.invocation.AsyncResponse)}. * * @author lytscu */ @@ -48,10 +49,7 @@ public class ProducerOperationHandlerInterceptor implements InstanceMethodsAroun next = next.next(); next.setHeadValue(invocation.getContext().get(next.getHeadKey())); } - String operationName = "servicecomb/chassis" + method.getName(); - if (null != invocation.getOperationMeta()) { - operationName = invocation.getMicroserviceQualifiedName(); - } + String operationName = invocation.getMicroserviceQualifiedName(); AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier); String url = invocation.getOperationMeta().getOperationPath(); Tags.URL.set(span, url); 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/TransportClientHandlerInterceptor.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 index 10f39a814..c3d40d339 100644 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/TransportClientHandlerInterceptor.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 @@ -21,7 +21,6 @@ package org.apache.skywalking.apm.plugin.servicecomb; import io.servicecomb.core.Invocation; import java.lang.reflect.Method; import java.net.URI; -import java.net.URISyntaxException; 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; @@ -34,7 +33,8 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInt import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; /** - * {@link TransportClientHandlerInterceptor} define how to enhance class {@link Invocation#next(io.servicecomb.swagger.invocation.AsyncResponse)}. + * {@link TransportClientHandlerInterceptor} define how to enhance class {@link TransportClientHandler#handle(io.servicecomb.core.Invocation, + * io.servicecomb.swagger.invocation.AsyncResponse)}. * * @author lytscu */ @@ -44,10 +44,11 @@ public class TransportClientHandlerInterceptor implements InstanceMethodsAroundI public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { Invocation invocation = (Invocation)allArguments[0]; - String peer = AsserRegister(invocation); - if (null == peer) { + 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); @@ -65,8 +66,7 @@ public class TransportClientHandlerInterceptor implements InstanceMethodsAroundI @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Object ret) throws Throwable { Invocation invocation = (Invocation)allArguments[0]; - String peer = AsserRegister(invocation); - if (null == peer) { + if (!checkRegisterStatus(invocation)) { return ret; } AbstractSpan span = ContextManager.activeSpan(); @@ -82,7 +82,7 @@ public class TransportClientHandlerInterceptor implements InstanceMethodsAroundI @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Throwable t) { Invocation invocation = (Invocation)allArguments[0]; - if (null == invocation.getOperationMeta() || null == invocation.getEndpoint()) { + if (!checkRegisterStatus(invocation)) { return; } AbstractSpan span = ContextManager.activeSpan(); @@ -91,16 +91,14 @@ public class TransportClientHandlerInterceptor implements InstanceMethodsAroundI } /** - * Serviecomb chissis Consumers and providers need to register at the service center. If the consumer is not - * registered then return + * Serviecomb chassis Consumers and providers need to register at the service center. If the consumer is not + * registered then return false. */ - private String AsserRegister(Invocation invocation) throws URISyntaxException { + private Boolean checkRegisterStatus(Invocation invocation) { if (null == invocation.getOperationMeta() || null == invocation.getEndpoint()) { - return null; + return false; } - URI uri = new URI(invocation.getEndpoint().toString()); - String peer = uri.getHost() + ":" + uri.getPort(); - return peer; + return true; } } 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 index e160b8d42..3151782b8 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/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 @@ -29,8 +29,8 @@ 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 + * {@link ProducerOperationHandlerInstrumentation} represents that skywalking intercept {@link + * ProducerOperationHandler#handle(io.servicecomb.core.Invocation, io.servicecomb.swagger.invocation.AsyncResponse)}by * using {@link ProducerOperationHandlerInterceptor} * * @author lytscu 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/TransportClientHandlerInstrumentation.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 index 2c644fe69..5c0848243 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/TransportClientHandlerInstrumentation.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 @@ -30,7 +30,7 @@ import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; import static net.bytebuddy.matcher.ElementMatchers.named; /** - * {@link TransportClientHandlerInstrumentation} presents that skywalking intercept {@link TransportClientHandler}by + * {@link TransportClientHandlerInstrumentation} represents that skywalking intercept {@link TransportClientHandler}by * using {@linkTransportClientHandlerInterceptor } * * @author lytscu From 6e56c7fdb403ce418ad310b010cb1e268213c93c Mon Sep 17 00:00:00 2001 From: lytscu Date: Mon, 12 Feb 2018 15:50:18 +0800 Subject: [PATCH 14/14] Update /org/apache/skywalking/apm/collector/storage/table/register/ServerTypeDefine.java --- .../apm/collector/storage/table/register/ServerTypeDefine.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ServerTypeDefine.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ServerTypeDefine.java index 2810c2ab1..71e2ae346 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ServerTypeDefine.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ServerTypeDefine.java @@ -32,7 +32,7 @@ public class ServerTypeDefine { private ServerType[] serverTypes; private ServerTypeDefine() { - this.serverTypes = new ServerType[28]; + this.serverTypes = new ServerType[29]; this.serverTypeNames = new String[11]; addServerType(new ServerType(ComponentsDefine.TOMCAT.getId(), Const.NONE, Const.EMPTY_STRING)); addServerType(new ServerType(ComponentsDefine.HTTPCLIENT.getId(), Const.NONE, Const.EMPTY_STRING)); @@ -61,6 +61,7 @@ public class ServerTypeDefine { addServerType(new ServerType(ComponentsDefine.ROCKET_MQ.getId(), 9, ComponentsDefine.ROCKET_MQ.getName())); addServerType(new ServerType(ComponentsDefine.HTTP_ASYNC_CLIENT.getId(), Const.NONE, Const.EMPTY_STRING)); addServerType(new ServerType(ComponentsDefine.KAFKA.getId(), 10, ComponentsDefine.KAFKA.getName())); + addServerType(new ServerType(ComponentsDefine.SERVICECOMB.getId(), Const.NONE, ComponentsDefine.SERVICECOMB.getName())); } public static ServerTypeDefine getInstance() {