You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ki...@apache.org on 2020/12/08 13:50:28 UTC
[shardingsphere] branch master updated: agent classLoader (#8537)
This is an automated email from the ASF dual-hosted git repository.
kimmking 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 2b9db78 agent classLoader (#8537)
2b9db78 is described below
commit 2b9db78152fcc5a2ab8a9669fb0f1efff00e4e2b
Author: xiaoyu <54...@qq.com>
AuthorDate: Tue Dec 8 21:50:07 2020 +0800
agent classLoader (#8537)
---
.../agent/bootstrap/ShardingSphereAgent.java | 1 +
.../agent/core/plugin/AgentPluginLoader.java | 77 +++++++++++++++-------
.../agent/core/spi/AgentServiceLoader.java | 3 +-
.../shardingsphere/agent/metrics/api/BaseTest.java | 45 +++++++++++++
.../agent/metrics/api/MetricsProviderTest.java | 33 ++++++++++
.../api/fixture/FixtureMetricsRegister.java | 63 ++++++++++++++++++
.../api/fixture/FixtureMetricsRegisterFactory.java | 34 ++++++++++
...sphere.agent.metrics.api.MetricsRegisterFactory | 18 +++++
.../src/test/resources/conf/agent.yaml | 24 +++++++
.../definition/MetricsPluginDefinition.java | 2 +
10 files changed, 277 insertions(+), 23 deletions(-)
diff --git a/shardingsphere-agent/shardingsphere-agent-bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java b/shardingsphere-agent/shardingsphere-agent-bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java
index 89f0934..56ac8c4 100644
--- a/shardingsphere-agent/shardingsphere-agent-bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java
+++ b/shardingsphere-agent/shardingsphere-agent-bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java
@@ -53,6 +53,7 @@ public class ShardingSphereAgent {
.ignore(ElementMatchers.isSynthetic())
.or(ElementMatchers.nameStartsWith("org.apache.shardingsphere.agent."));
AgentPluginLoader agentPluginLoader = AgentPluginLoader.getInstance();
+ agentPluginLoader.loadAllPlugins();
agentPluginLoader.initialAllServices();
builder.type(agentPluginLoader.typeMatcher())
.transform(new ShardingSphereTransformer(agentPluginLoader))
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/AgentPluginLoader.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/AgentPluginLoader.java
index 9f47a9a..78e887f 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/AgentPluginLoader.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/AgentPluginLoader.java
@@ -24,6 +24,11 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.io.ByteStreams;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.jar.JarEntry;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import net.bytebuddy.description.type.TypeDescription;
@@ -51,11 +56,12 @@ import java.util.zip.ZipEntry;
*/
@Slf4j
public final class AgentPluginLoader extends ClassLoader implements Closeable {
+
static {
registerAsParallelCapable();
}
- private static final AgentPluginLoader INSTANCE = new AgentPluginLoader();
+ private static volatile AgentPluginLoader agentPluginLoader;
private final ConcurrentHashMap<String, Object> objectPool = new ConcurrentHashMap<>();
@@ -65,15 +71,7 @@ public final class AgentPluginLoader extends ClassLoader implements Closeable {
private final List<Service> services = Lists.newArrayList();
- private Map<String, PluginAdviceDefinition> pluginDefineMap;
-
- private AgentPluginLoader() {
- try {
- pluginDefineMap = loadAllPlugins();
- } catch (IOException ioe) {
- log.error("Failed to load plugins.");
- }
- }
+ private Map<String, PluginAdviceDefinition> pluginDefineMap = Maps.newHashMap();
@Override
protected Class<?> findClass(final String name) throws ClassNotFoundException {
@@ -93,6 +91,29 @@ public final class AgentPluginLoader extends ClassLoader implements Closeable {
}
@Override
+ protected Enumeration<URL> findResources(final String name) throws IOException {
+ List<URL> allResources = new LinkedList<>();
+ for (JarFile jar : jars) {
+ JarEntry entry = jar.getJarEntry(name);
+ if (null != entry) {
+ allResources.add(new URL("jar:file:" + AgentPathBuilder.getAgentPath().getAbsolutePath() + "!/" + name));
+ }
+ }
+ final Iterator<URL> iterator = allResources.iterator();
+ return new Enumeration<URL>() {
+ @Override
+ public boolean hasMoreElements() {
+ return iterator.hasNext();
+ }
+
+ @Override
+ public URL nextElement() {
+ return iterator.next();
+ }
+ };
+ }
+
+ @Override
public void close() {
for (JarFile jar : jars) {
try {
@@ -109,18 +130,30 @@ public final class AgentPluginLoader extends ClassLoader implements Closeable {
* @return plugin loader
*/
public static AgentPluginLoader getInstance() {
- return INSTANCE;
+ if (null == agentPluginLoader) {
+ synchronized (AgentPluginLoader.class) {
+ if (null == agentPluginLoader) {
+ agentPluginLoader = new AgentPluginLoader();
+ }
+ }
+ }
+ return agentPluginLoader;
}
- private Map<String, PluginAdviceDefinition> loadAllPlugins() throws IOException {
+ /**
+ * Load all plugins.
+ *
+ * @throws IOException the IO exception
+ */
+ public void loadAllPlugins() throws IOException {
File[] jarFiles = AgentPathBuilder.getPluginPath().listFiles(file -> file.getName().endsWith(".jar"));
- Map<String, PluginAdviceDefinition> pluginDefineMap = Maps.newHashMap();
- if (jarFiles == null) {
- return pluginDefineMap;
+ if (null == jarFiles) {
+ return;
}
+ Map<String, PluginAdviceDefinition> pluginAdviceDefinitionMap = Maps.newHashMap();
AgentConfiguration configuration = SingletonHolder.INSTANCE.get(AgentConfiguration.class);
List<String> activatedLists = configuration.getActivatedPlugins();
- if (activatedLists == null) {
+ if (null == activatedLists) {
activatedLists = Lists.newArrayList();
}
Set<String> activatedPlugins = Sets.newHashSet(activatedLists);
@@ -128,13 +161,13 @@ public final class AgentPluginLoader extends ClassLoader implements Closeable {
for (File jarFile : jarFiles) {
outputStream.reset();
JarFile jar = new JarFile(jarFile, true);
+ jars.add(jar);
Attributes attributes = jar.getManifest().getMainAttributes();
String entrypoint = attributes.getValue("Entrypoint");
if (Strings.isNullOrEmpty(entrypoint)) {
log.warn("Entrypoint is not setting in {}.", jarFile.getName());
continue;
}
- jars.add(jar);
ByteStreams.copy(jar.getInputStream(jar.getEntry(classNameToPath(entrypoint))), outputStream);
try {
PluginDefinition pluginDefinition = (PluginDefinition) defineClass(entrypoint, outputStream.toByteArray(), 0, outputStream.size()).newInstance();
@@ -150,20 +183,20 @@ public final class AgentPluginLoader extends ClassLoader implements Closeable {
});
pluginDefinition.build().forEach(plugin -> {
String target = plugin.getClassNameOfTarget();
- if (pluginDefineMap.containsKey(target)) {
- PluginAdviceDefinition definition = pluginDefineMap.get(target);
+ if (pluginAdviceDefinitionMap.containsKey(target)) {
+ PluginAdviceDefinition definition = pluginAdviceDefinitionMap.get(target);
definition.getConstructorPoints().addAll(plugin.getConstructorPoints());
definition.getInstanceMethodPoints().addAll(plugin.getInstanceMethodPoints());
definition.getClassStaticMethodPoints().addAll(plugin.getClassStaticMethodPoints());
} else {
- pluginDefineMap.put(target, plugin);
+ pluginAdviceDefinitionMap.put(target, plugin);
}
});
} catch (InstantiationException | IllegalAccessException e) {
log.error("Failed to load plugin definition, {}.", entrypoint, e);
}
}
- return ImmutableMap.<String, PluginAdviceDefinition>builder().putAll(pluginDefineMap).build();
+ pluginDefineMap = ImmutableMap.<String, PluginAdviceDefinition>builder().putAll(pluginAdviceDefinitionMap).build();
}
private String classNameToPath(final String className) {
@@ -218,8 +251,8 @@ public final class AgentPluginLoader extends ClassLoader implements Closeable {
/**
* To get or create instance of the advice class. Create new one and caching when it is not exist.
*
+ * @param <T> advice type
* @param classNameOfAdvice class name of advice
- * @param <T> advice type
* @return instance of advice
*/
@SneakyThrows({ClassNotFoundException.class, IllegalAccessException.class, InstantiationException.class})
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/spi/AgentServiceLoader.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/spi/AgentServiceLoader.java
index 0b45846..2c8293b 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/spi/AgentServiceLoader.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/spi/AgentServiceLoader.java
@@ -22,6 +22,7 @@ import java.util.LinkedList;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.concurrent.ConcurrentHashMap;
+import org.apache.shardingsphere.agent.core.plugin.AgentPluginLoader;
/**
* Agent service loader.
@@ -76,7 +77,7 @@ public final class AgentServiceLoader<T> {
return;
}
serviceMap.put(service, new LinkedList<>());
- for (T each : ServiceLoader.load(service)) {
+ for (T each : ServiceLoader.load(service, AgentPluginLoader.getInstance())) {
serviceMap.get(service).add(each);
}
}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/BaseTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/BaseTest.java
new file mode 100644
index 0000000..14eee03
--- /dev/null
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/BaseTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.api;
+
+import java.io.IOException;
+import java.net.URL;
+import org.apache.shardingsphere.agent.core.config.AgentConfiguration;
+import org.apache.shardingsphere.agent.core.config.AgentConfigurationLoader;
+import org.apache.shardingsphere.agent.core.utils.SingletonHolder;
+import org.junit.Before;
+
+public class BaseTest {
+
+ private static final String DEFAULT_CONFIG_PATH = "/conf/agent.yaml";
+
+ @Before
+ public void assertLoad() throws IOException {
+ System.setProperty("agent-path", getResourceUrl());
+ AgentConfiguration configuration = AgentConfigurationLoader.load();
+ SingletonHolder.INSTANCE.put(configuration);
+ }
+
+ private static String getResourceUrl() {
+ URL url = AgentConfigurationLoader.class.getResource(DEFAULT_CONFIG_PATH);
+ if (null != url) {
+ return url.getFile();
+ }
+ return DEFAULT_CONFIG_PATH;
+ }
+}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/MetricsProviderTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/MetricsProviderTest.java
new file mode 100644
index 0000000..9a2d33a
--- /dev/null
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/MetricsProviderTest.java
@@ -0,0 +1,33 @@
+/*
+ * 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.api;
+
+import org.apache.shardingsphere.agent.metrics.api.fixture.FixtureMetricsRegister;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
+
+public final class MetricsProviderTest extends BaseTest {
+
+ @Test
+ public void assertInstance() {
+ MetricsRegister metricsRegister = MetricsProvider.INSTANCE.newInstance();
+ assertThat(metricsRegister, instanceOf(FixtureMetricsRegister.class));
+ }
+}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/fixture/FixtureMetricsRegister.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/fixture/FixtureMetricsRegister.java
new file mode 100644
index 0000000..21f89dd
--- /dev/null
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/fixture/FixtureMetricsRegister.java
@@ -0,0 +1,63 @@
+/*
+ * 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.api.fixture;
+
+import org.apache.shardingsphere.agent.metrics.api.MetricsRegister;
+
+public final class FixtureMetricsRegister implements MetricsRegister {
+
+ @Override
+ public void registerGauge(final String name, final String[] labelNames, final String document) {
+
+ }
+
+ @Override
+ public void registerCounter(final String name, final String[] labelNames, final String document) {
+
+ }
+
+ @Override
+ public void registerHistogram(final String name, final String[] labelNames, final String document) {
+
+ }
+
+ @Override
+ public void counterIncrement(final String name, final String[] labelValues) {
+
+ }
+
+ @Override
+ public void counterIncrement(final String name, final String[] labelValues, final long count) {
+
+ }
+
+ @Override
+ public void gaugeIncrement(final String name, final String[] labelValues) {
+
+ }
+
+ @Override
+ public void gaugeDecrement(final String name, final String[] labelValues) {
+
+ }
+
+ @Override
+ public void recordTime(final String name, final String[] labelValues, final long duration) {
+
+ }
+}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/fixture/FixtureMetricsRegisterFactory.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/fixture/FixtureMetricsRegisterFactory.java
new file mode 100644
index 0000000..6bc459a
--- /dev/null
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/fixture/FixtureMetricsRegisterFactory.java
@@ -0,0 +1,34 @@
+/*
+ * 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.api.fixture;
+
+import org.apache.shardingsphere.agent.metrics.api.MetricsRegister;
+import org.apache.shardingsphere.agent.metrics.api.MetricsRegisterFactory;
+
+public final class FixtureMetricsRegisterFactory implements MetricsRegisterFactory {
+
+ @Override
+ public MetricsRegister newInstance() {
+ return new FixtureMetricsRegister();
+ }
+
+ @Override
+ public String getType() {
+ return "fixture";
+ }
+}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/resources/META-INF/services/org.apache.shardingsphere.agent.metrics.api.MetricsRegisterFactory b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/resources/META-INF/services/org.apache.shardingsphere.agent.metrics.api.MetricsRegisterFactory
new file mode 100644
index 0000000..44452b9
--- /dev/null
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/resources/META-INF/services/org.apache.shardingsphere.agent.metrics.api.MetricsRegisterFactory
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.agent.metrics.api.fixture.FixtureMetricsRegisterFactory
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/resources/conf/agent.yaml b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/resources/conf/agent.yaml
new file mode 100644
index 0000000..90e5c3f
--- /dev/null
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/resources/conf/agent.yaml
@@ -0,0 +1,24 @@
+#
+# 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.
+#
+
+applicationName: shardingsphere-agent
+
+metrics:
+ host: localhost
+ port: 8090
+ type: fixture
+
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-bootstrap/src/main/java/org/apache/shardingsphere/agent/metrics/bootstrap/definition/MetricsPluginDefinition.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-bootstrap/src/main/java/org/apache/shardingsphere/agent/metrics/bootstrap/definition/MetricsPluginDefinition.java
index 0d2ab43..9c7d39e 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-bootstrap/src/main/java/org/apache/shardingsphere/agent/metrics/bootstrap/definition/MetricsPluginDefinition.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-bootstrap/src/main/java/org/apache/shardingsphere/agent/metrics/bootstrap/definition/MetricsPluginDefinition.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.agent.metrics.bootstrap.definition;
import net.bytebuddy.matcher.ElementMatchers;
import org.apache.shardingsphere.agent.core.plugin.PluginDefinition;
+import org.apache.shardingsphere.agent.metrics.api.MetricsProvider;
import org.apache.shardingsphere.agent.metrics.bootstrap.MethodNameConstant;
/**
@@ -65,5 +66,6 @@ public final class MetricsPluginDefinition extends PluginDefinition {
.aroundInstanceMethod(ElementMatchers.named(MethodNameConstant.COMMIT).or(ElementMatchers.named(MethodNameConstant.ROLL_BACK)))
.implement(TRANSACTION_ADVICE_CLASS)
.build();
+ MetricsProvider.INSTANCE.newInstance();
}
}