You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2024/08/21 02:38:40 UTC
(shardingsphere) branch master updated: Optimize advice avoid test errors caused by mock java.lang.reflect.Method (#32603)
This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 2a48c6a64ce Optimize advice avoid test errors caused by mock java.lang.reflect.Method (#32603)
2a48c6a64ce is described below
commit 2a48c6a64ce3e892d1ed1c49b70503bf84039907
Author: jiangML <10...@qq.com>
AuthorDate: Wed Aug 21 10:38:34 2024 +0800
Optimize advice avoid test errors caused by mock java.lang.reflect.Method (#32603)
* Optimize advice avoid test errors caused by mock java.lang.reflect.Method
* Add java doc for TargetAdviceMethod
---
.../agent/api/advice/TargetAdviceMethod.java | 31 ++++++++++++++++++++++
.../api/advice/type/InstanceMethodAdvice.java | 9 +++----
.../agent/api/advice/type/StaticMethodAdvice.java | 9 +++----
.../type/InstanceMethodAdviceExecutor.java | 7 ++---
.../executor/type/StaticMethodAdviceExecutor.java | 7 ++---
.../shardingsphere/fixture/advice/BarAdvice.java | 14 +++++-----
.../shardingsphere/fixture/advice/FooAdvice.java | 14 +++++-----
.../plugin/core/recorder/MethodTimeRecorder.java | 8 +++---
.../core/recorder/MethodTimeRecorderTest.java | 9 ++++---
.../file/advice/MetaDataContextsFactoryAdvice.java | 7 +++--
.../advice/MetaDataContextsFactoryAdviceTest.java | 4 +--
.../core/advice/RouteResultCountAdvice.java | 4 +--
.../metrics/core/advice/SQLParseCountAdvice.java | 4 +--
.../metrics/core/advice/SQLRouteCountAdvice.java | 4 +--
.../advice/jdbc/AbstractExecuteCountAdvice.java | 4 +--
.../jdbc/AbstractExecuteErrorsCountAdvice.java | 4 +--
.../AbstractExecuteLatencyHistogramAdvice.java | 6 ++---
.../jdbc/AbstractTransactionsCountAdvice.java | 4 +--
.../jdbc/ShardingSphereDataSourceAdvice.java | 7 +++--
.../proxy/CommitTransactionsCountAdvice.java | 4 +--
.../proxy/CurrentConnectionsCountAdvice.java | 4 +--
.../advice/proxy/ExecuteErrorsCountAdvice.java | 4 +--
.../proxy/ExecuteLatencyHistogramAdvice.java | 6 ++---
.../core/advice/proxy/RequestsCountAdvice.java | 4 +--
.../proxy/RollbackTransactionsCountAdvice.java | 4 +--
.../core/advice/RouteResultCountAdviceTest.java | 4 +--
.../core/advice/SQLParseCountAdviceTest.java | 4 +--
.../core/advice/SQLRouteCountAdviceTest.java | 4 +--
.../jdbc/AbstractExecuteCountAdviceTest.java | 8 +++---
.../jdbc/AbstractExecuteErrorsCountAdviceTest.java | 8 +++---
.../AbstractExecuteLatencyHistogramAdviceTest.java | 8 +++---
.../jdbc/AbstractTransactionsCountAdviceTest.java | 8 +++---
.../jdbc/ShardingSphereDataSourceAdviceTest.java | 7 +++--
.../proxy/CommitTransactionsCountAdviceTest.java | 6 ++---
.../proxy/CurrentConnectionsCountAdviceTest.java | 8 +++---
.../advice/proxy/ExecuteErrorsCountAdviceTest.java | 4 +--
.../proxy/ExecuteLatencyHistogramAdviceTest.java | 6 ++---
.../core/advice/proxy/RequestsCountAdviceTest.java | 4 +--
.../proxy/RollbackTransactionsCountAdviceTest.java | 4 +--
.../advice/TracingJDBCExecutorCallbackAdvice.java | 5 ++--
.../tracing/core/advice/TracingRootSpanAdvice.java | 11 ++++----
.../core/advice/TracingSQLParserEngineAdvice.java | 5 ++--
.../OpenTelemetryJDBCExecutorCallbackAdvice.java | 7 +++--
.../advice/OpenTelemetryRootSpanAdvice.java | 5 ++--
.../advice/OpenTelemetrySQLParserEngineAdvice.java | 7 +++--
45 files changed, 165 insertions(+), 140 deletions(-)
diff --git a/agent/api/src/main/java/org/apache/shardingsphere/agent/api/advice/TargetAdviceMethod.java b/agent/api/src/main/java/org/apache/shardingsphere/agent/api/advice/TargetAdviceMethod.java
new file mode 100644
index 00000000000..60b61c5759d
--- /dev/null
+++ b/agent/api/src/main/java/org/apache/shardingsphere/agent/api/advice/TargetAdviceMethod.java
@@ -0,0 +1,31 @@
+/*
+ * 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.api.advice;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+
+/**
+ * Target advice method.
+ */
+@RequiredArgsConstructor
+@Getter
+public final class TargetAdviceMethod {
+
+ private final String name;
+}
diff --git a/agent/api/src/main/java/org/apache/shardingsphere/agent/api/advice/type/InstanceMethodAdvice.java b/agent/api/src/main/java/org/apache/shardingsphere/agent/api/advice/type/InstanceMethodAdvice.java
index 9bd880a9f14..49a775b9d5e 100644
--- a/agent/api/src/main/java/org/apache/shardingsphere/agent/api/advice/type/InstanceMethodAdvice.java
+++ b/agent/api/src/main/java/org/apache/shardingsphere/agent/api/advice/type/InstanceMethodAdvice.java
@@ -17,11 +17,10 @@
package org.apache.shardingsphere.agent.api.advice.type;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.AgentAdvice;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
-import java.lang.reflect.Method;
-
/**
* Instance method advice.
*/
@@ -36,7 +35,7 @@ public interface InstanceMethodAdvice extends AgentAdvice {
* @param args all method arguments
* @param pluginType plugin type
*/
- default void beforeMethod(final TargetAdviceObject target, final Method method, final Object[] args, String pluginType) {
+ default void beforeMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, String pluginType) {
}
/**
@@ -49,7 +48,7 @@ public interface InstanceMethodAdvice extends AgentAdvice {
* @param result original call result
* @param pluginType plugin type
*/
- default void afterMethod(final TargetAdviceObject target, final Method method, final Object[] args, final Object result, String pluginType) {
+ default void afterMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final Object result, String pluginType) {
}
/**
@@ -61,6 +60,6 @@ public interface InstanceMethodAdvice extends AgentAdvice {
* @param throwable exception from target method
* @param pluginType plugin type
*/
- default void onThrowing(final TargetAdviceObject target, final Method method, final Object[] args, final Throwable throwable, String pluginType) {
+ default void onThrowing(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final Throwable throwable, String pluginType) {
}
}
diff --git a/agent/api/src/main/java/org/apache/shardingsphere/agent/api/advice/type/StaticMethodAdvice.java b/agent/api/src/main/java/org/apache/shardingsphere/agent/api/advice/type/StaticMethodAdvice.java
index 5b0c6c25d2b..7a9ed84bfbd 100644
--- a/agent/api/src/main/java/org/apache/shardingsphere/agent/api/advice/type/StaticMethodAdvice.java
+++ b/agent/api/src/main/java/org/apache/shardingsphere/agent/api/advice/type/StaticMethodAdvice.java
@@ -17,10 +17,9 @@
package org.apache.shardingsphere.agent.api.advice.type;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.AgentAdvice;
-import java.lang.reflect.Method;
-
/**
* Static method advice.
*/
@@ -35,7 +34,7 @@ public interface StaticMethodAdvice extends AgentAdvice {
* @param args all method arguments
* @param pluginType plugin type
*/
- default void beforeMethod(final Class<?> clazz, final Method method, final Object[] args, String pluginType) {
+ default void beforeMethod(final Class<?> clazz, final TargetAdviceMethod method, final Object[] args, String pluginType) {
}
/**
@@ -48,7 +47,7 @@ public interface StaticMethodAdvice extends AgentAdvice {
* @param result original call result
* @param pluginType plugin type
*/
- default void afterMethod(final Class<?> clazz, final Method method, final Object[] args, final Object result, String pluginType) {
+ default void afterMethod(final Class<?> clazz, final TargetAdviceMethod method, final Object[] args, final Object result, String pluginType) {
}
/**
@@ -60,6 +59,6 @@ public interface StaticMethodAdvice extends AgentAdvice {
* @param throwable exception from target method
* @param pluginType plugin type
*/
- default void onThrowing(final Class<?> clazz, final Method method, final Object[] args, final Throwable throwable, String pluginType) {
+ default void onThrowing(final Class<?> clazz, final TargetAdviceMethod method, final Object[] args, final Throwable throwable, String pluginType) {
}
}
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/executor/type/InstanceMethodAdviceExecutor.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/executor/type/InstanceMethodAdviceExecutor.java
index 9fff440ddfc..49cba660418 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/executor/type/InstanceMethodAdviceExecutor.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/executor/type/InstanceMethodAdviceExecutor.java
@@ -28,6 +28,7 @@ import net.bytebuddy.implementation.bind.annotation.RuntimeType;
import net.bytebuddy.implementation.bind.annotation.SuperCall;
import net.bytebuddy.implementation.bind.annotation.This;
import net.bytebuddy.matcher.ElementMatchers;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.plugin.AgentPluginEnable;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
@@ -83,7 +84,7 @@ public final class InstanceMethodAdviceExecutor implements AdviceExecutor {
for (Entry<String, Collection<InstanceMethodAdvice>> entry : advices.entrySet()) {
for (InstanceMethodAdvice each : entry.getValue()) {
if (isPluginEnabled(each)) {
- each.beforeMethod(target, method, args, entry.getKey());
+ each.beforeMethod(target, new TargetAdviceMethod(method.getName()), args, entry.getKey());
}
}
}
@@ -99,7 +100,7 @@ public final class InstanceMethodAdviceExecutor implements AdviceExecutor {
for (Entry<String, Collection<InstanceMethodAdvice>> entry : advices.entrySet()) {
for (InstanceMethodAdvice each : entry.getValue()) {
if (isPluginEnabled(each)) {
- each.onThrowing(target, method, args, ex, entry.getKey());
+ each.onThrowing(target, new TargetAdviceMethod(method.getName()), args, ex, entry.getKey());
}
}
}
@@ -115,7 +116,7 @@ public final class InstanceMethodAdviceExecutor implements AdviceExecutor {
for (Entry<String, Collection<InstanceMethodAdvice>> entry : advices.entrySet()) {
for (InstanceMethodAdvice each : entry.getValue()) {
if (isPluginEnabled(each)) {
- each.afterMethod(target, method, args, result, entry.getKey());
+ each.afterMethod(target, new TargetAdviceMethod(method.getName()), args, result, entry.getKey());
}
}
}
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/executor/type/StaticMethodAdviceExecutor.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/executor/type/StaticMethodAdviceExecutor.java
index 3e7182ed319..c3e7d717628 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/executor/type/StaticMethodAdviceExecutor.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/executor/type/StaticMethodAdviceExecutor.java
@@ -27,6 +27,7 @@ import net.bytebuddy.implementation.bind.annotation.Origin;
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
import net.bytebuddy.implementation.bind.annotation.SuperCall;
import net.bytebuddy.matcher.ElementMatchers;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.plugin.AgentPluginEnable;
import org.apache.shardingsphere.agent.api.advice.type.StaticMethodAdvice;
import org.apache.shardingsphere.agent.core.advisor.executor.AdviceExecutor;
@@ -81,7 +82,7 @@ public final class StaticMethodAdviceExecutor implements AdviceExecutor {
for (Entry<String, Collection<StaticMethodAdvice>> entry : advices.entrySet()) {
for (StaticMethodAdvice each : entry.getValue()) {
if (isPluginEnabled(each)) {
- each.beforeMethod(klass, method, args, entry.getKey());
+ each.beforeMethod(klass, new TargetAdviceMethod(method.getName()), args, entry.getKey());
}
}
}
@@ -97,7 +98,7 @@ public final class StaticMethodAdviceExecutor implements AdviceExecutor {
for (Entry<String, Collection<StaticMethodAdvice>> entry : advices.entrySet()) {
for (StaticMethodAdvice each : entry.getValue()) {
if (isPluginEnabled(each)) {
- each.onThrowing(klass, method, args, ex, entry.getKey());
+ each.onThrowing(klass, new TargetAdviceMethod(method.getName()), args, ex, entry.getKey());
}
}
}
@@ -113,7 +114,7 @@ public final class StaticMethodAdviceExecutor implements AdviceExecutor {
for (Entry<String, Collection<StaticMethodAdvice>> entry : advices.entrySet()) {
for (StaticMethodAdvice each : entry.getValue()) {
if (isPluginEnabled(each)) {
- each.afterMethod(klass, method, args, result, entry.getKey());
+ each.afterMethod(klass, new TargetAdviceMethod(method.getName()), args, result, entry.getKey());
}
}
}
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/fixture/advice/BarAdvice.java b/agent/core/src/test/java/org/apache/shardingsphere/fixture/advice/BarAdvice.java
index 87cbf574d7a..d61297197c8 100644
--- a/agent/core/src/test/java/org/apache/shardingsphere/fixture/advice/BarAdvice.java
+++ b/agent/core/src/test/java/org/apache/shardingsphere/fixture/advice/BarAdvice.java
@@ -17,12 +17,12 @@
package org.apache.shardingsphere.fixture.advice;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.api.advice.type.ConstructorAdvice;
import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
import org.apache.shardingsphere.agent.api.advice.type.StaticMethodAdvice;
-import java.lang.reflect.Method;
import java.util.List;
@SuppressWarnings("unchecked")
@@ -34,37 +34,37 @@ public final class BarAdvice implements ConstructorAdvice, InstanceMethodAdvice,
}
@Override
- public void beforeMethod(final TargetAdviceObject target, final Method method, final Object[] args, final String pluginType) {
+ public void beforeMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final String pluginType) {
List<String> queue = (List<String>) args[0];
queue.add("bar before instance method");
}
@Override
- public void beforeMethod(final Class<?> clazz, final Method method, final Object[] args, final String pluginType) {
+ public void beforeMethod(final Class<?> clazz, final TargetAdviceMethod method, final Object[] args, final String pluginType) {
List<String> queue = (List<String>) args[0];
queue.add("bar before static method");
}
@Override
- public void afterMethod(final TargetAdviceObject target, final Method method, final Object[] args, final Object result, final String pluginType) {
+ public void afterMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final Object result, final String pluginType) {
List<String> queue = (List<String>) args[0];
queue.add("bar after instance method");
}
@Override
- public void afterMethod(final Class<?> clazz, final Method method, final Object[] args, final Object result, final String pluginType) {
+ public void afterMethod(final Class<?> clazz, final TargetAdviceMethod method, final Object[] args, final Object result, final String pluginType) {
List<String> queue = (List<String>) args[0];
queue.add("bar after static method");
}
@Override
- public void onThrowing(final TargetAdviceObject target, final Method method, final Object[] args, final Throwable throwable, final String pluginType) {
+ public void onThrowing(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final Throwable throwable, final String pluginType) {
List<String> queue = (List<String>) args[0];
queue.add("bar throw instance method exception");
}
@Override
- public void onThrowing(final Class<?> clazz, final Method method, final Object[] args, final Throwable throwable, final String pluginType) {
+ public void onThrowing(final Class<?> clazz, final TargetAdviceMethod method, final Object[] args, final Throwable throwable, final String pluginType) {
List<String> queue = (List<String>) args[0];
queue.add("bar throw static method exception");
}
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/fixture/advice/FooAdvice.java b/agent/core/src/test/java/org/apache/shardingsphere/fixture/advice/FooAdvice.java
index 04baee22f7f..23e53faa7ad 100644
--- a/agent/core/src/test/java/org/apache/shardingsphere/fixture/advice/FooAdvice.java
+++ b/agent/core/src/test/java/org/apache/shardingsphere/fixture/advice/FooAdvice.java
@@ -17,12 +17,12 @@
package org.apache.shardingsphere.fixture.advice;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.api.advice.type.ConstructorAdvice;
import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
import org.apache.shardingsphere.agent.api.advice.type.StaticMethodAdvice;
-import java.lang.reflect.Method;
import java.util.List;
@SuppressWarnings("unchecked")
@@ -34,37 +34,37 @@ public final class FooAdvice implements ConstructorAdvice, InstanceMethodAdvice,
}
@Override
- public void beforeMethod(final TargetAdviceObject target, final Method method, final Object[] args, final String pluginType) {
+ public void beforeMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final String pluginType) {
List<String> queue = (List<String>) args[0];
queue.add("foo before instance method");
}
@Override
- public void beforeMethod(final Class<?> clazz, final Method method, final Object[] args, final String pluginType) {
+ public void beforeMethod(final Class<?> clazz, final TargetAdviceMethod method, final Object[] args, final String pluginType) {
List<String> queue = (List<String>) args[0];
queue.add("foo before static method");
}
@Override
- public void afterMethod(final TargetAdviceObject target, final Method method, final Object[] args, final Object result, final String pluginType) {
+ public void afterMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final Object result, final String pluginType) {
List<String> queue = (List<String>) args[0];
queue.add("foo after instance method");
}
@Override
- public void afterMethod(final Class<?> clazz, final Method method, final Object[] args, final Object result, final String pluginType) {
+ public void afterMethod(final Class<?> clazz, final TargetAdviceMethod method, final Object[] args, final Object result, final String pluginType) {
List<String> queue = (List<String>) args[0];
queue.add("foo after static method");
}
@Override
- public void onThrowing(final TargetAdviceObject target, final Method method, final Object[] args, final Throwable throwable, final String pluginType) {
+ public void onThrowing(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final Throwable throwable, final String pluginType) {
List<String> queue = (List<String>) args[0];
queue.add("foo throw instance method exception");
}
@Override
- public void onThrowing(final Class<?> clazz, final Method method, final Object[] args, final Throwable throwable, final String pluginType) {
+ public void onThrowing(final Class<?> clazz, final TargetAdviceMethod method, final Object[] args, final Throwable throwable, final String pluginType) {
List<String> queue = (List<String>) args[0];
queue.add("foo throw static method exception");
}
diff --git a/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/recorder/MethodTimeRecorder.java b/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/recorder/MethodTimeRecorder.java
index fa1c713bcf0..eb0192c4ae7 100644
--- a/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/recorder/MethodTimeRecorder.java
+++ b/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/recorder/MethodTimeRecorder.java
@@ -19,8 +19,8 @@ package org.apache.shardingsphere.agent.plugin.core.recorder;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.agent.api.advice.AgentAdvice;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
-import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
@@ -39,7 +39,7 @@ public final class MethodTimeRecorder {
*
* @param method method to be recorded
*/
- public void recordNow(final Method method) {
+ public void recordNow(final TargetAdviceMethod method) {
CURRENT_RECORDER.get().put(getKey(method), System.currentTimeMillis());
}
@@ -49,7 +49,7 @@ public final class MethodTimeRecorder {
* @param method method to be recorded
* @return elapsed time
*/
- public long getElapsedTimeAndClean(final Method method) {
+ public long getElapsedTimeAndClean(final TargetAdviceMethod method) {
String key = getKey(method);
try {
return getElapsedTime(key);
@@ -58,7 +58,7 @@ public final class MethodTimeRecorder {
}
}
- private String getKey(final Method method) {
+ private String getKey(final TargetAdviceMethod method) {
return String.format("%s@%s", adviceClass.getName(), method.getName());
}
diff --git a/agent/plugins/core/src/test/java/org/apache/shardingsphere/agent/plugin/core/recorder/MethodTimeRecorderTest.java b/agent/plugins/core/src/test/java/org/apache/shardingsphere/agent/plugin/core/recorder/MethodTimeRecorderTest.java
index e6bc3732c6d..fcb931ac297 100644
--- a/agent/plugins/core/src/test/java/org/apache/shardingsphere/agent/plugin/core/recorder/MethodTimeRecorderTest.java
+++ b/agent/plugins/core/src/test/java/org/apache/shardingsphere/agent/plugin/core/recorder/MethodTimeRecorderTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.agent.plugin.core.recorder;
import org.apache.shardingsphere.agent.api.advice.AgentAdvice;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Test;
@@ -32,13 +33,15 @@ class MethodTimeRecorderTest {
@Test
void assertGetElapsedTimeAndCleanWithRecorded() throws NoSuchMethodException {
MethodTimeRecorder methodTimeRecorder = new MethodTimeRecorder(AgentAdvice.class);
- methodTimeRecorder.recordNow(Object.class.getDeclaredMethod("toString"));
+ TargetAdviceMethod method = new TargetAdviceMethod("test");
+ methodTimeRecorder.recordNow(method);
Awaitility.await().pollDelay(5L, TimeUnit.MILLISECONDS).until(() -> true);
- assertThat(methodTimeRecorder.getElapsedTimeAndClean(Object.class.getDeclaredMethod("toString")), greaterThanOrEqualTo(5L));
+ assertThat(methodTimeRecorder.getElapsedTimeAndClean(method), greaterThanOrEqualTo(5L));
}
@Test
void assertGetElapsedTimeAndCleanWithoutRecorded() throws NoSuchMethodException {
- assertThat(new MethodTimeRecorder(AgentAdvice.class).getElapsedTimeAndClean(Object.class.getDeclaredMethod("toString")), is(0L));
+ TargetAdviceMethod method = new TargetAdviceMethod("test");
+ assertThat(new MethodTimeRecorder(AgentAdvice.class).getElapsedTimeAndClean(method), is(0L));
}
}
diff --git a/agent/plugins/logging/type/file/src/main/java/org/apache/shardingsphere/agent/plugin/logging/file/advice/MetaDataContextsFactoryAdvice.java b/agent/plugins/logging/type/file/src/main/java/org/apache/shardingsphere/agent/plugin/logging/file/advice/MetaDataContextsFactoryAdvice.java
index 159624b5f78..d1fbef261c9 100644
--- a/agent/plugins/logging/type/file/src/main/java/org/apache/shardingsphere/agent/plugin/logging/file/advice/MetaDataContextsFactoryAdvice.java
+++ b/agent/plugins/logging/type/file/src/main/java/org/apache/shardingsphere/agent/plugin/logging/file/advice/MetaDataContextsFactoryAdvice.java
@@ -18,11 +18,10 @@
package org.apache.shardingsphere.agent.plugin.logging.file.advice;
import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.plugin.core.advice.AbstractStaticMethodAdvice;
import org.apache.shardingsphere.agent.plugin.core.recorder.MethodTimeRecorder;
-import java.lang.reflect.Method;
-
/**
* Meta data contexts factory advice.
*/
@@ -32,12 +31,12 @@ public final class MetaDataContextsFactoryAdvice extends AbstractStaticMethodAdv
private final MethodTimeRecorder methodTimeRecorder = new MethodTimeRecorder(MetaDataContextsFactoryAdvice.class);
@Override
- public void beforeMethod(final Class<?> clazz, final Method method, final Object[] args, final String pluginType) {
+ public void beforeMethod(final Class<?> clazz, final TargetAdviceMethod method, final Object[] args, final String pluginType) {
methodTimeRecorder.recordNow(method);
}
@Override
- public void afterMethod(final Class<?> clazz, final Method method, final Object[] args, final Object result, final String pluginType) {
+ public void afterMethod(final Class<?> clazz, final TargetAdviceMethod method, final Object[] args, final Object result, final String pluginType) {
log.info("Build meta data contexts finished, cost {} milliseconds.", methodTimeRecorder.getElapsedTimeAndClean(method));
}
}
diff --git a/agent/plugins/logging/type/file/src/test/java/org/apache/shardingsphere/agent/plugin/logging/file/advice/MetaDataContextsFactoryAdviceTest.java b/agent/plugins/logging/type/file/src/test/java/org/apache/shardingsphere/agent/plugin/logging/file/advice/MetaDataContextsFactoryAdviceTest.java
index 38e2236aa2b..c8fb1e46f3e 100644
--- a/agent/plugins/logging/type/file/src/test/java/org/apache/shardingsphere/agent/plugin/logging/file/advice/MetaDataContextsFactoryAdviceTest.java
+++ b/agent/plugins/logging/type/file/src/test/java/org/apache/shardingsphere/agent/plugin/logging/file/advice/MetaDataContextsFactoryAdviceTest.java
@@ -21,11 +21,11 @@ import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.LoggerFactory;
-import java.lang.reflect.Method;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -48,7 +48,7 @@ class MetaDataContextsFactoryAdviceTest {
@Test
void assertLog() {
MetaDataContextsFactoryAdvice advice = new MetaDataContextsFactoryAdvice();
- Method method = mock(Method.class);
+ TargetAdviceMethod method = mock(TargetAdviceMethod.class);
advice.beforeMethod(null, method, new Object[]{}, "FIXTURE");
advice.afterMethod(null, method, new Object[]{}, null, "FIXTURE");
List<ILoggingEvent> logsList = listAppender.list;
diff --git a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdvice.java b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdvice.java
index bb995a0d913..548b0af20c3 100644
--- a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdvice.java
+++ b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdvice.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
@@ -26,7 +27,6 @@ import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfigur
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
-import java.lang.reflect.Method;
import java.util.Arrays;
/**
@@ -38,7 +38,7 @@ public final class RouteResultCountAdvice extends AbstractInstanceMethodAdvice {
MetricCollectorType.COUNTER, "Total count of routed result", Arrays.asList("object", "name"));
@Override
- public void afterMethod(final TargetAdviceObject target, final Method method, final Object[] args, final Object result, final String pluginType) {
+ public void afterMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final Object result, final String pluginType) {
if (null == result) {
return;
}
diff --git a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdvice.java b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdvice.java
index 1182c6df766..18e69fbe72d 100644
--- a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdvice.java
+++ b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdvice.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
import org.apache.shardingsphere.agent.plugin.core.util.SQLStatementUtils;
@@ -26,7 +27,6 @@ import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollecto
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
-import java.lang.reflect.Method;
import java.util.Collections;
import java.util.Optional;
@@ -39,7 +39,7 @@ public final class SQLParseCountAdvice extends AbstractInstanceMethodAdvice {
MetricCollectorType.COUNTER, "Total count of parsed SQL", Collections.singletonList("type"), Collections.emptyMap());
@Override
- public void afterMethod(final TargetAdviceObject target, final Method method, final Object[] args, final Object result, final String pluginType) {
+ public void afterMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final Object result, final String pluginType) {
getSQLType((SQLStatement) result).ifPresent(optional -> MetricsCollectorRegistry.<CounterMetricsCollector>get(config, pluginType).inc(optional));
}
diff --git a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdvice.java b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdvice.java
index a2991d9267d..3eeba05475f 100644
--- a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdvice.java
+++ b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdvice.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
import org.apache.shardingsphere.agent.plugin.core.util.SQLStatementUtils;
@@ -27,7 +28,6 @@ import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfigur
import org.apache.shardingsphere.infra.session.query.QueryContext;
import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
-import java.lang.reflect.Method;
import java.util.Collections;
import java.util.Optional;
@@ -40,7 +40,7 @@ public final class SQLRouteCountAdvice extends AbstractInstanceMethodAdvice {
MetricCollectorType.COUNTER, "Total count of routed SQL", Collections.singletonList("type"), Collections.emptyMap());
@Override
- public void beforeMethod(final TargetAdviceObject target, final Method method, final Object[] args, final String pluginType) {
+ public void beforeMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final String pluginType) {
QueryContext queryContext = (QueryContext) args[1];
SQLStatement sqlStatement = queryContext.getSqlStatementContext().getSqlStatement();
getSQLType(sqlStatement).ifPresent(optional -> MetricsCollectorRegistry.<CounterMetricsCollector>get(config, pluginType).inc(optional));
diff --git a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteCountAdvice.java b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteCountAdvice.java
index 3cc70c46bfd..77d1de45ee2 100644
--- a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteCountAdvice.java
+++ b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteCountAdvice.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.jdbc;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
@@ -24,7 +25,6 @@ import org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.Counte
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
-import java.lang.reflect.Method;
import java.util.Collections;
/**
@@ -36,7 +36,7 @@ public abstract class AbstractExecuteCountAdvice extends AbstractInstanceMethodA
"Total number of statement execute", Collections.singletonList("statement_type"));
@Override
- public void afterMethod(final TargetAdviceObject target, final Method method, final Object[] args, final Object result, final String pluginType) {
+ public void afterMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final Object result, final String pluginType) {
MetricsCollectorRegistry.<CounterMetricsCollector>get(config, pluginType).inc(getStatementType());
}
diff --git a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteErrorsCountAdvice.java b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteErrorsCountAdvice.java
index 3ec1523148d..836329e430e 100644
--- a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteErrorsCountAdvice.java
+++ b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteErrorsCountAdvice.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.jdbc;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
@@ -24,7 +25,6 @@ import org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.Counte
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
-import java.lang.reflect.Method;
import java.util.Collections;
/**
@@ -36,7 +36,7 @@ public abstract class AbstractExecuteErrorsCountAdvice extends AbstractInstanceM
"Total number of statement execute error", Collections.singletonList("statement_type"));
@Override
- public void onThrowing(final TargetAdviceObject target, final Method method, final Object[] args, final Throwable throwable, final String pluginType) {
+ public void onThrowing(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final Throwable throwable, final String pluginType) {
MetricsCollectorRegistry.<CounterMetricsCollector>get(config, pluginType).inc(getStatementType());
}
diff --git a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteLatencyHistogramAdvice.java b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteLatencyHistogramAdvice.java
index 06ca179d1d3..88cfc452305 100644
--- a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteLatencyHistogramAdvice.java
+++ b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteLatencyHistogramAdvice.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.jdbc;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
import org.apache.shardingsphere.agent.plugin.core.recorder.MethodTimeRecorder;
@@ -25,7 +26,6 @@ import org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.Histog
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
-import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -48,12 +48,12 @@ public abstract class AbstractExecuteLatencyHistogramAdvice extends AbstractInst
}
@Override
- public void beforeMethod(final TargetAdviceObject target, final Method method, final Object[] args, final String pluginType) {
+ public void beforeMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final String pluginType) {
getMethodTimeRecorder().recordNow(method);
}
@Override
- public void afterMethod(final TargetAdviceObject target, final Method method, final Object[] args, final Object result, final String pluginType) {
+ public void afterMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final Object result, final String pluginType) {
MetricsCollectorRegistry.<HistogramMetricsCollector>get(config, pluginType).observe(getMethodTimeRecorder().getElapsedTimeAndClean(method));
}
diff --git a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractTransactionsCountAdvice.java b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractTransactionsCountAdvice.java
index f74abc52a9a..b02f81ea602 100644
--- a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractTransactionsCountAdvice.java
+++ b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractTransactionsCountAdvice.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.jdbc;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
@@ -24,7 +25,6 @@ import org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.Counte
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
-import java.lang.reflect.Method;
import java.util.Collections;
/**
@@ -36,7 +36,7 @@ public abstract class AbstractTransactionsCountAdvice extends AbstractInstanceMe
"Total transactions of ShardingSphere-JDBC", Collections.singletonList("type"));
@Override
- public void afterMethod(final TargetAdviceObject target, final Method method, final Object[] args, final Object result, final String pluginType) {
+ public void afterMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final Object result, final String pluginType) {
MetricsCollectorRegistry.<CounterMetricsCollector>get(config, pluginType).inc(getTransactionType());
}
diff --git a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/ShardingSphereDataSourceAdvice.java b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/ShardingSphereDataSourceAdvice.java
index b7dada861c3..04bda4dcf28 100644
--- a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/ShardingSphereDataSourceAdvice.java
+++ b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/ShardingSphereDataSourceAdvice.java
@@ -17,28 +17,27 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.jdbc;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
import org.apache.shardingsphere.agent.plugin.core.holder.ContextManagerHolder;
import org.apache.shardingsphere.agent.plugin.core.util.AgentReflectionUtils;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import java.lang.reflect.Method;
-
/**
* ShardingSphere data source advice.
*/
public final class ShardingSphereDataSourceAdvice extends AbstractInstanceMethodAdvice {
@Override
- public void beforeMethod(final TargetAdviceObject target, final Method method, final Object[] args, final String pluginType) {
+ public void beforeMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final String pluginType) {
if ("close".equals(method.getName())) {
ContextManagerHolder.remove(getDatabaseName(target));
}
}
@Override
- public void afterMethod(final TargetAdviceObject target, final Method method, final Object[] args, final Object result, final String pluginType) {
+ public void afterMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final Object result, final String pluginType) {
if ("createContextManager".equals(method.getName())) {
ContextManagerHolder.put(getDatabaseName(target), (ContextManager) result);
}
diff --git a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdvice.java b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdvice.java
index a7c20d09c47..8b790da26fd 100644
--- a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdvice.java
+++ b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdvice.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
@@ -24,7 +25,6 @@ import org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.Counte
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
-import java.lang.reflect.Method;
import java.util.Collections;
/**
@@ -36,7 +36,7 @@ public final class CommitTransactionsCountAdvice extends AbstractInstanceMethodA
MetricCollectorType.COUNTER, "Total transactions of ShardingSphere-Proxy", Collections.singletonList("type"), Collections.emptyMap());
@Override
- public void beforeMethod(final TargetAdviceObject target, final Method method, final Object[] args, final String pluginType) {
+ public void beforeMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final String pluginType) {
MetricsCollectorRegistry.<CounterMetricsCollector>get(config, pluginType).inc("commit");
}
}
diff --git a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdvice.java b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdvice.java
index 3aad6ce0b02..107ccd26140 100644
--- a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdvice.java
+++ b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdvice.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
@@ -24,7 +25,6 @@ import org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeM
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
-import java.lang.reflect.Method;
import java.util.Collections;
/**
@@ -36,7 +36,7 @@ public final class CurrentConnectionsCountAdvice extends AbstractInstanceMethodA
MetricCollectorType.GAUGE, "Current connections of ShardingSphere-Proxy", Collections.emptyList(), Collections.emptyMap());
@Override
- public void beforeMethod(final TargetAdviceObject target, final Method method, final Object[] args, final String pluginType) {
+ public void beforeMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final String pluginType) {
switch (method.getName()) {
case "channelActive":
MetricsCollectorRegistry.<GaugeMetricsCollector>get(config, pluginType).inc();
diff --git a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdvice.java b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdvice.java
index 64a21d65919..374bd8b1a1d 100644
--- a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdvice.java
+++ b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdvice.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
@@ -24,7 +25,6 @@ import org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.Counte
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
-import java.lang.reflect.Method;
import java.util.Collections;
/**
@@ -36,7 +36,7 @@ public final class ExecuteErrorsCountAdvice extends AbstractInstanceMethodAdvice
"proxy_execute_errors_total", MetricCollectorType.COUNTER, "Total execute errors of ShardingSphere-Proxy", Collections.emptyList(), Collections.emptyMap());
@Override
- public void afterMethod(final TargetAdviceObject target, final Method method, final Object[] args, final Object result, final String pluginType) {
+ public void afterMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final Object result, final String pluginType) {
MetricsCollectorRegistry.<CounterMetricsCollector>get(config, pluginType).inc();
}
}
diff --git a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdvice.java b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdvice.java
index 55697a60253..fb666e92917 100644
--- a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdvice.java
+++ b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdvice.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
import org.apache.shardingsphere.agent.plugin.core.recorder.MethodTimeRecorder;
@@ -26,7 +27,6 @@ import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollecto
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor;
-import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -51,14 +51,14 @@ public final class ExecuteLatencyHistogramAdvice extends AbstractInstanceMethodA
}
@Override
- public void beforeMethod(final TargetAdviceObject target, final Method method, final Object[] args, final String pluginType) {
+ public void beforeMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final String pluginType) {
if (args[2] instanceof QueryCommandExecutor) {
methodTimeRecorder.recordNow(method);
}
}
@Override
- public void afterMethod(final TargetAdviceObject target, final Method method, final Object[] args, final Object result, final String pluginType) {
+ public void afterMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final Object result, final String pluginType) {
if (args[2] instanceof QueryCommandExecutor) {
MetricsCollectorRegistry.<HistogramMetricsCollector>get(config, pluginType).observe(methodTimeRecorder.getElapsedTimeAndClean(method));
}
diff --git a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdvice.java b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdvice.java
index f0fbacb5208..780a2cf83a4 100644
--- a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdvice.java
+++ b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdvice.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
@@ -24,7 +25,6 @@ import org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.Counte
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
-import java.lang.reflect.Method;
import java.util.Collections;
/**
@@ -36,7 +36,7 @@ public final class RequestsCountAdvice extends AbstractInstanceMethodAdvice {
MetricCollectorType.COUNTER, "Total requests of ShardingSphere-Proxy", Collections.emptyList(), Collections.emptyMap());
@Override
- public void afterMethod(final TargetAdviceObject target, final Method method, final Object[] args, final Object result, final String pluginType) {
+ public void afterMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final Object result, final String pluginType) {
MetricsCollectorRegistry.<CounterMetricsCollector>get(config, pluginType).inc();
}
}
diff --git a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdvice.java b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdvice.java
index d37d2c8c955..839483aab76 100644
--- a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdvice.java
+++ b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdvice.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
@@ -24,7 +25,6 @@ import org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.Counte
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
-import java.lang.reflect.Method;
import java.util.Collections;
/**
@@ -36,7 +36,7 @@ public final class RollbackTransactionsCountAdvice extends AbstractInstanceMetho
MetricCollectorType.COUNTER, "Total transactions of ShardingSphere-Proxy", Collections.singletonList("type"), Collections.emptyMap());
@Override
- public void beforeMethod(final TargetAdviceObject target, final Method method, final Object[] args, final String pluginType) {
+ public void beforeMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final String pluginType) {
MetricsCollectorRegistry.<CounterMetricsCollector>get(config, pluginType).inc("rollback");
}
}
diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdviceTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdviceTest.java
index c8bb4a26511..4acd99a3382 100644
--- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdviceTest.java
+++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdviceTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
@@ -28,7 +29,6 @@ import org.apache.shardingsphere.infra.route.context.RouteUnit;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
-import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
@@ -51,7 +51,7 @@ class RouteResultCountAdviceTest {
RouteMapper dataSourceMapper = new RouteMapper("logic_db", "ds_0");
RouteMapper tableMapper = new RouteMapper("t_order", "t_order_0");
routeContext.getRouteUnits().add(new RouteUnit(dataSourceMapper, Collections.singleton(tableMapper)));
- new RouteResultCountAdvice().afterMethod(new TargetAdviceObjectFixture(), mock(Method.class), new Object[]{}, routeContext, "FIXTURE");
+ new RouteResultCountAdvice().afterMethod(new TargetAdviceObjectFixture(), mock(TargetAdviceMethod.class), new Object[]{}, routeContext, "FIXTURE");
assertThat(MetricsCollectorRegistry.get(routedResultConfig, "FIXTURE").toString(), is("data_source.ds_0=1, table.t_order_0=1"));
}
}
diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdviceTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdviceTest.java
index 475da88adcb..9e459914be7 100644
--- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdviceTest.java
+++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdviceTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
@@ -39,7 +40,6 @@ import org.apache.shardingsphere.sql.parser.statement.mysql.tcl.MySQLCommitState
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
-import java.lang.reflect.Method;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
@@ -116,7 +116,7 @@ class SQLParseCountAdviceTest {
}
private void assertParse(final SQLStatement sqlStatement, final String expected) {
- new SQLParseCountAdvice().afterMethod(new TargetAdviceObjectFixture(), mock(Method.class), new Object[]{}, sqlStatement, "FIXTURE");
+ new SQLParseCountAdvice().afterMethod(new TargetAdviceObjectFixture(), mock(TargetAdviceMethod.class), new Object[]{}, sqlStatement, "FIXTURE");
assertThat(MetricsCollectorRegistry.get(config, "FIXTURE").toString(), is(expected));
}
}
diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdviceTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdviceTest.java
index c55bc4e33d1..95867b3560b 100644
--- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdviceTest.java
+++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdviceTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
@@ -35,7 +36,6 @@ import org.apache.shardingsphere.sql.parser.statement.mysql.dml.MySQLUpdateState
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
-import java.lang.reflect.Method;
import java.util.Collections;
import java.util.Optional;
@@ -90,7 +90,7 @@ class SQLRouteCountAdviceTest {
}
void assertRoute(final QueryContext queryContext, final String expected) {
- advice.beforeMethod(new TargetAdviceObjectFixture(), mock(Method.class), new Object[]{new ConnectionContext(Collections::emptySet), queryContext}, "FIXTURE");
+ advice.beforeMethod(new TargetAdviceObjectFixture(), mock(TargetAdviceMethod.class), new Object[]{new ConnectionContext(Collections::emptySet), queryContext}, "FIXTURE");
assertThat(MetricsCollectorRegistry.get(config, "FIXTURE").toString(), is(expected));
}
}
diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteCountAdviceTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteCountAdviceTest.java
index 70e9600a1ef..51438fb7911 100644
--- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteCountAdviceTest.java
+++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteCountAdviceTest.java
@@ -17,15 +17,15 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.jdbc;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
-import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.collector.MetricsCollectorFixture;
import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.TargetAdviceObjectFixture;
+import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.collector.MetricsCollectorFixture;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
-import java.lang.reflect.Method;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
@@ -45,14 +45,14 @@ class AbstractExecuteCountAdviceTest {
@Test
void assertWithStatement() {
StatementExecuteCountAdvice advice = new StatementExecuteCountAdvice();
- advice.afterMethod(new TargetAdviceObjectFixture(), mock(Method.class), new Object[]{}, null, "FIXTURE");
+ advice.afterMethod(new TargetAdviceObjectFixture(), mock(TargetAdviceMethod.class), new Object[]{}, null, "FIXTURE");
assertThat(MetricsCollectorRegistry.get(config, "FIXTURE").toString(), is("statement=1"));
}
@Test
void assertWithPreparedStatement() {
PreparedStatementExecuteCountAdvice advice = new PreparedStatementExecuteCountAdvice();
- advice.afterMethod(new TargetAdviceObjectFixture(), mock(Method.class), new Object[]{}, null, "FIXTURE");
+ advice.afterMethod(new TargetAdviceObjectFixture(), mock(TargetAdviceMethod.class), new Object[]{}, null, "FIXTURE");
assertThat(MetricsCollectorRegistry.get(config, "FIXTURE").toString(), is("prepared_statement=1"));
}
}
diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteErrorsCountAdviceTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteErrorsCountAdviceTest.java
index 516863f1c92..f3986eb529b 100644
--- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteErrorsCountAdviceTest.java
+++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteErrorsCountAdviceTest.java
@@ -17,16 +17,16 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.jdbc;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
-import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.collector.MetricsCollectorFixture;
import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.TargetAdviceObjectFixture;
+import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.collector.MetricsCollectorFixture;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import java.io.IOException;
-import java.lang.reflect.Method;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
@@ -46,14 +46,14 @@ class AbstractExecuteErrorsCountAdviceTest {
@Test
void assertWithStatement() {
StatementExecuteErrorsCountAdvice advice = new StatementExecuteErrorsCountAdvice();
- advice.onThrowing(new TargetAdviceObjectFixture(), mock(Method.class), new Object[]{}, mock(IOException.class), "FIXTURE");
+ advice.onThrowing(new TargetAdviceObjectFixture(), mock(TargetAdviceMethod.class), new Object[]{}, mock(IOException.class), "FIXTURE");
assertThat(MetricsCollectorRegistry.get(config, "FIXTURE").toString(), is("statement=1"));
}
@Test
void assertWithPreparedStatement() {
PreparedStatementExecuteErrorsCountAdvice advice = new PreparedStatementExecuteErrorsCountAdvice();
- advice.onThrowing(new TargetAdviceObjectFixture(), mock(Method.class), new Object[]{}, mock(IOException.class), "FIXTURE");
+ advice.onThrowing(new TargetAdviceObjectFixture(), mock(TargetAdviceMethod.class), new Object[]{}, mock(IOException.class), "FIXTURE");
assertThat(MetricsCollectorRegistry.get(config, "FIXTURE").toString(), is("prepared_statement=1"));
}
}
diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteLatencyHistogramAdviceTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteLatencyHistogramAdviceTest.java
index 8ba1a362819..4a530ebb023 100644
--- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteLatencyHistogramAdviceTest.java
+++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteLatencyHistogramAdviceTest.java
@@ -17,16 +17,16 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.jdbc;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
-import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.collector.MetricsCollectorFixture;
import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.TargetAdviceObjectFixture;
+import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.collector.MetricsCollectorFixture;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
-import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -46,7 +46,7 @@ class AbstractExecuteLatencyHistogramAdviceTest {
void assertWithStatement() {
StatementExecuteLatencyHistogramAdvice advice = new StatementExecuteLatencyHistogramAdvice();
TargetAdviceObjectFixture targetObject = new TargetAdviceObjectFixture();
- Method method = mock(Method.class);
+ TargetAdviceMethod method = mock(TargetAdviceMethod.class);
advice.beforeMethod(targetObject, method, new Object[]{}, "FIXTURE");
Awaitility.await().pollDelay(200L, TimeUnit.MILLISECONDS).until(() -> true);
advice.afterMethod(targetObject, method, new Object[]{}, null, "FIXTURE");
@@ -57,7 +57,7 @@ class AbstractExecuteLatencyHistogramAdviceTest {
void assertWithPreparedStatement() {
PreparedStatementExecuteLatencyHistogramAdvice advice = new PreparedStatementExecuteLatencyHistogramAdvice();
TargetAdviceObjectFixture targetObject = new TargetAdviceObjectFixture();
- Method method = mock(Method.class);
+ TargetAdviceMethod method = mock(TargetAdviceMethod.class);
advice.beforeMethod(targetObject, method, new Object[]{}, "FIXTURE");
Awaitility.await().pollDelay(200L, TimeUnit.MILLISECONDS).until(() -> true);
advice.afterMethod(targetObject, method, new Object[]{}, null, "FIXTURE");
diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractTransactionsCountAdviceTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractTransactionsCountAdviceTest.java
index d3f56fc0cd8..ff31e875135 100644
--- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractTransactionsCountAdviceTest.java
+++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractTransactionsCountAdviceTest.java
@@ -17,15 +17,15 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.jdbc;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
-import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.collector.MetricsCollectorFixture;
import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.TargetAdviceObjectFixture;
+import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.collector.MetricsCollectorFixture;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
-import java.lang.reflect.Method;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
@@ -45,14 +45,14 @@ class AbstractTransactionsCountAdviceTest {
@Test
void assertWithCommit() {
CommitTransactionsCountAdvice advice = new CommitTransactionsCountAdvice();
- advice.afterMethod(new TargetAdviceObjectFixture(), mock(Method.class), new Object[]{}, null, "FIXTURE");
+ advice.afterMethod(new TargetAdviceObjectFixture(), mock(TargetAdviceMethod.class), new Object[]{}, null, "FIXTURE");
assertThat(MetricsCollectorRegistry.get(config, "FIXTURE").toString(), is("commit=1"));
}
@Test
void assertWithRollback() {
RollbackTransactionsCountAdvice advice = new RollbackTransactionsCountAdvice();
- advice.afterMethod(new TargetAdviceObjectFixture(), mock(Method.class), new Object[]{}, null, "FIXTURE");
+ advice.afterMethod(new TargetAdviceObjectFixture(), mock(TargetAdviceMethod.class), new Object[]{}, null, "FIXTURE");
assertThat(MetricsCollectorRegistry.get(config, "FIXTURE").toString(), is("rollback=1"));
}
}
diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/ShardingSphereDataSourceAdviceTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/ShardingSphereDataSourceAdviceTest.java
index f77162e8d1e..e2cba8879d2 100644
--- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/ShardingSphereDataSourceAdviceTest.java
+++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/ShardingSphereDataSourceAdviceTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.jdbc;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.plugin.core.holder.ContextManagerHolder;
import org.apache.shardingsphere.agent.plugin.core.util.AgentReflectionUtils;
import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.TargetAdviceObjectFixture;
@@ -28,8 +29,6 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
-import java.lang.reflect.Method;
-
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
@@ -58,7 +57,7 @@ class ShardingSphereDataSourceAdviceTest {
void assertBeforeMethod() {
ContextManagerHolder.put(databaseName, mock(ContextManager.class, RETURNS_DEEP_STUBS));
assertThat(ContextManagerHolder.getDatabaseContextManager().size(), is(1));
- Method method = mock(Method.class);
+ TargetAdviceMethod method = mock(TargetAdviceMethod.class);
when(method.getName()).thenReturn("close");
ShardingSphereDataSourceAdvice advice = new ShardingSphereDataSourceAdvice();
advice.beforeMethod(fixture, method, new Object[]{}, "FIXTURE");
@@ -68,7 +67,7 @@ class ShardingSphereDataSourceAdviceTest {
@Test
void assertAfterMethod() {
assertThat(ContextManagerHolder.getDatabaseContextManager().size(), is(0));
- Method method = mock(Method.class);
+ TargetAdviceMethod method = mock(TargetAdviceMethod.class);
when(method.getName()).thenReturn("createContextManager");
ShardingSphereDataSourceAdvice advice = new ShardingSphereDataSourceAdvice();
advice.afterMethod(fixture, method, new Object[]{}, mock(ContextManager.class, RETURNS_DEEP_STUBS), "FIXTURE");
diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdviceTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdviceTest.java
index 1d3e3915fdd..512be2f317d 100644
--- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdviceTest.java
+++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdviceTest.java
@@ -17,15 +17,15 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
-import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.collector.MetricsCollectorFixture;
import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.TargetAdviceObjectFixture;
+import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.collector.MetricsCollectorFixture;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
-import java.lang.reflect.Method;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
@@ -45,7 +45,7 @@ class CommitTransactionsCountAdviceTest {
@Test
void assertMethod() {
- advice.beforeMethod(new TargetAdviceObjectFixture(), mock(Method.class), new Object[]{}, "FIXTURE");
+ advice.beforeMethod(new TargetAdviceObjectFixture(), mock(TargetAdviceMethod.class), new Object[]{}, "FIXTURE");
assertThat(MetricsCollectorRegistry.get(config, "FIXTURE").toString(), is("commit=1"));
}
}
diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdviceTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdviceTest.java
index f88827fea97..b52d8eadfc7 100644
--- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdviceTest.java
+++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdviceTest.java
@@ -17,15 +17,15 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
-import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.collector.MetricsCollectorFixture;
import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.TargetAdviceObjectFixture;
+import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.collector.MetricsCollectorFixture;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
-import java.lang.reflect.Method;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
@@ -53,8 +53,8 @@ class CurrentConnectionsCountAdviceTest {
assertThat(MetricsCollectorRegistry.get(config, "FIXTURE").toString(), is("1"));
}
- private Method mockMethod(final String methodName) {
- Method result = mock(Method.class);
+ private TargetAdviceMethod mockMethod(final String methodName) {
+ TargetAdviceMethod result = mock(TargetAdviceMethod.class);
when(result.getName()).thenReturn(methodName);
return result;
}
diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdviceTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdviceTest.java
index df3c8fa24b5..a1c4e98ce4e 100644
--- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdviceTest.java
+++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdviceTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
@@ -25,7 +26,6 @@ import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.TargetAdviceO
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
-import java.lang.reflect.Method;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
@@ -44,7 +44,7 @@ class ExecuteErrorsCountAdviceTest {
@Test
void assertCountExecuteErrors() {
TargetAdviceObjectFixture targetObject = new TargetAdviceObjectFixture();
- new ExecuteErrorsCountAdvice().afterMethod(targetObject, mock(Method.class), new Object[]{}, null, "FIXTURE");
+ new ExecuteErrorsCountAdvice().afterMethod(targetObject, mock(TargetAdviceMethod.class), new Object[]{}, null, "FIXTURE");
assertThat(MetricsCollectorRegistry.get(config, "FIXTURE").toString(), is("1"));
}
}
diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdviceTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdviceTest.java
index d1857ef129f..c28299228f0 100644
--- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdviceTest.java
+++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdviceTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
@@ -28,7 +29,6 @@ import org.awaitility.Awaitility;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
-import java.lang.reflect.Method;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
@@ -50,7 +50,7 @@ class ExecuteLatencyHistogramAdviceTest {
void assertExecuteLatencyHistogramWhenQueryCommandExecutor() {
ExecuteLatencyHistogramAdvice advice = new ExecuteLatencyHistogramAdvice();
TargetAdviceObjectFixture targetObject = new TargetAdviceObjectFixture();
- Method method = mock(Method.class);
+ TargetAdviceMethod method = mock(TargetAdviceMethod.class);
Object[] args = new Object[]{null, null, mock(MySQLComQueryPacketExecutor.class)};
advice.beforeMethod(targetObject, method, args, "FIXTURE");
Awaitility.await().pollDelay(500L, TimeUnit.MILLISECONDS).until(() -> true);
@@ -62,7 +62,7 @@ class ExecuteLatencyHistogramAdviceTest {
void assertExecuteLatencyHistogramWhenNotQueryCommandExecutor() {
ExecuteLatencyHistogramAdvice advice = new ExecuteLatencyHistogramAdvice();
TargetAdviceObjectFixture targetObject = new TargetAdviceObjectFixture();
- Method method = mock(Method.class);
+ TargetAdviceMethod method = mock(TargetAdviceMethod.class);
Object[] args = new Object[]{null, null, mock(MySQLComQuitExecutor.class)};
advice.beforeMethod(targetObject, method, args, "FIXTURE");
Awaitility.await().pollDelay(20L, TimeUnit.MILLISECONDS).until(() -> true);
diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdviceTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdviceTest.java
index 1617ccf71d0..6debcd907e8 100644
--- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdviceTest.java
+++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdviceTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
@@ -25,7 +26,6 @@ import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.TargetAdviceO
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
-import java.lang.reflect.Method;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
@@ -46,7 +46,7 @@ class RequestsCountAdviceTest {
@Test
void assertCountRequests() {
TargetAdviceObjectFixture targetObject = new TargetAdviceObjectFixture();
- advice.afterMethod(targetObject, mock(Method.class), new Object[]{}, null, "FIXTURE");
+ advice.afterMethod(targetObject, mock(TargetAdviceMethod.class), new Object[]{}, null, "FIXTURE");
assertThat(MetricsCollectorRegistry.get(config, "FIXTURE").toString(), is("1"));
}
}
diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdviceTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdviceTest.java
index 0d4127e47b2..bfe4a669f95 100644
--- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdviceTest.java
+++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdviceTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
@@ -25,7 +26,6 @@ import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.TargetAdviceO
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
-import java.lang.reflect.Method;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
@@ -45,7 +45,7 @@ class RollbackTransactionsCountAdviceTest {
@Test
void assertMethod() {
- advice.beforeMethod(new TargetAdviceObjectFixture(), mock(Method.class), new Object[]{}, "FIXTURE");
+ advice.beforeMethod(new TargetAdviceObjectFixture(), mock(TargetAdviceMethod.class), new Object[]{}, "FIXTURE");
assertThat(MetricsCollectorRegistry.get(config, "FIXTURE").toString(), is("rollback=1"));
}
}
diff --git a/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingJDBCExecutorCallbackAdvice.java b/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingJDBCExecutorCallbackAdvice.java
index de151c669c7..c9d96225613 100644
--- a/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingJDBCExecutorCallbackAdvice.java
+++ b/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingJDBCExecutorCallbackAdvice.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.plugin.tracing.core.advice;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
import org.apache.shardingsphere.agent.plugin.core.util.AgentReflectionUtils;
@@ -26,8 +27,6 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutionUnit;
import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
-import java.lang.reflect.Method;
-
/**
* Tracing JDBC executor callback advice executor.
*
@@ -38,7 +37,7 @@ public abstract class TracingJDBCExecutorCallbackAdvice<T> extends AbstractInsta
protected static final String OPERATION_NAME = "/ShardingSphere/executeSQL/";
@Override
- public final void beforeMethod(final TargetAdviceObject target, final Method method, final Object[] args, final String pluginType) {
+ public final void beforeMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final String pluginType) {
JDBCExecutionUnit executionUnit = (JDBCExecutionUnit) args[0];
ResourceMetaData resourceMetaData = AgentReflectionUtils.getFieldValue(target, "resourceMetaData");
ConnectionProperties connectionProps = resourceMetaData.getStorageUnits().get(executionUnit.getExecutionUnit().getDataSourceName()).getConnectionProperties();
diff --git a/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingRootSpanAdvice.java b/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingRootSpanAdvice.java
index f8702d27054..195c2b3ed6b 100644
--- a/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingRootSpanAdvice.java
+++ b/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingRootSpanAdvice.java
@@ -17,12 +17,11 @@
package org.apache.shardingsphere.agent.plugin.tracing.core.advice;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
import org.apache.shardingsphere.agent.plugin.tracing.core.RootSpanContext;
-import java.lang.reflect.Method;
-
/**
* Tracing root span advice.
*
@@ -33,21 +32,21 @@ public abstract class TracingRootSpanAdvice<T> extends AbstractInstanceMethodAdv
protected static final String OPERATION_NAME = "/ShardingSphere/rootInvoke/";
@Override
- public final void beforeMethod(final TargetAdviceObject target, final Method method, final Object[] args, final String pluginType) {
+ public final void beforeMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final String pluginType) {
RootSpanContext.set(createRootSpan(target, method, args));
}
- protected abstract T createRootSpan(TargetAdviceObject target, Method method, Object[] args);
+ protected abstract T createRootSpan(TargetAdviceObject target, TargetAdviceMethod method, Object[] args);
@Override
- public final void afterMethod(final TargetAdviceObject target, final Method method, final Object[] args, final Object result, final String pluginType) {
+ public final void afterMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final Object result, final String pluginType) {
finishRootSpan(RootSpanContext.get(), target);
}
protected abstract void finishRootSpan(T rootSpan, TargetAdviceObject target);
@Override
- public final void onThrowing(final TargetAdviceObject target, final Method method, final Object[] args, final Throwable throwable, final String pluginType) {
+ public final void onThrowing(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final Throwable throwable, final String pluginType) {
recordException(RootSpanContext.get(), target, throwable);
}
diff --git a/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingSQLParserEngineAdvice.java b/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingSQLParserEngineAdvice.java
index 39ba1fe25ef..893b1ab3e2f 100644
--- a/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingSQLParserEngineAdvice.java
+++ b/agent/plugins/tracing/core/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/core/advice/TracingSQLParserEngineAdvice.java
@@ -17,12 +17,11 @@
package org.apache.shardingsphere.agent.plugin.tracing.core.advice;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice;
import org.apache.shardingsphere.agent.plugin.tracing.core.RootSpanContext;
-import java.lang.reflect.Method;
-
/**
* Tracing SQL parser engine advice executor.
*
@@ -33,7 +32,7 @@ public abstract class TracingSQLParserEngineAdvice<T> extends AbstractInstanceMe
protected static final String OPERATION_NAME = "/ShardingSphere/parseSQL/";
@Override
- public final void beforeMethod(final TargetAdviceObject target, final Method method, final Object[] args, final String pluginType) {
+ public final void beforeMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final String pluginType) {
recordSQLParseInfo(RootSpanContext.get(), target, String.valueOf(args[0]));
}
diff --git a/agent/plugins/tracing/type/opentelemetry/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/advice/OpenTelemetryJDBCExecutorCallbackAdvice.java b/agent/plugins/tracing/type/opentelemetry/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/advice/OpenTelemetryJDBCExecutorCallbackAdvice.java
index 9eeb7325f95..951a18f7aea 100644
--- a/agent/plugins/tracing/type/opentelemetry/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/advice/OpenTelemetryJDBCExecutorCallbackAdvice.java
+++ b/agent/plugins/tracing/type/opentelemetry/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/advice/OpenTelemetryJDBCExecutorCallbackAdvice.java
@@ -23,6 +23,7 @@ import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Context;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.plugin.tracing.core.advice.TracingJDBCExecutorCallbackAdvice;
import org.apache.shardingsphere.agent.plugin.tracing.core.constant.AttributeConstants;
@@ -31,8 +32,6 @@ import org.apache.shardingsphere.infra.database.core.connector.ConnectionPropert
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutionUnit;
-import java.lang.reflect.Method;
-
/**
* OpenTelemetry JDBC executor callback advice executor.
*/
@@ -56,14 +55,14 @@ public final class OpenTelemetryJDBCExecutorCallbackAdvice extends TracingJDBCEx
}
@Override
- public void afterMethod(final TargetAdviceObject target, final Method method, final Object[] args, final Object result, final String pluginType) {
+ public void afterMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final Object result, final String pluginType) {
Span span = (Span) target.getAttachment();
span.setStatus(StatusCode.OK);
span.end();
}
@Override
- public void onThrowing(final TargetAdviceObject target, final Method method, final Object[] args, final Throwable throwable, final String pluginType) {
+ public void onThrowing(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final Throwable throwable, final String pluginType) {
Span span = (Span) target.getAttachment();
span.setStatus(StatusCode.ERROR).recordException(throwable);
span.end();
diff --git a/agent/plugins/tracing/type/opentelemetry/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/advice/OpenTelemetryRootSpanAdvice.java b/agent/plugins/tracing/type/opentelemetry/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/advice/OpenTelemetryRootSpanAdvice.java
index aa0263b8b4a..8bf080ee012 100644
--- a/agent/plugins/tracing/type/opentelemetry/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/advice/OpenTelemetryRootSpanAdvice.java
+++ b/agent/plugins/tracing/type/opentelemetry/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/advice/OpenTelemetryRootSpanAdvice.java
@@ -21,20 +21,19 @@ import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.api.trace.StatusCode;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.plugin.tracing.core.advice.TracingRootSpanAdvice;
import org.apache.shardingsphere.agent.plugin.tracing.core.constant.AttributeConstants;
import org.apache.shardingsphere.agent.plugin.tracing.opentelemetry.constant.OpenTelemetryConstants;
-import java.lang.reflect.Method;
-
/**
* OpenTelemetry root span advice.
*/
public final class OpenTelemetryRootSpanAdvice extends TracingRootSpanAdvice<Span> {
@Override
- protected Span createRootSpan(final TargetAdviceObject target, final Method method, final Object[] args) {
+ protected Span createRootSpan(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args) {
SpanBuilder spanBuilder = GlobalOpenTelemetry.getTracer(OpenTelemetryConstants.TRACER_NAME)
.spanBuilder(OPERATION_NAME)
.setAttribute(AttributeConstants.COMPONENT, AttributeConstants.COMPONENT_NAME)
diff --git a/agent/plugins/tracing/type/opentelemetry/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/advice/OpenTelemetrySQLParserEngineAdvice.java b/agent/plugins/tracing/type/opentelemetry/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/advice/OpenTelemetrySQLParserEngineAdvice.java
index ab3bd90b714..4f87b13e586 100644
--- a/agent/plugins/tracing/type/opentelemetry/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/advice/OpenTelemetrySQLParserEngineAdvice.java
+++ b/agent/plugins/tracing/type/opentelemetry/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/advice/OpenTelemetrySQLParserEngineAdvice.java
@@ -23,13 +23,12 @@ import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Context;
+import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.plugin.tracing.core.advice.TracingSQLParserEngineAdvice;
import org.apache.shardingsphere.agent.plugin.tracing.core.constant.AttributeConstants;
import org.apache.shardingsphere.agent.plugin.tracing.opentelemetry.constant.OpenTelemetryConstants;
-import java.lang.reflect.Method;
-
/**
* OpenTelemetry SQL parser engine advice executor.
*/
@@ -49,14 +48,14 @@ public final class OpenTelemetrySQLParserEngineAdvice extends TracingSQLParserEn
}
@Override
- public void afterMethod(final TargetAdviceObject target, final Method method, final Object[] args, final Object result, final String pluginType) {
+ public void afterMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final Object result, final String pluginType) {
Span span = (Span) target.getAttachment();
span.setStatus(StatusCode.OK);
span.end();
}
@Override
- public void onThrowing(final TargetAdviceObject target, final Method method, final Object[] args, final Throwable throwable, final String pluginType) {
+ public void onThrowing(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final Throwable throwable, final String pluginType) {
Span span = (Span) target.getAttachment();
span.setStatus(StatusCode.ERROR).recordException(throwable);
span.end();