You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by zh...@apache.org on 2021/03/29 02:50:45 UTC

[skywalking] branch master updated: Remove the close_before_method and close_after_method parameters of custom-enhance-plugin to avoid memory leaks (#6632)

This is an automated email from the ASF dual-hosted git repository.

zhaoyuguang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git


The following commit(s) were added to refs/heads/master by this push:
     new 56bebb8  Remove the close_before_method and close_after_method parameters of custom-enhance-plugin to avoid memory leaks (#6632)
56bebb8 is described below

commit 56bebb8bafcdc4c0164ae3682c99a44d00312246
Author: liqiangz <li...@gmail.com>
AuthorDate: Mon Mar 29 10:50:27 2021 +0800

    Remove the close_before_method and close_after_method parameters of custom-enhance-plugin to avoid memory leaks (#6632)
    
    * Remove the close_before_method and close_after_method parameters of custom-enhance-plugin to avoid memory leaks
    
    * refine
    
    Co-authored-by: 吴晟 Wu Sheng <wu...@foxmail.com>
---
 CHANGES.md                                         |  1 +
 .../customize/conf/CustomizeConfiguration.java     | 16 -----
 .../plugin/customize/conf/MethodConfiguration.java | 16 -----
 .../apm/plugin/customize/constants/Constants.java  |  8 ---
 .../interceptor/BaseInterceptorMethods.java        | 72 ++++++++++------------
 5 files changed, 35 insertions(+), 78 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index a464a65..d5c1d81 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -25,6 +25,7 @@ Release Notes.
 * Support jedis pipeline in jedis-2.x-plugin.
 * Fix apm-toolkit-log4j-2.x-activation no trace Id in async log.
 * Replace hbase-1.x-plugin with hbase-1.x-2.x-plugin to adapt hbase client 2.x
+* Remove the close_before_method and close_after_method parameters of custom-enhance-plugin to avoid memory leaks.
 * Fix bug that springmvn-annotation-4.x-plugin, witness class does not exist in some versions.
 
 #### OAP-Backend
diff --git a/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/conf/CustomizeConfiguration.java b/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/conf/CustomizeConfiguration.java
index 2c1864b..ba48a92 100644
--- a/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/conf/CustomizeConfiguration.java
+++ b/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/conf/CustomizeConfiguration.java
@@ -172,22 +172,6 @@ public enum CustomizeConfiguration {
                             Constants.XML_ELEMENT_OPERATION_NAME)
                     .getNodeValue());
         }
-        if (methodDesc.getAttributes().getNamedItem(Constants.XML_ELEMENT_CLOSE_BEFORE_METHOD) != null) {
-            MethodConfiguration.setCloseBeforeMethod(configuration, Boolean.valueOf(methodDesc.getAttributes()
-                    .getNamedItem(
-                            Constants.XML_ELEMENT_CLOSE_BEFORE_METHOD)
-                    .getNodeValue()));
-        } else {
-            MethodConfiguration.setCloseBeforeMethod(configuration, false);
-        }
-        if (methodDesc.getAttributes().getNamedItem(Constants.XML_ELEMENT_CLOSE_AFTER_METHOD) != null) {
-            MethodConfiguration.setCloseAfterMethod(configuration, Boolean.valueOf(methodDesc.getAttributes()
-                    .getNamedItem(
-                            Constants.XML_ELEMENT_CLOSE_AFTER_METHOD)
-                    .getNodeValue()));
-        } else {
-            MethodConfiguration.setCloseAfterMethod(configuration, false);
-        }
         if (methodDesc.getAttributes().getNamedItem(Constants.XML_ELEMENT_METHOD_IS_STATIC) != null) {
             MethodConfiguration.setStatic(configuration, Boolean.valueOf(methodDesc.getAttributes()
                     .getNamedItem(
diff --git a/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/conf/MethodConfiguration.java b/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/conf/MethodConfiguration.java
index 89d544b..375672e 100644
--- a/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/conf/MethodConfiguration.java
+++ b/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/conf/MethodConfiguration.java
@@ -55,14 +55,6 @@ public class MethodConfiguration {
         configuration.put(Constants.CONFIGURATION_ATTRIBUTE_OPERATION_NAME, operationName);
     }
 
-    static void setCloseBeforeMethod(Map<String, Object> configuration, Boolean closeBeforeMethod) {
-        configuration.put(Constants.CONFIGURATION_ATTRIBUTE_CLOSE_BEFORE_METHOD, closeBeforeMethod);
-    }
-
-    static void setCloseAfterMethod(Map<String, Object> configuration, Boolean closeAfterMethod) {
-        configuration.put(Constants.CONFIGURATION_ATTRIBUTE_CLOSE_AFTER_METHOD, closeAfterMethod);
-    }
-
     static void setStatic(Map<String, Object> configuration, Boolean isStatic) {
         configuration.put(Constants.CONFIGURATION_ATTRIBUTE_IS_STATIC, isStatic);
     }
@@ -123,14 +115,6 @@ public class MethodConfiguration {
         return (String) configuration.get(Constants.CONFIGURATION_ATTRIBUTE_OPERATION_NAME);
     }
 
-    public static boolean isCloseBeforeMethod(Map<String, Object> configuration) {
-        return (Boolean) configuration.get(Constants.CONFIGURATION_ATTRIBUTE_CLOSE_BEFORE_METHOD);
-    }
-
-    public static boolean isCloseAfterMethod(Map<String, Object> configuration) {
-        return (Boolean) configuration.get(Constants.CONFIGURATION_ATTRIBUTE_CLOSE_AFTER_METHOD);
-    }
-
     @SuppressWarnings("unchecked")
     public static Map<String, String> getTags(Map<String, Object> configuration) {
         return (Map<String, String>) configuration.get(Constants.CONFIGURATION_ATTRIBUTE_TAGS);
diff --git a/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/constants/Constants.java b/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/constants/Constants.java
index b9f1863..87e5c87 100644
--- a/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/constants/Constants.java
+++ b/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/constants/Constants.java
@@ -42,10 +42,6 @@ public class Constants {
 
     public static final String XML_ELEMENT_OPERATION_NAME = "operation_name";
 
-    public static final String XML_ELEMENT_CLOSE_BEFORE_METHOD = "close_before_method";
-
-    public static final String XML_ELEMENT_CLOSE_AFTER_METHOD = "close_after_method";
-
     public static final String XML_ELEMENT_OPERATION_NAME_SUFFIX = "operation_name_suffix";
 
     public static final String XML_ELEMENT_TAG = "tag";
@@ -70,10 +66,6 @@ public class Constants {
 
     public static final String CONFIGURATION_ATTRIBUTE_OPERATION_NAME = "CONFIGURATION_ATTRIBUTE_OPERATION_NAME";
 
-    public static final String CONFIGURATION_ATTRIBUTE_CLOSE_BEFORE_METHOD = "CONFIGURATION_ATTRIBUTE_CLOSE_BEFORE_METHOD";
-
-    public static final String CONFIGURATION_ATTRIBUTE_CLOSE_AFTER_METHOD = "CONFIGURATION_ATTRIBUTE_CLOSE_AFTER_METHOD";
-
     public static final String CONFIGURATION_ATTRIBUTE_OPERATION_NAME_SUFFIXES = "CONFIGURATION_ATTRIBUTE_OPERATION_NAME_SUFFIXES";
 
     public static final String CONFIGURATION_ATTRIBUTE_TAGS = "CONFIGURATION_ATTRIBUTE_TAGS";
diff --git a/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/interceptor/BaseInterceptorMethods.java b/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/interceptor/BaseInterceptorMethods.java
index 1097663..dcef43e 100644
--- a/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/interceptor/BaseInterceptorMethods.java
+++ b/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/interceptor/BaseInterceptorMethods.java
@@ -35,56 +35,52 @@ class BaseInterceptorMethods {
 
     void beforeMethod(Method method, Object[] allArguments) {
         Map<String, Object> configuration = CustomizeConfiguration.INSTANCE.getConfiguration(method);
-        if (!MethodConfiguration.isCloseBeforeMethod(configuration)) {
-            String operationName = MethodConfiguration.getOperationName(configuration);
-            Map<String, Object> context = CustomizeExpression.evaluationContext(allArguments);
-            if (context == null || context.isEmpty()) {
-                ContextManager.createLocalSpan(operationName);
-            } else {
+        String operationName = MethodConfiguration.getOperationName(configuration);
+        Map<String, Object> context = CustomizeExpression.evaluationContext(allArguments);
+        if (context == null || context.isEmpty()) {
+            ContextManager.createLocalSpan(operationName);
+        } else {
 
-                Map<String, String> tags = MethodConfiguration.getTags(configuration);
-                Map<String, String> spanTags = new HashMap<String, String>();
-                Map<String, String> logs = MethodConfiguration.getLogs(configuration);
-                Map<String, String> spanLogs = new HashMap<String, String>();
+            Map<String, String> tags = MethodConfiguration.getTags(configuration);
+            Map<String, String> spanTags = new HashMap<String, String>();
+            Map<String, String> logs = MethodConfiguration.getLogs(configuration);
+            Map<String, String> spanLogs = new HashMap<String, String>();
 
-                List<String> operationNameSuffixes = MethodConfiguration.getOperationNameSuffixes(configuration);
-                StringBuilder operationNameSuffix = new StringBuilder();
-                if (operationNameSuffixes != null && !operationNameSuffixes.isEmpty()) {
-                    for (String expression : operationNameSuffixes) {
-                        operationNameSuffix.append(Constants.OPERATION_NAME_SEPARATOR);
-                        operationNameSuffix.append(CustomizeExpression.parseExpression(expression, context));
-                    }
+            List<String> operationNameSuffixes = MethodConfiguration.getOperationNameSuffixes(configuration);
+            StringBuilder operationNameSuffix = new StringBuilder();
+            if (operationNameSuffixes != null && !operationNameSuffixes.isEmpty()) {
+                for (String expression : operationNameSuffixes) {
+                    operationNameSuffix.append(Constants.OPERATION_NAME_SEPARATOR);
+                    operationNameSuffix.append(CustomizeExpression.parseExpression(expression, context));
                 }
-                if (tags != null && !tags.isEmpty()) {
-                    for (Map.Entry<String, String> expression: tags.entrySet()) {
-                        spanTags.put(expression.getKey(), CustomizeExpression.parseExpression(expression.getValue(), context));
-                    }
+            }
+            if (tags != null && !tags.isEmpty()) {
+                for (Map.Entry<String, String> expression : tags.entrySet()) {
+                    spanTags.put(expression.getKey(), CustomizeExpression.parseExpression(expression.getValue(), context));
                 }
-                if (logs != null && !logs.isEmpty()) {
-                    for (Map.Entry<String, String> entries : logs.entrySet()) {
-                        String expression = logs.get(entries.getKey());
-                        spanLogs.put(entries.getKey(), CustomizeExpression.parseExpression(expression, context));
-                    }
+            }
+            if (logs != null && !logs.isEmpty()) {
+                for (Map.Entry<String, String> entries : logs.entrySet()) {
+                    String expression = logs.get(entries.getKey());
+                    spanLogs.put(entries.getKey(), CustomizeExpression.parseExpression(expression, context));
                 }
-                operationName = operationNameSuffix.insert(0, operationName).toString();
+            }
+            operationName = operationNameSuffix.insert(0, operationName).toString();
 
-                AbstractSpan span = ContextManager.createLocalSpan(operationName);
-                if (!spanTags.isEmpty()) {
-                    for (Map.Entry<String, String> tag : spanTags.entrySet()) {
-                        span.tag(Tags.ofKey(tag.getKey()), tag.getValue());
-                    }
-                }
-                if (!spanLogs.isEmpty()) {
-                    span.log(System.currentTimeMillis(), spanLogs);
+            AbstractSpan span = ContextManager.createLocalSpan(operationName);
+            if (!spanTags.isEmpty()) {
+                for (Map.Entry<String, String> tag : spanTags.entrySet()) {
+                    span.tag(Tags.ofKey(tag.getKey()), tag.getValue());
                 }
             }
+            if (!spanLogs.isEmpty()) {
+                span.log(System.currentTimeMillis(), spanLogs);
+            }
         }
     }
 
     void afterMethod(Method method) {
-        if (!MethodConfiguration.isCloseAfterMethod(CustomizeConfiguration.INSTANCE.getConfiguration(method))) {
-            ContextManager.stopSpan();
-        }
+        ContextManager.stopSpan();
     }
 
     void handleMethodException(Throwable t) {