diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/conf/ConfigInitializer.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/conf/ConfigInitializer.java index 18f5bc61ebd4270078e5cd561b9129dc2f9e9bde..4ef806719739361c4709f19b6afa7dfa7e804326 100644 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/conf/ConfigInitializer.java +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/conf/ConfigInitializer.java @@ -26,7 +26,7 @@ public class ConfigInitializer { properties.load(inputStream); initNextLevel(properties, Config.class, new ConfigDesc()); AuthDesc.isAuth = Boolean.valueOf(System.getenv(AUTH_SYSTEM_ENV_NAME)); - logger.info("sky-walking auth check : " + AuthDesc.isAuth); + logger.info("sky-walking system-env auth : " + AuthDesc.isAuth); if(!AuthDesc.isAuth && AUTH_OVERRIDE){ AuthDesc.isAuth = AUTH_OVERRIDE; logger.info("sky-walking auth override: " + AuthDesc.isAuth); diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java index a4493cb10efbd4379fbca049dd5a043dbc4bb687..97e39e2bdca7ff28ee6985ee9fc6c0a20586fc83 100644 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java @@ -119,9 +119,16 @@ public class EnhanceClazz4Interceptor { MethodMatcher[] methodMatchers = define.getBeInterceptedMethodsMatchers(); ClassMethodInterceptor classMethodInterceptor = new ClassMethodInterceptor( interceptor); + + StringBuilder enhanceRules = new StringBuilder("\nprepare to enhance class [" + enhanceOriginClassName + "] as following rules:\n"); + int ruleIdx = 1; + for (MethodMatcher methodMatcher : methodMatchers) { + enhanceRules.append("\t" + ruleIdx++ + ". " + methodMatcher + "\n"); + } + logger.debug(enhanceRules); for (MethodMatcher methodMatcher : methodMatchers) { - logger.debug("prepare to enhance class {} {}", + logger.debug("enhance class {} by rule: {}", enhanceOriginClassName, methodMatcher); newClassBuilder = newClassBuilder.method( methodMatcher.builderMatcher()).intercept( diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/MethodMatcher.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/MethodMatcher.java index b9feacf62f22559cd643595adf721e10b8a4580f..1c85806dd5106540acba7065d213f49b29932a66 100644 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/MethodMatcher.java +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/MethodMatcher.java @@ -92,18 +92,24 @@ public abstract class MethodMatcher { @Override public String toString() { - StringBuilder stringBuilder = new StringBuilder(" the method named " + getMethodMatchDescribe()); + StringBuilder stringBuilder = new StringBuilder("method name=" + getMethodMatchDescribe()); if (getModifier() != null) { - stringBuilder.append(" with " + getModifier() + " modifier"); + stringBuilder.insert(0, getModifier() + " "); } if (getArgNum() > -1) { - stringBuilder.append("," + getArgNum() + " arguments"); + stringBuilder.append(", argnum=" + getArgNum()); } if (getArgTypeArray() != null) { - stringBuilder.append(",argument type are "); - for (Class argType : getArgTypeArray()) { + stringBuilder.append(", types of arguments are "); + boolean isFirst = true; + for (Class argType : getArgTypeArray()) { + if(isFirst){ + isFirst = false; + }else{ + stringBuilder.append(","); + } stringBuilder.append(argType.getName()); } } diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/MethodExclusiveMatcher.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/MethodExclusiveMatcher.java deleted file mode 100644 index 6a2ef1249423678d0ff0b7151b01530e489a5847..0000000000000000000000000000000000000000 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/MethodExclusiveMatcher.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.ai.cloud.skywalking.plugin.interceptor.matcher; - -import com.ai.cloud.skywalking.plugin.interceptor.MethodMatcher; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.not; - -public class MethodExclusiveMatcher extends MethodMatcher { - - public MethodExclusiveMatcher(String methodMatchDescribe) { - super(methodMatchDescribe); - } - - public MethodExclusiveMatcher(String methodMatchDescribe, int argNum) { - super(methodMatchDescribe, argNum); - } - - public MethodExclusiveMatcher(String methodMatchDescribe, Class[] argTypeArray) { - super(methodMatchDescribe, argTypeArray); - } - - public MethodExclusiveMatcher(Modifier modifier, String methodMatchDescribe) { - super(modifier, methodMatchDescribe); - } - - public MethodExclusiveMatcher(Modifier modifier, String methodMatchDescribe, int argNum) { - super(modifier, methodMatchDescribe, argNum); - } - - public MethodExclusiveMatcher(Modifier modifier, String methodMatchDescribe, Class[] argTypeArray) { - super(modifier, methodMatchDescribe, argTypeArray); - } - - @Override - public ElementMatcher.Junction builderMatcher() { - ElementMatcher.Junction matcher = named(getMethodMatchDescribe()); - return not(mergeArgumentsIfNecessary(matcher)); - } - - @Override - public String toString() { - StringBuilder stringBuilder = new StringBuilder("any method exclude "); - - stringBuilder.append(" method named " + getMethodMatchDescribe()); - - if (getModifier() != null) { - stringBuilder.append(getModifier()); - } - - if (getArgNum() > -1) { - stringBuilder.append(" with " + getArgNum() + " arguments"); - } - - if (getArgTypeArray() != null) { - stringBuilder.append(" with "); - for (Class argType : getArgTypeArray()) { - stringBuilder.append(argType.getName()); - } - } - - return stringBuilder.toString(); - } -} diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/MethodsExclusiveMatcher.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/MethodsExclusiveMatcher.java index f15b85b45b7c2ccd50f754b1b79fc35d2dc5cf22..d3bc20cebe0b28a578772816df8b466d0811e62b 100644 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/MethodsExclusiveMatcher.java +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/MethodsExclusiveMatcher.java @@ -18,14 +18,14 @@ public class MethodsExclusiveMatcher extends MethodMatcher { private List matchers = new ArrayList(); public MethodsExclusiveMatcher(String... methodNames) { - super("Exclusive method name: " + methodNames.toString()); + super("exclude method name: " + methodNames.toString()); for (String methodName : methodNames) { matchers.add(new SimpleMethodMatcher(methodName)); } } public MethodsExclusiveMatcher(MethodMatcher... matchers) { - super("Exclusive methods description :" + matchers.toString()); + super("exclude methods description :" + matchers.toString()); this.matchers.addAll(Arrays.asList(matchers)); } @@ -48,15 +48,10 @@ public class MethodsExclusiveMatcher extends MethodMatcher { @Override public String toString() { - StringBuilder stringBuilder = new StringBuilder("any method exclude the method(s) as follow:\n "); - int i = 0; + StringBuilder stringBuilder = new StringBuilder("exclude following method(s): "); + int idx = 1; for (MethodMatcher methodMatcher : matchers) { - if (i == 0) { - stringBuilder.append(methodMatcher.toString() + " or "); - i++; - } else { - stringBuilder.append(methodMatcher.toString()); - } + stringBuilder.append(idx++ + "." + methodMatcher.toString() + ". "); } return stringBuilder.toString(); diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/SimpleMethodMatcher.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/SimpleMethodMatcher.java index 612a48c1f20242e18ba0365909e992c580b59fd9..cf2496f095193d5fdc9e1cfc4a9a9c0261525e8a 100644 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/SimpleMethodMatcher.java +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/matcher/SimpleMethodMatcher.java @@ -1,11 +1,12 @@ package com.ai.cloud.skywalking.plugin.interceptor.matcher; +import static net.bytebuddy.matcher.ElementMatchers.named; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; -import static net.bytebuddy.matcher.ElementMatchers.named; +import com.ai.cloud.skywalking.plugin.interceptor.MethodMatcher; -public class SimpleMethodMatcher extends com.ai.cloud.skywalking.plugin.interceptor.MethodMatcher { +public class SimpleMethodMatcher extends MethodMatcher { public SimpleMethodMatcher(String methodName) { super(methodName); diff --git a/skywalking-api/src/test/java/test/ai/cloud/matcher/ExclusionMatcherTest.java b/skywalking-api/src/test/java/test/ai/cloud/matcher/ExclusionMatcherTest.java index 949dc0a911467bfcf65593059b3ec26f54447774..f22cd7cf096a047b2476c5712d603021cfccef6d 100644 --- a/skywalking-api/src/test/java/test/ai/cloud/matcher/ExclusionMatcherTest.java +++ b/skywalking-api/src/test/java/test/ai/cloud/matcher/ExclusionMatcherTest.java @@ -1,11 +1,12 @@ package test.ai.cloud.matcher; -import com.ai.cloud.skywalking.plugin.PluginBootstrap; +import junit.framework.TestCase; -public class ExclusionMatcherTest { +import com.ai.cloud.skywalking.plugin.PluginBootstrap; +public class ExclusionMatcherTest extends TestCase{ - public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException { + public void testMatcher() throws ClassNotFoundException, IllegalAccessException, InstantiationException { new PluginBootstrap().start(); TestMatcherClass testMatcherClass = (TestMatcherClass) Class.forName("test.ai.cloud.matcher.TestMatcherClass").newInstance(); diff --git a/skywalking-api/src/test/java/test/ai/cloud/matcher/TestMatcherDefine.java b/skywalking-api/src/test/java/test/ai/cloud/matcher/TestMatcherDefine.java index 90bad5df4dfd42810ad99a6c6189740241b142e2..332640cf22d1c81796bfb93d789ed6474acddefd 100644 --- a/skywalking-api/src/test/java/test/ai/cloud/matcher/TestMatcherDefine.java +++ b/skywalking-api/src/test/java/test/ai/cloud/matcher/TestMatcherDefine.java @@ -23,6 +23,10 @@ public class TestMatcherDefine implements InterceptorDefine { new MethodsExclusiveMatcher(new SimpleMethodMatcher("set"), new SimpleMethodMatcher(MethodMatcher.Modifier.Public,"get")), new SimpleMethodMatcher(MethodMatcher.Modifier.Private, "set", 1) }; + //return new MethodMatcher[] { new SimpleMethodMatcher(Modifier.Public, "printabc", new Class[]{String.class, String.class}) }; + //return new MethodMatcher[] { new PrivateMethodMatcher()}; + //return new MethodMatcher[]{new AnyMethodMatcher()}; + //return new MethodMatcher[]{new MethodsExclusiveMatcher(new SimpleMethodMatcher("set"), new SimpleMethodMatcher(MethodMatcher.Modifier.Public,"get"))}; } @Override diff --git a/skywalking-api/src/test/java/test/ai/cloud/plugin/PluginMainTest.java b/skywalking-api/src/test/java/test/ai/cloud/plugin/PluginMainTest.java index ed30c53be6ebc113f29f25f5b4cebe4226c7fb75..9cff3731f785538df7838f9ca21d776a37b79ba8 100644 --- a/skywalking-api/src/test/java/test/ai/cloud/plugin/PluginMainTest.java +++ b/skywalking-api/src/test/java/test/ai/cloud/plugin/PluginMainTest.java @@ -12,10 +12,9 @@ public class PluginMainTest { .main(new String[] { "test.ai.cloud.plugin.PluginMainTest" }); } - public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException { + public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { long start = System.currentTimeMillis(); - BeInterceptedClass inst = (BeInterceptedClass) Class.forName("test.ai.cloud.plugin.BeInterceptedClass").newInstance(); inst.printabc(); long end = System.currentTimeMillis(); diff --git a/skywalking-api/src/test/resources/skywalking-plugin.def b/skywalking-api/src/test/resources/skywalking-plugin.def index dcfaaef7dcf27cc83e0820744283a931db3d0e79..3f730e2d3f49c5ede79a4060efdc1392ad3e1c65 100644 --- a/skywalking-api/src/test/resources/skywalking-plugin.def +++ b/skywalking-api/src/test/resources/skywalking-plugin.def @@ -1 +1 @@ -test.ai.cloud.plugin.TestInterceptorDefine \ No newline at end of file +test.ai.cloud.matcher.TestMatcherDefine \ No newline at end of file