From 7bc4c23fae6942b86bd4b2f2cd425371889bd028 Mon Sep 17 00:00:00 2001 From: andrew shan <45474304+andrewshan@users.noreply.github.com> Date: Mon, 15 Apr 2024 13:14:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=A0=B7=E4=BE=8B=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8C=E5=A2=9E=E5=8A=A0=E4=BB=A3=E7=A0=81=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8C=96=20(#153)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: optimize the discovery inject logic and fix nacos config not working issue * feat: 删除无用的导入 * feat: 增加actuator到demo中 * fix: add lossless healthcheck for example * fix: add configuration comments --- polaris-agent-build/conf/polaris-agent.config | 2 +- .../consumer/deployment.yaml | 4 +- .../quickstart-examples/consumer/pom.xml | 5 ++ .../gateway/deployment.yaml | 2 +- .../provider/deployment.yaml | 4 +- .../quickstart-examples/provider/pom.xml | 5 ++ .../spring-cloud-2023/application.properties | 73 +++++++------------ .../agent/plugin/spring/cloud/MainPlugin.java | 2 +- .../AbstractContextHandler.java | 2 +- .../{context => base}/BaseBeanHandler.java | 14 +--- .../spring/cloud/config/ConfigHandler.java | 2 +- .../cloud/discovery/DiscoveryHandler.java | 2 +- .../ApplicationContextAwareInterceptor.java | 3 +- .../ConfigurationInjectInterceptor.java | 1 - .../EnvironmentChangeEventListener.java | 48 ------------ .../cloud/metadata/MetadataHandler.java | 2 +- .../spring/cloud/router/RouterHandler.java | 17 +++-- .../cloud/rpc/RpcEnhancementHandler.java | 2 +- 18 files changed, 59 insertions(+), 131 deletions(-) rename polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/{context => base}/AbstractContextHandler.java (96%) rename polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/{context => base}/BaseBeanHandler.java (84%) delete mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/EnvironmentChangeEventListener.java diff --git a/polaris-agent-build/conf/polaris-agent.config b/polaris-agent-build/conf/polaris-agent.config index 0a206306..0e3aab95 100644 --- a/polaris-agent-build/conf/polaris-agent.config +++ b/polaris-agent-build/conf/polaris-agent.config @@ -1 +1 @@ -plugins.enable=spring-cloud-2021-plugin,spring-cloud-2020-plugin \ No newline at end of file +plugins.enable=spring-cloud-2023-plugin \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/consumer/deployment.yaml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/consumer/deployment.yaml index f63d0a19..abfbf9f1 100644 --- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/consumer/deployment.yaml +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/consumer/deployment.yaml @@ -20,10 +20,10 @@ spec: polarismesh.cn/javaagentVersion: "1.7.0-RC.0" polarismesh.cn/javaagentFrameworkName: "spring-cloud" polarismesh.cn/javaagentFrameworkVersion: "2023" - polarismesh.cn/javaagentConfig: "{\"spring.cloud.polaris.namespace\": \"default\", \"spring.cloud.polaris.router.nearby-router.matchLevel\": \"campus\"}" + polarismesh.cn/javaagentConfig: "{\"spring.cloud.polaris.namespace\": \"default\", \"spring.cloud.polaris.router.nearby-router.matchLevel\": \"campus\", \"spring.cloud.polaris.lossless.healthCheckPath\": \"/actuator/health\"}" spec: containers: - - image: polarismesh/polaris-javaagent-demo-sc-quickstart-service-consumer-2023:1.7.0-RC.0-java17 + - image: polarismesh/polaris-javaagent-demo-sc-quickstart-2023-consumer:1.7.0-RC.0-java17 imagePullPolicy: Always name: consumer resources: diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/consumer/pom.xml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/consumer/pom.xml index 08bb97ab..a508d3bb 100644 --- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/consumer/pom.xml +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/consumer/pom.xml @@ -56,6 +56,11 @@ org.springframework.cloud spring-cloud-starter-loadbalancer + + + org.springframework.boot + spring-boot-starter-actuator + diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/gateway/deployment.yaml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/gateway/deployment.yaml index bf18dc10..e2d9a806 100644 --- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/gateway/deployment.yaml +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/gateway/deployment.yaml @@ -20,7 +20,7 @@ spec: polarismesh.cn/javaagentVersion: "1.7.0-RC.0" polarismesh.cn/javaagentFrameworkName: "spring-cloud" polarismesh.cn/javaagentFrameworkVersion: "2023" - polarismesh.cn/javaagentConfig: "{\"spring.cloud.polaris.namespace\": \"default\", \"spring.cloud.polaris.router.nearby-router.matchLevel\": \"campus\"}" + polarismesh.cn/javaagentConfig: "{\"spring.cloud.polaris.namespace\": \"default\", \"spring.cloud.polaris.router.nearby-router.matchLevel\": \"campus\", \"spring.cloud.polaris.lossless.healthCheckPath\": \"/actuator/health\"}" spec: containers: - image: polarismesh/polaris-javaagent-demo-sc-quickstart-2023-scg:1.7.0-RC.0-java17 diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/deployment.yaml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/deployment.yaml index 042215fd..92b066b3 100644 --- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/deployment.yaml +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/deployment.yaml @@ -20,10 +20,10 @@ spec: polarismesh.cn/javaagentVersion: "1.7.0-RC.0" polarismesh.cn/javaagentFrameworkName: "spring-cloud" polarismesh.cn/javaagentFrameworkVersion: "2023" - polarismesh.cn/javaagentConfig: "{\"spring.cloud.polaris.namespace\": \"default\", \"spring.cloud.polaris.router.nearby-router.matchLevel\": \"campus\"}" + polarismesh.cn/javaagentConfig: "{\"spring.cloud.polaris.namespace\": \"default\", \"spring.cloud.polaris.router.nearby-router.matchLevel\": \"campus\", \"spring.cloud.polaris.lossless.healthCheckPath\": \"/actuator/health\"}" spec: containers: - - image: polarismesh/polaris-javaagent-demo-sc-quickstart-service-provider-2023:1.7.0-RC.0-java17 + - image: polarismesh/polaris-javaagent-demo-sc-quickstart-2023-provider:1.7.0-RC.0-java17 imagePullPolicy: Always name: consumer resources: diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/pom.xml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/pom.xml index 12b87e59..e10ef71c 100644 --- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/pom.xml +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/pom.xml @@ -51,6 +51,11 @@ com.alibaba.cloud spring-cloud-starter-alibaba-nacos-config + + + org.springframework.boot + spring-boot-starter-actuator + diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/conf/plugin/spring-cloud-2023/application.properties b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/conf/plugin/spring-cloud-2023/application.properties index e86ea73c..2aa0c330 100644 --- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/conf/plugin/spring-cloud-2023/application.properties +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/conf/plugin/spring-cloud-2023/application.properties @@ -1,61 +1,40 @@ -# 应用名称(必填) +# the application name for spring cloud, register as the service name in registry center spring.application.name=application-name -# 配置北极星服务端地址 +# polaris server address spring.cloud.polaris.address=grpc\://127.0.0.1\:8091 +# switch for spring cloud polaris all features spring.cloud.polaris.enabled=true - -# 启用 Java Agent 的 Spring Cloud Tencent 注册发现能力 +# switch for spring cloud discovery feature spring.cloud.discovery.enabled=true -# 配置服务注册发现的命名空间信息 +# service discovery namespace value spring.cloud.polaris.discovery.namespace=default -# 启用从北极星 +# switch for polaris discovery feature spring.cloud.polaris.discovery.enabled=true +# switch for polaris discovery(register) feature spring.cloud.polaris.discovery.register=true - -## 是否启用北极星的 LoadBalancer +# switch for polaris loadbalancer feature spring.cloud.polaris.loadbalancer.enabled=true -#spring.cloud.polaris.loadbalancer.discoveryType=POLARIS -#spring.cloud.polaris.loadbalancer.strategy=random - -## 是否启用北极星服务路由能力 -spring.cloud.polaris.router.enabled=false -# 是否启用北极星的自定义路由能力 -spring.cloud.polaris.router.rule-router.enabled=false -# 是否启用北极星的元数据路由能力 -spring.cloud.polaris.router.metadata-router.enabled=false -# 是否启用北极星的就近路由能力 -spring.cloud.polaris.router.nearby-router.enabled=false - -## 是否启用北极星的服务限流能力 +# switch for polaris router feature +spring.cloud.polaris.router.enabled=true +# switch for polaris router(rule-router) feature +spring.cloud.polaris.router.rule-router.enabled=true +# switch for polaris router(metadata-router) feature +spring.cloud.polaris.router.metadata-router.enabled=true +# switch for polaris router(nearby-router) feature +spring.cloud.polaris.router.nearby-router.enabled=true +# switch for polaris ratelimit feature spring.cloud.polaris.ratelimit.enabled=false -# 设置触发限流时的提示信息 -# spring.cloud.polaris.ratelimit.rejectRequestTips="" -# 设置触发限流时的响应码 +# rejectHttpCode for polaris ratelimit, will be returned as limited spring.cloud.polaris.ratelimit.rejectHttpCode=429 -# 设置限流匀速排队最大排队时间 +# maxQueuingTime for polaris ratelimit spring.cloud.polaris.ratelimit.maxQueuingTime=1000 - -## RPC 调用增强 -spring.cloud.tencent.rpc-enhancement.enabled=false -# 开启 RPC 调用结果上报 -spring.cloud.tencent.rpc-enhancement.reporter.enabled=false - -# 配置北极星监控指标上报 +# switch for rpc-enhancement feature +spring.cloud.tencent.rpc-enhancement.enabled=true +# switch for rpc-enhancement reporter feature +spring.cloud.tencent.rpc-enhancement.reporter.enabled=true +# switch for polaris stat feature spring.cloud.polaris.stat.enabled=false -# 指标上报监听端口 +# port for polaris stat spring.cloud.polaris.stat.port=0 -# 指标上报暴露的 http path +# path for polaris stat spring.cloud.polaris.stat.path=/metrics - - -## 开启双注册双发现到 nacos(默认情况不开启) -#spring.cloud.nacos.enabled=false -## 设置 nacos 服务注册中心的地址 -#spring.cloud.nacos.discovery.server-addr=127.0.0.1\:8848 -## 设置 nacos 的账户信息 -#spring.cloud.nacos.username=nacos -#spring.cloud.nacos.password=nacos -## 是否开启从 nacos 拉取服务实例信息 -#spring.cloud.nacos.discovery.enabled=false -## 是否开启将服务注册到 nacos -#spring.cloud.nacos.discovery.register-enabled=false diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/MainPlugin.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/MainPlugin.java index b8a08dbe..bc86a5bd 100644 --- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/MainPlugin.java +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/MainPlugin.java @@ -56,7 +56,7 @@ private void addPolarisTransformers(TransformOperations operations) { operations.transform(ClassNames.APPLICATION_CONTEXT_AWARE, ApplicationContextAwareTransform.class); // EnvironmentPostProcessor 处理 - operations.transform(ClassNames.ENVIRONMENT_POST_PROCESSOR, ConfigurationInjectTransform.class); + // operations.transform(ClassNames.ENVIRONMENT_POST_PROCESSOR, ConfigurationInjectTransform.class); } diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/context/AbstractContextHandler.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/base/AbstractContextHandler.java similarity index 96% rename from polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/context/AbstractContextHandler.java rename to polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/base/AbstractContextHandler.java index 73215c91..400790d6 100644 --- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/context/AbstractContextHandler.java +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/base/AbstractContextHandler.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations under the License. */ -package cn.polarismesh.agent.plugin.spring.cloud.context; +package cn.polarismesh.agent.plugin.spring.cloud.base; import java.util.function.BiConsumer; diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/context/BaseBeanHandler.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/base/BaseBeanHandler.java similarity index 84% rename from polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/context/BaseBeanHandler.java rename to polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/base/BaseBeanHandler.java index 13e4adcd..38974ef9 100644 --- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/context/BaseBeanHandler.java +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/base/BaseBeanHandler.java @@ -15,29 +15,17 @@ * specific language governing permissions and limitations under the License. */ -package cn.polarismesh.agent.plugin.spring.cloud.context; +package cn.polarismesh.agent.plugin.spring.cloud.base; import java.util.function.Supplier; import cn.polarismesh.agent.plugin.spring.cloud.common.Holder; -import cn.polarismesh.agent.plugin.spring.cloud.interceptor.EnvironmentChangeEventListener; import com.tencent.cloud.common.metadata.StaticMetadataManager; -import com.tencent.cloud.plugin.lossless.config.LosslessAutoConfiguration; -import com.tencent.cloud.polaris.PolarisDiscoveryProperties; import com.tencent.cloud.polaris.context.PolarisSDKContextManager; import com.tencent.cloud.polaris.context.ServiceRuleManager; import com.tencent.cloud.polaris.context.config.PolarisContextPostConfiguration; import com.tencent.cloud.polaris.context.config.PolarisContextProperties; -import com.tencent.cloud.polaris.discovery.PolarisDiscoveryAutoConfiguration; -import com.tencent.cloud.polaris.discovery.PolarisDiscoveryHandler; import com.tencent.cloud.polaris.loadbalancer.PolarisLoadBalancerAutoConfiguration; -import com.tencent.cloud.polaris.registry.PolarisAutoServiceRegistration; -import com.tencent.cloud.polaris.registry.PolarisRegistration; -import com.tencent.cloud.polaris.registry.PolarisServiceRegistry; -import com.tencent.cloud.polaris.registry.PolarisServiceRegistryAutoConfiguration; -import com.tencent.cloud.rpc.enhancement.stat.config.PolarisStatProperties; -import com.tencent.polaris.assembly.api.AssemblyAPI; -import com.tencent.polaris.client.api.SDKContext; import org.springframework.beans.BeansException; import org.springframework.beans.factory.support.BeanDefinitionBuilder; diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/config/ConfigHandler.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/config/ConfigHandler.java index 68c5e904..9f5a7212 100644 --- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/config/ConfigHandler.java +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/config/ConfigHandler.java @@ -20,7 +20,7 @@ import java.util.function.Supplier; import cn.polarismesh.agent.plugin.spring.cloud.common.Holder; -import cn.polarismesh.agent.plugin.spring.cloud.context.AbstractContextHandler; +import cn.polarismesh.agent.plugin.spring.cloud.base.AbstractContextHandler; import com.tencent.cloud.polaris.config.PolarisConfigAutoConfiguration; import com.tencent.cloud.polaris.config.adapter.PolarisConfigFileLocator; import com.tencent.cloud.polaris.config.adapter.PolarisPropertySourceManager; diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/discovery/DiscoveryHandler.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/discovery/DiscoveryHandler.java index 4f4e30e0..d949f594 100644 --- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/discovery/DiscoveryHandler.java +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/discovery/DiscoveryHandler.java @@ -3,7 +3,7 @@ import java.util.function.Supplier; import cn.polarismesh.agent.plugin.spring.cloud.common.Holder; -import cn.polarismesh.agent.plugin.spring.cloud.context.AbstractContextHandler; +import cn.polarismesh.agent.plugin.spring.cloud.base.AbstractContextHandler; import com.tencent.cloud.plugin.lossless.config.LosslessAutoConfiguration; import com.tencent.cloud.polaris.PolarisDiscoveryProperties; import com.tencent.cloud.polaris.context.PolarisSDKContextManager; diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ApplicationContextAwareInterceptor.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ApplicationContextAwareInterceptor.java index bfcc6aee..2b0e79d4 100644 --- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ApplicationContextAwareInterceptor.java +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ApplicationContextAwareInterceptor.java @@ -23,8 +23,7 @@ import cn.polarismesh.agent.core.common.logger.CommonLogger; import cn.polarismesh.agent.core.common.logger.StdoutCommonLoggerFactory; import cn.polarismesh.agent.plugin.spring.cloud.common.Holder; -import cn.polarismesh.agent.plugin.spring.cloud.config.ConfigHandler; -import cn.polarismesh.agent.plugin.spring.cloud.context.BaseBeanHandler; +import cn.polarismesh.agent.plugin.spring.cloud.base.BaseBeanHandler; import cn.polarismesh.agent.plugin.spring.cloud.discovery.DiscoveryHandler; import cn.polarismesh.agent.plugin.spring.cloud.metadata.MetadataHandler; import cn.polarismesh.agent.plugin.spring.cloud.router.RouterHandler; diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationInjectInterceptor.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationInjectInterceptor.java index 0d614de6..526f75e8 100644 --- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationInjectInterceptor.java +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationInjectInterceptor.java @@ -74,7 +74,6 @@ private void disableSpringCloudAlibabaAbility(ConfigurableEnvironment environmen String disableCheck = "__disable__check__"; Properties properties = new Properties(); properties.setProperty("spring.cloud.polaris.config.import-check.enabled", "false"); - // 设置 spring.cloud.sentinel.enabled 为 false environment.getPropertySources().addFirst(new PropertiesPropertySource(disableCheck, properties)); LOGGER.info("[PolarisAgent] disable spring cloud alibaba all ability"); diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/EnvironmentChangeEventListener.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/EnvironmentChangeEventListener.java deleted file mode 100644 index e6000579..00000000 --- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/EnvironmentChangeEventListener.java +++ /dev/null @@ -1,48 +0,0 @@ -package cn.polarismesh.agent.plugin.spring.cloud.interceptor; - -import cn.polarismesh.agent.plugin.spring.cloud.config.ConfigHandler; -import cn.polarismesh.agent.plugin.spring.cloud.metadata.MetadataHandler; -import cn.polarismesh.agent.plugin.spring.cloud.router.RouterHandler; -import cn.polarismesh.agent.plugin.spring.cloud.rpc.RpcEnhancementHandler; - -import org.springframework.cloud.context.environment.EnvironmentChangeEvent; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationEvent; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.event.ContextRefreshedEvent; -import org.springframework.context.event.SmartApplicationListener; - -public class EnvironmentChangeEventListener implements SmartApplicationListener { - - private final RouterHandler routerHandler = new RouterHandler(); - - private final MetadataHandler metadataHandler = new MetadataHandler(); - - private final RpcEnhancementHandler rpcEnhancementHandler = new RpcEnhancementHandler(); - - private final ConfigHandler configHandler = new ConfigHandler(); - - @Override - public boolean supportsEventType(Class eventType) { - return eventType == EnvironmentChangeEvent.class || eventType == ContextRefreshedEvent.class; - } - - @Override - public void onApplicationEvent(ApplicationEvent event) { - Object source = event.getSource(); - if (!(source instanceof ApplicationContext)) { - return; - } - ApplicationContext applicationContext = (ApplicationContext) source; - ConfigurableApplicationContext cfgCtx1 = (ConfigurableApplicationContext) applicationContext; - String enable = cfgCtx1.getEnvironment().getProperty("spring.cloud.polaris.enabled"); - System.out.println("enable is " + enable); - if (null == enable || Boolean.parseBoolean(enable)) { - configHandler.setApplicationContext(applicationContext); - routerHandler.setApplicationContext(applicationContext); - metadataHandler.setApplicationContext(applicationContext); - rpcEnhancementHandler.setApplicationContext(applicationContext); - } - } - -} diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/metadata/MetadataHandler.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/metadata/MetadataHandler.java index 1212f44d..b248ec4b 100644 --- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/metadata/MetadataHandler.java +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/metadata/MetadataHandler.java @@ -17,7 +17,7 @@ package cn.polarismesh.agent.plugin.spring.cloud.metadata; -import cn.polarismesh.agent.plugin.spring.cloud.context.AbstractContextHandler; +import cn.polarismesh.agent.plugin.spring.cloud.base.AbstractContextHandler; import com.tencent.cloud.metadata.config.MetadataTransferAutoConfiguration; import org.springframework.beans.BeansException; diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/router/RouterHandler.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/router/RouterHandler.java index a9c53a65..bebe86c5 100644 --- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/router/RouterHandler.java +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/router/RouterHandler.java @@ -23,11 +23,10 @@ import cn.polarismesh.agent.core.common.utils.ClassUtils; import cn.polarismesh.agent.plugin.spring.cloud.common.Holder; -import cn.polarismesh.agent.plugin.spring.cloud.context.AbstractContextHandler; +import cn.polarismesh.agent.plugin.spring.cloud.base.AbstractContextHandler; import com.tencent.cloud.polaris.context.PolarisSDKContextManager; import com.tencent.cloud.polaris.router.PolarisRouterServiceInstanceListSupplier; import com.tencent.cloud.polaris.router.config.FeignAutoConfiguration; -import com.tencent.cloud.polaris.router.config.LoadBalancerConfiguration; import com.tencent.cloud.polaris.router.config.RouterAutoConfiguration; import com.tencent.cloud.polaris.router.config.properties.PolarisMetadataRouterProperties; import com.tencent.cloud.polaris.router.config.properties.PolarisNearByRouterProperties; @@ -80,7 +79,7 @@ public PolarisRuleBasedRouterProperties get() { } }).getBeanDefinition()); }); - registerBean(applicationContext, "routerAutoConfiguration", (ctx, name) -> { + registerBean(applicationContext, "routerAutoConfiguration", (ctx, name) -> { ConfigurableApplicationContext cfgCtx = (ConfigurableApplicationContext) ctx; DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) cfgCtx.getBeanFactory(); beanFactory.registerBeanDefinition(name, @@ -88,7 +87,7 @@ public PolarisRuleBasedRouterProperties get() { }); if (null != ClassUtils.getClazz("feign.RequestInterceptor", Thread.currentThread().getContextClassLoader())) { - registerBean(applicationContext, "feignAutoConfiguration", (ctx, name) -> { + registerBean(applicationContext, "feignAutoConfiguration", (ctx, name) -> { ConfigurableApplicationContext cfgCtx = (ConfigurableApplicationContext) ctx; DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) cfgCtx.getBeanFactory(); beanFactory.registerBeanDefinition(name, @@ -124,9 +123,10 @@ public ServiceInstanceListSupplier get() { }); } } - String blockingEnable = applicationContext.getEnvironment().getProperty("spring.cloud.discovery.blocking.enabled"); + String blockingEnable = applicationContext.getEnvironment() + .getProperty("spring.cloud.discovery.blocking.enabled"); if (null == blockingEnable || Boolean.parseBoolean(blockingEnable)) { - registerBean(applicationContext, "polarisRouterDiscoveryClientServiceInstanceListSupplier", (ctx, name) -> { + registerBean(applicationContext, "polarisRouterDiscoveryClientServiceInstanceListSupplier", (ctx, name) -> { ConfigurableApplicationContext cfgCtx = (ConfigurableApplicationContext) ctx; DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) cfgCtx.getBeanFactory(); beanFactory.registerBeanDefinition(name, BeanDefinitionBuilder.genericBeanDefinition(ServiceInstanceListSupplier.class, new Supplier() { @@ -137,14 +137,15 @@ public ServiceInstanceListSupplier get() { Map responseInterceptors = applicationContext.getBeansOfType(RouterResponseInterceptor.class); InstanceTransformer instanceTransformer = applicationContext.getBean("instanceTransformer", InstanceTransformer.class); return new PolarisRouterServiceInstanceListSupplier( - ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient().build((ConfigurableApplicationContext) applicationContext), + ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient() + .build((ConfigurableApplicationContext) applicationContext), polarisSDKContextManager.getRouterAPI(), new ArrayList<>(requestInterceptors.values()), new ArrayList<>(responseInterceptors.values()), instanceTransformer); } }).getBeanDefinition()); - }); + }); } // registerBean(applicationContext, "loadBalancerConfiguration", (ctx, name) -> { diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/rpc/RpcEnhancementHandler.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/rpc/RpcEnhancementHandler.java index 8039d5c5..da1c979e 100644 --- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/rpc/RpcEnhancementHandler.java +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/rpc/RpcEnhancementHandler.java @@ -17,7 +17,7 @@ package cn.polarismesh.agent.plugin.spring.cloud.rpc; -import cn.polarismesh.agent.plugin.spring.cloud.context.AbstractContextHandler; +import cn.polarismesh.agent.plugin.spring.cloud.base.AbstractContextHandler; import com.tencent.cloud.plugin.discovery.adapter.config.NacosDiscoveryAdapterAutoConfiguration; import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementAutoConfiguration; import org.slf4j.Logger;