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.sheng@foxmail.com>
This commit is contained in:
parent
0047829b9f
commit
56bebb8baf
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue