This is an automated email from the ASF dual-hosted git repository.
sunnianjun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new ee98d500ca8 Agent: Optimize PluginBootService startup (#23113)
ee98d500ca8 is described below
commit ee98d500ca881a01641dc4b74999ef8df282498c
Author: jiangML <[email protected]>
AuthorDate: Thu Dec 29 10:58:02 2022 +0800
Agent: Optimize PluginBootService startup (#23113)
* Optimize plugin startup
* add MetaDataContextsFactoryAdvice for metric
* Adjust JDBCBackendTransactionManager to BackendTransactionManager
* fix it error
* add blank line
* Optimize field names
* optimize code
* remove logback.xml from agent distribution
* fix error of advisor config load
* optimize code
* format code
---
.../agent/bootstrap/ShardingSphereAgent.java | 14 +---
.../ClassLoaderContext.java} | 33 +++++----
.../plugin/loader/AdvisorConfigurationLoader.java | 36 ++++++----
.../bootstrap/spi/PluginBootServiceRegistry.java | 16 -----
.../bootstrap/transformer/AgentTransformer.java | 25 +++++--
.../transformer/builder/advise/AdviceFactory.java | 29 ++++----
.../builder/advise/JDBCAdviceFactory.java | 82 ----------------------
.../shardingsphere-agent-binary-distribution.xml | 9 ---
agent/distribution/src/main/resources/logback.xml | 33 ---------
.../core/advice/MetaDataContextsFactoryAdvice.java | 26 +++++++
.../main/resources/prometheus/jdbc-advisors.yaml | 10 +++
.../main/resources/prometheus/proxy-advisors.yaml | 10 ++-
12 files changed, 118 insertions(+), 205 deletions(-)
diff --git
a/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java
b/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java
index b66c594c74e..a7ad053a11d 100644
---
a/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java
+++
b/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java
@@ -23,17 +23,15 @@ import net.bytebuddy.ByteBuddy;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.dynamic.scaffold.TypeValidation;
import net.bytebuddy.matcher.ElementMatchers;
-import org.apache.shardingsphere.agent.config.advisor.AdvisorConfiguration;
-import org.apache.shardingsphere.agent.config.plugin.PluginConfiguration;
-import org.apache.shardingsphere.agent.bootstrap.classloader.AgentClassLoader;
import
org.apache.shardingsphere.agent.bootstrap.config.loader.PluginConfigurationLoader;
import org.apache.shardingsphere.agent.bootstrap.logging.LoggingListener;
-import
org.apache.shardingsphere.agent.bootstrap.plugin.PluginBootServiceManager;
import org.apache.shardingsphere.agent.bootstrap.plugin.PluginJar;
import
org.apache.shardingsphere.agent.bootstrap.plugin.loader.AdvisorConfigurationLoader;
import
org.apache.shardingsphere.agent.bootstrap.plugin.loader.AgentPluginLoader;
import org.apache.shardingsphere.agent.bootstrap.transformer.AgentJunction;
import org.apache.shardingsphere.agent.bootstrap.transformer.AgentTransformer;
+import org.apache.shardingsphere.agent.config.advisor.AdvisorConfiguration;
+import org.apache.shardingsphere.agent.config.plugin.PluginConfiguration;
import java.io.IOException;
import java.lang.instrument.Instrumentation;
@@ -59,9 +57,6 @@ public final class ShardingSphereAgent {
Collection<PluginJar> pluginJars = AgentPluginLoader.load();
Map<String, AdvisorConfiguration> advisorConfigs =
AdvisorConfigurationLoader.load(pluginJars, pluginConfigs.keySet(),
isEnhancedForProxy);
setUpAgentBuilder(instrumentation, pluginConfigs, pluginJars,
advisorConfigs, isEnhancedForProxy);
- if (isEnhancedForProxy) {
- setupPluginBootService(pluginConfigs, pluginJars);
- }
}
private static boolean isEnhancedForProxy() {
@@ -83,9 +78,4 @@ public final class ShardingSphereAgent {
.with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
.with(new LoggingListener()).installOn(instrumentation);
}
-
- private static void setupPluginBootService(final Map<String,
PluginConfiguration> pluginConfigs, final Collection<PluginJar> pluginJars) {
- PluginBootServiceManager.startAllServices(pluginConfigs,
AgentClassLoader.getClassLoader(), true);
- Runtime.getRuntime().addShutdownHook(new Thread(() ->
PluginBootServiceManager.closeAllServices(pluginJars)));
- }
}
diff --git
a/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/transformer/builder/advise/ProxyAdviceFactory.java
b/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/classloader/ClassLoaderContext.java
similarity index 51%
rename from
agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/transformer/builder/advise/ProxyAdviceFactory.java
rename to
agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/classloader/ClassLoaderContext.java
index 59223762d95..12b18c806c2 100644
---
a/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/transformer/builder/advise/ProxyAdviceFactory.java
+++
b/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/classloader/ClassLoaderContext.java
@@ -15,36 +15,35 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.bootstrap.transformer.builder.advise;
+package org.apache.shardingsphere.agent.bootstrap.classloader;
+import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import lombok.SneakyThrows;
-import org.apache.shardingsphere.agent.advice.AgentAdvice;
-import org.apache.shardingsphere.agent.bootstrap.classloader.AgentClassLoader;
+import org.apache.shardingsphere.agent.bootstrap.plugin.PluginJar;
+import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
- * Proxy Advice factory.
+ * Class loader context.
*/
@RequiredArgsConstructor
-public final class ProxyAdviceFactory {
+@Getter
+public final class ClassLoaderContext {
- private static final Map<String, AgentAdvice> CACHED_ADVICES = new
ConcurrentHashMap<>();
+ private static final Map<ClassLoader, AgentClassLoader>
AGENT_CLASS_LOADERS = new ConcurrentHashMap<>();
+
+ private final ClassLoader appClassLoader;
+
+ private final Collection<PluginJar> pluginJars;
/**
- * Get advice.
+ * Get agent class loader.
*
- * @param adviceClassName advice class name
- * @return got advance
+ * @return agent class loader
*/
- public AgentAdvice getAdvice(final String adviceClassName) {
- return CACHED_ADVICES.computeIfAbsent(adviceClassName,
this::createAdviceForProxy);
- }
-
- @SneakyThrows(ReflectiveOperationException.class)
- private AgentAdvice createAdviceForProxy(final String adviceClassName) {
- return (AgentAdvice) Class.forName(adviceClassName, true,
AgentClassLoader.getClassLoader()).getDeclaredConstructor().newInstance();
+ public AgentClassLoader getAgentClassLoader() {
+ return AGENT_CLASS_LOADERS.computeIfAbsent(appClassLoader, key -> new
AgentClassLoader(key, pluginJars));
}
}
diff --git
a/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/plugin/loader/AdvisorConfigurationLoader.java
b/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/plugin/loader/AdvisorConfigurationLoader.java
index abd2e1a4a3e..2f70121bc18 100644
---
a/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/plugin/loader/AdvisorConfigurationLoader.java
+++
b/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/plugin/loader/AdvisorConfigurationLoader.java
@@ -21,19 +21,17 @@ import com.google.common.collect.ImmutableMap;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.agent.bootstrap.classloader.AgentClassLoader;
+import org.apache.shardingsphere.agent.bootstrap.logging.LoggerFactory;
+import org.apache.shardingsphere.agent.bootstrap.logging.LoggerFactory.Logger;
import org.apache.shardingsphere.agent.bootstrap.plugin.PluginJar;
import
org.apache.shardingsphere.agent.bootstrap.plugin.yaml.loader.YamlAdvisorsConfigurationLoader;
import
org.apache.shardingsphere.agent.bootstrap.plugin.yaml.swapper.YamlAdvisorsConfigurationSwapper;
-import org.apache.shardingsphere.agent.bootstrap.spi.PluginBootServiceRegistry;
import org.apache.shardingsphere.agent.config.advisor.AdvisorConfiguration;
-import org.apache.shardingsphere.agent.spi.PluginBootService;
import java.io.InputStream;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-import java.util.function.Function;
-import java.util.stream.Collectors;
/**
* Advisor configuration loader.
@@ -41,6 +39,8 @@ import java.util.stream.Collectors;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class AdvisorConfigurationLoader {
+ private static final Logger LOGGER =
LoggerFactory.getLogger(AgentPluginLoader.class);
+
/**
* Load advisor configurations.
*
@@ -52,22 +52,30 @@ public final class AdvisorConfigurationLoader {
public static Map<String, AdvisorConfiguration> load(final
Collection<PluginJar> pluginJars, final Collection<String> pluginTypes, final
boolean isEnhancedForProxy) {
Map<String, AdvisorConfiguration> result = new HashMap<>();
AgentClassLoader.init(pluginJars);
- for (PluginBootService each :
PluginBootServiceRegistry.newInstances(AgentClassLoader.getClassLoader())) {
- if (pluginTypes.contains(each.getType())) {
- Collection<AdvisorConfiguration> advisorConfigs =
YamlAdvisorsConfigurationSwapper
-
.swapToObject(YamlAdvisorsConfigurationLoader.load(getAdvisorsResourceStream(each,
isEnhancedForProxy)), each.getType());
-
result.putAll(advisorConfigs.stream().collect(Collectors.toMap(AdvisorConfiguration::getTargetClassName,
Function.identity())));
+ for (String each : pluginTypes) {
+ InputStream advisorsResourceStream =
getAdvisorsResourceStream(each, isEnhancedForProxy);
+ if (null == advisorsResourceStream) {
+ LOGGER.error("No configuration of advisor for type `{}`",
each);
+ continue;
}
+ Collection<AdvisorConfiguration> advisorConfigs =
YamlAdvisorsConfigurationSwapper.swapToObject(YamlAdvisorsConfigurationLoader.load(advisorsResourceStream),
each);
+ mergeAdvisorConfigurations(result, advisorConfigs);
}
return ImmutableMap.<String,
AdvisorConfiguration>builder().putAll(result).build();
}
- private static InputStream getAdvisorsResourceStream(final
PluginBootService pluginBootService, final boolean isEnhancedForProxy) {
- InputStream result =
pluginBootService.getClass().getResourceAsStream(getAdvisorsResourceFile(pluginBootService,
(isEnhancedForProxy ? "proxy" : "jdbc") + "-advisors.yaml"));
- return null == result ?
pluginBootService.getClass().getResourceAsStream(getAdvisorsResourceFile(pluginBootService,
"advisors.yaml")) : result;
+ private static InputStream getAdvisorsResourceStream(final String type,
final boolean isEnhancedForProxy) {
+ InputStream result =
AgentClassLoader.getClassLoader().getResourceAsStream(getAdvisorsResourceFile(type,
(isEnhancedForProxy ? "proxy" : "jdbc") + "-advisors.yaml"));
+ return null == result ?
AgentClassLoader.getClassLoader().getResourceAsStream(getAdvisorsResourceFile(type,
"advisors.yaml")) : result;
+ }
+
+ private static String getAdvisorsResourceFile(final String type, final
String fileName) {
+ return String.join("/", type.toLowerCase(), fileName);
}
- private static String getAdvisorsResourceFile(final PluginBootService
pluginBootService, final String fileName) {
- return String.join("/", "", pluginBootService.getType().toLowerCase(),
fileName);
+ private static void mergeAdvisorConfigurations(final Map<String,
AdvisorConfiguration> advisorConfigMap, final Collection<AdvisorConfiguration>
advisorConfigs) {
+ for (AdvisorConfiguration each : advisorConfigs) {
+ advisorConfigMap.computeIfAbsent(each.getTargetClassName(), key ->
new
AdvisorConfiguration(each.getTargetClassName())).getAdvisors().addAll(each.getAdvisors());
+ }
}
}
diff --git
a/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/spi/PluginBootServiceRegistry.java
b/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/spi/PluginBootServiceRegistry.java
index 90f7fb2f274..46ab5508c8d 100644
---
a/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/spi/PluginBootServiceRegistry.java
+++
b/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/spi/PluginBootServiceRegistry.java
@@ -22,9 +22,7 @@ import lombok.NoArgsConstructor;
import org.apache.shardingsphere.agent.spi.PluginBootService;
import java.util.Collection;
-import java.util.LinkedList;
import java.util.Optional;
-import java.util.ServiceLoader;
/**
* Plugin boot service registry.
@@ -50,18 +48,4 @@ public final class PluginBootServiceRegistry {
public static Collection<PluginBootService> getAllRegisteredServices() {
return
AgentServiceLoader.getServiceLoader(PluginBootService.class).getServices();
}
-
- /**
- * Create new instances.
- *
- * @param classLoader class loader
- * @return created instances
- */
- public static Collection<PluginBootService> newInstances(final ClassLoader
classLoader) {
- Collection<PluginBootService> result = new LinkedList<>();
- for (PluginBootService each :
ServiceLoader.load(PluginBootService.class, classLoader)) {
- result.add(each);
- }
- return result;
- }
}
diff --git
a/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/transformer/AgentTransformer.java
b/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/transformer/AgentTransformer.java
index 7eea7ec2749..f50a579e1a2 100644
---
a/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/transformer/AgentTransformer.java
+++
b/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/transformer/AgentTransformer.java
@@ -25,14 +25,17 @@ import net.bytebuddy.implementation.FieldAccessor;
import net.bytebuddy.jar.asm.Opcodes;
import net.bytebuddy.utility.JavaModule;
import org.apache.shardingsphere.agent.advice.TargetAdviceObject;
+import
org.apache.shardingsphere.agent.bootstrap.classloader.ClassLoaderContext;
+import
org.apache.shardingsphere.agent.bootstrap.plugin.PluginBootServiceManager;
import org.apache.shardingsphere.agent.bootstrap.plugin.PluginJar;
-import org.apache.shardingsphere.agent.config.advisor.AdvisorConfiguration;
-import org.apache.shardingsphere.agent.config.plugin.PluginConfiguration;
import
org.apache.shardingsphere.agent.bootstrap.transformer.builder.MethodAdvisorBuilder;
import
org.apache.shardingsphere.agent.bootstrap.transformer.builder.advise.AdviceFactory;
+import org.apache.shardingsphere.agent.config.advisor.AdvisorConfiguration;
+import org.apache.shardingsphere.agent.config.plugin.PluginConfiguration;
import java.util.Collection;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
/**
* Agent transformer.
@@ -42,6 +45,8 @@ public final class AgentTransformer implements Transformer {
private static final String EXTRA_DATA = "_$EXTRA_DATA$_";
+ private static final AtomicBoolean STARTED_FLAG = new AtomicBoolean(false);
+
private final Map<String, PluginConfiguration> pluginConfigs;
private final Collection<PluginJar> pluginJars;
@@ -56,10 +61,16 @@ public final class AgentTransformer implements Transformer {
if (!advisorConfigs.containsKey(typeDescription.getTypeName())) {
return builder;
}
- Builder<?> result = builder.defineField(EXTRA_DATA, Object.class,
Opcodes.ACC_PRIVATE |
Opcodes.ACC_VOLATILE).implement(TargetAdviceObject.class).intercept(FieldAccessor.ofField(EXTRA_DATA));
- AdviceFactory adviceFactory = new AdviceFactory(classLoader,
pluginConfigs, pluginJars, isEnhancedForProxy);
- AdvisorConfiguration advisorConfig =
advisorConfigs.get(typeDescription.getTypeName());
- result = new MethodAdvisorBuilder(adviceFactory, advisorConfig,
typeDescription).build(result);
- return result;
+ ClassLoaderContext classLoaderContext = new
ClassLoaderContext(classLoader, pluginJars);
+ startAllServices(classLoaderContext.getAgentClassLoader());
+ return new MethodAdvisorBuilder(new AdviceFactory(classLoaderContext),
advisorConfigs.get(typeDescription.getTypeName()), typeDescription)
+ .build(builder.defineField(EXTRA_DATA, Object.class,
Opcodes.ACC_PRIVATE |
Opcodes.ACC_VOLATILE).implement(TargetAdviceObject.class).intercept(FieldAccessor.ofField(EXTRA_DATA)));
+ }
+
+ private void startAllServices(final ClassLoader classLoader) {
+ if (STARTED_FLAG.compareAndSet(false, true)) {
+ PluginBootServiceManager.startAllServices(pluginConfigs,
classLoader, isEnhancedForProxy);
+ Runtime.getRuntime().addShutdownHook(new Thread(() ->
PluginBootServiceManager.closeAllServices(pluginJars)));
+ }
}
}
diff --git
a/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/transformer/builder/advise/AdviceFactory.java
b/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/transformer/builder/advise/AdviceFactory.java
index a0ece22914b..f5cdcbdc0cf 100644
---
a/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/transformer/builder/advise/AdviceFactory.java
+++
b/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/transformer/builder/advise/AdviceFactory.java
@@ -17,29 +17,23 @@
package org.apache.shardingsphere.agent.bootstrap.transformer.builder.advise;
+import lombok.RequiredArgsConstructor;
+import lombok.SneakyThrows;
import org.apache.shardingsphere.agent.advice.AgentAdvice;
-import org.apache.shardingsphere.agent.bootstrap.plugin.PluginJar;
-import org.apache.shardingsphere.agent.config.plugin.PluginConfiguration;
+import
org.apache.shardingsphere.agent.bootstrap.classloader.ClassLoaderContext;
-import java.util.Collection;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
/**
* Advice factory.
*/
+@RequiredArgsConstructor
public final class AdviceFactory {
- private final ProxyAdviceFactory proxyAdviceFactory;
+ private static final Map<String, AgentAdvice> CACHED_ADVICES = new
ConcurrentHashMap<>();
- private final JDBCAdviceFactory jdbcAdviceFactory;
-
- private final boolean isEnhancedForProxy;
-
- public AdviceFactory(final ClassLoader classLoader, final Map<String,
PluginConfiguration> pluginConfigs, final Collection<PluginJar> pluginJars,
final boolean isEnhancedForProxy) {
- proxyAdviceFactory = new ProxyAdviceFactory();
- jdbcAdviceFactory = new JDBCAdviceFactory(classLoader, pluginConfigs,
pluginJars);
- this.isEnhancedForProxy = isEnhancedForProxy;
- }
+ private final ClassLoaderContext classLoaderContext;
/**
* Get advice.
@@ -48,6 +42,13 @@ public final class AdviceFactory {
* @return got advance
*/
public AgentAdvice getAdvice(final String adviceClassName) {
- return isEnhancedForProxy ?
proxyAdviceFactory.getAdvice(adviceClassName) :
jdbcAdviceFactory.getAdvice(adviceClassName);
+ String adviceInstanceCacheKey = String.format("%s_%s@%s",
adviceClassName, classLoaderContext.getAppClassLoader().getClass().getName(),
+
Integer.toHexString(classLoaderContext.getAppClassLoader().hashCode()));
+ return CACHED_ADVICES.computeIfAbsent(adviceInstanceCacheKey, key ->
createAdvice(adviceClassName));
+ }
+
+ @SneakyThrows(ReflectiveOperationException.class)
+ private AgentAdvice createAdvice(final String adviceClassName) {
+ return (AgentAdvice) Class.forName(adviceClassName, true,
classLoaderContext.getAgentClassLoader()).getDeclaredConstructor().newInstance();
}
}
diff --git
a/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/transformer/builder/advise/JDBCAdviceFactory.java
b/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/transformer/builder/advise/JDBCAdviceFactory.java
deleted file mode 100644
index bdc365f11ec..00000000000
---
a/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/transformer/builder/advise/JDBCAdviceFactory.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * 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.shardingsphere.agent.bootstrap.transformer.builder.advise;
-
-import lombok.RequiredArgsConstructor;
-import lombok.SneakyThrows;
-import org.apache.shardingsphere.agent.bootstrap.classloader.AgentClassLoader;
-import org.apache.shardingsphere.agent.bootstrap.plugin.PluginJar;
-import org.apache.shardingsphere.agent.config.plugin.PluginConfiguration;
-import
org.apache.shardingsphere.agent.bootstrap.plugin.PluginBootServiceManager;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * JDBC advice factory.
- */
-@RequiredArgsConstructor
-public final class JDBCAdviceFactory {
-
- private static final Map<String, Object> CACHED_ADVICES = new
ConcurrentHashMap<>();
-
- private static final Map<ClassLoader, ClassLoader> PLUGIN_CLASS_LOADERS =
new HashMap<>();
-
- private static boolean isStarted;
-
- private final ClassLoader classLoader;
-
- private final Map<String, PluginConfiguration> pluginConfigs;
-
- private final Collection<PluginJar> pluginJars;
-
- /**
- * Get advice.
- *
- * @param adviceClassName advice class name
- * @param <T> type of advice
- * @return got advance
- */
- @SuppressWarnings("unchecked")
- public <T> T getAdvice(final String adviceClassName) {
- String adviceInstanceCacheKey = String.format("%s_%s@%s",
adviceClassName, classLoader.getClass().getName(),
Integer.toHexString(classLoader.hashCode()));
- return (T) CACHED_ADVICES.computeIfAbsent(adviceInstanceCacheKey, key
-> createAdviceForJDBC(adviceClassName));
- }
-
- @SneakyThrows(ReflectiveOperationException.class)
- private Object createAdviceForJDBC(final String adviceClassName) {
- ClassLoader pluginClassLoader =
PLUGIN_CLASS_LOADERS.computeIfAbsent(classLoader, key -> new
AgentClassLoader(key, pluginJars));
- Object result = Class.forName(adviceClassName, true,
pluginClassLoader).getDeclaredConstructor().newInstance();
- setupPluginBootService(pluginClassLoader);
- return result;
- }
-
- private void setupPluginBootService(final ClassLoader pluginClassLoader) {
- if (isStarted) {
- return;
- }
- try {
- PluginBootServiceManager.startAllServices(pluginConfigs,
pluginClassLoader, false);
- Runtime.getRuntime().addShutdownHook(new Thread(() ->
PluginBootServiceManager.closeAllServices(pluginJars)));
- } finally {
- isStarted = true;
- }
- }
-}
diff --git
a/agent/distribution/src/main/assembly/shardingsphere-agent-binary-distribution.xml
b/agent/distribution/src/main/assembly/shardingsphere-agent-binary-distribution.xml
index 56a14de20e9..7d6031fc801 100644
---
a/agent/distribution/src/main/assembly/shardingsphere-agent-binary-distribution.xml
+++
b/agent/distribution/src/main/assembly/shardingsphere-agent-binary-distribution.xml
@@ -31,15 +31,6 @@
<outputDirectory>conf</outputDirectory>
<fileMode>0644</fileMode>
</fileSet>
- <fileSet>
- <directory>src/main/resources</directory>
- <includes>
- <include>logback.xml</include>
- </includes>
- <outputDirectory>conf</outputDirectory>
- <fileMode>0644</fileMode>
- </fileSet>
-
<fileSet>
<directory>../../</directory>
<includes>
diff --git a/agent/distribution/src/main/resources/logback.xml
b/agent/distribution/src/main/resources/logback.xml
deleted file mode 100644
index 1494746120c..00000000000
--- a/agent/distribution/src/main/resources/logback.xml
+++ /dev/null
@@ -1,33 +0,0 @@
-<?xml version="1.0"?>
-<!--
- ~ 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.
- -->
-
-<configuration>
- <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
- <encoder>
- <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread]
%logger{36} - %msg%n</pattern>
- </encoder>
- </appender>
- <logger name="org.apache.shardingsphere" level="info" additivity="false">
- <appender-ref ref="console" />
- </logger>
-
- <root>
- <level value="info" />
- <appender-ref ref="console" />
- </root>
-</configuration>
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/metrics/core/advice/MetaDataContextsFactoryAdvice.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/metrics/core/advice/MetaDataContextsFactoryAdvice.java
new file mode 100644
index 00000000000..8fd9c8211a5
--- /dev/null
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/metrics/core/advice/MetaDataContextsFactoryAdvice.java
@@ -0,0 +1,26 @@
+/*
+ * 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.shardingsphere.agent.metrics.core.advice;
+
+import org.apache.shardingsphere.agent.advice.type.StaticMethodAdvice;
+
+/**
+ * Meta data contexts factory advice.
+ */
+public final class MetaDataContextsFactoryAdvice implements StaticMethodAdvice
{
+}
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/resources/prometheus/jdbc-advisors.yaml
b/agent/plugins/metrics/type/prometheus/src/main/resources/prometheus/jdbc-advisors.yaml
index b1312a0905c..aa4272008f8 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/resources/prometheus/jdbc-advisors.yaml
+++
b/agent/plugins/metrics/type/prometheus/src/main/resources/prometheus/jdbc-advisors.yaml
@@ -14,3 +14,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+
+advisors:
+ - target: org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory
+ advice:
org.apache.shardingsphere.agent.metrics.core.advice.MetaDataContextsFactoryAdvice
+ pointcuts:
+ - name: create
+ type: method
+ params:
+ - index: 3
+ type: java.util.Map
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/resources/prometheus/proxy-advisors.yaml
b/agent/plugins/metrics/type/prometheus/src/main/resources/prometheus/proxy-advisors.yaml
index b72dea54591..9d651a363d6 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/resources/prometheus/proxy-advisors.yaml
+++
b/agent/plugins/metrics/type/prometheus/src/main/resources/prometheus/proxy-advisors.yaml
@@ -37,7 +37,7 @@ advisors:
pointcuts:
- name: route
type: method
- - target:
org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.JDBCBackendTransactionManager
+ - target:
org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.BackendTransactionManager
advice:
org.apache.shardingsphere.agent.metrics.core.advice.TransactionAdvice
pointcuts:
- name: commit
@@ -49,3 +49,11 @@ advisors:
pointcuts:
- name: parse
type: method
+ - target: org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory
+ advice:
org.apache.shardingsphere.agent.metrics.core.advice.MetaDataContextsFactoryAdvice
+ pointcuts:
+ - name: create
+ type: method
+ params:
+ - index: 3
+ type: java.util.Map