From 279ae780a251a4c6caf204eb1ba7babda5926729 Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Fri, 21 Jun 2019 09:43:30 +0800 Subject: [PATCH 01/29] Fix ci --- .../hessian-4.0.x-plugin/pom.xml | 65 +++++++ .../apm/plugin/hessian/v4/Constants.java | 42 +++++ .../v4/HessianAddHeaderInterceptor.java | 70 ++++++++ .../HessianProxyConstructorInterceptor.java | 42 +++++ .../HessianProxySendRequestInterceptor.java | 88 +++++++++ ...HessianSkeletonConstructorInterceptor.java | 37 ++++ .../v4/HessianSkeletonInterceptor.java | 105 +++++++++++ .../v4/define/HessianEnhanceCache.java | 44 +++++ .../define/HessianProxyInstrumentation.java | 96 ++++++++++ .../HessianSkeletonInstrumentation.java | 81 +++++++++ .../src/main/resources/skywalking-plugin.def | 19 ++ .../v4/HessianAddHeaderInterceptorTest.java | 119 +++++++++++++ ...essianProxySendRequestInterceptorTest.java | 119 +++++++++++++ .../v4/HessianSkeletonInterceptorTest.java | 167 ++++++++++++++++++ 14 files changed, 1094 insertions(+) create mode 100644 apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml create mode 100644 apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/Constants.java create mode 100644 apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianAddHeaderInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxyConstructorInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianEnhanceCache.java create mode 100644 apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianProxyInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/resources/skywalking-plugin.def create mode 100644 apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianAddHeaderInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptorTest.java diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml new file mode 100644 index 000000000000..98e2f964ff47 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml @@ -0,0 +1,65 @@ + + + + + + apm-sdk-plugin + org.apache.skywalking + 6.2.0-SNAPSHOT + + 4.0.0 + + hessian-4.0.x-plugin + + hessian-4.0.x-plugin + + http://www.example.com + + + UTF-8 + 1.8 + 1.8 + + + + + junit + junit + 4.12 + test + + + + com.caucho + hessian + 4.0.38 + + + + + javax.servlet + javax.servlet-api + 4.0.1 + provided + + + + + diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/Constants.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/Constants.java new file mode 100644 index 000000000000..792cc5ab6693 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/Constants.java @@ -0,0 +1,42 @@ +/* + * 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.hessian.v4; + +/** + * Constant field for hessian plugin + * + * @author Alan Lau + */ +public class Constants { + + public static final String ENHANCE_CLASS = "com.caucho.hessian.client.HessianProxy"; + + public static final String ADDHEADER_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.hessian.v4.HessianAddHeaderInterceptor"; + + public static final String HESSIAN_SENDREQUEST_CLASS = "org.apache.skywalking.apm.plugin.hessian.v4.HessianProxySendRequestInterceptor"; + + public static final String HESSIAN_SERVLET_ENHANCE_CLASS = "com.caucho.hessian.server.HessianSkeleton"; + + public static final String SKELETON_INTERCPTOR_CLASS = "org.apache.skywalking.apm.plugin.hessian.v4.HessianSkeletonInterceptor"; + + public static final String CONSTRUCT_INTERCEPTOR = "org.apache.skywalking.apm.plugin.hessian.v4.HessianProxyConstructorInterceptor"; + + public static final String SKELETON_CONSTRUCT_INTERCEPTOR = "org.apache.skywalking.apm.plugin.hessian.v4.HessianSkeletonConstructorInterceptor"; + +} diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianAddHeaderInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianAddHeaderInterceptor.java new file mode 100644 index 000000000000..ce60bc4862b4 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianAddHeaderInterceptor.java @@ -0,0 +1,70 @@ +/* + * 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.hessian.v4; + +import com.caucho.hessian.client.HessianURLConnection; +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.trace.AbstractSpan; +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; + +/** + * intercept method {@link HessianURLConnection#addHeader}. + * + * @author Alan Lau + */ +public class HessianAddHeaderInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + HessianURLConnection conn = (HessianURLConnection)allArguments[0]; + ContextCarrier carrier = new ContextCarrier(); + ContextManager.inject(carrier); + + CarrierItem next = carrier.items(); + while (next.hasNext()) { + next = next.next(); + conn.addHeader(next.getHeadKey(), next.getHeadValue()); + } + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + dealException(t); + } + + public void dealException(Throwable t) { + AbstractSpan activeSpan = ContextManager.activeSpan(); + activeSpan.errorOccurred(); + activeSpan.log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxyConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxyConstructorInterceptor.java new file mode 100644 index 000000000000..57fd9a3a7d9e --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxyConstructorInterceptor.java @@ -0,0 +1,42 @@ +/* + * 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.hessian.v4; + +import com.caucho.hessian.client.HessianProxy; +import java.net.URL; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; +import org.apache.skywalking.apm.plugin.hessian.v4.define.HessianEnhanceCache; + +/** + * intercept contructor {@link HessianProxy#HessianProxy}, save the url into the objInst + * + * @author Alan Lau + */ +public class HessianProxyConstructorInterceptor implements InstanceConstructorInterceptor { + + @Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + + if (allArguments[0] == null) { + return; + } + URL url = (URL)allArguments[0]; + objInst.setSkyWalkingDynamicField(new HessianEnhanceCache(url)); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java new file mode 100644 index 000000000000..399c7ec32389 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java @@ -0,0 +1,88 @@ +/* + * 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.hessian.v4; + +import com.caucho.hessian.client.HessianProxy; +import java.lang.reflect.Method; +import java.net.URL; +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; +import org.apache.skywalking.apm.plugin.hessian.v4.define.HessianEnhanceCache; + +/** + * intercept {@link HessianProxy#sendRequest(String, Object[])} + * + * @author Alan Lau + */ +public class HessianProxySendRequestInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + HessianEnhanceCache cache = (HessianEnhanceCache)objInst.getSkyWalkingDynamicField(); + URL url = cache.getUrl(); + if (url == null) { + return; + } + + if (allArguments.length < 0) { + return; + } + + String operateName = url.getPath(); + final ContextCarrier contextCarrier = new ContextCarrier(); + AbstractSpan span = ContextManager.createExitSpan(operateName, contextCarrier, String.format(":", url.getHost(), url.getPort())); + + span.setComponent(ComponentsDefine.HESSIAN); + span.start(System.currentTimeMillis()); + span.setOperationName(url.getPath()); + + Tags.URL.set(span, url.getPath()); + SpanLayer.asRPCFramework(span); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) { + if (allArguments.length == 0) { + return ret; + } + + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + dealException(t); + } + + public void dealException(Throwable t) { + AbstractSpan activeSpan = ContextManager.activeSpan(); + activeSpan.errorOccurred(); + activeSpan.log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java new file mode 100644 index 000000000000..be4067b13406 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java @@ -0,0 +1,37 @@ +/* + * 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.hessian.v4; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; + +/** + * @author Alan Lau + */ +public class HessianSkeletonConstructorInterceptor implements InstanceConstructorInterceptor { + + @Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + + if (allArguments[0] == null) { + return; + } + Object service = allArguments[1]; + objInst.setSkyWalkingDynamicField(service); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java new file mode 100644 index 000000000000..7758105cfb8d --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java @@ -0,0 +1,105 @@ +/* + * 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.hessian.v4; + +import com.caucho.hessian.io.AbstractHessianInput; +import com.caucho.hessian.io.AbstractHessianOutput; +import com.caucho.hessian.server.HessianSkeleton; +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; + +/** + * intercept method {@link HessianSkeleton#invoke(Object service, AbstractHessianInput in, AbstractHessianOutput out)} + * + * @author Alan Lau + */ +public class HessianSkeletonInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + Object service = allArguments[0]; + + if (service == null) { + return; + } + + if (argumentsTypes.length < 3) { + return; + } + + if (!argumentsTypes[1].isAssignableFrom(AbstractHessianInput.class)) { + return; + } + + AbstractHessianInput in = (AbstractHessianInput)allArguments[1]; + + final ContextCarrier contextCarrier = new ContextCarrier(); + + Object realService = objInst.getSkyWalkingDynamicField(); + + String operationName = ((Class)realService).getName(); + AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier); + + span.start(System.currentTimeMillis()); + span.setComponent(ComponentsDefine.HESSIAN); + Tags.URL.set(span, operationName); + SpanLayer.asRPCFramework(span); + + CarrierItem next = contextCarrier.items(); + while (next.hasNext() && in.readHeader() != null) { + next = next.next(); + next.setHeadValue((String)in.readObject()); + } + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) { + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + dealException(t); + } + + /** + * Log the throwable, which occurs in Hessian RPC service. + * + * @param throwable + */ + public void dealException(Throwable throwable) { + AbstractSpan span = ContextManager.activeSpan(); + span.errorOccurred(); + span.log(throwable); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianEnhanceCache.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianEnhanceCache.java new file mode 100644 index 000000000000..d9cec1b37656 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianEnhanceCache.java @@ -0,0 +1,44 @@ +/* + * 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.hessian.v4.define; + +import java.net.URL; + +/** + * cache field for EnhanceInstance, using for create Trace Spans. + * + * @author Alan Lau + */ +public class HessianEnhanceCache { + + private URL url; + + public HessianEnhanceCache(URL url) { + this.url = url; + } + + public URL getUrl() { + return url; + } + + public void setUrl(URL url) { + this.url = url; + } +} + diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianProxyInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianProxyInstrumentation.java new file mode 100644 index 000000000000..94c7e2b6aefe --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianProxyInstrumentation.java @@ -0,0 +1,96 @@ +/* + * 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.hessian.v4.define; + +import com.caucho.hessian.client.HessianConnection; +import com.caucho.hessian.client.HessianProxy; +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 static net.bytebuddy.matcher.ElementMatchers.any; +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; +import static org.apache.skywalking.apm.plugin.hessian.v4.Constants.ADDHEADER_INTERCEPTOR_CLASS; +import static org.apache.skywalking.apm.plugin.hessian.v4.Constants.CONSTRUCT_INTERCEPTOR; +import static org.apache.skywalking.apm.plugin.hessian.v4.Constants.ENHANCE_CLASS; +import static org.apache.skywalking.apm.plugin.hessian.v4.Constants.HESSIAN_SENDREQUEST_CLASS; + +/** + * enhance method {@link HessianProxy#addRequestHeaders(HessianConnection)} + * + * @author Alan Lau + */ +public class HessianProxyInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + + new ConstructorInterceptPoint() { + @Override public ElementMatcher getConstructorMatcher() { + return any(); + } + + @Override public String getConstructorInterceptor() { + return CONSTRUCT_INTERCEPTOR; + } + } + }; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("addRequestHeaders"); + } + + @Override public String getMethodsInterceptor() { + return ADDHEADER_INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("sendRequest"); + } + + @Override public String getMethodsInterceptor() { + return HESSIAN_SENDREQUEST_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java new file mode 100644 index 000000000000..5acc93d326e0 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java @@ -0,0 +1,81 @@ +/* + * 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.hessian.v4.define; + +import com.caucho.hessian.server.HessianSkeleton; +import java.io.InputStream; +import java.io.OutputStream; +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 static net.bytebuddy.matcher.ElementMatchers.any; +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; +import static org.apache.skywalking.apm.plugin.hessian.v4.Constants.HESSIAN_SERVLET_ENHANCE_CLASS; +import static org.apache.skywalking.apm.plugin.hessian.v4.Constants.SKELETON_CONSTRUCT_INTERCEPTOR; +import static org.apache.skywalking.apm.plugin.hessian.v4.Constants.SKELETON_INTERCPTOR_CLASS; + +/** + * enhance method {@link HessianSkeleton#invoke(InputStream, OutputStream)} + * + * @author Alan Lau + */ +public class HessianSkeletonInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + + new ConstructorInterceptPoint() { + @Override public ElementMatcher getConstructorMatcher() { + return any(); + } + + @Override public String getConstructorInterceptor() { + return SKELETON_CONSTRUCT_INTERCEPTOR; + } + } + }; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("invoke"); + } + + @Override public String getMethodsInterceptor() { + return SKELETON_INTERCPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(HESSIAN_SERVLET_ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/resources/skywalking-plugin.def new file mode 100644 index 000000000000..e258562ee635 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/resources/skywalking-plugin.def @@ -0,0 +1,19 @@ +# 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. + + +hessian-4.0.x=org.apache.skywalking.apm.plugin.hessian.v4.define.HessianProxyInstrumentation +hessian-4.0.x=org.apache.skywalking.apm.plugin.hessian.v4.define.HessianSkeletonInstrumentation \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianAddHeaderInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianAddHeaderInterceptorTest.java new file mode 100644 index 000000000000..29f0f1e06b7a --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianAddHeaderInterceptorTest.java @@ -0,0 +1,119 @@ +/* + * 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.hessian.v4; + +import com.caucho.hessian.client.HessianConnection; +import com.caucho.hessian.client.HessianProxy; +import com.caucho.hessian.client.HessianURLConnection; +import java.net.URL; +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.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +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.apache.skywalking.apm.plugin.hessian.v4.define.HessianEnhanceCache; +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.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; + +import static org.hamcrest.CoreMatchers.is; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +@PrepareForTest(value = {HessianProxy.class, ContextManager.class}) +public class HessianAddHeaderInterceptorTest { + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule agentServiceRule = new AgentServiceRule(); + + @Mock + private HessianProxy hessianProxy; + + @Mock + private String methodName; + + @Mock + private ContextCarrier carrier; + + private HessianAddHeaderInterceptor interceptor; + + @Mock + private AbstractSpan span; + + @Mock + private MethodInterceptResult methodInterceptResult; + + private Object[] allArguments; + private Class[] argumentTypes; + + private EnhancedInstance enhancedInstance = new EnhancedInstance() { + + private Object object; + + @Override + public Object getSkyWalkingDynamicField() { + return object; + } + + @Override public void setSkyWalkingDynamicField(Object value) { + this.object = value; + } + }; + + @Before + public void setUp() throws Exception { + interceptor = new HessianAddHeaderInterceptor(); + PowerMockito.when(hessianProxy.getURL()).thenReturn(new URL("http://127.0.0.1:8080/TestHessian")); + HessianEnhanceCache cache = new HessianEnhanceCache(hessianProxy.getURL()); + enhancedInstance.setSkyWalkingDynamicField(cache); + + HessianConnection huc = PowerMockito.mock(HessianURLConnection.class); + + PowerMockito.when(huc.getStatusCode()).thenReturn(200); + + PowerMockito.mockStatic(ContextManager.class); + PowerMockito.when(ContextManager.activeSpan()).thenReturn(span); + + allArguments = new Object[] {huc}; + argumentTypes = new Class[] {HessianConnection.class}; + } + + @Test + public void testAddHeader() throws Throwable { + interceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, methodInterceptResult); + interceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, methodInterceptResult); + + Assert.assertThat(segmentStorage.getTraceSegments().size(), is(0)); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptorTest.java new file mode 100644 index 000000000000..d848f37bb0a1 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptorTest.java @@ -0,0 +1,119 @@ +/* + * 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.hessian.v4; + +import com.caucho.hessian.client.HessianConnection; +import com.caucho.hessian.client.HessianProxy; +import com.caucho.hessian.client.HessianURLConnection; +import java.net.URL; +import java.util.List; +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.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +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.apache.skywalking.apm.plugin.hessian.v4.define.HessianEnhanceCache; +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.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; + +import static org.hamcrest.CoreMatchers.is; + +/** + * @author Alan Lau + */ + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +@PrepareForTest(HessianProxy.class) +public class HessianProxySendRequestInterceptorTest { + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule agentServiceRule = new AgentServiceRule(); + + @Mock + private HessianProxy hessianProxy; + + @Mock + private String methodName; + + private HessianProxySendRequestInterceptor interceptor; + + private HessianConnection hessianConnection; + + @Mock + private MethodInterceptResult methodInterceptResult; + + private Object[] allArguments; + private Class[] argumentTypes; + + private EnhancedInstance enhancedInstance = new EnhancedInstance() { + + private Object object; + + @Override + public Object getSkyWalkingDynamicField() { + return object; + } + + @Override public void setSkyWalkingDynamicField(Object value) { + this.object = value; + } + }; + + @Before + public void setUp() throws Exception { + interceptor = new HessianProxySendRequestInterceptor(); + PowerMockito.when(hessianProxy.getURL()).thenReturn(new URL("http://127.0.0.1:8080/TestHessian")); + HessianEnhanceCache cache = new HessianEnhanceCache(hessianProxy.getURL()); + enhancedInstance.setSkyWalkingDynamicField(cache); + + HessianConnection huc = PowerMockito.mock(HessianURLConnection.class); + + PowerMockito.when(huc.getStatusCode()).thenReturn(200); + + allArguments = new Object[] {huc}; + argumentTypes = new Class[] {HessianConnection.class}; + } + + @Test + public void testSendRequest() throws Throwable { + interceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, methodInterceptResult); + interceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, methodInterceptResult); + + Assert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + Assert.assertThat(spans.size(), is(1)); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptorTest.java new file mode 100644 index 000000000000..3b712d0cf485 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptorTest.java @@ -0,0 +1,167 @@ +/* + * 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.hessian.v4; + +import com.caucho.hessian.io.AbstractHessianInput; +import com.caucho.hessian.io.AbstractHessianOutput; +import com.caucho.hessian.server.HessianSkeleton; +import java.util.List; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +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.SpanAssert; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +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.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; + +import static org.apache.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * unit tests for hessian plugin + * + * @author Alan Lau + */ +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +@PrepareForTest(HessianSkeleton.class) +public class HessianSkeletonInterceptorTest { + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule agentServiceRule = new AgentServiceRule(); + + @Mock + private String methodName; + + private HessianSkeletonInterceptor interceptor; + + @Mock + private AbstractHessianInput input; + + @Mock + private AbstractHessianOutput out; + + @Mock + private MethodInterceptResult methodInterceptResult; + + private Object[] allArguments; + private Class[] argumentTypes; + + @Mock + private Object service; + + private EnhancedInstance enhancedInstance = new EnhancedInstance() { + + private Object object; + + @Override + public Object getSkyWalkingDynamicField() { + return object; + } + + @Override public void setSkyWalkingDynamicField(Object value) { + this.object = value; + } + }; + + @Before + public void setUp() throws Exception { + interceptor = new HessianSkeletonInterceptor(); + + input = PowerMockito.mock(AbstractHessianInput.class); + out = PowerMockito.mock(AbstractHessianOutput.class); + + service = PowerMockito.mock(Object.class); + allArguments = new Object[] {service, input, out}; + argumentTypes = new Class[] {Object.class, AbstractHessianInput.class, AbstractHessianOutput.class}; + } + + @Test + public void testWithoutSerializedContextData() throws Throwable { + interceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, methodInterceptResult); + interceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, methodInterceptResult); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertHessianSpan(spans.get(0)); + } + + @Test + public void testWithSerializedContextData() throws Throwable { +// when(request.getHeader(SW3CarrierItem.HEADER_NAME)).thenReturn("1.234.111|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"); + + interceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, methodInterceptResult); + interceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, methodInterceptResult); + + Assert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + Assert.assertThat(spans.size(), is(1)); + + assertHessianSpan(spans.get(0)); + } + + @Test + public void testWithErrorException() throws Throwable { + interceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, methodInterceptResult); + interceptor.handleMethodException(enhancedInstance, null, allArguments, argumentTypes, new RuntimeException()); + interceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, null); + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + assertHessianSpan(spans.get(0)); + List logDataEntities = SpanHelper.getLogs(spans.get(0)); + assertThat(logDataEntities.size(), is(1)); + SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class); + } + + private void assertHessianSpan(AbstractTracingSpan span) { + assertThat(span.getOperationName(), is(service.getClass().getName())); + assertComponent(span, ComponentsDefine.HESSIAN); + SpanAssert.assertTag(span, 0, service.getClass().getName()); + assertThat(span.isEntry(), is(true)); + SpanAssert.assertLayer(span, SpanLayer.RPC_FRAMEWORK); + } + +} + + From 155f85146f0ae368f9d870a2eaf1894e53610f4d Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Fri, 21 Jun 2019 10:04:35 +0800 Subject: [PATCH 02/29] Add Hessian Config --- .../apm/network/trace/component/ComponentsDefine.java | 3 +++ 1 file changed, 3 insertions(+) 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 c8dec42ee00f..be9d1501b594 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 @@ -124,6 +124,8 @@ public class ComponentsDefine { public static final OfficialComponent SOLRJ = new OfficialComponent(63, "solrj"); + public static final OfficialComponent HESSIAN = new OfficialComponent(65, "Hessian"); + private static ComponentsDefine INSTANCE = new ComponentsDefine(); private String[] components; @@ -182,6 +184,7 @@ public ComponentsDefine() { addComponent(SPRING_CLOUD_GATEWAY); addComponent(RESTEASY); addComponent(SOLRJ); + addComponent(HESSIAN); } private void addComponent(OfficialComponent component) { From 8d354f67fce09aadf131bb25b2fc22f4f6b84e35 Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Fri, 21 Jun 2019 14:38:14 +0800 Subject: [PATCH 03/29] Fix config. --- apm-sniffer/apm-sdk-plugin/pom.xml | 1 + .../server-core/src/test/resources/component-libraries.yml | 3 +++ .../server-starter/src/main/resources/component-libraries.yml | 4 +++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml index 90bb1a886cc2..5bb5f073b76f 100644 --- a/apm-sniffer/apm-sdk-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/pom.xml @@ -74,6 +74,7 @@ vertx-plugins resteasy-plugin solrj-7.x-plugin + hessian-4.0.x-plugin pom diff --git a/oap-server/server-core/src/test/resources/component-libraries.yml b/oap-server/server-core/src/test/resources/component-libraries.yml index defa1d68732e..e484f4328dc4 100644 --- a/oap-server/server-core/src/test/resources/component-libraries.yml +++ b/oap-server/server-core/src/test/resources/component-libraries.yml @@ -204,6 +204,9 @@ SolrJ: Solr: id: 64 languages: Java +Hessian: + id: 65 + languages: Java # .NET/.NET Core components # [3000, 4000) for C#/.NET only diff --git a/oap-server/server-starter/src/main/resources/component-libraries.yml b/oap-server/server-starter/src/main/resources/component-libraries.yml index 3179c6b5d8b2..3bad43cffb32 100644 --- a/oap-server/server-starter/src/main/resources/component-libraries.yml +++ b/oap-server/server-starter/src/main/resources/component-libraries.yml @@ -222,7 +222,9 @@ SolrJ: Solr: id: 64 languages: Java - +Hessian: + id: 65 + languages: Java # .NET/.NET Core components # [3000, 4000) for C#/.NET only From 0d3c35ed2204d953150d03caa7c4519f4ea9185c Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Fri, 21 Jun 2019 15:22:31 +0800 Subject: [PATCH 04/29] rename plugin. --- apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml index 98e2f964ff47..e18a962b22ad 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml @@ -26,7 +26,7 @@ 4.0.0 - hessian-4.0.x-plugin + apm-hessian-4.0.x-plugin hessian-4.0.x-plugin From fdf28d5826aacd86b5b642585c26b3cd7fe241ec Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Fri, 21 Jun 2019 16:34:46 +0800 Subject: [PATCH 05/29] Add hessian tags. --- .../HessianProxySendRequestInterceptor.java | 2 +- .../apm/plugin/hessian/v4/HessianTags.java | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianTags.java diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java index 399c7ec32389..bbb649fc1e93 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java @@ -60,7 +60,7 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr span.start(System.currentTimeMillis()); span.setOperationName(url.getPath()); - Tags.URL.set(span, url.getPath()); + span.tag(HessianTags.HESSIAN_RPC, url.getPath()); SpanLayer.asRPCFramework(span); } diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianTags.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianTags.java new file mode 100644 index 000000000000..fef98172788a --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianTags.java @@ -0,0 +1,29 @@ +/* + * 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.hessian.v4; + +import org.apache.skywalking.apm.agent.core.context.tag.StringTag; + +/** + * @author Alan Lau + */ +public class HessianTags { + public static StringTag HESSIAN_RPC = new StringTag("hessian_uri"); + +} From baf4c465abd141a7cf2b51a5dac3c8a6a14ea108 Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Fri, 21 Jun 2019 16:48:10 +0800 Subject: [PATCH 06/29] remote unused import --- .../plugin/hessian/v4/HessianProxySendRequestInterceptor.java | 1 - 1 file changed, 1 deletion(-) diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java index bbb649fc1e93..e31b620cea95 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java @@ -23,7 +23,6 @@ import java.net.URL; 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; From ea19c45b1fef2debe24d5b452b9a0fd8bc989c5b Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Mon, 24 Jun 2019 09:24:31 +0800 Subject: [PATCH 07/29] Remove the third classes. --- .../plugin/hessian/v4/HessianProxyConstructorInterceptor.java | 3 +-- .../plugin/hessian/v4/HessianProxySendRequestInterceptor.java | 3 +-- .../apm/plugin/hessian/v4/HessianSkeletonInterceptor.java | 4 +--- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxyConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxyConstructorInterceptor.java index 57fd9a3a7d9e..b4f0ad1c91c1 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxyConstructorInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxyConstructorInterceptor.java @@ -18,14 +18,13 @@ package org.apache.skywalking.apm.plugin.hessian.v4; -import com.caucho.hessian.client.HessianProxy; import java.net.URL; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; import org.apache.skywalking.apm.plugin.hessian.v4.define.HessianEnhanceCache; /** - * intercept contructor {@link HessianProxy#HessianProxy}, save the url into the objInst + * intercept HessianProxy * * @author Alan Lau */ diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java index e31b620cea95..e502e90e223c 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java @@ -18,7 +18,6 @@ package org.apache.skywalking.apm.plugin.hessian.v4; -import com.caucho.hessian.client.HessianProxy; import java.lang.reflect.Method; import java.net.URL; import org.apache.skywalking.apm.agent.core.context.ContextCarrier; @@ -32,7 +31,7 @@ import org.apache.skywalking.apm.plugin.hessian.v4.define.HessianEnhanceCache; /** - * intercept {@link HessianProxy#sendRequest(String, Object[])} + * intercept sendRequest of HessianProxy * * @author Alan Lau */ diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java index 7758105cfb8d..5c6c9407568f 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java @@ -19,8 +19,6 @@ package org.apache.skywalking.apm.plugin.hessian.v4; import com.caucho.hessian.io.AbstractHessianInput; -import com.caucho.hessian.io.AbstractHessianOutput; -import com.caucho.hessian.server.HessianSkeleton; import java.lang.reflect.Method; import org.apache.skywalking.apm.agent.core.context.CarrierItem; import org.apache.skywalking.apm.agent.core.context.ContextCarrier; @@ -34,7 +32,7 @@ import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; /** - * intercept method {@link HessianSkeleton#invoke(Object service, AbstractHessianInput in, AbstractHessianOutput out)} + * intercept invoke of HessianSkeleton * * @author Alan Lau */ From f3103703d2da9d8e064789d46f55eba4322faf65 Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Mon, 24 Jun 2019 10:05:02 +0800 Subject: [PATCH 08/29] Fix ci. --- .../hessian/v4/define/HessianProxyInstrumentation.java | 4 +--- .../hessian/v4/define/HessianSkeletonInstrumentation.java | 5 +---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianProxyInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianProxyInstrumentation.java index 94c7e2b6aefe..9dc8d719c32e 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianProxyInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianProxyInstrumentation.java @@ -18,8 +18,6 @@ package org.apache.skywalking.apm.plugin.hessian.v4.define; -import com.caucho.hessian.client.HessianConnection; -import com.caucho.hessian.client.HessianProxy; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; @@ -36,7 +34,7 @@ import static org.apache.skywalking.apm.plugin.hessian.v4.Constants.HESSIAN_SENDREQUEST_CLASS; /** - * enhance method {@link HessianProxy#addRequestHeaders(HessianConnection)} + * enhance method addRequestHeaders * * @author Alan Lau */ diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java index 5acc93d326e0..811e5350a75a 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java @@ -18,9 +18,6 @@ package org.apache.skywalking.apm.plugin.hessian.v4.define; -import com.caucho.hessian.server.HessianSkeleton; -import java.io.InputStream; -import java.io.OutputStream; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; @@ -36,7 +33,7 @@ import static org.apache.skywalking.apm.plugin.hessian.v4.Constants.SKELETON_INTERCPTOR_CLASS; /** - * enhance method {@link HessianSkeleton#invoke(InputStream, OutputStream)} + * enhance method invoke of HessianSkeleton * * @author Alan Lau */ From 685f160c341ba90becc4719fb0d35da767902112 Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Mon, 24 Jun 2019 11:01:32 +0800 Subject: [PATCH 09/29] Fix testcases. --- .../apm/plugin/hessian/v4/HessianSkeletonInterceptorTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptorTest.java index 3b712d0cf485..b5b784b25207 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptorTest.java @@ -109,6 +109,7 @@ public void setUp() throws Exception { out = PowerMockito.mock(AbstractHessianOutput.class); service = PowerMockito.mock(Object.class); + enhancedInstance.setSkyWalkingDynamicField(service.getClass()); allArguments = new Object[] {service, input, out}; argumentTypes = new Class[] {Object.class, AbstractHessianInput.class, AbstractHessianOutput.class}; } From 0656f6310fb0e762d600ac00f5f9a2206ad0742e Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Tue, 2 Jul 2019 14:25:35 +0800 Subject: [PATCH 10/29] Fix version 6.3.0. --- apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml index e18a962b22ad..48e0fe593d84 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml @@ -22,7 +22,7 @@ apm-sdk-plugin org.apache.skywalking - 6.2.0-SNAPSHOT + 6.3.0-SNAPSHOT 4.0.0 From 89bfcb57644fdf5c8b18226ccf66a8b81cdf22c5 Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Tue, 2 Jul 2019 17:33:38 +0800 Subject: [PATCH 11/29] Add config for hessian server side. --- .../apm/plugin/hessian/v4/Constants.java | 5 + .../v4/HessianServiceExporterInterceptor.java | 92 +++++++++++++++++++ ...HessianSkeletonConstructorInterceptor.java | 9 +- .../v4/HessianSkeletonInterceptor.java | 10 +- ...HessianServiceExporterInstrumentation.java | 64 +++++++++++++ .../plugin/hessian/v4/util/HessianUtils.java | 43 +++++++++ .../src/main/resources/skywalking-plugin.def | 3 +- 7 files changed, 221 insertions(+), 5 deletions(-) create mode 100644 apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianServiceExporterInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianServiceExporterInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/util/HessianUtils.java diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/Constants.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/Constants.java index 792cc5ab6693..dfd3ad8a0485 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/Constants.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/Constants.java @@ -27,6 +27,8 @@ public class Constants { public static final String ENHANCE_CLASS = "com.caucho.hessian.client.HessianProxy"; + public static final String HESSIAN_SERVICE_EXPORTER_CLASS = "org.springframework.remoting.caucho.HessianServiceExporter"; + public static final String ADDHEADER_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.hessian.v4.HessianAddHeaderInterceptor"; public static final String HESSIAN_SENDREQUEST_CLASS = "org.apache.skywalking.apm.plugin.hessian.v4.HessianProxySendRequestInterceptor"; @@ -39,4 +41,7 @@ public class Constants { public static final String SKELETON_CONSTRUCT_INTERCEPTOR = "org.apache.skywalking.apm.plugin.hessian.v4.HessianSkeletonConstructorInterceptor"; + public static final String URI_AS_OPERATE_NAME = "plugin.hessian.use_uri_name_as_operate_name"; + + public static final String HESSIAN_SERVICE_EXPORTER_INTERCEOTPOR = "org.apache.skywalking.apm.plugin.hessian.v4.HessianServiceExporterInterceptor"; } diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianServiceExporterInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianServiceExporterInterceptor.java new file mode 100644 index 000000000000..89cbdf72c706 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianServiceExporterInterceptor.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.hessian.v4; + +import java.lang.reflect.Method; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +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; +import org.apache.skywalking.apm.plugin.hessian.v4.util.HessianUtils; + +/** + * @author Alan Lau + */ +public class HessianServiceExporterInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + if (argumentsTypes.length != 2) { + return; + } + + if (!argumentsTypes[0].isAssignableFrom(HttpServletRequest.class)) { + return; + } + + if (!argumentsTypes[1].isAssignableFrom(HttpServletResponse.class)) { + return; + } + + HttpServletRequest request = (HttpServletRequest)allArguments[0]; + + if (!HessianUtils.getOperationNameLike()) { + objInst.setSkyWalkingDynamicField(request.getRequestURI()); + } + + String operateName = request.getRequestURI(); + AbstractSpan span = ContextManager.createLocalSpan(operateName); + + span.setComponent(ComponentsDefine.HESSIAN); + span.start(System.currentTimeMillis()); + span.setOperationName(operateName); + Tags.URL.set(span, operateName); + SpanLayer.asRPCFramework(span); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) { + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + dealException(t); + } + + /** + * Log the throwable, which occurs in Hessian RPC service. + * + * @param throwable + */ + public void dealException(Throwable throwable) { + AbstractSpan span = ContextManager.activeSpan(); + span.errorOccurred(); + span.log(throwable); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java index be4067b13406..33438d99dd5f 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java @@ -20,6 +20,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; +import org.apache.skywalking.apm.plugin.hessian.v4.util.HessianUtils; /** * @author Alan Lau @@ -31,7 +32,11 @@ public class HessianSkeletonConstructorInterceptor implements InstanceConstructo if (allArguments[0] == null) { return; } - Object service = allArguments[1]; - objInst.setSkyWalkingDynamicField(service); + + if (HessianUtils.getOperationNameLike()) { + Object service = allArguments[1]; + objInst.setSkyWalkingDynamicField(service); + } + } } diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java index 5c6c9407568f..a3d9c3fdd6dd 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java @@ -30,6 +30,7 @@ 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; +import org.apache.skywalking.apm.plugin.hessian.v4.util.HessianUtils; /** * intercept invoke of HessianSkeleton @@ -60,9 +61,14 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr final ContextCarrier contextCarrier = new ContextCarrier(); - Object realService = objInst.getSkyWalkingDynamicField(); + String operationName = null; + if (HessianUtils.getOperationNameLike()) { + Object realService = objInst.getSkyWalkingDynamicField(); + operationName = ((Class)realService).getName(); + } else { + operationName = ContextManager.activeSpan().getOperationName(); + } - String operationName = ((Class)realService).getName(); AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier); span.start(System.currentTimeMillis()); diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianServiceExporterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianServiceExporterInstrumentation.java new file mode 100644 index 000000000000..9890b5a5c7a6 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianServiceExporterInstrumentation.java @@ -0,0 +1,64 @@ +/* + * 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.hessian.v4.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 static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; +import static org.apache.skywalking.apm.plugin.hessian.v4.Constants.HESSIAN_SERVICE_EXPORTER_CLASS; +import static org.apache.skywalking.apm.plugin.hessian.v4.Constants.HESSIAN_SERVICE_EXPORTER_INTERCEOTPOR; + +/** + * @author Alan Lau + */ +public class HessianServiceExporterInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return null; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("handleRequest"); + } + + @Override public String getMethodsInterceptor() { + return HESSIAN_SERVICE_EXPORTER_INTERCEOTPOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(HESSIAN_SERVICE_EXPORTER_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/util/HessianUtils.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/util/HessianUtils.java new file mode 100644 index 000000000000..939e402cc4f1 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/util/HessianUtils.java @@ -0,0 +1,43 @@ +/* + * 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.hessian.v4.util; + +import org.apache.skywalking.apm.util.StringUtil; + +import static org.apache.skywalking.apm.plugin.hessian.v4.Constants.URI_AS_OPERATE_NAME; + +/** + * @author Alan Lau + */ +public class HessianUtils { + + /** + * which kind format of the format the server side used. + * + * @return true: the interface class used, false uri used. default false. + */ + public static boolean getOperationNameLike() { + String format = System.getProperty(URI_AS_OPERATE_NAME); + if (StringUtil.isEmpty(format)) { + return false; + } + + return Boolean.valueOf(format); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/resources/skywalking-plugin.def index e258562ee635..03dc375cf6a0 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/resources/skywalking-plugin.def @@ -16,4 +16,5 @@ hessian-4.0.x=org.apache.skywalking.apm.plugin.hessian.v4.define.HessianProxyInstrumentation -hessian-4.0.x=org.apache.skywalking.apm.plugin.hessian.v4.define.HessianSkeletonInstrumentation \ No newline at end of file +hessian-4.0.x=org.apache.skywalking.apm.plugin.hessian.v4.define.HessianSkeletonInstrumentation +hessian-4.0.x=org.apache.skywalking.apm.plugin.hessian.v4.define.HessianServiceExporterInstrumentation \ No newline at end of file From 85e480a99f3d21eec98c958bc82fd0ecc8ef223f Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Wed, 3 Jul 2019 11:36:02 +0800 Subject: [PATCH 12/29] Remove unused code. --- .../plugin/hessian/v4/HessianServiceExporterInterceptor.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianServiceExporterInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianServiceExporterInterceptor.java index 89cbdf72c706..c6b86268e1cf 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianServiceExporterInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianServiceExporterInterceptor.java @@ -53,10 +53,6 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr HttpServletRequest request = (HttpServletRequest)allArguments[0]; - if (!HessianUtils.getOperationNameLike()) { - objInst.setSkyWalkingDynamicField(request.getRequestURI()); - } - String operateName = request.getRequestURI(); AbstractSpan span = ContextManager.createLocalSpan(operateName); From 543c4e9ee5f9bf15e1e9ce4b2ed01059d5415c8e Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Wed, 3 Jul 2019 11:39:23 +0800 Subject: [PATCH 13/29] Fix the config. --- .../hessian/v4/HessianSkeletonConstructorInterceptor.java | 2 +- .../apm/plugin/hessian/v4/HessianSkeletonInterceptor.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java index 33438d99dd5f..f9af74fef708 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java @@ -33,7 +33,7 @@ public class HessianSkeletonConstructorInterceptor implements InstanceConstructo return; } - if (HessianUtils.getOperationNameLike()) { + if (!HessianUtils.getOperationNameLike()) { Object service = allArguments[1]; objInst.setSkyWalkingDynamicField(service); } diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java index a3d9c3fdd6dd..1f2ccf3df95b 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java @@ -62,7 +62,7 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr final ContextCarrier contextCarrier = new ContextCarrier(); String operationName = null; - if (HessianUtils.getOperationNameLike()) { + if (!HessianUtils.getOperationNameLike()) { Object realService = objInst.getSkyWalkingDynamicField(); operationName = ((Class)realService).getName(); } else { From 24273e75287ec47594b96fdb474a6ff896ae798d Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Wed, 3 Jul 2019 13:41:50 +0800 Subject: [PATCH 14/29] Remove unused import. --- .../apm/plugin/hessian/v4/HessianServiceExporterInterceptor.java | 1 - 1 file changed, 1 deletion(-) diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianServiceExporterInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianServiceExporterInterceptor.java index c6b86268e1cf..6a127a70e118 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianServiceExporterInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianServiceExporterInterceptor.java @@ -28,7 +28,6 @@ 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; -import org.apache.skywalking.apm.plugin.hessian.v4.util.HessianUtils; /** * @author Alan Lau From 58d70c095ee2498c6ca036b2bfcd2e0204d3f03e Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Wed, 3 Jul 2019 17:58:34 +0800 Subject: [PATCH 15/29] Fix the docs. & Fix hessian config as variable to Config. --- .../apm/agent/core/conf/Config.java | 7 +++ .../apm/plugin/hessian/v4/Constants.java | 2 - ...HessianSkeletonConstructorInterceptor.java | 4 +- .../v4/HessianSkeletonInterceptor.java | 4 +- .../plugin/hessian/v4/util/HessianUtils.java | 43 ------------------- .../setup/service-agent/java-agent/README.md | 1 + .../java-agent/Supported-list.md | 1 + 7 files changed, 13 insertions(+), 49 deletions(-) delete mode 100644 apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/util/HessianUtils.java diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java index 9efab982bf5b..589af64777f2 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java @@ -226,5 +226,12 @@ public static class SolrJ { public static boolean TRACE_OPS_PARAMS = false; } + public static class Hessian { + /** + * If true, the request uri name will be used as the operation name instead of the interface class name, default is false. + */ + public static boolean USE_URI_NAME_AS_OPERATE_NAME = false; + } + } } diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/Constants.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/Constants.java index dfd3ad8a0485..3000150ee272 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/Constants.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/Constants.java @@ -41,7 +41,5 @@ public class Constants { public static final String SKELETON_CONSTRUCT_INTERCEPTOR = "org.apache.skywalking.apm.plugin.hessian.v4.HessianSkeletonConstructorInterceptor"; - public static final String URI_AS_OPERATE_NAME = "plugin.hessian.use_uri_name_as_operate_name"; - public static final String HESSIAN_SERVICE_EXPORTER_INTERCEOTPOR = "org.apache.skywalking.apm.plugin.hessian.v4.HessianServiceExporterInterceptor"; } diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java index f9af74fef708..f60249d89e62 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java @@ -18,9 +18,9 @@ package org.apache.skywalking.apm.plugin.hessian.v4; +import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; -import org.apache.skywalking.apm.plugin.hessian.v4.util.HessianUtils; /** * @author Alan Lau @@ -33,7 +33,7 @@ public class HessianSkeletonConstructorInterceptor implements InstanceConstructo return; } - if (!HessianUtils.getOperationNameLike()) { + if (!Config.Plugin.Hessian.USE_URI_NAME_AS_OPERATE_NAME) { Object service = allArguments[1]; objInst.setSkyWalkingDynamicField(service); } diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java index 1f2ccf3df95b..958daffcfecd 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java @@ -20,6 +20,7 @@ import com.caucho.hessian.io.AbstractHessianInput; import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.conf.Config; 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; @@ -30,7 +31,6 @@ 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; -import org.apache.skywalking.apm.plugin.hessian.v4.util.HessianUtils; /** * intercept invoke of HessianSkeleton @@ -62,7 +62,7 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr final ContextCarrier contextCarrier = new ContextCarrier(); String operationName = null; - if (!HessianUtils.getOperationNameLike()) { + if (!Config.Plugin.Hessian.USE_URI_NAME_AS_OPERATE_NAME) { Object realService = objInst.getSkyWalkingDynamicField(); operationName = ((Class)realService).getName(); } else { diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/util/HessianUtils.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/util/HessianUtils.java deleted file mode 100644 index 939e402cc4f1..000000000000 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/util/HessianUtils.java +++ /dev/null @@ -1,43 +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.hessian.v4.util; - -import org.apache.skywalking.apm.util.StringUtil; - -import static org.apache.skywalking.apm.plugin.hessian.v4.Constants.URI_AS_OPERATE_NAME; - -/** - * @author Alan Lau - */ -public class HessianUtils { - - /** - * which kind format of the format the server side used. - * - * @return true: the interface class used, false uri used. default false. - */ - public static boolean getOperationNameLike() { - String format = System.getProperty(URI_AS_OPERATE_NAME); - if (StringUtil.isEmpty(format)) { - return false; - } - - return Boolean.valueOf(format); - } -} diff --git a/docs/en/setup/service-agent/java-agent/README.md b/docs/en/setup/service-agent/java-agent/README.md index 247dd43845d1..9f879fa8d70a 100644 --- a/docs/en/setup/service-agent/java-agent/README.md +++ b/docs/en/setup/service-agent/java-agent/README.md @@ -87,6 +87,7 @@ property key | Description | Default | `plugin.mysql.sql_parameters_max_length`|If set to positive number, the `db.sql.parameters` would be truncated to this length, otherwise it would be completely saved, which may cause performance problem.|`512`| `plugin.solrj.trace_statement`|If true, trace all the query parameters(include deleteByIds and deleteByQuery) in Solr query request, default is false.|`false`| `plugin.solrj.trace_ops_params`|If true, trace all the operation parameters in Solr request, default is false.|`false`| +`plugin.use_uri_name_as_operate_name`|If true, the request uri name will be used as the operation name instead of the interface class name, default is false.|`false`| ## Optional Plugins Java agent plugins are all pluggable. Optional plugins could be provided in `optional-plugins` folder under agent or 3rd party repositories. diff --git a/docs/en/setup/service-agent/java-agent/Supported-list.md b/docs/en/setup/service-agent/java-agent/Supported-list.md index 1f52dffdddaa..4868352b5975 100644 --- a/docs/en/setup/service-agent/java-agent/Supported-list.md +++ b/docs/en/setup/service-agent/java-agent/Supported-list.md @@ -37,6 +37,7 @@ * [gRPC](https://github.com/grpc/grpc-java) 1.x * [Apache ServiceComb Java Chassis](https://github.com/apache/servicecomb-java-chassis) 0.1 -> 0.5,1.0.x * [SOFARPC](https://github.com/alipay/sofa-rpc) 5.4.0 + * [Hessian](http://http://hessian.caucho.com) 4.0.x * MQ * [RocketMQ](https://github.com/apache/rocketmq) 4.x * [Kafka](http://kafka.apache.org) 0.11.0.0 -> 1.0 From 21991e655098f0c1d397c0e8f03a367299c213f9 Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Wed, 3 Jul 2019 18:12:08 +0800 Subject: [PATCH 16/29] Fix md. --- docs/en/setup/service-agent/java-agent/Supported-list.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/setup/service-agent/java-agent/Supported-list.md b/docs/en/setup/service-agent/java-agent/Supported-list.md index 4868352b5975..aa1121aaacb4 100644 --- a/docs/en/setup/service-agent/java-agent/Supported-list.md +++ b/docs/en/setup/service-agent/java-agent/Supported-list.md @@ -37,7 +37,7 @@ * [gRPC](https://github.com/grpc/grpc-java) 1.x * [Apache ServiceComb Java Chassis](https://github.com/apache/servicecomb-java-chassis) 0.1 -> 0.5,1.0.x * [SOFARPC](https://github.com/alipay/sofa-rpc) 5.4.0 - * [Hessian](http://http://hessian.caucho.com) 4.0.x + * [Hessian](http://hessian.caucho.com) 4.0.x * MQ * [RocketMQ](https://github.com/apache/rocketmq) 4.x * [Kafka](http://kafka.apache.org) 0.11.0.0 -> 1.0 From e81507d73a9783dd0af8ebb7d2065c77c790903b Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Wed, 3 Jul 2019 19:27:42 +0800 Subject: [PATCH 17/29] Rename name of the hessian config. --- .../java/org/apache/skywalking/apm/agent/core/conf/Config.java | 2 +- .../hessian/v4/HessianSkeletonConstructorInterceptor.java | 2 +- .../apm/plugin/hessian/v4/HessianSkeletonInterceptor.java | 2 +- docs/en/setup/service-agent/java-agent/README.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java index 589af64777f2..9ba5608ba33f 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java @@ -230,7 +230,7 @@ public static class Hessian { /** * If true, the request uri name will be used as the operation name instead of the interface class name, default is false. */ - public static boolean USE_URI_NAME_AS_OPERATE_NAME = false; + public static boolean USE_URL_AS_OPERATION_NAME = false; } } diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java index f60249d89e62..7e5f86e33f25 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java @@ -33,7 +33,7 @@ public class HessianSkeletonConstructorInterceptor implements InstanceConstructo return; } - if (!Config.Plugin.Hessian.USE_URI_NAME_AS_OPERATE_NAME) { + if (!Config.Plugin.Hessian.USE_URL_AS_OPERATION_NAME) { Object service = allArguments[1]; objInst.setSkyWalkingDynamicField(service); } diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java index 958daffcfecd..5cae50903fec 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java @@ -62,7 +62,7 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr final ContextCarrier contextCarrier = new ContextCarrier(); String operationName = null; - if (!Config.Plugin.Hessian.USE_URI_NAME_AS_OPERATE_NAME) { + if (!Config.Plugin.Hessian.USE_URL_AS_OPERATION_NAME) { Object realService = objInst.getSkyWalkingDynamicField(); operationName = ((Class)realService).getName(); } else { diff --git a/docs/en/setup/service-agent/java-agent/README.md b/docs/en/setup/service-agent/java-agent/README.md index 9f879fa8d70a..4dd9bd86cf95 100644 --- a/docs/en/setup/service-agent/java-agent/README.md +++ b/docs/en/setup/service-agent/java-agent/README.md @@ -87,7 +87,7 @@ property key | Description | Default | `plugin.mysql.sql_parameters_max_length`|If set to positive number, the `db.sql.parameters` would be truncated to this length, otherwise it would be completely saved, which may cause performance problem.|`512`| `plugin.solrj.trace_statement`|If true, trace all the query parameters(include deleteByIds and deleteByQuery) in Solr query request, default is false.|`false`| `plugin.solrj.trace_ops_params`|If true, trace all the operation parameters in Solr request, default is false.|`false`| -`plugin.use_uri_name_as_operate_name`|If true, the request uri name will be used as the operation name instead of the interface class name, default is false.|`false`| +`plugin.hessian.use_url_as_operation_name`|If true, the request url name will be used as the operation name instead of the interface class name, default is false.|`false`| ## Optional Plugins Java agent plugins are all pluggable. Optional plugins could be provided in `optional-plugins` folder under agent or 3rd party repositories. From 86de488692df6aa813e4c4ed5efc9d48720dcec7 Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Thu, 11 Jul 2019 09:43:45 +0800 Subject: [PATCH 18/29] Remove the properties in the pom.xml, change the hessian jar scope. --- .../apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml index 48e0fe593d84..147145a572c1 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml @@ -20,8 +20,8 @@ - apm-sdk-plugin org.apache.skywalking + apm-sdk-plugin 6.3.0-SNAPSHOT 4.0.0 @@ -33,23 +33,15 @@ http://www.example.com - UTF-8 - 1.8 - 1.8 + 4.0.38 - - junit - junit - 4.12 - test - - com.caucho hessian - 4.0.38 + ${hessian.version} + provided From 9a6334f83ec138d0d91d0c4c79e3bfd8078d45d1 Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Mon, 22 Jul 2019 09:51:02 +0800 Subject: [PATCH 19/29] Remove hessian_uri & Mv the matcher to instrumentation define. --- .../HessianProxySendRequestInterceptor.java | 4 ++- .../v4/HessianSkeletonInterceptor.java | 4 --- .../apm/plugin/hessian/v4/HessianTags.java | 29 ------------------- .../HessianSkeletonInstrumentation.java | 5 +++- 4 files changed, 7 insertions(+), 35 deletions(-) delete mode 100644 apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianTags.java diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java index e502e90e223c..adac203e41f5 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java @@ -18,10 +18,12 @@ package org.apache.skywalking.apm.plugin.hessian.v4; +import io.opencensus.trace.Span; import java.lang.reflect.Method; import java.net.URL; 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; @@ -58,7 +60,7 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr span.start(System.currentTimeMillis()); span.setOperationName(url.getPath()); - span.tag(HessianTags.HESSIAN_RPC, url.getPath()); + Tags.URL.set(span, url.getPath()); SpanLayer.asRPCFramework(span); } diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java index 5cae50903fec..e9fe208a22e5 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java @@ -53,10 +53,6 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr return; } - if (!argumentsTypes[1].isAssignableFrom(AbstractHessianInput.class)) { - return; - } - AbstractHessianInput in = (AbstractHessianInput)allArguments[1]; final ContextCarrier contextCarrier = new ContextCarrier(); diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianTags.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianTags.java deleted file mode 100644 index fef98172788a..000000000000 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianTags.java +++ /dev/null @@ -1,29 +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.hessian.v4; - -import org.apache.skywalking.apm.agent.core.context.tag.StringTag; - -/** - * @author Alan Lau - */ -public class HessianTags { - public static StringTag HESSIAN_RPC = new StringTag("hessian_uri"); - -} diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java index 811e5350a75a..e1d3be1e8992 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java @@ -18,6 +18,8 @@ package org.apache.skywalking.apm.plugin.hessian.v4.define; +import com.caucho.hessian.io.AbstractHessianInput; +import com.caucho.hessian.io.AbstractHessianOutput; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; @@ -27,6 +29,7 @@ import static net.bytebuddy.matcher.ElementMatchers.any; import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArgument; import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; import static org.apache.skywalking.apm.plugin.hessian.v4.Constants.HESSIAN_SERVLET_ENHANCE_CLASS; import static org.apache.skywalking.apm.plugin.hessian.v4.Constants.SKELETON_CONSTRUCT_INTERCEPTOR; @@ -58,7 +61,7 @@ public class HessianSkeletonInstrumentation extends ClassInstanceMethodsEnhanceP return new InstanceMethodsInterceptPoint[] { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named("invoke"); + return named("invoke").and(takesArgument(1, AbstractHessianInput.class)).and(takesArgument(2, AbstractHessianOutput.class)); } @Override public String getMethodsInterceptor() { From 3cd7c7b8c72f13f5f1bb31107bf8f5957cdc73e6 Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Mon, 22 Jul 2019 10:26:27 +0800 Subject: [PATCH 20/29] fix the import. --- .../hessian/v4/HessianProxySendRequestInterceptor.java | 1 - .../hessian/v4/define/HessianSkeletonInstrumentation.java | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java index adac203e41f5..b5fef633023c 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java @@ -18,7 +18,6 @@ package org.apache.skywalking.apm.plugin.hessian.v4; -import io.opencensus.trace.Span; import java.lang.reflect.Method; import java.net.URL; import org.apache.skywalking.apm.agent.core.context.ContextCarrier; diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java index e1d3be1e8992..ca78aa609606 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java @@ -18,8 +18,6 @@ package org.apache.skywalking.apm.plugin.hessian.v4.define; -import com.caucho.hessian.io.AbstractHessianInput; -import com.caucho.hessian.io.AbstractHessianOutput; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; @@ -29,7 +27,7 @@ import static net.bytebuddy.matcher.ElementMatchers.any; import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.takesArgument; +import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; import static org.apache.skywalking.apm.plugin.hessian.v4.Constants.HESSIAN_SERVLET_ENHANCE_CLASS; import static org.apache.skywalking.apm.plugin.hessian.v4.Constants.SKELETON_CONSTRUCT_INTERCEPTOR; @@ -61,7 +59,7 @@ public class HessianSkeletonInstrumentation extends ClassInstanceMethodsEnhanceP return new InstanceMethodsInterceptPoint[] { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named("invoke").and(takesArgument(1, AbstractHessianInput.class)).and(takesArgument(2, AbstractHessianOutput.class)); + return named("invoke").and(takesArgumentWithType(1, "AbstractHessianInput")).and(takesArgumentWithType(2, "AbstractHessianOutput")); } @Override public String getMethodsInterceptor() { From ac49d1b7f3ac3313a8252726672b4b2305591abf Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Mon, 22 Jul 2019 11:14:52 +0800 Subject: [PATCH 21/29] Give the full name. --- .../hessian/v4/define/HessianSkeletonInstrumentation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java index ca78aa609606..8012eab9350a 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java @@ -59,7 +59,7 @@ public class HessianSkeletonInstrumentation extends ClassInstanceMethodsEnhanceP return new InstanceMethodsInterceptPoint[] { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named("invoke").and(takesArgumentWithType(1, "AbstractHessianInput")).and(takesArgumentWithType(2, "AbstractHessianOutput")); + return named("invoke").and(takesArgumentWithType(1, "com.caucho.hessian.io.AbstractHessianInput")).and(takesArgumentWithType(2, "com.caucho.hessian.io.AbstractHessianOutput")); } @Override public String getMethodsInterceptor() { From 3a7231a51ec302e90b2daa001f2d9b23198f095e Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Mon, 22 Jul 2019 13:58:01 +0800 Subject: [PATCH 22/29] =?UTF-8?q?Fix=20the=20typos=20&=20Fix=20the=20condi?= =?UTF-8?q?tions=20when=20stop=20span.=20&=20Fix=20follow=20useful=20sugge?= =?UTF-8?q?stions.=C3=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml | 3 --- .../skywalking/apm/plugin/hessian/v4/Constants.java | 2 +- .../v4/HessianProxySendRequestInterceptor.java | 8 +++++++- .../v4/HessianServiceExporterInterceptor.java | 12 +++--------- .../hessian/v4/HessianSkeletonInterceptor.java | 11 +++++++++++ .../HessianServiceExporterInstrumentation.java | 7 ++++--- .../v4/define/HessianSkeletonInstrumentation.java | 4 ++-- 7 files changed, 28 insertions(+), 19 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml index 147145a572c1..a9d08225cc48 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml @@ -29,8 +29,6 @@ apm-hessian-4.0.x-plugin hessian-4.0.x-plugin - - http://www.example.com 4.0.38 @@ -44,7 +42,6 @@ provided - javax.servlet javax.servlet-api diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/Constants.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/Constants.java index 3000150ee272..22b50ca512cb 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/Constants.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/Constants.java @@ -41,5 +41,5 @@ public class Constants { public static final String SKELETON_CONSTRUCT_INTERCEPTOR = "org.apache.skywalking.apm.plugin.hessian.v4.HessianSkeletonConstructorInterceptor"; - public static final String HESSIAN_SERVICE_EXPORTER_INTERCEOTPOR = "org.apache.skywalking.apm.plugin.hessian.v4.HessianServiceExporterInterceptor"; + public static final String HESSIAN_SERVICE_EXPORTER_INCERCEPTOR = "org.apache.skywalking.apm.plugin.hessian.v4.HessianServiceExporterInterceptor"; } diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java index b5fef633023c..f1bdfb4366ce 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java @@ -66,7 +66,13 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Object ret) { - if (allArguments.length == 0) { + HessianEnhanceCache cache = (HessianEnhanceCache)objInst.getSkyWalkingDynamicField(); + URL url = cache.getUrl(); + if (url == null) { + return ret; + } + + if (allArguments.length < 0) { return ret; } diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianServiceExporterInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianServiceExporterInterceptor.java index 6a127a70e118..3de131f2ed2d 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianServiceExporterInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianServiceExporterInterceptor.java @@ -19,7 +19,6 @@ import java.lang.reflect.Method; import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; 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; @@ -42,14 +41,6 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr return; } - if (!argumentsTypes[0].isAssignableFrom(HttpServletRequest.class)) { - return; - } - - if (!argumentsTypes[1].isAssignableFrom(HttpServletResponse.class)) { - return; - } - HttpServletRequest request = (HttpServletRequest)allArguments[0]; String operateName = request.getRequestURI(); @@ -65,6 +56,9 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Object ret) { + if (argumentsTypes.length != 2) { + return ret; + } ContextManager.stopSpan(); return ret; } diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java index e9fe208a22e5..873fafbcc5b2 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java @@ -82,7 +82,18 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Object ret) { + Object service = allArguments[0]; + + if (service == null) { + return ret; + } + + if (argumentsTypes.length < 3) { + return ret; + } + ContextManager.stopSpan(); + return ret; } diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianServiceExporterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianServiceExporterInstrumentation.java index 9890b5a5c7a6..8d9ef835d712 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianServiceExporterInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianServiceExporterInstrumentation.java @@ -26,9 +26,10 @@ import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; import static org.apache.skywalking.apm.plugin.hessian.v4.Constants.HESSIAN_SERVICE_EXPORTER_CLASS; -import static org.apache.skywalking.apm.plugin.hessian.v4.Constants.HESSIAN_SERVICE_EXPORTER_INTERCEOTPOR; +import static org.apache.skywalking.apm.plugin.hessian.v4.Constants.HESSIAN_SERVICE_EXPORTER_INCERCEPTOR; /** * @author Alan Lau @@ -43,11 +44,11 @@ public class HessianServiceExporterInstrumentation extends ClassInstanceMethodsE new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named("handleRequest"); + return named("handleRequest").and(takesArgumentWithType(1, "javax.servlet.http.HttpServletRequest")).and(takesArgumentWithType(1, "javax.servlet.http.HttpServletResponse")); } @Override public String getMethodsInterceptor() { - return HESSIAN_SERVICE_EXPORTER_INTERCEOTPOR; + return HESSIAN_SERVICE_EXPORTER_INCERCEPTOR; } @Override public boolean isOverrideArgs() { diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java index 8012eab9350a..779d8e80d559 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java @@ -20,12 +20,12 @@ import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; +import net.bytebuddy.matcher.ElementMatchers; 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 static net.bytebuddy.matcher.ElementMatchers.any; import static net.bytebuddy.matcher.ElementMatchers.named; import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; @@ -45,7 +45,7 @@ public class HessianSkeletonInstrumentation extends ClassInstanceMethodsEnhanceP new ConstructorInterceptPoint() { @Override public ElementMatcher getConstructorMatcher() { - return any(); + return ElementMatchers.takesArguments(2); } @Override public String getConstructorInterceptor() { From 53bffe02032a7fa6ff10ae91c00f879341956784 Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Mon, 22 Jul 2019 14:30:01 +0800 Subject: [PATCH 23/29] Fix the index. --- .../v4/define/HessianServiceExporterInstrumentation.java | 2 +- .../hessian/v4/define/HessianSkeletonInstrumentation.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianServiceExporterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianServiceExporterInstrumentation.java index 8d9ef835d712..fabc8db092fe 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianServiceExporterInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianServiceExporterInstrumentation.java @@ -44,7 +44,7 @@ public class HessianServiceExporterInstrumentation extends ClassInstanceMethodsE new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named("handleRequest").and(takesArgumentWithType(1, "javax.servlet.http.HttpServletRequest")).and(takesArgumentWithType(1, "javax.servlet.http.HttpServletResponse")); + return named("handleRequest").and(takesArgumentWithType(0, "javax.servlet.http.HttpServletRequest")).and(takesArgumentWithType(1, "javax.servlet.http.HttpServletResponse")); } @Override public String getMethodsInterceptor() { diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java index 779d8e80d559..bec18262ffa8 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java @@ -59,7 +59,7 @@ public class HessianSkeletonInstrumentation extends ClassInstanceMethodsEnhanceP return new InstanceMethodsInterceptPoint[] { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named("invoke").and(takesArgumentWithType(1, "com.caucho.hessian.io.AbstractHessianInput")).and(takesArgumentWithType(2, "com.caucho.hessian.io.AbstractHessianOutput")); + return named("invoke").and(takesArgumentWithType(0, "com.caucho.hessian.io.AbstractHessianInput")).and(takesArgumentWithType(1, "com.caucho.hessian.io.AbstractHessianOutput")); } @Override public String getMethodsInterceptor() { From a30640bc5d0a9c17a46d44c9a5436f80ba693000 Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Tue, 30 Jul 2019 10:04:07 +0800 Subject: [PATCH 24/29] Remove third party instrumentation. --- .../hessian-4.0.x-plugin/pom.xml | 6 ++ .../apm/plugin/hessian/v4/Constants.java | 1 - .../HessianProxyConstructorInterceptor.java | 6 +- .../HessianProxySendRequestInterceptor.java | 40 ++++++--- .../v4/HessianServiceExporterInterceptor.java | 81 ------------------- ...HessianSkeletonConstructorInterceptor.java | 7 +- .../v4/HessianSkeletonInterceptor.java | 10 +-- .../v4/define/HessianEnhanceCache.java | 23 +++--- ...HessianServiceExporterInstrumentation.java | 65 --------------- 9 files changed, 52 insertions(+), 187 deletions(-) delete mode 100644 apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianServiceExporterInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianServiceExporterInstrumentation.java diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml index a9d08225cc48..31d1b16d9bd4 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml @@ -42,6 +42,12 @@ provided + + org.projectlombok + lombok + 1.18.6 + + javax.servlet javax.servlet-api diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/Constants.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/Constants.java index 22b50ca512cb..b491743c31d3 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/Constants.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/Constants.java @@ -41,5 +41,4 @@ public class Constants { public static final String SKELETON_CONSTRUCT_INTERCEPTOR = "org.apache.skywalking.apm.plugin.hessian.v4.HessianSkeletonConstructorInterceptor"; - public static final String HESSIAN_SERVICE_EXPORTER_INCERCEPTOR = "org.apache.skywalking.apm.plugin.hessian.v4.HessianServiceExporterInterceptor"; } diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxyConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxyConstructorInterceptor.java index b4f0ad1c91c1..c9ed3870d998 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxyConstructorInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxyConstructorInterceptor.java @@ -18,7 +18,6 @@ package org.apache.skywalking.apm.plugin.hessian.v4; -import java.net.URL; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; import org.apache.skywalking.apm.plugin.hessian.v4.define.HessianEnhanceCache; @@ -35,7 +34,8 @@ public class HessianProxyConstructorInterceptor implements InstanceConstructorIn if (allArguments[0] == null) { return; } - URL url = (URL)allArguments[0]; - objInst.setSkyWalkingDynamicField(new HessianEnhanceCache(url)); + Class clazz = (Class)allArguments[2]; + objInst.setSkyWalkingDynamicField(new HessianEnhanceCache(clazz)); + } } diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java index f1bdfb4366ce..c921d772f9bb 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java @@ -20,6 +20,7 @@ import java.lang.reflect.Method; import java.net.URL; +import org.apache.skywalking.apm.agent.core.conf.Config; 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; @@ -41,8 +42,12 @@ public class HessianProxySendRequestInterceptor implements InstanceMethodsAround @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - HessianEnhanceCache cache = (HessianEnhanceCache)objInst.getSkyWalkingDynamicField(); - URL url = cache.getUrl(); + + if (allArguments.length < 0) { + return; + } + + URL url = (URL)allArguments[0]; if (url == null) { return; } @@ -50,24 +55,39 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr if (allArguments.length < 0) { return; } - - String operateName = url.getPath(); + HessianEnhanceCache cache = (HessianEnhanceCache)objInst.getSkyWalkingDynamicField(); + AbstractSpan span; final ContextCarrier contextCarrier = new ContextCarrier(); - AbstractSpan span = ContextManager.createExitSpan(operateName, contextCarrier, String.format(":", url.getHost(), url.getPort())); + String operateName; + if (Config.Plugin.Hessian.USE_URL_AS_OPERATION_NAME) { + operateName = url.getPath(); + span = ContextManager.createExitSpan(operateName, contextCarrier, String.format(":", url.getHost(), url.getPort())); + Tags.URL.set(span, url.getPath()); + }else { + Class clazz = (Class)cache.getT(); + if (clazz == null) { + return ; + } + operateName = clazz.getName(); + span = ContextManager.createExitSpan(operateName, contextCarrier, String.format(":", url.getHost(), url.getPort())); + Tags.URL.set(span, operateName); + } + + span.setOperationName(operateName); span.setComponent(ComponentsDefine.HESSIAN); span.start(System.currentTimeMillis()); - span.setOperationName(url.getPath()); - - Tags.URL.set(span, url.getPath()); SpanLayer.asRPCFramework(span); } @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Object ret) { - HessianEnhanceCache cache = (HessianEnhanceCache)objInst.getSkyWalkingDynamicField(); - URL url = cache.getUrl(); + if (allArguments.length < 0) { + return ret; + } + + URL url = (URL)allArguments[0]; if (url == null) { return ret; } diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianServiceExporterInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianServiceExporterInterceptor.java deleted file mode 100644 index 3de131f2ed2d..000000000000 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianServiceExporterInterceptor.java +++ /dev/null @@ -1,81 +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.hessian.v4; - -import java.lang.reflect.Method; -import javax.servlet.http.HttpServletRequest; -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; - -/** - * @author Alan Lau - */ -public class HessianServiceExporterInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - - if (argumentsTypes.length != 2) { - return; - } - - HttpServletRequest request = (HttpServletRequest)allArguments[0]; - - String operateName = request.getRequestURI(); - AbstractSpan span = ContextManager.createLocalSpan(operateName); - - span.setComponent(ComponentsDefine.HESSIAN); - span.start(System.currentTimeMillis()); - span.setOperationName(operateName); - Tags.URL.set(span, operateName); - SpanLayer.asRPCFramework(span); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) { - if (argumentsTypes.length != 2) { - return ret; - } - ContextManager.stopSpan(); - return ret; - } - - @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - dealException(t); - } - - /** - * Log the throwable, which occurs in Hessian RPC service. - * - * @param throwable - */ - public void dealException(Throwable throwable) { - AbstractSpan span = ContextManager.activeSpan(); - span.errorOccurred(); - span.log(throwable); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java index 7e5f86e33f25..32750c74063f 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonConstructorInterceptor.java @@ -18,7 +18,6 @@ package org.apache.skywalking.apm.plugin.hessian.v4; -import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; @@ -33,10 +32,8 @@ public class HessianSkeletonConstructorInterceptor implements InstanceConstructo return; } - if (!Config.Plugin.Hessian.USE_URL_AS_OPERATION_NAME) { - Object service = allArguments[1]; - objInst.setSkyWalkingDynamicField(service); - } + Object service = allArguments[1]; + objInst.setSkyWalkingDynamicField(service); } } diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java index 873fafbcc5b2..c5a907baf08d 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java @@ -20,7 +20,6 @@ import com.caucho.hessian.io.AbstractHessianInput; import java.lang.reflect.Method; -import org.apache.skywalking.apm.agent.core.conf.Config; 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; @@ -57,13 +56,8 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr final ContextCarrier contextCarrier = new ContextCarrier(); - String operationName = null; - if (!Config.Plugin.Hessian.USE_URL_AS_OPERATION_NAME) { - Object realService = objInst.getSkyWalkingDynamicField(); - operationName = ((Class)realService).getName(); - } else { - operationName = ContextManager.activeSpan().getOperationName(); - } + Object realService = objInst.getSkyWalkingDynamicField(); + String operationName = ((Class)realService).getName(); AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier); diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianEnhanceCache.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianEnhanceCache.java index d9cec1b37656..35f10e62b075 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianEnhanceCache.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianEnhanceCache.java @@ -18,27 +18,22 @@ package org.apache.skywalking.apm.plugin.hessian.v4.define; -import java.net.URL; +import lombok.Getter; +import lombok.Setter; /** * cache field for EnhanceInstance, using for create Trace Spans. * * @author Alan Lau */ -public class HessianEnhanceCache { +public class HessianEnhanceCache { - private URL url; + @Getter + @Setter + private T t; - public HessianEnhanceCache(URL url) { - this.url = url; + public HessianEnhanceCache(T t) { + this.t = t; } - public URL getUrl() { - return url; - } - - public void setUrl(URL url) { - this.url = url; - } -} - +} \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianServiceExporterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianServiceExporterInstrumentation.java deleted file mode 100644 index fabc8db092fe..000000000000 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianServiceExporterInstrumentation.java +++ /dev/null @@ -1,65 +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.hessian.v4.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 static net.bytebuddy.matcher.ElementMatchers.named; -import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; -import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; -import static org.apache.skywalking.apm.plugin.hessian.v4.Constants.HESSIAN_SERVICE_EXPORTER_CLASS; -import static org.apache.skywalking.apm.plugin.hessian.v4.Constants.HESSIAN_SERVICE_EXPORTER_INCERCEPTOR; - -/** - * @author Alan Lau - */ -public class HessianServiceExporterInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return null; - } - - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named("handleRequest").and(takesArgumentWithType(0, "javax.servlet.http.HttpServletRequest")).and(takesArgumentWithType(1, "javax.servlet.http.HttpServletResponse")); - } - - @Override public String getMethodsInterceptor() { - return HESSIAN_SERVICE_EXPORTER_INCERCEPTOR; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - - }; - } - - @Override protected ClassMatch enhanceClass() { - return byName(HESSIAN_SERVICE_EXPORTER_CLASS); - } -} From 42eca6b4d5c82b980addb8fa26dc3748690b7193 Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Tue, 30 Jul 2019 10:16:52 +0800 Subject: [PATCH 25/29] Fix the style. --- .../plugin/hessian/v4/HessianProxySendRequestInterceptor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java index c921d772f9bb..3b5a42b96e51 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java @@ -64,10 +64,10 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr operateName = url.getPath(); span = ContextManager.createExitSpan(operateName, contextCarrier, String.format(":", url.getHost(), url.getPort())); Tags.URL.set(span, url.getPath()); - }else { + } else { Class clazz = (Class)cache.getT(); if (clazz == null) { - return ; + return; } operateName = clazz.getName(); span = ContextManager.createExitSpan(operateName, contextCarrier, String.format(":", url.getHost(), url.getPort())); From cceeccba217b6d945cb3ef8ce8e64e367eabf86a Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Tue, 30 Jul 2019 14:27:43 +0800 Subject: [PATCH 26/29] Remove lombok & fix ci. --- .../hessian-4.0.x-plugin/pom.xml | 6 ----- .../HessianProxyConstructorInterceptor.java | 12 ++++++++- .../HessianProxySendRequestInterceptor.java | 15 +++-------- .../v4/define/HessianEnhanceCache.java | 26 +++++++++++++------ .../v4/HessianAddHeaderInterceptorTest.java | 3 ++- ...essianProxySendRequestInterceptorTest.java | 7 ++++- 6 files changed, 40 insertions(+), 29 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml index 31d1b16d9bd4..a9d08225cc48 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/pom.xml @@ -42,12 +42,6 @@ provided - - org.projectlombok - lombok - 1.18.6 - - javax.servlet javax.servlet-api diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxyConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxyConstructorInterceptor.java index c9ed3870d998..55d8ec63988a 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxyConstructorInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxyConstructorInterceptor.java @@ -18,6 +18,7 @@ package org.apache.skywalking.apm.plugin.hessian.v4; +import java.net.URL; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; import org.apache.skywalking.apm.plugin.hessian.v4.define.HessianEnhanceCache; @@ -31,11 +32,20 @@ public class HessianProxyConstructorInterceptor implements InstanceConstructorIn @Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + if (allArguments.length < 3) { + return; + } + if (allArguments[0] == null) { return; } + + URL url = (URL)allArguments[0]; Class clazz = (Class)allArguments[2]; - objInst.setSkyWalkingDynamicField(new HessianEnhanceCache(clazz)); + HessianEnhanceCache cache = new HessianEnhanceCache(); + cache.setUrl(url); + cache.setObj(clazz); + objInst.setSkyWalkingDynamicField(cache); } } diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java index 3b5a42b96e51..2e9c97916f95 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptor.java @@ -47,15 +47,11 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr return; } - URL url = (URL)allArguments[0]; - if (url == null) { - return; - } - if (allArguments.length < 0) { return; } HessianEnhanceCache cache = (HessianEnhanceCache)objInst.getSkyWalkingDynamicField(); + URL url = cache.getUrl(); AbstractSpan span; final ContextCarrier contextCarrier = new ContextCarrier(); String operateName; @@ -65,11 +61,11 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr span = ContextManager.createExitSpan(operateName, contextCarrier, String.format(":", url.getHost(), url.getPort())); Tags.URL.set(span, url.getPath()); } else { - Class clazz = (Class)cache.getT(); + Object clazz = cache.getObj(); if (clazz == null) { return; } - operateName = clazz.getName(); + operateName = ((Class)clazz).getName(); span = ContextManager.createExitSpan(operateName, contextCarrier, String.format(":", url.getHost(), url.getPort())); Tags.URL.set(span, operateName); } @@ -87,11 +83,6 @@ public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allA return ret; } - URL url = (URL)allArguments[0]; - if (url == null) { - return ret; - } - if (allArguments.length < 0) { return ret; } diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianEnhanceCache.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianEnhanceCache.java index 35f10e62b075..32eeb7dd5eaa 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianEnhanceCache.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianEnhanceCache.java @@ -18,22 +18,32 @@ package org.apache.skywalking.apm.plugin.hessian.v4.define; -import lombok.Getter; -import lombok.Setter; +import java.net.URL; /** * cache field for EnhanceInstance, using for create Trace Spans. * * @author Alan Lau */ -public class HessianEnhanceCache { +public class HessianEnhanceCache { - @Getter - @Setter - private T t; + private Object obj; - public HessianEnhanceCache(T t) { - this.t = t; + private URL url; + + public Object getObj() { + return obj; + } + + public void setObj(Object obj) { + this.obj = obj; } + public URL getUrl() { + return url; + } + + public void setUrl(URL url) { + this.url = url; + } } \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianAddHeaderInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianAddHeaderInterceptorTest.java index 29f0f1e06b7a..255240c1d66e 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianAddHeaderInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianAddHeaderInterceptorTest.java @@ -94,7 +94,8 @@ public Object getSkyWalkingDynamicField() { public void setUp() throws Exception { interceptor = new HessianAddHeaderInterceptor(); PowerMockito.when(hessianProxy.getURL()).thenReturn(new URL("http://127.0.0.1:8080/TestHessian")); - HessianEnhanceCache cache = new HessianEnhanceCache(hessianProxy.getURL()); + HessianEnhanceCache cache = new HessianEnhanceCache(); + cache.setUrl(hessianProxy.getURL()); enhancedInstance.setSkyWalkingDynamicField(cache); HessianConnection huc = PowerMockito.mock(HessianURLConnection.class); diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptorTest.java index d848f37bb0a1..9274b4e3ac16 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptorTest.java @@ -67,6 +67,9 @@ public class HessianProxySendRequestInterceptorTest { @Mock private String methodName; + @Mock + private Object object; + private HessianProxySendRequestInterceptor interceptor; private HessianConnection hessianConnection; @@ -95,7 +98,9 @@ public Object getSkyWalkingDynamicField() { public void setUp() throws Exception { interceptor = new HessianProxySendRequestInterceptor(); PowerMockito.when(hessianProxy.getURL()).thenReturn(new URL("http://127.0.0.1:8080/TestHessian")); - HessianEnhanceCache cache = new HessianEnhanceCache(hessianProxy.getURL()); + HessianEnhanceCache cache = new HessianEnhanceCache(); + cache.setUrl(hessianProxy.getURL()); + cache.setObj(object); enhancedInstance.setSkyWalkingDynamicField(cache); HessianConnection huc = PowerMockito.mock(HessianURLConnection.class); From de6ca7efeced6a1ecc5e3ac6c6411b14d3fae225 Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Tue, 30 Jul 2019 16:25:56 +0800 Subject: [PATCH 27/29] Fix server side interceptor. --- .../plugin/hessian/v4/HessianSkeletonInterceptor.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java index c5a907baf08d..eca0e3f524ed 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java @@ -48,11 +48,7 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr return; } - if (argumentsTypes.length < 3) { - return; - } - - AbstractHessianInput in = (AbstractHessianInput)allArguments[1]; + AbstractHessianInput in = (AbstractHessianInput)allArguments[0]; final ContextCarrier contextCarrier = new ContextCarrier(); @@ -82,10 +78,6 @@ public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allA return ret; } - if (argumentsTypes.length < 3) { - return ret; - } - ContextManager.stopSpan(); return ret; From e64442641bdce45efcab003eb5658b83835b8e8f Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Wed, 31 Jul 2019 14:59:16 +0800 Subject: [PATCH 28/29] Fix ci. --- .../apm/plugin/hessian/v4/HessianSkeletonInterceptor.java | 2 +- .../hessian/v4/define/HessianSkeletonInstrumentation.java | 2 +- .../hessian/v4/HessianProxySendRequestInterceptorTest.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java index eca0e3f524ed..aaaaec8812e4 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianSkeletonInterceptor.java @@ -48,7 +48,7 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr return; } - AbstractHessianInput in = (AbstractHessianInput)allArguments[0]; + AbstractHessianInput in = (AbstractHessianInput)allArguments[1]; final ContextCarrier contextCarrier = new ContextCarrier(); diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java index bec18262ffa8..7bc035fbd002 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java @@ -59,7 +59,7 @@ public class HessianSkeletonInstrumentation extends ClassInstanceMethodsEnhanceP return new InstanceMethodsInterceptPoint[] { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named("invoke").and(takesArgumentWithType(0, "com.caucho.hessian.io.AbstractHessianInput")).and(takesArgumentWithType(1, "com.caucho.hessian.io.AbstractHessianOutput")); + return named("invoke").and(ElementMatchers.takesArguments(3)).and(takesArgumentWithType(1, "com.caucho.hessian.io.AbstractHessianInput")).and(takesArgumentWithType(2, "com.caucho.hessian.io.AbstractHessianOutput")); } @Override public String getMethodsInterceptor() { diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptorTest.java index 9274b4e3ac16..d45f84e17e71 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianProxySendRequestInterceptorTest.java @@ -67,8 +67,8 @@ public class HessianProxySendRequestInterceptorTest { @Mock private String methodName; - @Mock - private Object object; + + private Class object = new Object().getClass(); private HessianProxySendRequestInterceptor interceptor; From c75bb217411cf8a73b6ac152aba6ec41690fc681 Mon Sep 17 00:00:00 2001 From: liuweiyi Date: Wed, 31 Jul 2019 15:53:13 +0800 Subject: [PATCH 29/29] Move protecd to public to fix the ci. --- .../plugin/hessian/v4/define/HessianProxyInstrumentation.java | 4 ++-- .../hessian/v4/define/HessianSkeletonInstrumentation.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianProxyInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianProxyInstrumentation.java index 9dc8d719c32e..94f8e570f648 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianProxyInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianProxyInstrumentation.java @@ -40,7 +40,7 @@ */ public class HessianProxyInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + @Override public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { return new ConstructorInterceptPoint[] { new ConstructorInterceptPoint() { @@ -55,7 +55,7 @@ public class HessianProxyInstrumentation extends ClassInstanceMethodsEnhancePlug }; } - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + @Override public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[] { new InstanceMethodsInterceptPoint() { diff --git a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java index 7bc035fbd002..baaf599f5426 100644 --- a/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/define/HessianSkeletonInstrumentation.java @@ -40,7 +40,7 @@ */ public class HessianSkeletonInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + @Override public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { return new ConstructorInterceptPoint[] { new ConstructorInterceptPoint() { @@ -55,7 +55,7 @@ public class HessianSkeletonInstrumentation extends ClassInstanceMethodsEnhanceP }; } - @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + @Override public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[] { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() {