From fa99652d5b1e0e15dd4de5046db3de6c12c349f3 Mon Sep 17 00:00:00 2001 From: ascrutae Date: Sun, 25 Feb 2018 21:02:38 +0800 Subject: [PATCH 01/10] [Agent] Support hystrix plugin --- .../table/register/ServerTypeDefine.java | 3 +- .../trace/component/ComponentsDefine.java | 5 +- .../apm-sdk-plugin/hystrix-1.x-plugin/pom.xml | 24 +++++ .../hystrix/v1/EnhanceRequireObjectCache.java | 42 ++++++++ .../HystrixCommandConstructorInterceptor.java | 57 ++++++++++ .../hystrix/v1/HystrixPluginsInterceptor.java | 44 ++++++++ .../hystrix/v1/SWExecutionHookWrapper.java | 101 ++++++++++++++++++ .../define/HystrixCommandInstrumentation.java | 58 ++++++++++ .../define/HystrixPluginsInstrumentation.java | 65 +++++++++++ .../src/main/resources/skywalking-plugin.def | 2 + apm-sniffer/apm-sdk-plugin/pom.xml | 1 + 11 files changed, 400 insertions(+), 2 deletions(-) create mode 100644 apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/pom.xml create mode 100644 apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/EnhanceRequireObjectCache.java create mode 100644 apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandConstructorInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixPluginsInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/SWExecutionHookWrapper.java create mode 100644 apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixCommandInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixPluginsInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/resources/skywalking-plugin.def diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ServerTypeDefine.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ServerTypeDefine.java index 71e2ae346..61a91fb66 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ServerTypeDefine.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ServerTypeDefine.java @@ -32,7 +32,7 @@ public class ServerTypeDefine { private ServerType[] serverTypes; private ServerTypeDefine() { - this.serverTypes = new ServerType[29]; + this.serverTypes = new ServerType[30]; this.serverTypeNames = new String[11]; addServerType(new ServerType(ComponentsDefine.TOMCAT.getId(), Const.NONE, Const.EMPTY_STRING)); addServerType(new ServerType(ComponentsDefine.HTTPCLIENT.getId(), Const.NONE, Const.EMPTY_STRING)); @@ -62,6 +62,7 @@ public class ServerTypeDefine { addServerType(new ServerType(ComponentsDefine.HTTP_ASYNC_CLIENT.getId(), Const.NONE, Const.EMPTY_STRING)); addServerType(new ServerType(ComponentsDefine.KAFKA.getId(), 10, ComponentsDefine.KAFKA.getName())); addServerType(new ServerType(ComponentsDefine.SERVICECOMB.getId(), Const.NONE, ComponentsDefine.SERVICECOMB.getName())); + addServerType(new ServerType(ComponentsDefine.HYSTRIX.getId(), Const.NONE, ComponentsDefine.HYSTRIX.getName())); } public static ServerTypeDefine getInstance() { 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 fa6e9c24e..40bc356f3 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 @@ -82,6 +82,8 @@ public class ComponentsDefine { public static final OfficialComponent SERVICECOMB = new OfficialComponent(28, "ServiceComb"); + public static final OfficialComponent HYSTRIX = new OfficialComponent(29, "Hystrix"); + private static ComponentsDefine INSTANCE = new ComponentsDefine(); private String[] components; @@ -91,7 +93,7 @@ public class ComponentsDefine { } public ComponentsDefine() { - components = new String[29]; + components = new String[30]; addComponent(TOMCAT); addComponent(HTTPCLIENT); addComponent(DUBBO); @@ -120,6 +122,7 @@ public class ComponentsDefine { addComponent(HTTP_ASYNC_CLIENT); addComponent(KAFKA); addComponent(SERVICECOMB); + addComponent(HYSTRIX); } private void addComponent(OfficialComponent component) { diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/pom.xml new file mode 100644 index 000000000..bbc67f076 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/pom.xml @@ -0,0 +1,24 @@ + + + + apm-sdk-plugin + org.apache.skywalking + 5.0.0-alpha + + 4.0.0 + + apm-hystrix-1.x-plugin + + + + + com.netflix.hystrix + hystrix-core + 1.4.0 + provided + + + + \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/EnhanceRequireObjectCache.java b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/EnhanceRequireObjectCache.java new file mode 100644 index 000000000..e6724beb9 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/EnhanceRequireObjectCache.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.hystrix.v1; + +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; + +public class EnhanceRequireObjectCache { + private final String operationNamePrefix; + private ContextSnapshot contextSnapshot; + + public EnhanceRequireObjectCache(String prefix) { + operationNamePrefix = prefix; + } + + public String getOperationNamePrefix() { + return operationNamePrefix; + } + + public ContextSnapshot getContextSnapshot() { + return contextSnapshot; + } + + public void setContextSnapshot(ContextSnapshot contextSnapshot) { + this.contextSnapshot = contextSnapshot; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandConstructorInterceptor.java new file mode 100644 index 000000000..161fb2cb0 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandConstructorInterceptor.java @@ -0,0 +1,57 @@ +/* + * 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.hystrix.v1; + +import com.netflix.hystrix.HystrixCollapser; +import com.netflix.hystrix.HystrixCommand; +import com.netflix.hystrix.HystrixObservableCollapser; +import com.netflix.hystrix.HystrixObservableCommand; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; + +public class HystrixCommandConstructorInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + String identifyKey = ""; + + if (HystrixCommand.class.isAssignableFrom(objInst.getClass())) { + HystrixCommand hystrixCommand = (HystrixCommand)objInst; + identifyKey = hystrixCommand.getCommandKey().name(); + } + + if (HystrixCollapser.class.isAssignableFrom(objInst.getClass())) { + HystrixCollapser hystrixCommand = (HystrixCollapser)objInst; + identifyKey = hystrixCommand.getCollapserKey().name(); + } + + if (HystrixObservableCollapser.class.isAssignableFrom(objInst.getClass())) { + HystrixObservableCollapser hystrixCommand = (HystrixObservableCollapser)objInst; + identifyKey = hystrixCommand.getCollapserKey().name(); + } + + if (HystrixObservableCommand.class.isAssignableFrom(objInst.getClass())) { + HystrixObservableCommand hystrixCommand = (HystrixObservableCommand)objInst; + identifyKey = hystrixCommand.getCommandKey().name(); + } + + objInst.setSkyWalkingDynamicField(new EnhanceRequireObjectCache("Hystrix/" + identifyKey)); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixPluginsInterceptor.java b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixPluginsInterceptor.java new file mode 100644 index 000000000..91a9bf8a9 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixPluginsInterceptor.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.hystrix.v1; + +import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook; +import java.lang.reflect.Method; +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; + +public class HystrixPluginsInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + return new SWExecutionHookWrapper((HystrixCommandExecutionHook)ret); + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/SWExecutionHookWrapper.java b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/SWExecutionHookWrapper.java new file mode 100644 index 000000000..ec8c82407 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/SWExecutionHookWrapper.java @@ -0,0 +1,101 @@ +/* + * 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.hystrix.v1; + +import com.netflix.hystrix.HystrixInvokable; +import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; +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.network.trace.component.ComponentsDefine; + +public class SWExecutionHookWrapper extends HystrixCommandExecutionHook { + private final HystrixCommandExecutionHook actual; + + public SWExecutionHookWrapper(HystrixCommandExecutionHook actual) { + this.actual = actual; + } + + @Override + public void onStart(HystrixInvokable commandInstance) { + EnhancedInstance enhancedInstance = (EnhancedInstance)commandInstance; + EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache)enhancedInstance.getSkyWalkingDynamicField(); + enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture()); + actual.onStart(commandInstance); + } + + /** + * execution method + */ + + @Override public void onExecutionStart(HystrixInvokable commandInstance) { + // create a local span, and continued, The `execution method` running in other thread if the + // hystrix strategy is `THREAD`. + EnhancedInstance enhancedInstance = (EnhancedInstance)commandInstance; + EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache)enhancedInstance.getSkyWalkingDynamicField(); + ContextSnapshot snapshot = enhanceRequireObjectCache.getContextSnapshot(); + + AbstractSpan activeSpan = ContextManager.createLocalSpan(enhanceRequireObjectCache.getOperationNamePrefix() + "/Execution"); + activeSpan.setComponent(ComponentsDefine.HYSTRIX); + ContextManager.continued(snapshot); + actual.onExecutionStart(commandInstance); + + // Because of `fall back` method running in other thread. so we need capture concurrent span for tracing. + enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture()); + } + + @Override public Exception onExecutionError(HystrixInvokable commandInstance, Exception e) { + ContextManager.activeSpan().errorOccurred().log(e); + ContextManager.stopSpan(); + return actual.onExecutionError(commandInstance, e); + } + + @Override public void onExecutionSuccess(HystrixInvokable commandInstance) { + ContextManager.stopSpan(); + actual.onExecutionSuccess(commandInstance); + } + + /** + * Fallback + */ + + @Override public void onFallbackStart(HystrixInvokable commandInstance) { + EnhancedInstance enhancedInstance = (EnhancedInstance)commandInstance; + EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache)enhancedInstance.getSkyWalkingDynamicField(); + ContextSnapshot snapshot = enhanceRequireObjectCache.getContextSnapshot(); + + AbstractSpan activeSpan = ContextManager.createLocalSpan(enhanceRequireObjectCache.getOperationNamePrefix() + "/Fallback"); + activeSpan.setComponent(ComponentsDefine.HYSTRIX); + ContextManager.continued(snapshot); + + actual.onFallbackStart(commandInstance); + } + + @Override public Exception onFallbackError(HystrixInvokable commandInstance, Exception e) { + ContextManager.activeSpan().errorOccurred().log(e); + ContextManager.stopSpan(); + return actual.onFallbackError(commandInstance, e); + } + + @Override public void onFallbackSuccess(HystrixInvokable commandInstance) { + ContextManager.stopSpan(); + actual.onFallbackSuccess(commandInstance); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixCommandInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixCommandInstrumentation.java new file mode 100644 index 000000000..ade25d491 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixCommandInstrumentation.java @@ -0,0 +1,58 @@ +/* + * 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.hystrix.v1.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.any; +import static org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch; + +public class HystrixCommandInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.hystrix.v1.HystrixCommandConstructorInterceptor"; + public static final String ENHANCE_CLASS = "com.netflix.hystrix.HystrixCommand"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override public ElementMatcher getConstructorMatcher() { + return any(); + } + + @Override public String getConstructorInterceptor() { + return INTERCEPT_CLASS; + } + } + }; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[0]; + } + + @Override protected ClassMatch enhanceClass() { + return byHierarchyMatch(new String[] {ENHANCE_CLASS}); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixPluginsInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixPluginsInstrumentation.java new file mode 100644 index 000000000..0c59115d4 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixPluginsInstrumentation.java @@ -0,0 +1,65 @@ +/* + * 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.hystrix.v1.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +public class HystrixPluginsInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.hystrix.v1.HystrixPluginsInterceptor"; + public static final String ENHANCE_METHOD = "getCommandExecutionHook"; + public static final String ENHANCE_CLASS = "com.netflix.hystrix.strategy.HystrixPlugins"; + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_METHOD); + } + + @Override public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/resources/skywalking-plugin.def new file mode 100644 index 000000000..0c9c9c94f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/resources/skywalking-plugin.def @@ -0,0 +1,2 @@ +hystrix-1.x=org.apache.skywalking.apm.plugin.hystrix.v1.define.HystrixCommandInstrumentation +hystrix-1.x=org.apache.skywalking.apm.plugin.hystrix.v1.define.HystrixPluginsInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml index be0a02e80..9babd5c1d 100644 --- a/apm-sniffer/apm-sdk-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/pom.xml @@ -55,6 +55,7 @@ httpasyncclient-4.x-plugin kafka-v1-plugin servicecomb-plugin + hystrix-1.x-plugin pom From 65456716a3fbfabb2e78814f21a531c69b66e141 Mon Sep 17 00:00:00 2001 From: ascrutae Date: Sun, 25 Feb 2018 21:43:27 +0800 Subject: [PATCH 02/10] add comment --- .../apm/plugin/hystrix/v1/EnhanceRequireObjectCache.java | 6 ++++++ .../hystrix/v1/HystrixCommandConstructorInterceptor.java | 7 +++++++ .../apm/plugin/hystrix/v1/HystrixPluginsInterceptor.java | 8 +++++++- .../apm/plugin/hystrix/v1/SWExecutionHookWrapper.java | 5 +++++ .../hystrix/v1/define/HystrixCommandInstrumentation.java | 7 +++++++ .../hystrix/v1/define/HystrixPluginsInstrumentation.java | 7 +++++++ 6 files changed, 39 insertions(+), 1 deletion(-) diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/EnhanceRequireObjectCache.java b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/EnhanceRequireObjectCache.java index e6724beb9..2be967ede 100644 --- a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/EnhanceRequireObjectCache.java +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/EnhanceRequireObjectCache.java @@ -20,6 +20,12 @@ package org.apache.skywalking.apm.plugin.hystrix.v1; import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; +/** + * {@link EnhanceRequireObjectCache} record the prefix operation name of span and {@link ContextSnapshot} object for + * tracing. + * + * @author zhang xin + */ public class EnhanceRequireObjectCache { private final String operationNamePrefix; private ContextSnapshot contextSnapshot; diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandConstructorInterceptor.java index 161fb2cb0..a6f4ecd06 100644 --- a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandConstructorInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandConstructorInterceptor.java @@ -25,6 +25,13 @@ import com.netflix.hystrix.HystrixObservableCommand; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; +/** + * {@link HystrixCommandConstructorInterceptor} get CommandKey or CollapserKey as the + * operation name prefix of span when the constructor that the class hierarchy com.netflix.hystrix.HystrixCommand + * invoked. + * + * @author zhang xin + */ public class HystrixCommandConstructorInterceptor implements InstanceConstructorInterceptor { @Override diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixPluginsInterceptor.java b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixPluginsInterceptor.java index 91a9bf8a9..d29b62fd4 100644 --- a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixPluginsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixPluginsInterceptor.java @@ -18,17 +18,23 @@ package org.apache.skywalking.apm.plugin.hystrix.v1; +import com.netflix.hystrix.strategy.HystrixPlugins; import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook; import java.lang.reflect.Method; 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; +/** + * {@link HystrixPluginsInterceptor} wrapper the {@link HystrixCommandExecutionHook} object by using {@link + * SWExecutionHookWrapper} when the {@link HystrixPlugins#getCommandExecutionHook()} method invoked. + * + * @author zhang xin + */ public class HystrixPluginsInterceptor implements InstanceMethodsAroundInterceptor { @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - } @Override diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/SWExecutionHookWrapper.java b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/SWExecutionHookWrapper.java index ec8c82407..cc60c4ebd 100644 --- a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/SWExecutionHookWrapper.java +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/SWExecutionHookWrapper.java @@ -26,6 +26,11 @@ 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.network.trace.component.ComponentsDefine; +/** + * {@link SWExecutionHookWrapper} wrapper the HystrixCommandExecutionHook object for tracing. + * + * @author zhang xin + */ public class SWExecutionHookWrapper extends HystrixCommandExecutionHook { private final HystrixCommandExecutionHook actual; diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixCommandInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixCommandInstrumentation.java index ade25d491..54c2faf72 100644 --- a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixCommandInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixCommandInstrumentation.java @@ -28,6 +28,13 @@ import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import static net.bytebuddy.matcher.ElementMatchers.any; import static org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch; +/** + * {@link HystrixCommandInstrumentation} represent that the hystrix plugin intercept the constructor in the class that + * hierarchy {@link com.netflix.hystrix.HystrixCommand} class by using the {@link org.apache.skywalking.apm.plugin.hystrix.v1.HystrixCommandConstructorInterceptor} + * class. + * + * @author zhangxin + */ public class HystrixCommandInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.hystrix.v1.HystrixCommandConstructorInterceptor"; diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixPluginsInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixPluginsInstrumentation.java index 0c59115d4..e7b82a9de 100644 --- a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixPluginsInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixPluginsInstrumentation.java @@ -28,6 +28,13 @@ 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; +/** + * {@link HystrixPluginsInstrumentation} represent that the hystrix plugin intercept the + * getCommandExecutionHook method in the {@link com.netflix.hystrix.strategy.HystrixPlugins} class class by + * using the {@link org.apache.skywalking.apm.plugin.hystrix.v1.HystrixCommandConstructorInterceptor} class. + * + * @author zhangxin + */ public class HystrixPluginsInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.hystrix.v1.HystrixPluginsInterceptor"; From b4d58cd19bf6853d8d96d7c8abb88482a4832e15 Mon Sep 17 00:00:00 2001 From: ascrutae Date: Sun, 25 Feb 2018 23:15:14 +0800 Subject: [PATCH 03/10] Adjust variable name and remove some confuse comment --- .../HystrixCommandConstructorInterceptor.java | 32 ++++++++----------- .../hystrix/v1/SWExecutionHookWrapper.java | 26 +++++++-------- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandConstructorInterceptor.java index a6f4ecd06..e6f8aeb31 100644 --- a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandConstructorInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandConstructorInterceptor.java @@ -34,31 +34,27 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceC */ public class HystrixCommandConstructorInterceptor implements InstanceConstructorInterceptor { + public static final String OPERATION_NAME_PREFIX = "Hystrix/"; + @Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - String identifyKey = ""; + String commandIdentify = ""; if (HystrixCommand.class.isAssignableFrom(objInst.getClass())) { HystrixCommand hystrixCommand = (HystrixCommand)objInst; - identifyKey = hystrixCommand.getCommandKey().name(); + commandIdentify = hystrixCommand.getCommandKey().name(); + } else if (HystrixCollapser.class.isAssignableFrom(objInst.getClass())) { + HystrixCollapser hystrixCollapser = (HystrixCollapser)objInst; + commandIdentify = hystrixCollapser.getCollapserKey().name(); + } else if (HystrixObservableCollapser.class.isAssignableFrom(objInst.getClass())) { + HystrixObservableCollapser hystrixObservableCollapser = (HystrixObservableCollapser)objInst; + commandIdentify = hystrixObservableCollapser.getCollapserKey().name(); + } else if (HystrixObservableCommand.class.isAssignableFrom(objInst.getClass())) { + HystrixObservableCommand hystrixObservableCommand = (HystrixObservableCommand)objInst; + commandIdentify = hystrixObservableCommand.getCommandKey().name(); } - if (HystrixCollapser.class.isAssignableFrom(objInst.getClass())) { - HystrixCollapser hystrixCommand = (HystrixCollapser)objInst; - identifyKey = hystrixCommand.getCollapserKey().name(); - } - - if (HystrixObservableCollapser.class.isAssignableFrom(objInst.getClass())) { - HystrixObservableCollapser hystrixCommand = (HystrixObservableCollapser)objInst; - identifyKey = hystrixCommand.getCollapserKey().name(); - } - - if (HystrixObservableCommand.class.isAssignableFrom(objInst.getClass())) { - HystrixObservableCommand hystrixCommand = (HystrixObservableCommand)objInst; - identifyKey = hystrixCommand.getCommandKey().name(); - } - - objInst.setSkyWalkingDynamicField(new EnhanceRequireObjectCache("Hystrix/" + identifyKey)); + objInst.setSkyWalkingDynamicField(new EnhanceRequireObjectCache(OPERATION_NAME_PREFIX + commandIdentify)); } } diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/SWExecutionHookWrapper.java b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/SWExecutionHookWrapper.java index cc60c4ebd..dafba818a 100644 --- a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/SWExecutionHookWrapper.java +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/SWExecutionHookWrapper.java @@ -46,11 +46,8 @@ public class SWExecutionHookWrapper extends HystrixCommandExecutionHook { actual.onStart(commandInstance); } - /** - * execution method - */ - - @Override public void onExecutionStart(HystrixInvokable commandInstance) { + @Override + public void onExecutionStart(HystrixInvokable commandInstance) { // create a local span, and continued, The `execution method` running in other thread if the // hystrix strategy is `THREAD`. EnhancedInstance enhancedInstance = (EnhancedInstance)commandInstance; @@ -66,22 +63,21 @@ public class SWExecutionHookWrapper extends HystrixCommandExecutionHook { enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture()); } - @Override public Exception onExecutionError(HystrixInvokable commandInstance, Exception e) { + @Override + public Exception onExecutionError(HystrixInvokable commandInstance, Exception e) { ContextManager.activeSpan().errorOccurred().log(e); ContextManager.stopSpan(); return actual.onExecutionError(commandInstance, e); } - @Override public void onExecutionSuccess(HystrixInvokable commandInstance) { + @Override + public void onExecutionSuccess(HystrixInvokable commandInstance) { ContextManager.stopSpan(); actual.onExecutionSuccess(commandInstance); } - /** - * Fallback - */ - - @Override public void onFallbackStart(HystrixInvokable commandInstance) { + @Override + public void onFallbackStart(HystrixInvokable commandInstance) { EnhancedInstance enhancedInstance = (EnhancedInstance)commandInstance; EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache)enhancedInstance.getSkyWalkingDynamicField(); ContextSnapshot snapshot = enhanceRequireObjectCache.getContextSnapshot(); @@ -93,13 +89,15 @@ public class SWExecutionHookWrapper extends HystrixCommandExecutionHook { actual.onFallbackStart(commandInstance); } - @Override public Exception onFallbackError(HystrixInvokable commandInstance, Exception e) { + @Override + public Exception onFallbackError(HystrixInvokable commandInstance, Exception e) { ContextManager.activeSpan().errorOccurred().log(e); ContextManager.stopSpan(); return actual.onFallbackError(commandInstance, e); } - @Override public void onFallbackSuccess(HystrixInvokable commandInstance) { + @Override + public void onFallbackSuccess(HystrixInvokable commandInstance) { ContextManager.stopSpan(); actual.onFallbackSuccess(commandInstance); } From 107eaacfa7a08029a1c4e0577c856c5035b27eea Mon Sep 17 00:00:00 2001 From: ascrutae Date: Tue, 27 Feb 2018 00:23:33 +0800 Subject: [PATCH 04/10] Adjust hystrix plugin buried point --- .../HystrixCommandGetFallbackInterceptor.java | 53 +++++++ .../v1/HystrixCommandRunInterceptor.java | 57 ++++++++ .../hystrix/v1/SWExecutionHookWrapper.java | 134 ++++++++++++++---- .../define/HystrixCommandInstrumentation.java | 30 +++- 4 files changed, 244 insertions(+), 30 deletions(-) create mode 100644 apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandGetFallbackInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandRunInterceptor.java diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandGetFallbackInterceptor.java b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandGetFallbackInterceptor.java new file mode 100644 index 000000000..f935c77eb --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandGetFallbackInterceptor.java @@ -0,0 +1,53 @@ +/* + * 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.hystrix.v1; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; +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; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +public class HystrixCommandGetFallbackInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache)objInst.getSkyWalkingDynamicField(); + ContextSnapshot snapshot = enhanceRequireObjectCache.getContextSnapshot(); + + AbstractSpan activeSpan = ContextManager.createLocalSpan(enhanceRequireObjectCache.getOperationNamePrefix() + "/Fallback"); + activeSpan.setComponent(ComponentsDefine.HYSTRIX); + ContextManager.continued(snapshot); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandRunInterceptor.java b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandRunInterceptor.java new file mode 100644 index 000000000..c281f59f9 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixCommandRunInterceptor.java @@ -0,0 +1,57 @@ +/* + * 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.hystrix.v1; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; +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; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +public class HystrixCommandRunInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + // create a local span, and continued, The `execution method` running in other thread if the + // hystrix strategy is `THREAD`. + EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache)objInst.getSkyWalkingDynamicField(); + ContextSnapshot snapshot = enhanceRequireObjectCache.getContextSnapshot(); + + AbstractSpan activeSpan = ContextManager.createLocalSpan(enhanceRequireObjectCache.getOperationNamePrefix() + "/Execution"); + activeSpan.setComponent(ComponentsDefine.HYSTRIX); + ContextManager.continued(snapshot); + // Because of `fall back` method running in other thread. so we need capture concurrent span for tracing. + enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture()); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/SWExecutionHookWrapper.java b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/SWExecutionHookWrapper.java index dafba818a..eedc646cd 100644 --- a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/SWExecutionHookWrapper.java +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/SWExecutionHookWrapper.java @@ -18,13 +18,12 @@ package org.apache.skywalking.apm.plugin.hystrix.v1; +import com.netflix.hystrix.HystrixCommand; import com.netflix.hystrix.HystrixInvokable; +import com.netflix.hystrix.exception.HystrixRuntimeException; import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook; import org.apache.skywalking.apm.agent.core.context.ContextManager; -import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; -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.network.trace.component.ComponentsDefine; /** * {@link SWExecutionHookWrapper} wrapper the HystrixCommandExecutionHook object for tracing. @@ -48,57 +47,134 @@ public class SWExecutionHookWrapper extends HystrixCommandExecutionHook { @Override public void onExecutionStart(HystrixInvokable commandInstance) { - // create a local span, and continued, The `execution method` running in other thread if the - // hystrix strategy is `THREAD`. - EnhancedInstance enhancedInstance = (EnhancedInstance)commandInstance; - EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache)enhancedInstance.getSkyWalkingDynamicField(); - ContextSnapshot snapshot = enhanceRequireObjectCache.getContextSnapshot(); - - AbstractSpan activeSpan = ContextManager.createLocalSpan(enhanceRequireObjectCache.getOperationNamePrefix() + "/Execution"); - activeSpan.setComponent(ComponentsDefine.HYSTRIX); - ContextManager.continued(snapshot); actual.onExecutionStart(commandInstance); - - // Because of `fall back` method running in other thread. so we need capture concurrent span for tracing. - enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture()); } @Override public Exception onExecutionError(HystrixInvokable commandInstance, Exception e) { - ContextManager.activeSpan().errorOccurred().log(e); - ContextManager.stopSpan(); return actual.onExecutionError(commandInstance, e); } @Override public void onExecutionSuccess(HystrixInvokable commandInstance) { - ContextManager.stopSpan(); actual.onExecutionSuccess(commandInstance); } @Override public void onFallbackStart(HystrixInvokable commandInstance) { - EnhancedInstance enhancedInstance = (EnhancedInstance)commandInstance; - EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache)enhancedInstance.getSkyWalkingDynamicField(); - ContextSnapshot snapshot = enhanceRequireObjectCache.getContextSnapshot(); - - AbstractSpan activeSpan = ContextManager.createLocalSpan(enhanceRequireObjectCache.getOperationNamePrefix() + "/Fallback"); - activeSpan.setComponent(ComponentsDefine.HYSTRIX); - ContextManager.continued(snapshot); - actual.onFallbackStart(commandInstance); } @Override public Exception onFallbackError(HystrixInvokable commandInstance, Exception e) { - ContextManager.activeSpan().errorOccurred().log(e); - ContextManager.stopSpan(); return actual.onFallbackError(commandInstance, e); } @Override public void onFallbackSuccess(HystrixInvokable commandInstance) { - ContextManager.stopSpan(); actual.onFallbackSuccess(commandInstance); } + + @Override public Exception onRunError(HystrixInvokable commandInstance, Exception e) { + return actual.onRunError(commandInstance, e); + } + + @Override public Exception onRunError(HystrixCommand commandInstance, Exception e) { + return actual.onRunError(commandInstance, e); + } + + @Override + public Exception onError(HystrixInvokable commandInstance, HystrixRuntimeException.FailureType failureType, + Exception e) { + return actual.onError(commandInstance, failureType, e); + } + + @Override public void onSuccess(HystrixInvokable commandInstance) { + actual.onSuccess(commandInstance); + } + + @Override public T onEmit(HystrixInvokable commandInstance, T value) { + return actual.onEmit(commandInstance, value); + } + + @Override public T onExecutionEmit(HystrixInvokable commandInstance, T value) { + return actual.onExecutionEmit(commandInstance, value); + } + + @Override public T onFallbackEmit(HystrixInvokable commandInstance, T value) { + return actual.onFallbackEmit(commandInstance, value); + } + + @Override public void onCacheHit(HystrixInvokable commandInstance) { + actual.onCacheHit(commandInstance); + } + + @Override public void onThreadComplete(HystrixInvokable commandInstance) { + actual.onThreadComplete(commandInstance); + } + + @Override public void onThreadStart(HystrixInvokable commandInstance) { + actual.onThreadStart(commandInstance); + } + + @Override + public Exception onError(HystrixCommand commandInstance, HystrixRuntimeException.FailureType failureType, + Exception e) { + return actual.onError(commandInstance, failureType, e); + } + + @Override public Exception onFallbackError(HystrixCommand commandInstance, Exception e) { + return actual.onFallbackError(commandInstance, e); + } + + @Override public T onComplete(HystrixCommand commandInstance, T response) { + return actual.onComplete(commandInstance, response); + } + + @Override public T onComplete(HystrixInvokable commandInstance, T response) { + return actual.onComplete(commandInstance, response); + } + + @Override public T onFallbackSuccess(HystrixCommand commandInstance, T fallbackResponse) { + return actual.onFallbackSuccess(commandInstance, fallbackResponse); + } + + @Override public T onFallbackSuccess(HystrixInvokable commandInstance, T fallbackResponse) { + return actual.onFallbackSuccess(commandInstance, fallbackResponse); + } + + @Override public T onRunSuccess(HystrixCommand commandInstance, T response) { + return actual.onRunSuccess(commandInstance, response); + } + + @Override public T onRunSuccess(HystrixInvokable commandInstance, T response) { + return actual.onRunSuccess(commandInstance, response); + } + + @Override public void onFallbackStart(HystrixCommand commandInstance) { + actual.onFallbackStart(commandInstance); + } + + @Override public void onRunStart(HystrixCommand commandInstance) { + actual.onRunStart(commandInstance); + } + + @Override public void onRunStart(HystrixInvokable commandInstance) { + actual.onRunStart(commandInstance); + } + + @Override public void onStart(HystrixCommand commandInstance) { + EnhancedInstance enhancedInstance = (EnhancedInstance)commandInstance; + EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache)enhancedInstance.getSkyWalkingDynamicField(); + enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture()); + actual.onStart(commandInstance); + } + + @Override public void onThreadComplete(HystrixCommand commandInstance) { + actual.onThreadComplete(commandInstance); + } + + @Override public void onThreadStart(HystrixCommand commandInstance) { + actual.onThreadStart(commandInstance); + } } diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixCommandInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixCommandInstrumentation.java index 54c2faf72..fe23ef30d 100644 --- a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixCommandInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixCommandInstrumentation.java @@ -26,6 +26,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInst 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.HierarchyMatch.byHierarchyMatch; /** @@ -55,7 +56,34 @@ public class HystrixCommandInstrumentation extends ClassInstanceMethodsEnhancePl } @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[0]; + return new InstanceMethodsInterceptPoint[]{ + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("run"); + } + + @Override public String getMethodsInterceptor() { + return "org.apache.skywalking.apm.plugin.hystrix.v1.HystrixCommandRunInterceptor"; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("getFallback"); + } + + @Override public String getMethodsInterceptor() { + return "org.apache.skywalking.apm.plugin.hystrix.v1.HystrixCommandGetFallbackInterceptor"; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; } @Override protected ClassMatch enhanceClass() { From a1711f73903be8f604b3577e1fd4eae39d866fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=99=9F=20Wu=20Sheng?= Date: Tue, 27 Feb 2018 08:33:59 +0800 Subject: [PATCH 05/10] Update pom.xml --- apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/pom.xml index bbc67f076..bc7b8bedd 100644 --- a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/pom.xml @@ -5,7 +5,7 @@ apm-sdk-plugin org.apache.skywalking - 5.0.0-alpha + 5.0.0-alpha-SNAPSHOT 4.0.0 @@ -21,4 +21,4 @@ - \ No newline at end of file + From 64c48ea7a78375187e140620fec2c2994d9219dd Mon Sep 17 00:00:00 2001 From: ascrutae Date: Tue, 27 Feb 2018 11:32:17 +0800 Subject: [PATCH 06/10] remove javadoc --- .../hystrix/v1/define/HystrixCommandInstrumentation.java | 9 +-------- .../hystrix/v1/define/HystrixPluginsInstrumentation.java | 7 ------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixCommandInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixCommandInstrumentation.java index fe23ef30d..780db9359 100644 --- a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixCommandInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixCommandInstrumentation.java @@ -29,13 +29,6 @@ import static net.bytebuddy.matcher.ElementMatchers.any; import static net.bytebuddy.matcher.ElementMatchers.named; import static org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch; -/** - * {@link HystrixCommandInstrumentation} represent that the hystrix plugin intercept the constructor in the class that - * hierarchy {@link com.netflix.hystrix.HystrixCommand} class by using the {@link org.apache.skywalking.apm.plugin.hystrix.v1.HystrixCommandConstructorInterceptor} - * class. - * - * @author zhangxin - */ public class HystrixCommandInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.hystrix.v1.HystrixCommandConstructorInterceptor"; @@ -56,7 +49,7 @@ public class HystrixCommandInstrumentation extends ClassInstanceMethodsEnhancePl } @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[]{ + return new InstanceMethodsInterceptPoint[] { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { return named("run"); diff --git a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixPluginsInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixPluginsInstrumentation.java index e7b82a9de..0c59115d4 100644 --- a/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixPluginsInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/hystrix-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hystrix/v1/define/HystrixPluginsInstrumentation.java @@ -28,13 +28,6 @@ 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; -/** - * {@link HystrixPluginsInstrumentation} represent that the hystrix plugin intercept the - * getCommandExecutionHook method in the {@link com.netflix.hystrix.strategy.HystrixPlugins} class class by - * using the {@link org.apache.skywalking.apm.plugin.hystrix.v1.HystrixCommandConstructorInterceptor} class. - * - * @author zhangxin - */ public class HystrixPluginsInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.hystrix.v1.HystrixPluginsInterceptor"; From a3cb3e41307ccd4b53edd83720538c5a512bb7e2 Mon Sep 17 00:00:00 2001 From: ascrutae Date: Tue, 27 Feb 2018 11:51:12 +0800 Subject: [PATCH 07/10] add hystrix framework to support list --- docs/Supported-list.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/Supported-list.md b/docs/Supported-list.md index cf1e4a26e..17cb5fc63 100644 --- a/docs/Supported-list.md +++ b/docs/Supported-list.md @@ -47,6 +47,7 @@ * Scheduler * [Elastic Job](https://github.com/elasticjob/elastic-job) 2.x * OpenTracing community supported +* [Hystrix: Latency and Fault Tolerance for Distributed Systems](https://github.com/Netflix/Hystrix) 1.4.20 -> 1.5.12 ¹Required dependencies for these components must be first manually downloaded before being built, due to license incompatibilities. For this reason these components are not by default included in the SkyWalking releases. From b090cfaf37930cf9fa4467a9e723237e7e1e68fb Mon Sep 17 00:00:00 2001 From: ascrutae Date: Tue, 27 Feb 2018 11:57:49 +0800 Subject: [PATCH 08/10] Move Hystrix to Spring Ecosystem --- docs/Supported-list.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Supported-list.md b/docs/Supported-list.md index 17cb5fc63..d804e0aa9 100644 --- a/docs/Supported-list.md +++ b/docs/Supported-list.md @@ -44,10 +44,10 @@ * Spring Ecosystem * Spring Bean annotations(@Bean, @Service, @Component, @Repository) 3.x and 4.x (Optional²) * Spring Core Async SuccessCallback/FailureCallback/ListenableFutureCallback 4.x + * [Hystrix](https://github.com/Netflix/Hystrix) 1.4.20 -> 1.5.12 * Scheduler * [Elastic Job](https://github.com/elasticjob/elastic-job) 2.x * OpenTracing community supported -* [Hystrix: Latency and Fault Tolerance for Distributed Systems](https://github.com/Netflix/Hystrix) 1.4.20 -> 1.5.12 ¹Required dependencies for these components must be first manually downloaded before being built, due to license incompatibilities. For this reason these components are not by default included in the SkyWalking releases. From 66e3eb0765913be0c918686c6472fc50cc52e739 Mon Sep 17 00:00:00 2001 From: ascrutae Date: Tue, 27 Feb 2018 14:37:22 +0800 Subject: [PATCH 09/10] [Agent] fix some intercept package name about toolkit's class is incorrect --- .../log4j/v1/x/TraceIdPatternConverterActivation.java | 11 ++++++++--- .../log4j/v2/x/Log4j2OutputAppenderActivation.java | 11 ++++++++--- .../v1/x/LogbackPatternConverterActivation.java | 11 ++++++++--- .../log/logback/v1/x/mdc/MDCConverterActivation.java | 10 +++++++--- .../activation/trace/TraceContextActivation.java | 11 ++++++++--- 5 files changed, 39 insertions(+), 15 deletions(-) diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v1/x/TraceIdPatternConverterActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v1/x/TraceIdPatternConverterActivation.java index 4e13bd648..37a7246db 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v1/x/TraceIdPatternConverterActivation.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v1/x/TraceIdPatternConverterActivation.java @@ -38,12 +38,17 @@ import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName * @author wusheng */ public class TraceIdPatternConverterActivation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String ENHANCE_CLASS = "org.apache.skywalking.apm.toolkit.log.log4j.v1.x.TraceIdPatternConverter"; + public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.toolkit.activation.log.log4j.v1.x.PrintTraceIdInterceptor"; + public static final String ENHANCE_METHOD = "convert"; + /** * @return the target class, which needs active. */ @Override protected ClassMatch enhanceClass() { - return byName("TraceIdPatternConverter"); + return byName(ENHANCE_CLASS); } /** @@ -64,12 +69,12 @@ public class TraceIdPatternConverterActivation extends ClassInstanceMethodsEnhan new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named("convert"); + return named(ENHANCE_METHOD); } @Override public String getMethodsInterceptor() { - return "PrintTraceIdInterceptor"; + return INTERCEPT_CLASS; } @Override public boolean isOverrideArgs() { diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v2/x/Log4j2OutputAppenderActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v2/x/Log4j2OutputAppenderActivation.java index fc337bdf0..fcc98f638 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v2/x/Log4j2OutputAppenderActivation.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/log4j/v2/x/Log4j2OutputAppenderActivation.java @@ -37,12 +37,17 @@ import static net.bytebuddy.matcher.ElementMatchers.named; * @author wusheng */ public class Log4j2OutputAppenderActivation extends ClassStaticMethodsEnhancePluginDefine { + + public static final String ENHANCE_CLASS = "org.apache.skywalking.apm.toolkit.log.log4j.v2.x.Log4j2OutputAppender"; + public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.toolkit.activation.log.log4j.v2.x.PrintTraceIdInterceptor"; + public static final String ENHANCE_METHOD = "append"; + /** * @return the target class, which needs active. */ @Override protected ClassMatch enhanceClass() { - return NameMatch.byName("org.apache.skywalking.apm.toolkit.log.log4j.v2.x.Log4j2OutputAppender"); + return NameMatch.byName(ENHANCE_CLASS); } /** @@ -55,12 +60,12 @@ public class Log4j2OutputAppenderActivation extends ClassStaticMethodsEnhancePlu new StaticMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named("append"); + return named(ENHANCE_METHOD); } @Override public String getMethodsInterceptor() { - return "PrintTraceIdInterceptor"; + return INTERCEPT_CLASS; } @Override public boolean isOverrideArgs() { diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/LogbackPatternConverterActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/LogbackPatternConverterActivation.java index d3c599266..57c567369 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/LogbackPatternConverterActivation.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/LogbackPatternConverterActivation.java @@ -39,12 +39,17 @@ import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName * Created by wusheng on 2016/12/7. */ public class LogbackPatternConverterActivation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.toolkit.activation.log.logback.v1.x.PrintTraceIdInterceptor"; + public static final String ENHANCE_CLASS = "org.apache.skywalking.apm.toolkit.log.logback.v1.x.LogbackPatternConverter"; + public static final String ENHANCE_METHOD = "convert"; + /** * @return the target class, which needs active. */ @Override protected ClassMatch enhanceClass() { - return byName("org.apache.skywalking.apm.toolkit.log.logback.v1.x.LogbackPatternConverter"); + return byName(ENHANCE_CLASS); } /** @@ -65,12 +70,12 @@ public class LogbackPatternConverterActivation extends ClassInstanceMethodsEnhan new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named("convert"); + return named(ENHANCE_METHOD); } @Override public String getMethodsInterceptor() { - return "PrintTraceIdInterceptor"; + return INTERCEPT_CLASS; } @Override public boolean isOverrideArgs() { diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/mdc/MDCConverterActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/mdc/MDCConverterActivation.java index 202486bc9..dea164bab 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/mdc/MDCConverterActivation.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/log/logback/v1/x/mdc/MDCConverterActivation.java @@ -34,6 +34,10 @@ import static net.bytebuddy.matcher.ElementMatchers.named; */ public class MDCConverterActivation extends ClassInstanceMethodsEnhancePluginDefine { + public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.toolkit.activation.log.logback.v1.x.mdc.PrintMDCTraceIdInterceptor"; + public static final String ENHANCE_CLASS = "org.apache.skywalking.apm.toolkit.log.logback.v1.x.mdc.LogbackMDCPatternConverter"; + public static final String ENHANCE_METHOD = "convertTID"; + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { return null; @@ -45,12 +49,12 @@ public class MDCConverterActivation extends ClassInstanceMethodsEnhancePluginDef new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named("convertTID"); + return named(ENHANCE_METHOD); } @Override public String getMethodsInterceptor() { - return "PrintMDCTraceIdInterceptor"; + return INTERCEPT_CLASS; } @Override public boolean isOverrideArgs() { @@ -62,6 +66,6 @@ public class MDCConverterActivation extends ClassInstanceMethodsEnhancePluginDef @Override protected ClassMatch enhanceClass() { - return NameMatch.byName("org.apache.skywalking.apm.toolkit.log.logback.v1.x.mdc.LogbackMDCPatternConverter"); + return NameMatch.byName(ENHANCE_CLASS); } } diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceContextActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceContextActivation.java index 301424893..3d04f0914 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceContextActivation.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceContextActivation.java @@ -37,12 +37,17 @@ import static net.bytebuddy.matcher.ElementMatchers.named; * Created by xin on 2016/12/15. */ public class TraceContextActivation extends ClassStaticMethodsEnhancePluginDefine { + + public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.toolkit.activation.trace.TraceContextInterceptor"; + public static final String ENHANCE_CLASS = "org.apache.skywalking.apm.toolkit.trace.TraceContext"; + public static final String ENHANCE_METHOD = "traceId"; + /** * @return the target class, which needs active. */ @Override protected ClassMatch enhanceClass() { - return NameMatch.byName("TraceContext"); + return NameMatch.byName(ENHANCE_CLASS); } /** @@ -55,12 +60,12 @@ public class TraceContextActivation extends ClassStaticMethodsEnhancePluginDefin new StaticMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named("traceId"); + return named(ENHANCE_METHOD); } @Override public String getMethodsInterceptor() { - return "TraceContextInterceptor"; + return INTERCEPT_CLASS; } @Override public boolean isOverrideArgs() { From fe587c8f297b7f0c02f6390bcce12d0d284a4bdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=99=9F=20Wu=20Sheng?= Date: Tue, 27 Feb 2018 15:52:31 +0800 Subject: [PATCH 10/10] Update Supported-list.md --- docs/Supported-list.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Supported-list.md b/docs/Supported-list.md index d804e0aa9..e0db31239 100644 --- a/docs/Supported-list.md +++ b/docs/Supported-list.md @@ -44,7 +44,7 @@ * Spring Ecosystem * Spring Bean annotations(@Bean, @Service, @Component, @Repository) 3.x and 4.x (Optional²) * Spring Core Async SuccessCallback/FailureCallback/ListenableFutureCallback 4.x - * [Hystrix](https://github.com/Netflix/Hystrix) 1.4.20 -> 1.5.12 +* [Hystrix: Latency and Fault Tolerance for Distributed Systems](https://github.com/Netflix/Hystrix) 1.4.20 -> 1.5.12 * Scheduler * [Elastic Job](https://github.com/elasticjob/elastic-job) 2.x * OpenTracing community supported