You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by su...@apache.org on 2022/12/14 15:39:50 UTC
[shardingsphere] branch master updated: Refactor advisor.yaml (#22874)
This is an automated email from the ASF dual-hosted git repository.
sunnianjun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 4768ef3774b Refactor advisor.yaml (#22874)
4768ef3774b is described below
commit 4768ef3774b7d97c46b68578351cd180a94d260b
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Wed Dec 14 23:39:36 2022 +0800
Refactor advisor.yaml (#22874)
---
.../plugin/interceptor/ConstructorInterceptor.java | 2 +-
.../ComposedConstructorInterceptor.java | 2 +-
.../ComposedInstanceMethodAroundInterceptor.java | 2 +-
...posedInstanceMethodInterceptorArgsOverride.java | 2 +-
.../ComposedStaticMethodAroundInterceptor.java | 2 +-
...omposedStaticMethodInterceptorArgsOverride.java | 2 +-
.../agent/core/transformer/AgentTransformer.java | 10 +--
...erceptor.java => YamlAdvisorConfiguration.java} | 6 +-
...ceptors.java => YamlAdvisorsConfiguration.java} | 6 +-
...etPoint.java => YamlPointcutConfiguration.java} | 4 +-
....java => YamlAdvisorsConfigurationSwapper.java} | 14 ++--
...> ConstructorYamlAdvisorConfigurationTest.java} | 2 +-
...eMethodAroundYamlAdvisorConfigurationTest.java} | 2 +-
...cMethodAroundYamlAdvisorConfigurationTest.java} | 2 +-
.../yaml/swapper/InterceptorsYamlSwapperTest.java | 88 ---------------------
.../YamlAdvisorsConfigurationSwapperTest.java | 90 ++++++++++++++++++++++
.../resources/{interceptors.yaml => advisors.yaml} | 12 +--
.../PrometheusAdvisorDefinitionService.java | 28 +++----
.../{interceptors.yaml => advisors.yaml} | 12 +--
19 files changed, 145 insertions(+), 143 deletions(-)
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/ConstructorInterceptor.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/ConstructorInterceptor.java
index 746b4ec197e..b83f7ab2108 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/ConstructorInterceptor.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/ConstructorInterceptor.java
@@ -45,8 +45,8 @@ public class ConstructorInterceptor {
*/
@RuntimeType
public void intercept(@This final TargetAdviceObject target, @AllArguments final Object[] args) {
+ boolean adviceEnabled = constructorAdvice.disableCheck() || PluginContext.isPluginEnabled();
try {
- boolean adviceEnabled = constructorAdvice.disableCheck() || PluginContext.isPluginEnabled();
if (adviceEnabled) {
constructorAdvice.onConstructor(target, args);
}
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/compose/ComposedConstructorInterceptor.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/composed/ComposedConstructorInterceptor.java
similarity index 99%
rename from agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/compose/ComposedConstructorInterceptor.java
rename to agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/composed/ComposedConstructorInterceptor.java
index f253b03638a..178fb5565d1 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/compose/ComposedConstructorInterceptor.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/composed/ComposedConstructorInterceptor.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.plugin.interceptor.compose;
+package org.apache.shardingsphere.agent.core.plugin.interceptor.composed;
import org.apache.shardingsphere.agent.core.plugin.advice.ConstructorAdvice;
import org.apache.shardingsphere.agent.core.plugin.advice.composed.ComposedConstructorAdvice;
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/compose/ComposedInstanceMethodAroundInterceptor.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/composed/ComposedInstanceMethodAroundInterceptor.java
similarity index 99%
rename from agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/compose/ComposedInstanceMethodAroundInterceptor.java
rename to agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/composed/ComposedInstanceMethodAroundInterceptor.java
index e11e91ff5ad..ea0b317ca48 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/compose/ComposedInstanceMethodAroundInterceptor.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/composed/ComposedInstanceMethodAroundInterceptor.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.plugin.interceptor.compose;
+package org.apache.shardingsphere.agent.core.plugin.interceptor.composed;
import org.apache.shardingsphere.agent.core.plugin.advice.InstanceMethodAroundAdvice;
import org.apache.shardingsphere.agent.core.plugin.advice.composed.ComposedInstanceMethodAroundAdvice;
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/compose/ComposedInstanceMethodInterceptorArgsOverride.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/composed/ComposedInstanceMethodInterceptorArgsOverride.java
similarity index 99%
rename from agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/compose/ComposedInstanceMethodInterceptorArgsOverride.java
rename to agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/composed/ComposedInstanceMethodInterceptorArgsOverride.java
index 823306de4a9..af8b241cdb0 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/compose/ComposedInstanceMethodInterceptorArgsOverride.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/composed/ComposedInstanceMethodInterceptorArgsOverride.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.plugin.interceptor.compose;
+package org.apache.shardingsphere.agent.core.plugin.interceptor.composed;
import org.apache.shardingsphere.agent.core.plugin.advice.InstanceMethodAroundAdvice;
import org.apache.shardingsphere.agent.core.plugin.advice.composed.ComposedInstanceMethodAroundAdvice;
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/compose/ComposedStaticMethodAroundInterceptor.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/composed/ComposedStaticMethodAroundInterceptor.java
similarity index 99%
rename from agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/compose/ComposedStaticMethodAroundInterceptor.java
rename to agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/composed/ComposedStaticMethodAroundInterceptor.java
index dc5e24e13a2..b3bc2dcd3bf 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/compose/ComposedStaticMethodAroundInterceptor.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/composed/ComposedStaticMethodAroundInterceptor.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.plugin.interceptor.compose;
+package org.apache.shardingsphere.agent.core.plugin.interceptor.composed;
import org.apache.shardingsphere.agent.core.plugin.advice.StaticMethodAroundAdvice;
import org.apache.shardingsphere.agent.core.plugin.advice.composed.ComposedStaticMethodAroundAdvice;
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/compose/ComposedStaticMethodInterceptorArgsOverride.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/composed/ComposedStaticMethodInterceptorArgsOverride.java
similarity index 99%
rename from agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/compose/ComposedStaticMethodInterceptorArgsOverride.java
rename to agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/composed/ComposedStaticMethodInterceptorArgsOverride.java
index 1f9003afb38..4b3dedb0ade 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/compose/ComposedStaticMethodInterceptorArgsOverride.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/interceptor/composed/ComposedStaticMethodInterceptorArgsOverride.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.plugin.interceptor.compose;
+package org.apache.shardingsphere.agent.core.plugin.interceptor.composed;
import org.apache.shardingsphere.agent.core.plugin.advice.StaticMethodAroundAdvice;
import org.apache.shardingsphere.agent.core.plugin.advice.composed.ComposedStaticMethodAroundAdvice;
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/transformer/AgentTransformer.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/transformer/AgentTransformer.java
index be8fa7165fc..27127617c5e 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/transformer/AgentTransformer.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/transformer/AgentTransformer.java
@@ -45,11 +45,11 @@ import org.apache.shardingsphere.agent.core.plugin.interceptor.InstanceMethodAro
import org.apache.shardingsphere.agent.core.plugin.interceptor.InstanceMethodInterceptorArgsOverride;
import org.apache.shardingsphere.agent.core.plugin.interceptor.StaticMethodAroundInterceptor;
import org.apache.shardingsphere.agent.core.plugin.interceptor.StaticMethodInterceptorArgsOverride;
-import org.apache.shardingsphere.agent.core.plugin.interceptor.compose.ComposedConstructorInterceptor;
-import org.apache.shardingsphere.agent.core.plugin.interceptor.compose.ComposedInstanceMethodAroundInterceptor;
-import org.apache.shardingsphere.agent.core.plugin.interceptor.compose.ComposedInstanceMethodInterceptorArgsOverride;
-import org.apache.shardingsphere.agent.core.plugin.interceptor.compose.ComposedStaticMethodAroundInterceptor;
-import org.apache.shardingsphere.agent.core.plugin.interceptor.compose.ComposedStaticMethodInterceptorArgsOverride;
+import org.apache.shardingsphere.agent.core.plugin.interceptor.composed.ComposedConstructorInterceptor;
+import org.apache.shardingsphere.agent.core.plugin.interceptor.composed.ComposedInstanceMethodAroundInterceptor;
+import org.apache.shardingsphere.agent.core.plugin.interceptor.composed.ComposedInstanceMethodInterceptorArgsOverride;
+import org.apache.shardingsphere.agent.core.plugin.interceptor.composed.ComposedStaticMethodAroundInterceptor;
+import org.apache.shardingsphere.agent.core.plugin.interceptor.composed.ComposedStaticMethodInterceptorArgsOverride;
import org.apache.shardingsphere.agent.core.plugin.AgentAdvisors;
import java.util.Collection;
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/entity/Interceptor.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/entity/YamlAdvisorConfiguration.java
similarity index 87%
rename from agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/entity/Interceptor.java
rename to agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/entity/YamlAdvisorConfiguration.java
index bdbd105cded..2fb6c629926 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/entity/Interceptor.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/entity/YamlAdvisorConfiguration.java
@@ -24,11 +24,11 @@ import java.util.Collection;
import java.util.LinkedList;
/**
- * Interceptor.
+ * YAML advisor configuration.
*/
@Getter
@Setter
-public final class Interceptor {
+public final class YamlAdvisorConfiguration {
private String target;
@@ -38,5 +38,5 @@ public final class Interceptor {
private String constructAdvice;
- private Collection<TargetPoint> points = new LinkedList<>();
+ private Collection<YamlPointcutConfiguration> pointcuts = new LinkedList<>();
}
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/entity/Interceptors.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/entity/YamlAdvisorsConfiguration.java
similarity index 86%
rename from agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/entity/Interceptors.java
rename to agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/entity/YamlAdvisorsConfiguration.java
index c063a03563e..75cc83b7d5b 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/entity/Interceptors.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/entity/YamlAdvisorsConfiguration.java
@@ -24,11 +24,11 @@ import java.util.Collection;
import java.util.LinkedList;
/**
- * Interceptors.
+ * YAML advisors configuration.
*/
@Setter
@Getter
-public final class Interceptors {
+public final class YamlAdvisorsConfiguration {
- private Collection<Interceptor> interceptors = new LinkedList<>();
+ private Collection<YamlAdvisorConfiguration> advisors = new LinkedList<>();
}
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/entity/TargetPoint.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/entity/YamlPointcutConfiguration.java
similarity index 92%
rename from agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/entity/TargetPoint.java
rename to agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/entity/YamlPointcutConfiguration.java
index 8d8a3b610ac..1889255ded3 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/entity/TargetPoint.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/entity/YamlPointcutConfiguration.java
@@ -21,11 +21,11 @@ import lombok.Getter;
import lombok.Setter;
/**
- * Target function.
+ * Yaml pointcut configuration.
*/
@Getter
@Setter
-public final class TargetPoint {
+public final class YamlPointcutConfiguration {
private String name;
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/InterceptorsYamlSwapper.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlAdvisorsConfigurationSwapper.java
similarity index 70%
rename from agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/InterceptorsYamlSwapper.java
rename to agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlAdvisorsConfigurationSwapper.java
index f184f3000a0..5cf112f11d3 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/InterceptorsYamlSwapper.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlAdvisorsConfigurationSwapper.java
@@ -17,23 +17,23 @@
package org.apache.shardingsphere.agent.core.yaml.swapper;
-import org.apache.shardingsphere.agent.core.yaml.entity.Interceptors;
+import org.apache.shardingsphere.agent.core.yaml.entity.YamlAdvisorsConfiguration;
import org.yaml.snakeyaml.Yaml;
import java.io.InputStream;
/**
- * Interceptors YAML swapper.
+ * YAML advisors configuration swapper.
*/
-public final class InterceptorsYamlSwapper {
+public final class YamlAdvisorsConfigurationSwapper {
/**
- * unmarshal interceptors.
+ * unmarshal advisors configuration.
*
* @param inputStream input stream
- * @return unmarshalled interceptors
+ * @return unmarshalled advisors configuration
*/
- public Interceptors unmarshal(final InputStream inputStream) {
- return new Yaml().loadAs(inputStream, Interceptors.class);
+ public YamlAdvisorsConfiguration unmarshal(final InputStream inputStream) {
+ return new Yaml().loadAs(inputStream, YamlAdvisorsConfiguration.class);
}
}
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/interceptor/ConstructorInterceptorTest.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/interceptor/ConstructorYamlAdvisorConfigurationTest.java
similarity index 98%
rename from agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/interceptor/ConstructorInterceptorTest.java
rename to agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/interceptor/ConstructorYamlAdvisorConfigurationTest.java
index 9d7c15bd265..7cb42d72ada 100644
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/interceptor/ConstructorInterceptorTest.java
+++ b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/interceptor/ConstructorYamlAdvisorConfigurationTest.java
@@ -43,7 +43,7 @@ import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertArrayEquals;
import static org.hamcrest.MatcherAssert.assertThat;
-public final class ConstructorInterceptorTest {
+public final class ConstructorYamlAdvisorConfigurationTest {
private static final String EXTRA_DATA = "_$EXTRA_DATA$_";
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/interceptor/InstanceMethodAroundInterceptorTest.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/interceptor/InstanceMethodAroundYamlAdvisorConfigurationTest.java
similarity index 98%
rename from agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/interceptor/InstanceMethodAroundInterceptorTest.java
rename to agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/interceptor/InstanceMethodAroundYamlAdvisorConfigurationTest.java
index 441778c6311..ece107956b5 100644
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/interceptor/InstanceMethodAroundInterceptorTest.java
+++ b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/interceptor/InstanceMethodAroundYamlAdvisorConfigurationTest.java
@@ -49,7 +49,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
@RunWith(Parameterized.class)
@RequiredArgsConstructor
-public final class InstanceMethodAroundInterceptorTest {
+public final class InstanceMethodAroundYamlAdvisorConfigurationTest {
private static final String EXTRA_DATA = "_$EXTRA_DATA$_";
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/interceptor/StaticMethodAroundInterceptorTest.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/interceptor/StaticMethodAroundYamlAdvisorConfigurationTest.java
similarity index 98%
rename from agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/interceptor/StaticMethodAroundInterceptorTest.java
rename to agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/interceptor/StaticMethodAroundYamlAdvisorConfigurationTest.java
index 8ceb2ed3c5e..00967b270e9 100644
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/interceptor/StaticMethodAroundInterceptorTest.java
+++ b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/interceptor/StaticMethodAroundYamlAdvisorConfigurationTest.java
@@ -49,7 +49,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
@RunWith(Parameterized.class)
@RequiredArgsConstructor
-public final class StaticMethodAroundInterceptorTest {
+public final class StaticMethodAroundYamlAdvisorConfigurationTest {
private static final String EXTRA_DATA = "_$EXTRA_DATA$_";
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/yaml/swapper/InterceptorsYamlSwapperTest.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/yaml/swapper/InterceptorsYamlSwapperTest.java
deleted file mode 100644
index b8713027c7b..00000000000
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/yaml/swapper/InterceptorsYamlSwapperTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.agent.core.yaml.swapper;
-
-import org.apache.shardingsphere.agent.core.yaml.entity.Interceptor;
-import org.apache.shardingsphere.agent.core.yaml.entity.Interceptors;
-import org.apache.shardingsphere.agent.core.yaml.entity.TargetPoint;
-import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-public final class InterceptorsYamlSwapperTest {
-
- @Test
- public void assertUnmarshal() {
- Interceptors actual = new InterceptorsYamlSwapper().unmarshal(getClass().getResourceAsStream("/interceptors.yaml"));
- assertThat(actual.getInterceptors().size(), is(5));
- List<Interceptor> actualInterceptors = new ArrayList<>(actual.getInterceptors());
- assertInterceptor(actualInterceptors.get(0), createExpectedInterceptor("org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask",
- "org.apache.shardingsphere.agent.metrics.api.advice.CommandExecutorTaskAdvice",
- null, null, Arrays.asList(createExpectedTargetPoint("run", "instance"), createExpectedTargetPoint("processException", "instance"))));
- assertInterceptor(actualInterceptors.get(1), createExpectedInterceptor("org.apache.shardingsphere.proxy.frontend.netty.FrontendChannelInboundHandler",
- "org.apache.shardingsphere.agent.metrics.api.advice.ChannelHandlerAdvice",
- null, null, Arrays.asList(
- createExpectedTargetPoint("channelActive", "instance"), createExpectedTargetPoint("channelRead", "instance"), createExpectedTargetPoint("channelInactive", "instance"))));
- assertInterceptor(actualInterceptors.get(2), createExpectedInterceptor("org.apache.shardingsphere.infra.route.engine.SQLRouteEngine",
- "org.apache.shardingsphere.agent.metrics.api.advice.SQLRouteEngineAdvice", null, null, Collections.singleton(createExpectedTargetPoint("route", "instance"))));
- assertInterceptor(actualInterceptors.get(3), createExpectedInterceptor("org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.BackendTransactionManager",
- "org.apache.shardingsphere.agent.metrics.api.advice.TransactionAdvice",
- null, null, Arrays.asList(createExpectedTargetPoint("commit", "instance"), createExpectedTargetPoint("rollback", "instance"))));
- assertInterceptor(actualInterceptors.get(4), createExpectedInterceptor("org.apache.shardingsphere.infra.config.datasource.JDBCParameterDecoratorHelper",
- null, "org.apache.shardingsphere.agent.metrics.api.advice.DataSourceAdvice", null, Collections.singleton(createExpectedTargetPoint("decorate", "static"))));
- }
-
- private void assertInterceptor(final Interceptor actual, final Interceptor expected) {
- assertThat(actual.getTarget(), is(expected.getTarget()));
- assertThat(actual.getInstanceAdvice(), is(expected.getInstanceAdvice()));
- assertThat(actual.getStaticAdvice(), is(expected.getStaticAdvice()));
- assertThat(actual.getConstructAdvice(), is(expected.getConstructAdvice()));
- assertThat(actual.getPoints().isEmpty(), is(expected.getPoints().isEmpty()));
- Iterator<TargetPoint> expectedTargetPoints = expected.getPoints().iterator();
- for (TargetPoint each : actual.getPoints()) {
- TargetPoint expectedTargetPoint = expectedTargetPoints.next();
- assertThat(each.getName(), is(expectedTargetPoint.getName()));
- assertThat(each.getType(), is(expectedTargetPoint.getType()));
- }
- }
-
- private Interceptor createExpectedInterceptor(final String target, final String instanceAdvice, final String staticAdvice, final String constructAdvice, final Collection<TargetPoint> points) {
- Interceptor result = new Interceptor();
- result.setTarget(target);
- result.setInstanceAdvice(instanceAdvice);
- result.setStaticAdvice(staticAdvice);
- result.setConstructAdvice(constructAdvice);
- result.setPoints(points);
- return result;
- }
-
- private TargetPoint createExpectedTargetPoint(final String name, final String type) {
- TargetPoint result = new TargetPoint();
- result.setName(name);
- result.setType(type);
- return result;
- }
-}
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlAdvisorsConfigurationSwapperTest.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlAdvisorsConfigurationSwapperTest.java
new file mode 100644
index 00000000000..4abfc118876
--- /dev/null
+++ b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlAdvisorsConfigurationSwapperTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.core.yaml.swapper;
+
+import org.apache.shardingsphere.agent.core.yaml.entity.YamlAdvisorConfiguration;
+import org.apache.shardingsphere.agent.core.yaml.entity.YamlAdvisorsConfiguration;
+import org.apache.shardingsphere.agent.core.yaml.entity.YamlPointcutConfiguration;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public final class YamlAdvisorsConfigurationSwapperTest {
+
+ @Test
+ public void assertUnmarshal() {
+ YamlAdvisorsConfiguration actual = new YamlAdvisorsConfigurationSwapper().unmarshal(getClass().getResourceAsStream("/advisors.yaml"));
+ assertThat(actual.getAdvisors().size(), is(5));
+ List<YamlAdvisorConfiguration> actualYamlAdvisorConfigs = new ArrayList<>(actual.getAdvisors());
+ assertYamlAdvisorConfiguration(actualYamlAdvisorConfigs.get(0), createExpectedYamlAdvisorConfiguration("org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask",
+ "org.apache.shardingsphere.agent.metrics.api.advice.CommandExecutorTaskAdvice",
+ null, null, Arrays.asList(createExpectedYamlPointcutConfiguration("run", "instance"), createExpectedYamlPointcutConfiguration("processException", "instance"))));
+ assertYamlAdvisorConfiguration(actualYamlAdvisorConfigs.get(1), createExpectedYamlAdvisorConfiguration("org.apache.shardingsphere.proxy.frontend.netty.FrontendChannelInboundHandler",
+ "org.apache.shardingsphere.agent.metrics.api.advice.ChannelHandlerAdvice",
+ null, null, Arrays.asList(createExpectedYamlPointcutConfiguration("channelActive", "instance"),
+ createExpectedYamlPointcutConfiguration("channelRead", "instance"), createExpectedYamlPointcutConfiguration("channelInactive", "instance"))));
+ assertYamlAdvisorConfiguration(actualYamlAdvisorConfigs.get(2), createExpectedYamlAdvisorConfiguration("org.apache.shardingsphere.infra.route.engine.SQLRouteEngine",
+ "org.apache.shardingsphere.agent.metrics.api.advice.SQLRouteEngineAdvice", null, null, Collections.singleton(createExpectedYamlPointcutConfiguration("route", "instance"))));
+ assertYamlAdvisorConfiguration(actualYamlAdvisorConfigs.get(3), createExpectedYamlAdvisorConfiguration(
+ "org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.BackendTransactionManager",
+ "org.apache.shardingsphere.agent.metrics.api.advice.TransactionAdvice",
+ null, null, Arrays.asList(createExpectedYamlPointcutConfiguration("commit", "instance"), createExpectedYamlPointcutConfiguration("rollback", "instance"))));
+ assertYamlAdvisorConfiguration(actualYamlAdvisorConfigs.get(4), createExpectedYamlAdvisorConfiguration("org.apache.shardingsphere.infra.config.datasource.JDBCParameterDecoratorHelper",
+ null, "org.apache.shardingsphere.agent.metrics.api.advice.DataSourceAdvice", null, Collections.singleton(createExpectedYamlPointcutConfiguration("decorate", "static"))));
+ }
+
+ private void assertYamlAdvisorConfiguration(final YamlAdvisorConfiguration actual, final YamlAdvisorConfiguration expected) {
+ assertThat(actual.getTarget(), is(expected.getTarget()));
+ assertThat(actual.getInstanceAdvice(), is(expected.getInstanceAdvice()));
+ assertThat(actual.getStaticAdvice(), is(expected.getStaticAdvice()));
+ assertThat(actual.getConstructAdvice(), is(expected.getConstructAdvice()));
+ assertThat(actual.getPointcuts().isEmpty(), is(expected.getPointcuts().isEmpty()));
+ Iterator<YamlPointcutConfiguration> expectedYamlPointcutConfigs = expected.getPointcuts().iterator();
+ for (YamlPointcutConfiguration each : actual.getPointcuts()) {
+ YamlPointcutConfiguration expectedYamlPointcutConfig = expectedYamlPointcutConfigs.next();
+ assertThat(each.getName(), is(expectedYamlPointcutConfig.getName()));
+ assertThat(each.getType(), is(expectedYamlPointcutConfig.getType()));
+ }
+ }
+
+ private YamlAdvisorConfiguration createExpectedYamlAdvisorConfiguration(final String target, final String instanceAdvice,
+ final String staticAdvice, final String constructAdvice, final Collection<YamlPointcutConfiguration> yamlPointcutConfigs) {
+ YamlAdvisorConfiguration result = new YamlAdvisorConfiguration();
+ result.setTarget(target);
+ result.setInstanceAdvice(instanceAdvice);
+ result.setStaticAdvice(staticAdvice);
+ result.setConstructAdvice(constructAdvice);
+ result.setPointcuts(yamlPointcutConfigs);
+ return result;
+ }
+
+ private YamlPointcutConfiguration createExpectedYamlPointcutConfiguration(final String name, final String type) {
+ YamlPointcutConfiguration result = new YamlPointcutConfiguration();
+ result.setName(name);
+ result.setType(type);
+ return result;
+ }
+}
diff --git a/agent/core/src/test/resources/interceptors.yaml b/agent/core/src/test/resources/advisors.yaml
similarity index 96%
rename from agent/core/src/test/resources/interceptors.yaml
rename to agent/core/src/test/resources/advisors.yaml
index 98d2a654221..514545019cf 100644
--- a/agent/core/src/test/resources/interceptors.yaml
+++ b/agent/core/src/test/resources/advisors.yaml
@@ -15,17 +15,17 @@
# limitations under the License.
#
-interceptors:
+advisors:
- target: org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask
instanceAdvice: org.apache.shardingsphere.agent.metrics.api.advice.CommandExecutorTaskAdvice
- points:
+ pointcuts:
- name: run
type: instance
- name: processException
type: instance
- target: org.apache.shardingsphere.proxy.frontend.netty.FrontendChannelInboundHandler
instanceAdvice: org.apache.shardingsphere.agent.metrics.api.advice.ChannelHandlerAdvice
- points:
+ pointcuts:
- name: channelActive
type: instance
- name: channelRead
@@ -34,18 +34,18 @@ interceptors:
type: instance
- target: org.apache.shardingsphere.infra.route.engine.SQLRouteEngine
instanceAdvice: org.apache.shardingsphere.agent.metrics.api.advice.SQLRouteEngineAdvice
- points:
+ pointcuts:
- name: route
type: instance
- target: org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.BackendTransactionManager
instanceAdvice: org.apache.shardingsphere.agent.metrics.api.advice.TransactionAdvice
- points:
+ pointcuts:
- name: commit
type: instance
- name: rollback
type: instance
- target: org.apache.shardingsphere.infra.config.datasource.JDBCParameterDecoratorHelper
staticAdvice: org.apache.shardingsphere.agent.metrics.api.advice.DataSourceAdvice
- points:
+ pointcuts:
- name: decorate
type: static
diff --git a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/definition/PrometheusAdvisorDefinitionService.java b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/definition/PrometheusAdvisorDefinitionService.java
index 22608bb40c8..280f896a867 100644
--- a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/definition/PrometheusAdvisorDefinitionService.java
+++ b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/definition/PrometheusAdvisorDefinitionService.java
@@ -23,9 +23,9 @@ import org.apache.shardingsphere.agent.advisor.ConstructorAdvisor;
import org.apache.shardingsphere.agent.advisor.InstanceMethodAdvisor;
import org.apache.shardingsphere.agent.advisor.StaticMethodAdvisor;
import org.apache.shardingsphere.agent.core.advisor.ClassAdvisorRegistryFactory;
-import org.apache.shardingsphere.agent.core.yaml.entity.Interceptor;
-import org.apache.shardingsphere.agent.core.yaml.entity.TargetPoint;
-import org.apache.shardingsphere.agent.core.yaml.swapper.InterceptorsYamlSwapper;
+import org.apache.shardingsphere.agent.core.yaml.entity.YamlAdvisorConfiguration;
+import org.apache.shardingsphere.agent.core.yaml.entity.YamlPointcutConfiguration;
+import org.apache.shardingsphere.agent.core.yaml.swapper.YamlAdvisorsConfigurationSwapper;
import org.apache.shardingsphere.agent.spi.AdvisorDefinitionService;
import java.util.Collection;
@@ -40,7 +40,7 @@ public final class PrometheusAdvisorDefinitionService implements AdvisorDefiniti
@Override
public Collection<ClassAdvisor> getProxyAdvisors() {
Collection<ClassAdvisor> result = new LinkedList<>();
- for (Interceptor each : new InterceptorsYamlSwapper().unmarshal(getClass().getResourceAsStream("/prometheus/interceptors.yaml")).getInterceptors()) {
+ for (YamlAdvisorConfiguration each : new YamlAdvisorsConfigurationSwapper().unmarshal(getClass().getResourceAsStream("/prometheus/advisors.yaml")).getAdvisors()) {
if (null != each.getTarget()) {
result.add(createClassAdvisor(each));
}
@@ -48,18 +48,18 @@ public final class PrometheusAdvisorDefinitionService implements AdvisorDefiniti
return result;
}
- private ClassAdvisor createClassAdvisor(final Interceptor interceptor) {
- ClassAdvisor result = ClassAdvisorRegistryFactory.getRegistry(getType()).getAdvisor(interceptor.getTarget());
- if (null != interceptor.getConstructAdvice() && !("".equals(interceptor.getConstructAdvice()))) {
- result.getConstructorAdvisors().add(new ConstructorAdvisor(ElementMatchers.isConstructor(), interceptor.getConstructAdvice()));
+ private ClassAdvisor createClassAdvisor(final YamlAdvisorConfiguration yamlAdvisorConfiguration) {
+ ClassAdvisor result = ClassAdvisorRegistryFactory.getRegistry(getType()).getAdvisor(yamlAdvisorConfiguration.getTarget());
+ if (null != yamlAdvisorConfiguration.getConstructAdvice() && !("".equals(yamlAdvisorConfiguration.getConstructAdvice()))) {
+ result.getConstructorAdvisors().add(new ConstructorAdvisor(ElementMatchers.isConstructor(), yamlAdvisorConfiguration.getConstructAdvice()));
}
- String[] instancePoints = interceptor.getPoints().stream().filter(i -> "instance".equals(i.getType())).map(TargetPoint::getName).toArray(String[]::new);
- if (instancePoints.length > 0) {
- result.getInstanceMethodAdvisors().add(new InstanceMethodAdvisor(ElementMatchers.namedOneOf(instancePoints), interceptor.getInstanceAdvice()));
+ String[] instancePointcuts = yamlAdvisorConfiguration.getPointcuts().stream().filter(i -> "instance".equals(i.getType())).map(YamlPointcutConfiguration::getName).toArray(String[]::new);
+ if (instancePointcuts.length > 0) {
+ result.getInstanceMethodAdvisors().add(new InstanceMethodAdvisor(ElementMatchers.namedOneOf(instancePointcuts), yamlAdvisorConfiguration.getInstanceAdvice()));
}
- String[] staticPoints = interceptor.getPoints().stream().filter(i -> "static".equals(i.getType())).map(TargetPoint::getName).toArray(String[]::new);
- if (staticPoints.length > 0) {
- result.getStaticMethodAdvisors().add(new StaticMethodAdvisor(ElementMatchers.namedOneOf(staticPoints), interceptor.getStaticAdvice()));
+ String[] staticPointcuts = yamlAdvisorConfiguration.getPointcuts().stream().filter(i -> "static".equals(i.getType())).map(YamlPointcutConfiguration::getName).toArray(String[]::new);
+ if (staticPointcuts.length > 0) {
+ result.getStaticMethodAdvisors().add(new StaticMethodAdvisor(ElementMatchers.namedOneOf(staticPointcuts), yamlAdvisorConfiguration.getStaticAdvice()));
}
return result;
}
diff --git a/agent/plugins/metrics/type/prometheus/src/main/resources/prometheus/interceptors.yaml b/agent/plugins/metrics/type/prometheus/src/main/resources/prometheus/advisors.yaml
similarity index 96%
rename from agent/plugins/metrics/type/prometheus/src/main/resources/prometheus/interceptors.yaml
rename to agent/plugins/metrics/type/prometheus/src/main/resources/prometheus/advisors.yaml
index 2b6b9aeaa19..63dddf9dc82 100644
--- a/agent/plugins/metrics/type/prometheus/src/main/resources/prometheus/interceptors.yaml
+++ b/agent/plugins/metrics/type/prometheus/src/main/resources/prometheus/advisors.yaml
@@ -15,17 +15,17 @@
# limitations under the License.
#
-interceptors:
+advisors:
- target: org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask
instanceAdvice: org.apache.shardingsphere.agent.metrics.api.advice.CommandExecutorTaskAdvice
- points:
+ pointcuts:
- name: run
type: instance
- name: processException
type: instance
- target: org.apache.shardingsphere.proxy.frontend.netty.FrontendChannelInboundHandler
instanceAdvice: org.apache.shardingsphere.agent.metrics.api.advice.ChannelHandlerAdvice
- points:
+ pointcuts:
- name: channelActive
type: instance
- name: channelRead
@@ -34,18 +34,18 @@ interceptors:
type: instance
- target: org.apache.shardingsphere.infra.route.engine.SQLRouteEngine
instanceAdvice: org.apache.shardingsphere.agent.metrics.api.advice.SQLRouteEngineAdvice
- points:
+ pointcuts:
- name: route
type: instance
- target: org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.JDBCBackendTransactionManager
instanceAdvice: org.apache.shardingsphere.agent.metrics.api.advice.TransactionAdvice
- points:
+ pointcuts:
- name: commit
type: instance
- name: rollback
type: instance
- target: org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine
instanceAdvice: org.apache.shardingsphere.agent.metrics.api.advice.SQLParserEngineAdvice
- points:
+ pointcuts:
- name: parse
type: instance