From da1b6143dae4e72b7ea869207367f123b8bf24b4 Mon Sep 17 00:00:00 2001
From: fredrikliu <139424001+fredrikliu@users.noreply.github.com>
Date: Thu, 20 Jun 2024 16:32:56 +0800
Subject: [PATCH] fix:fix agent 2023/2022 could not statrt by double registry
(#198)
---
.../src/main/resources/bootstrap.properties | 24 +++++++++++++++---
.../src/main/resources/bootstrap.properties | 14 ++++++++---
.../src/main/resources/bootstrap.yaml | 4 +--
.../src/main/resources/application.yaml | 4 +--
.../src/main/resources/application.properties | 25 ++++++++++++++++---
.../src/main/resources/application.properties | 14 ++++++++---
.../spring-cloud-2020-plugin/pom.xml | 2 --
.../spring-cloud-2021-plugin/pom.xml | 2 --
.../spring-cloud-2022-plugin/pom.xml | 2 --
.../inject/MetadataTransferBeanInjector.java | 9 ++++---
.../interceptor/RegisterBeanInterceptor.java | 4 ++-
.../spring-cloud-2023-plugin/pom.xml | 2 --
.../spring-cloud-hoxton-plugin/pom.xml | 2 --
.../spring-cloud/application.properties | 6 ++++-
14 files changed, 80 insertions(+), 34 deletions(-)
diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/src/main/resources/bootstrap.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/src/main/resources/bootstrap.properties
index 4019bf5f..664d5d3c 100644
--- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/src/main/resources/bootstrap.properties
+++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/src/main/resources/bootstrap.properties
@@ -1,7 +1,25 @@
server.port=65002
spring.application.name=service-consumer-2022
+management.endpoints.web.exposure.include=*
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
-spring.cloud.nacos.discovery.enabled=false
-spring.cloud.nacos.config.enabled=false
-spring.main.allow-bean-definition-overriding=true
+spring.cloud.nacos.discovery.fail-fast=true
+
+spring.cloud.nacos.username=nacos
+spring.cloud.nacos.password=nacos
+
+feign.sentinel.enabled=true
+
+spring.cloud.sentinel.transport.dashboard=localhost:8080
+spring.cloud.sentinel.eager=true
+
+spring.cloud.sentinel.datasource.ds1.file.file=classpath: flowrule.json
+spring.cloud.sentinel.datasource.ds1.file.data-type=json
+spring.cloud.sentinel.datasource.ds1.file.rule-type=flow
+
+spring.cloud.sentinel.datasource.ds2.file.file=classpath: degraderule.json
+spring.cloud.sentinel.datasource.ds2.file.data-type=json
+spring.cloud.sentinel.datasource.ds2.file.rule-type=degrade
+spring.cloud.loadbalancer.nacos.enabled=true
+# use feign client in GraalVM environment need to set below config
+spring.cloud.refresh.enabled=false
spring.main.allow-circular-references=true
\ No newline at end of file
diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/src/main/resources/bootstrap.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/src/main/resources/bootstrap.properties
index 029dbc97..672e7e8e 100644
--- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/src/main/resources/bootstrap.properties
+++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/src/main/resources/bootstrap.properties
@@ -1,10 +1,16 @@
server.port=65001
spring.application.name=service-provider-2022
-spring.cloud.nacos.config.server-addr=127.0.0.1:8848
-spring.cloud.nacos.config.enabled=false
-spring.cloud.nacos.discovery.enabled=false
+spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
+spring.cloud.nacos.discovery.enabled=true
+#spring.cloud.nacos.discovery.instance-enabled=true
+#only register IPv4 instance
+#spring.cloud.nacos.discovery.ip-type=IPv4
+#only register IPv6 instance
+#spring.cloud.nacos.discovery.ip-type=IPv6
+
spring.cloud.nacos.username=nacos
spring.cloud.nacos.password=nacos
+
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
-spring.main.allow-bean-definition-overriding=true
\ No newline at end of file
+spring.main.allow-circular-references=true
\ No newline at end of file
diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/consumer/src/main/resources/bootstrap.yaml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/consumer/src/main/resources/bootstrap.yaml
index ea29f285..8555929f 100644
--- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/consumer/src/main/resources/bootstrap.yaml
+++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/consumer/src/main/resources/bootstrap.yaml
@@ -7,10 +7,10 @@ spring:
cloud:
nacos:
discovery:
- enabled: false
+ enabled: true
server-addr: 127.0.0.1:8848
config:
- enabled: false
+ enabled: true
serverAddr: 127.0.0.1:8848
username: 'nacos'
password: 'nacos'
diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/src/main/resources/application.yaml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/src/main/resources/application.yaml
index 649a698f..fbf160f0 100644
--- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/src/main/resources/application.yaml
+++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/src/main/resources/application.yaml
@@ -9,10 +9,10 @@ spring:
username: 'nacos'
password: 'nacos'
discovery:
- enabled: false
+ enabled: true
server-addr: 127.0.0.1:8848
config:
- enabled: false
+ enabled: true
serverAddr: 127.0.0.1:8848
username: 'nacos'
password: 'nacos'
diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/consumer/src/main/resources/application.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/consumer/src/main/resources/application.properties
index a28035ac..a0dd8275 100644
--- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/consumer/src/main/resources/application.properties
+++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/consumer/src/main/resources/application.properties
@@ -1,5 +1,24 @@
-server.port=65002
spring.application.name=service-consumer-hoxton
+server.port=18083
+management.endpoints.web.exposure.include=*
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
-spring.cloud.nacos.discovery.enabled=false
-spring.cloud.nacos.config.enabled=false
\ No newline at end of file
+spring.cloud.nacos.discovery.fail-fast=true
+
+spring.cloud.nacos.username=nacos
+spring.cloud.nacos.password=nacos
+
+feign.sentinel.enabled=true
+
+spring.cloud.sentinel.transport.dashboard=localhost:8080
+spring.cloud.sentinel.eager=true
+
+spring.cloud.sentinel.datasource.ds1.file.file=classpath: flowrule.json
+spring.cloud.sentinel.datasource.ds1.file.data-type=json
+spring.cloud.sentinel.datasource.ds1.file.rule-type=flow
+
+spring.cloud.sentinel.datasource.ds2.file.file=classpath: degraderule.json
+spring.cloud.sentinel.datasource.ds2.file.data-type=json
+spring.cloud.sentinel.datasource.ds2.file.rule-type=degrade
+spring.cloud.loadbalancer.nacos.enabled=true
+# use feign client in GraalVM environment need to set below config
+spring.cloud.refresh.enabled=false
\ No newline at end of file
diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-a/src/main/resources/application.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-a/src/main/resources/application.properties
index e804caa8..3cfbe8b5 100644
--- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-a/src/main/resources/application.properties
+++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-a/src/main/resources/application.properties
@@ -1,9 +1,15 @@
-server.port=65001
+server.port=0
spring.application.name=service-provider-hoxton
-spring.cloud.nacos.config.server-addr=127.0.0.1:8848
-spring.cloud.nacos.config.enabled=false
-spring.cloud.nacos.discovery.enabled=false
+spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
+spring.cloud.nacos.discovery.enabled=true
+#spring.cloud.nacos.discovery.instance-enabled=true
+#only register IPv4 instance
+#spring.cloud.nacos.discovery.ip-type=IPv4
+#only register IPv6 instance
+#spring.cloud.nacos.discovery.ip-type=IPv6
+
spring.cloud.nacos.username=nacos
spring.cloud.nacos.password=nacos
+
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
\ No newline at end of file
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2020-plugin/pom.xml b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2020-plugin/pom.xml
index 315e5069..e1e99544 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2020-plugin/pom.xml
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2020-plugin/pom.xml
@@ -90,12 +90,10 @@
org.springframework.cloud
spring-cloud-starter-openfeign
- provided
org.springframework.cloud
spring-cloud-loadbalancer
- provided
org.springframework.cloud
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2021-plugin/pom.xml b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2021-plugin/pom.xml
index e9eb1b26..9f30332b 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2021-plugin/pom.xml
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2021-plugin/pom.xml
@@ -90,12 +90,10 @@
org.springframework.cloud
spring-cloud-starter-openfeign
- provided
org.springframework.cloud
spring-cloud-loadbalancer
- provided
org.springframework.cloud
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/pom.xml b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/pom.xml
index e4455c4d..61369dba 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/pom.xml
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/pom.xml
@@ -86,12 +86,10 @@
org.springframework.cloud
spring-cloud-starter-openfeign
- provided
org.springframework.cloud
spring-cloud-loadbalancer
- provided
org.springframework.cloud
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/MetadataTransferBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/MetadataTransferBeanInjector.java
index 8ae77b18..fe1cabd8 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/MetadataTransferBeanInjector.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/MetadataTransferBeanInjector.java
@@ -50,14 +50,15 @@ public String getModule() {
@Override
public void onApplicationStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule());
- }
-
- @Override
- public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
Object metadataTransferAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, MetadataTransferAutoConfiguration.class, "metadataTransferAutoConfiguration");
ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, metadataTransferAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
registry.registerBeanDefinition("metadataTransferAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
MetadataTransferAutoConfiguration.class).getBeanDefinition());
}
+ @Override
+ public void onBootstrapStartup(Object configurationParser, Constructor> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
+
+ }
+
}
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/RegisterBeanInterceptor.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/RegisterBeanInterceptor.java
index ba15a1dc..99454caa 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/RegisterBeanInterceptor.java
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/RegisterBeanInterceptor.java
@@ -33,7 +33,9 @@ public class RegisterBeanInterceptor implements Interceptor {
private final Set primaryBeanNames = new HashSet<>();
public RegisterBeanInterceptor() {
-// primaryBeanNames.add("metadataTransferAutoConfiguratio");
+ primaryBeanNames.add("polarisAutoServiceRegistration");
+ primaryBeanNames.add("polarisRegistration");
+ primaryBeanNames.add("polarisServiceRegistry");
}
@Override
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/pom.xml b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/pom.xml
index 59d6b32b..7f97df10 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/pom.xml
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2023-plugin/pom.xml
@@ -86,12 +86,10 @@
org.springframework.cloud
spring-cloud-starter-openfeign
- provided
org.springframework.cloud
spring-cloud-loadbalancer
- provided
org.springframework.cloud
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/pom.xml b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/pom.xml
index ec2888bc..5345f013 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/pom.xml
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/pom.xml
@@ -91,12 +91,10 @@
org.springframework.cloud
spring-cloud-starter-openfeign
- provided
org.springframework.cloud
spring-cloud-loadbalancer
- provided
org.springframework.cloud
diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-plugin-common/src/main/conf/plugin/spring-cloud/application.properties b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-plugin-common/src/main/conf/plugin/spring-cloud/application.properties
index 2f992b50..d171d2dc 100644
--- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-plugin-common/src/main/conf/plugin/spring-cloud/application.properties
+++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-plugin-common/src/main/conf/plugin/spring-cloud/application.properties
@@ -41,4 +41,8 @@ spring.cloud.polaris.stat.enabled=false
spring.cloud.polaris.stat.port=0
# path for polaris stat
spring.cloud.polaris.stat.path=/metrics
-logging.level.root=INFO
\ No newline at end of file
+logging.level.root=INFO
+# switch for nacos discovery enable
+spring.cloud.nacos.discovery.enabled=false
+# switch for nacos config enable
+spring.cloud.nacos.config.enabled=false
\ No newline at end of file