wu-sheng commented on a change in pull request #6103:
URL: https://github.com/apache/skywalking/pull/6103#discussion_r549987577



##########
File path: 
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/AbstractClassEnhancePluginDefine.java
##########
@@ -104,6 +128,10 @@
         return new String[] {};
     }
 
+    protected List<WitnessMethod> witnessMethods() {
+        return Collections.emptyList();

Review comment:
       ```suggestion
           return null;
   ```
   Will be better performance.

##########
File path: 
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/AbstractClassEnhancePluginDefine.java
##########
@@ -70,6 +75,25 @@
                 }
             }
         }
+        List<WitnessMethod> witnessMethods = witnessMethods();
+        if (!CollectionUtil.isEmpty(witnessMethods)) {
+            for (WitnessMethod witnessMethod : witnessMethods) {
+                TypePool.Resolution resolution = 
WitnessClassFinder.INSTANCE.getResolution(witnessMethod.declaringClassName, 
classLoader);
+                if (!resolution.isResolved()) {
+                    LOGGER.warn("enhance class {} by plugin {} is not working. 
Because declaringClass {} of the witness method is not existed.", 
transformClassName, interceptorDefineClassName, 
witnessMethod.declaringClassName);
+                    return null;
+                }
+                boolean empty = resolution.resolve()
+                        .getDeclaredMethods()

Review comment:
       `getDeclaredMethods` doesn't include the inherited methods, right?

##########
File path: CHANGES.md
##########
@@ -22,6 +22,7 @@ Release Notes.
 * Fix DataCarrier's 
`org.apache.skywalking.apm.commons.datacarrier.buffer.Buffer` implementation 
isn't activated in `IF_POSSIBLE` mode.
 * Fix ArrayBlockingQueueBuffer's useless `IF_POSSIBLE` mode list
 * Support building gRPC TLS channel but CA file is not required.
+* Add witness method for plugin develop.

Review comment:
       ```suggestion
   * Add witness method mechanism in the agent plugin core.
   ```

##########
File path: 
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/AbstractClassEnhancePluginDefine.java
##########
@@ -70,6 +75,25 @@
                 }
             }
         }
+        List<WitnessMethod> witnessMethods = witnessMethods();

Review comment:
       This existing logic should move into the `WitnessClassFinder` from my 
understanding. And you should add UTs for WitnessClassFinder.

##########
File path: CHANGES.md
##########
@@ -22,6 +22,7 @@ Release Notes.
 * Fix DataCarrier's 
`org.apache.skywalking.apm.commons.datacarrier.buffer.Buffer` implementation 
isn't activated in `IF_POSSIBLE` mode.
 * Fix ArrayBlockingQueueBuffer's useless `IF_POSSIBLE` mode list
 * Support building gRPC TLS channel but CA file is not required.
+* Add witness method for plugin develop.

Review comment:
       The plugin development doc is required to update too.

##########
File path: 
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/AbstractClassEnhancePluginDefine.java
##########
@@ -70,6 +75,25 @@
                 }
             }
         }
+        List<WitnessMethod> witnessMethods = witnessMethods();
+        if (!CollectionUtil.isEmpty(witnessMethods)) {
+            for (WitnessMethod witnessMethod : witnessMethods) {
+                TypePool.Resolution resolution = 
WitnessClassFinder.INSTANCE.getResolution(witnessMethod.declaringClassName, 
classLoader);
+                if (!resolution.isResolved()) {
+                    LOGGER.warn("enhance class {} by plugin {} is not working. 
Because declaringClass {} of the witness method is not existed.", 
transformClassName, interceptorDefineClassName, 
witnessMethod.declaringClassName);
+                    return null;
+                }
+                boolean empty = resolution.resolve()
+                        .getDeclaredMethods()
+                        .filter(witnessMethod.elementMatcher)

Review comment:
       Please provide the `getElementMatcher()` method, don't access the fields 
of another class.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to