From 531cf606ebf6daa76489f277d181240989701e7c Mon Sep 17 00:00:00 2001 From: fredrikliu <139424001+fredrikliu@users.noreply.github.com> Date: Thu, 13 Jun 2024 16:23:36 +0800 Subject: [PATCH] feat:support agent2022 (#193) * feat:support agent2022 * feat:support agent2022 --------- Co-authored-by: fredrikliu --- polaris-agent-build/conf/polaris-agent.config | 2 +- .../spring-cloud-plugins-examples/pom.xml | 1 + .../spring-cloud-2022-examples/pom.xml | 21 + .../quickstart-examples/consumer/Dockerfile | 29 ++ .../consumer/deployment.yaml | 48 ++ .../quickstart-examples/consumer/pom.xml | 105 ++++ .../cloud/cloud/ConsumerApplication.java | 147 ++++++ .../src/main/resources/application.properties | 7 + .../src/main/resources/bootstrap.properties | 7 + .../consumer/src/main/resources/polaris.yml | 8 + .../quickstart-examples/pom.xml | 22 + .../quickstart-examples/provider-a/Dockerfile | 29 ++ .../provider-a/deployment.yaml | 48 ++ .../quickstart-examples/provider-a/pom.xml | 119 +++++ .../cloud/cloud/ProviderApplication.java | 78 +++ .../src/main/resources/application.properties | 10 + .../src/main/resources/bootstrap.properties | 10 + .../quickstart-examples/provider-b/Dockerfile | 29 ++ .../provider-b/deployment.yaml | 48 ++ .../quickstart-examples/provider-b/pom.xml | 119 +++++ .../cloud/cloud/ProviderApplication.java | 80 +++ .../src/main/resources/application.properties | 9 + .../src/main/resources/bootstrap.properties | 9 + .../quickstart-examples/scg/Dockerfile | 29 ++ .../quickstart-examples/scg/deployment.yaml | 48 ++ .../quickstart-examples/scg/pom.xml | 83 ++++ .../cloud/cloud/GatewayApplication.java | 31 ++ .../src/main/resources/bootstrap.properties | 6 + .../quickstart-examples/consumer/pom.xml | 4 + .../src/main/resources/application.yaml | 32 ++ .../quickstart-examples/provider/pom.xml | 8 +- .../src/main/resources/application.yaml | 32 ++ .../src/main/resources/bootstrap.yaml | 64 +-- .../spring-cloud-plugins/pom.xml | 1 + .../spring-cloud-2022-plugin/pom.xml | 470 ++++++++++++++++++ .../spring-cloud-2022/application.properties | 45 ++ .../agent/plugin/spring/cloud/MainPlugin.java | 123 +++++ .../inject/CircuitBreakerBeanInjector.java | 46 ++ .../cloud/inject/CommonBeanInjector.java | 83 ++++ .../cloud/inject/ConfigBeanInjector.java | 78 +++ .../inject/LoadbalancerBeanInjector.java | 54 ++ .../cloud/inject/LosslessBeanInjector.java | 68 +++ .../inject/MetadataTransferBeanInjector.java | 63 +++ .../inject/PolarisContextBeanInjector.java | 85 ++++ .../cloud/inject/RateLimitBeanInjector.java | 56 +++ .../cloud/inject/RegistryBeanInjector.java | 108 ++++ .../cloud/inject/RouterBeanInjector.java | 131 +++++ .../inject/RpcEnhancementBeanInjector.java | 77 +++ .../ConfigurationParserInterceptor.java | 160 ++++++ ...ConfigurationPostProcessorInterceptor.java | 55 ++ .../interceptor/RegisterBeanInterceptor.java | 49 ++ .../SpringFactoriesLoaderInterceptor.java | 97 ++++ ...larismesh.agent.core.extension.AgentPlugin | 1 + .../src/main/resources/default-plugin.conf | 59 +++ .../src/main/resources/polaris-log4j.xml | 103 ++++ .../src/main/resources/polaris-log4j2.xml | 142 ++++++ .../src/main/resources/polaris-logback.xml | 163 ++++++ .../cloud/common/PropertiesProvider.java | 2 +- pom.xml | 2 +- 59 files changed, 3604 insertions(+), 39 deletions(-) create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/pom.xml create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/Dockerfile create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/deployment.yaml create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/pom.xml create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/src/main/java/cn/polarismesh/agent/examples/alibaba/cloud/cloud/ConsumerApplication.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/src/main/resources/application.properties create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/src/main/resources/bootstrap.properties create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/src/main/resources/polaris.yml create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/pom.xml create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/Dockerfile create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/deployment.yaml create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/pom.xml create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/src/main/java/cn/polarismesh/agent/examples/alibaba/cloud/cloud/ProviderApplication.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/src/main/resources/application.properties create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/src/main/resources/bootstrap.properties create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/Dockerfile create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/deployment.yaml create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/pom.xml create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/src/main/java/cn/polarismesh/agent/examples/alibaba/cloud/cloud/ProviderApplication.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/src/main/resources/application.properties create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/src/main/resources/bootstrap.properties create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/scg/Dockerfile create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/scg/deployment.yaml create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/scg/pom.xml create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/scg/src/main/java/cn/polarismesh/agent/examples/alibaba/cloud/cloud/GatewayApplication.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/scg/src/main/resources/bootstrap.properties create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/consumer/src/main/resources/application.yaml create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/src/main/resources/application.yaml create mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/pom.xml create mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/conf/plugin/spring-cloud-2022/application.properties create mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/MainPlugin.java create mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CircuitBreakerBeanInjector.java create mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CommonBeanInjector.java create mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/ConfigBeanInjector.java create mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LoadbalancerBeanInjector.java create mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LosslessBeanInjector.java create mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/MetadataTransferBeanInjector.java create mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/PolarisContextBeanInjector.java create mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RateLimitBeanInjector.java create mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RegistryBeanInjector.java create mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RouterBeanInjector.java create mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RpcEnhancementBeanInjector.java create mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationParserInterceptor.java create mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationPostProcessorInterceptor.java create mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/RegisterBeanInterceptor.java create mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java create mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/resources/META-INF/services/cn.polarismesh.agent.core.extension.AgentPlugin create mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/resources/default-plugin.conf create mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/resources/polaris-log4j.xml create mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/resources/polaris-log4j2.xml create mode 100644 polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/resources/polaris-logback.xml diff --git a/polaris-agent-build/conf/polaris-agent.config b/polaris-agent-build/conf/polaris-agent.config index 0e3aab95..a34520fc 100644 --- a/polaris-agent-build/conf/polaris-agent.config +++ b/polaris-agent-build/conf/polaris-agent.config @@ -1 +1 @@ -plugins.enable=spring-cloud-2023-plugin \ No newline at end of file +plugins.enable=spring-cloud-2022-plugin \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/pom.xml b/polaris-agent-examples/spring-cloud-plugins-examples/pom.xml index a58d7295..17032c7b 100644 --- a/polaris-agent-examples/spring-cloud-plugins-examples/pom.xml +++ b/polaris-agent-examples/spring-cloud-plugins-examples/pom.xml @@ -18,6 +18,7 @@ spring-cloud-2020-examples spring-cloud-hoxton-examples spring-cloud-2023-examples + spring-cloud-2022-examples \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/pom.xml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/pom.xml new file mode 100644 index 00000000..2e7e1126 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/pom.xml @@ -0,0 +1,21 @@ + + + + spring-cloud-plugins-examples + com.tencent.polaris + ${revision} + ../pom.xml + + 4.0.0 + + spring-cloud-2022-examples + + pom + + + quickstart-examples + + + \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/Dockerfile b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/Dockerfile new file mode 100644 index 00000000..e4da5f69 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/Dockerfile @@ -0,0 +1,29 @@ +FROM alpine:3.19.1 + +ARG file_name +ARG java_version + +COPY ./target/${file_name} /app/main.jar + +WORKDIR /app + +RUN sed -i 's!http://dl-cdn.alpinelinux.org/!https://mirrors.tencent.com/!g' /etc/apk/repositories + +RUN set -eux && \ + apk add openjdk${java_version} && \ + apk add bind-tools && \ + apk add busybox-extras && \ + apk add findutils && \ + apk add tcpdump && \ + apk add tzdata && \ + apk add curl && \ + apk add bash && \ + cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ + echo "Asia/Shanghai" > /etc/timezone && \ + date + +RUN chmod 777 /app/ + +RUN ls -la /app/ + +ENTRYPOINT ["java", "-jar", "/app/main.jar"] \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/deployment.yaml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/deployment.yaml new file mode 100644 index 00000000..9926f1d7 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/deployment.yaml @@ -0,0 +1,48 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: service-consumer-2022 + name: service-consumer-2022 + namespace: default +spec: + replicas: 1 + selector: + matchLabels: + app: service-consumer-2022 + template: + metadata: + labels: + app: service-consumer-2022 + annotations: + polarismesh.cn/javaagent: "true" + polarismesh.cn/javaagentVersion: "1.7.0-RC4" + polarismesh.cn/javaagentFrameworkName: "spring-cloud" + polarismesh.cn/javaagentFrameworkVersion: "2022" + spec: + containers: + - image: polarismesh/polaris-javaagent-demo-sc-quickstart-2022-consumer:1.7.0-RC4-java17 + imagePullPolicy: Always + name: consumer + resources: + limits: + cpu: "500m" + memory: 1000Mi + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + command: + - /bin/bash + - -c + - cd /app && java -Dserver.port=65002 -jar main.jar + lifecycle: + preStop: + exec: + command: ["curl","-X","PUT","http://127.0.0.1:28080/offline","&&","sleep","30"] + readinessProbe: + httpGet: + path: /online + port: 28080 + initialDelaySeconds: 3 + periodSeconds: 3 + restartPolicy: Always \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/pom.xml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/pom.xml new file mode 100644 index 00000000..923ec9ee --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/pom.xml @@ -0,0 +1,105 @@ + + + + org.springframework.boot + spring-boot-starter-parent + 3.1.8 + + + 4.0.0 + + com.tencent.polaris + polaris-javaagent-demo-sc-quickstart-2022-consumer + jar + 1.7.0 + + 2022-consumer + Demo Consumer Project For Spring Cloud Alibaba + + + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + 2022.0.0.0 + pom + import + + + + org.springframework.cloud + spring-cloud-dependencies + 2022.0.5 + pom + import + + + + + + + + org.springframework.cloud + spring-cloud-starter-circuitbreaker-resilience4j + + + org.springframework.cloud + spring-cloud-starter-bootstrap + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + org.springframework.boot + spring-boot-starter-webflux + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + repackage + + + + + + + + \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/src/main/java/cn/polarismesh/agent/examples/alibaba/cloud/cloud/ConsumerApplication.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/src/main/java/cn/polarismesh/agent/examples/alibaba/cloud/cloud/ConsumerApplication.java new file mode 100644 index 00000000..b23317e6 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/src/main/java/cn/polarismesh/agent/examples/alibaba/cloud/cloud/ConsumerApplication.java @@ -0,0 +1,147 @@ +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 cn.polarismesh.agent.examples.alibaba.cloud.cloud; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory; +import org.springframework.cloud.client.loadbalancer.LoadBalanced; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.context.annotation.Bean; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.DefaultUriBuilderFactory; +import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; +import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + + + +/** + * @author liaochuntao + */ +@SpringBootApplication +public class ConsumerApplication { + + public static void main(String[] args) { + SpringApplication.run(ConsumerApplication.class, args); + } + + @LoadBalanced + @Bean + public RestTemplate restTemplate() { + return new RestTemplate(); + } + + + @RestController + public static class EchoController { + + private RestTemplate template; + + public EchoController(RestTemplate restTemplate) { + this.template = restTemplate; + } + + @Autowired + @Qualifier("defaultRestTemplate") + private RestTemplate defaultRestTemplate; + + + @Autowired + private CircuitBreakerFactory circuitBreakerFactory; + + @GetMapping("/rest") + public String circuitBreakRestTemplate() { + return circuitBreakerFactory + .create("service-provider-2022#/circuitBreak") + .run(() -> defaultRestTemplate.getForObject("/circuitBreak", String.class), + throwable -> "trigger the refuse for service callee." + ); + } + + + + @Bean + @LoadBalanced + public RestTemplate defaultRestTemplate() { + DefaultUriBuilderFactory uriBuilderFactory = new DefaultUriBuilderFactory("http://service-provider-2022"); + RestTemplate restTemplate = new RestTemplate(); + restTemplate.setUriTemplateHandler(uriBuilderFactory); + return restTemplate; + } + + + + @GetMapping("/echo/{str}") + public ResponseEntity rest(@PathVariable String str) { + ResponseEntity response = template.getForEntity("http://service-provider-2022/echo/" + str, + String.class); + return response; + } + + + + + } + @FeignClient(name = "service-provider-2022", contextId = "fallback-from-polaris") + public interface CircuitBreakerQuickstartCalleeService { + + /** + * Check circuit break. + * + * @return circuit break info + */ + @GetMapping("/circuitBreak") + String circuitBreak(); + } + @Component + public class CircuitBreakerQuickstartCalleeServiceFallback implements CircuitBreakerQuickstartCalleeServiceWithFallback { + + @Override + public String circuitBreak() { + return "fallback: trigger the refuse for service callee."; + } + } + + @FeignClient(name = "service-provider-2022", contextId = "fallback-from-code", fallback = CircuitBreakerQuickstartCalleeServiceFallback.class) + public interface CircuitBreakerQuickstartCalleeServiceWithFallback { + + /** + * Check circuit break. + * + * @return circuit break info + */ + @GetMapping("/circuitBreak") + String circuitBreak(); + } + +} diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/src/main/resources/application.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/src/main/resources/application.properties new file mode 100644 index 00000000..dd31f053 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/src/main/resources/application.properties @@ -0,0 +1,7 @@ +#server.port=65002 +#spring.application.name=service-consumer-2022 +#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.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/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 new file mode 100644 index 00000000..4019bf5f --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/src/main/resources/bootstrap.properties @@ -0,0 +1,7 @@ +server.port=65002 +spring.application.name=service-consumer-2022 +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.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/consumer/src/main/resources/polaris.yml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/src/main/resources/polaris.yml new file mode 100644 index 00000000..58dd214d --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/src/main/resources/polaris.yml @@ -0,0 +1,8 @@ +consumer: + serviceRouter: + plugin: + # 设置就近路由插件配置 + nearbyBasedRouter: + # 描述:就近路由的最小匹配级别,需要显示设置 + # 范围: zone(腾讯云地域信息,eg: ap-guangzhou)、campus(腾讯云可用区, eg: ap-guangzhou-3) + matchLevel: campus diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/pom.xml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/pom.xml new file mode 100644 index 00000000..760efe03 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/pom.xml @@ -0,0 +1,22 @@ + + + + spring-cloud-2022-examples + com.tencent.polaris + ${revision} + ../pom.xml + + 4.0.0 + + 2022-quickstart-examples + pom + + provider-b + provider-a + consumer + scg + + + \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/Dockerfile b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/Dockerfile new file mode 100644 index 00000000..e4da5f69 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/Dockerfile @@ -0,0 +1,29 @@ +FROM alpine:3.19.1 + +ARG file_name +ARG java_version + +COPY ./target/${file_name} /app/main.jar + +WORKDIR /app + +RUN sed -i 's!http://dl-cdn.alpinelinux.org/!https://mirrors.tencent.com/!g' /etc/apk/repositories + +RUN set -eux && \ + apk add openjdk${java_version} && \ + apk add bind-tools && \ + apk add busybox-extras && \ + apk add findutils && \ + apk add tcpdump && \ + apk add tzdata && \ + apk add curl && \ + apk add bash && \ + cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ + echo "Asia/Shanghai" > /etc/timezone && \ + date + +RUN chmod 777 /app/ + +RUN ls -la /app/ + +ENTRYPOINT ["java", "-jar", "/app/main.jar"] \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/deployment.yaml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/deployment.yaml new file mode 100644 index 00000000..a36403e9 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/deployment.yaml @@ -0,0 +1,48 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: service-provider-2022-a + name: service-provider-2022-a + namespace: default +spec: + replicas: 1 + selector: + matchLabels: + app: service-provider-2022-a + template: + metadata: + labels: + app: service-provider-2022-a + annotations: + polarismesh.cn/javaagent: "true" + polarismesh.cn/javaagentVersion: "1.7.0-RC4" + polarismesh.cn/javaagentFrameworkName: "spring-cloud" + polarismesh.cn/javaagentFrameworkVersion: "2022" + spec: + containers: + - image: polarismesh/polaris-javaagent-demo-sc-quickstart-2022-provider-a:1.7.0-RC4-java17 + imagePullPolicy: Always + name: provider + resources: + limits: + cpu: "500m" + memory: 1000Mi + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + command: + - /bin/bash + - -c + - cd /app && java -Dserver.port=65001 -jar main.jar + lifecycle: + preStop: + exec: + command: ["curl","-X","PUT","http://127.0.0.1:28080/offline","&&","sleep","30"] + readinessProbe: + httpGet: + path: /online + port: 28080 + initialDelaySeconds: 3 + periodSeconds: 3 + restartPolicy: Always \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/pom.xml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/pom.xml new file mode 100644 index 00000000..00e5b00a --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/pom.xml @@ -0,0 +1,119 @@ + + + + org.springframework.boot + spring-boot-starter-parent + 3.1.7 + + + 4.0.0 + + com.tencent.polaris + polaris-javaagent-demo-sc-quickstart-2022-provider-a + jar + 1.7.0 + + 2022-provider-a + Demo Provider Project For Spring Cloud Alibaba + + + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + 2022.0.0.0 + pom + import + + + + org.springframework.cloud + spring-cloud-dependencies + 2022.0.4 + pom + import + + + + + + + + org.springframework.cloud + spring-cloud-starter-bootstrap + + + org.springframework.boot + spring-boot-starter-web + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-webflux + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + repackage + + + + + + + + \ 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/java/cn/polarismesh/agent/examples/alibaba/cloud/cloud/ProviderApplication.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/src/main/java/cn/polarismesh/agent/examples/alibaba/cloud/cloud/ProviderApplication.java new file mode 100644 index 00000000..4acb29e9 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/src/main/java/cn/polarismesh/agent/examples/alibaba/cloud/cloud/ProviderApplication.java @@ -0,0 +1,78 @@ +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 cn.polarismesh.agent.examples.alibaba.cloud.cloud; + + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.client.serviceregistry.Registration; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author liaochuntao + */ +@EnableDiscoveryClient +@SpringBootApplication +public class ProviderApplication { + + public static void main(String[] args) { + SpringApplication.run(ProviderApplication.class, args); + } + + // @RefreshScope + @RestController + public static class EchoController { + + private static final Logger LOG = LoggerFactory.getLogger(ProviderApplication.class); + + @Value("${name:}") + private String name; + + @Value("${server.port}") + private String port; + + @Value("${spring.cloud.client.ip-address:127.0.0.1}") + private String ip; + + @GetMapping("/circuitBreak") + public String circuitBreak() { + LOG.info("Quickstart Callee Service [{}:{}] is called right.", ip, port); + return String.format("Quickstart Callee Service [%s:%s] is called right.", ip, port); + } + + @GetMapping("/echo/{string}") + public String echo(@PathVariable String string) { + return "Hello, I'm provider, receive msg : " + + string + + ", my metadata : " + + " name config : " + + name + + " " + + port; + } + + } + +} \ 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/application.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/src/main/resources/application.properties new file mode 100644 index 00000000..72bd21c1 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/src/main/resources/application.properties @@ -0,0 +1,10 @@ +#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.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 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 new file mode 100644 index 00000000..029dbc97 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/src/main/resources/bootstrap.properties @@ -0,0 +1,10 @@ +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.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 diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/Dockerfile b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/Dockerfile new file mode 100644 index 00000000..e4da5f69 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/Dockerfile @@ -0,0 +1,29 @@ +FROM alpine:3.19.1 + +ARG file_name +ARG java_version + +COPY ./target/${file_name} /app/main.jar + +WORKDIR /app + +RUN sed -i 's!http://dl-cdn.alpinelinux.org/!https://mirrors.tencent.com/!g' /etc/apk/repositories + +RUN set -eux && \ + apk add openjdk${java_version} && \ + apk add bind-tools && \ + apk add busybox-extras && \ + apk add findutils && \ + apk add tcpdump && \ + apk add tzdata && \ + apk add curl && \ + apk add bash && \ + cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ + echo "Asia/Shanghai" > /etc/timezone && \ + date + +RUN chmod 777 /app/ + +RUN ls -la /app/ + +ENTRYPOINT ["java", "-jar", "/app/main.jar"] \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/deployment.yaml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/deployment.yaml new file mode 100644 index 00000000..33abb3e9 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/deployment.yaml @@ -0,0 +1,48 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: service-provider-2022-b + name: service-provider-2022-b + namespace: default +spec: + replicas: 1 + selector: + matchLabels: + app: service-provider-2022-b + template: + metadata: + labels: + app: service-provider-2022-b + annotations: + polarismesh.cn/javaagent: "true" + polarismesh.cn/javaagentVersion: "1.7.0-RC4" + polarismesh.cn/javaagentFrameworkName: "spring-cloud" + polarismesh.cn/javaagentFrameworkVersion: "2022" + spec: + containers: + - image: polarismesh/polaris-javaagent-demo-sc-quickstart-2022-provider-b:1.7.0-RC4-java17 + imagePullPolicy: Always + name: provider + resources: + limits: + cpu: "500m" + memory: 1000Mi + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + command: + - /bin/bash + - -c + - cd /app && java -Dserver.port=65004 -jar main.jar + lifecycle: + preStop: + exec: + command: ["curl","-X","PUT","http://127.0.0.1:28080/offline","&&","sleep","30"] + readinessProbe: + httpGet: + path: /online + port: 28080 + initialDelaySeconds: 3 + periodSeconds: 3 + restartPolicy: Always \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/pom.xml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/pom.xml new file mode 100644 index 00000000..4c9ba5cc --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/pom.xml @@ -0,0 +1,119 @@ + + + + org.springframework.boot + spring-boot-starter-parent + 3.1.7 + + + 4.0.0 + + com.tencent.polaris + polaris-javaagent-demo-sc-quickstart-2022-provider-b + jar + 1.7.0 + + 2022-provider-b + Demo Provider Project For Spring Cloud Alibaba + + + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + 2022.0.0.0 + pom + import + + + + org.springframework.cloud + spring-cloud-dependencies + 2022.0.4 + pom + import + + + + + + + + org.springframework.cloud + spring-cloud-starter-bootstrap + + + org.springframework.boot + spring-boot-starter-web + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-webflux + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + repackage + + + + + + + + \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/src/main/java/cn/polarismesh/agent/examples/alibaba/cloud/cloud/ProviderApplication.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/src/main/java/cn/polarismesh/agent/examples/alibaba/cloud/cloud/ProviderApplication.java new file mode 100644 index 00000000..6efa0531 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/src/main/java/cn/polarismesh/agent/examples/alibaba/cloud/cloud/ProviderApplication.java @@ -0,0 +1,80 @@ +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 cn.polarismesh.agent.examples.alibaba.cloud.cloud; + + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.client.serviceregistry.Registration; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author liaochuntao + */ +@EnableDiscoveryClient +@SpringBootApplication +public class ProviderApplication { + + public static void main(String[] args) { + SpringApplication.run(ProviderApplication.class, args); + } + + // @RefreshScope + @RestController + public static class EchoController { + + private static final Logger LOG = LoggerFactory.getLogger(ProviderApplication.class); + + @Value("${name:}") + private String name; + + @Value("${server.port}") + private String port; + + @Value("${spring.cloud.client.ip-address:127.0.0.1}") + private String ip; + + @GetMapping("/circuitBreak") + public ResponseEntity circuitBreak() throws InterruptedException { + LOG.info("Quickstart Callee Service [{}:{}] is called wrong.", ip, port); + return new ResponseEntity<>("failed for call quickstart callee service.", HttpStatus.BAD_GATEWAY); + } + + @GetMapping("/echo/{string}") + public String echo(@PathVariable String string) { + return "Hello, I'm provider, receive msg : " + + string + + ", my metadata : " + + " name config : " + + name + + " " + + port; + } + + } + +} \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/src/main/resources/application.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/src/main/resources/application.properties new file mode 100644 index 00000000..ac3586c0 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/src/main/resources/application.properties @@ -0,0 +1,9 @@ +#server.port=65004 +#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.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-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/src/main/resources/bootstrap.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/src/main/resources/bootstrap.properties new file mode 100644 index 00000000..2d0ad795 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/src/main/resources/bootstrap.properties @@ -0,0 +1,9 @@ +server.port=65004 +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.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-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/scg/Dockerfile b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/scg/Dockerfile new file mode 100644 index 00000000..e4da5f69 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/scg/Dockerfile @@ -0,0 +1,29 @@ +FROM alpine:3.19.1 + +ARG file_name +ARG java_version + +COPY ./target/${file_name} /app/main.jar + +WORKDIR /app + +RUN sed -i 's!http://dl-cdn.alpinelinux.org/!https://mirrors.tencent.com/!g' /etc/apk/repositories + +RUN set -eux && \ + apk add openjdk${java_version} && \ + apk add bind-tools && \ + apk add busybox-extras && \ + apk add findutils && \ + apk add tcpdump && \ + apk add tzdata && \ + apk add curl && \ + apk add bash && \ + cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ + echo "Asia/Shanghai" > /etc/timezone && \ + date + +RUN chmod 777 /app/ + +RUN ls -la /app/ + +ENTRYPOINT ["java", "-jar", "/app/main.jar"] \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/scg/deployment.yaml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/scg/deployment.yaml new file mode 100644 index 00000000..10dd3eca --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/scg/deployment.yaml @@ -0,0 +1,48 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: scg-gateway-2022 + name: scg-gateway-2022 + namespace: default +spec: + replicas: 1 + selector: + matchLabels: + app: scg-gateway-2022 + template: + metadata: + labels: + app: scg-gateway-2022 + annotations: + polarismesh.cn/javaagent: "true" + polarismesh.cn/javaagentVersion: "1.7.0-RC4" + polarismesh.cn/javaagentFrameworkName: "spring-cloud" + polarismesh.cn/javaagentFrameworkVersion: "2022" + spec: + containers: + - image: polarismesh/polaris-javaagent-demo-sc-quickstart-2022-scg:1.7.0-RC4-java17 + imagePullPolicy: Always + name: consumer + resources: + limits: + cpu: "500m" + memory: 1000Mi + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + command: + - /bin/bash + - -c + - cd /app && java -Dserver.port=65000 -jar main.jar + lifecycle: + preStop: + exec: + command: ["curl","-X","PUT","http://127.0.0.1:28080/offline","&&","sleep","30"] + readinessProbe: + httpGet: + path: /online + port: 28080 + initialDelaySeconds: 3 + periodSeconds: 3 + restartPolicy: Always \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/scg/pom.xml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/scg/pom.xml new file mode 100644 index 00000000..1490c749 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/scg/pom.xml @@ -0,0 +1,83 @@ + + + + org.springframework.boot + spring-boot-starter-parent + 3.1.7 + + + 4.0.0 + + com.tencent.polaris + polaris-javaagent-demo-sc-quickstart-2022-scg + jar + 1.7.0 + + 2022-scg + Demo Consumer Project For Spring Cloud Alibaba + + + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + 2.2.10-RC2 + pom + import + + + + org.springframework.cloud + spring-cloud-dependencies + 2022.0.4 + pom + import + + + + + + + org.springframework.cloud + spring-cloud-starter-gateway + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + repackage + + + + + + + + \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/scg/src/main/java/cn/polarismesh/agent/examples/alibaba/cloud/cloud/GatewayApplication.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/scg/src/main/java/cn/polarismesh/agent/examples/alibaba/cloud/cloud/GatewayApplication.java new file mode 100644 index 00000000..831ec605 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/scg/src/main/java/cn/polarismesh/agent/examples/alibaba/cloud/cloud/GatewayApplication.java @@ -0,0 +1,31 @@ +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 cn.polarismesh.agent.examples.alibaba.cloud.cloud; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +@SpringBootApplication +@EnableDiscoveryClient +public class GatewayApplication { + + public static void main(String[] args) { + SpringApplication.run(GatewayApplication.class, args); + } +} diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/scg/src/main/resources/bootstrap.properties b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/scg/src/main/resources/bootstrap.properties new file mode 100644 index 00000000..618f2b85 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/scg/src/main/resources/bootstrap.properties @@ -0,0 +1,6 @@ +server.port=65000 +spring.application.name=scg-gateway-2022 +spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 +spring.cloud.nacos.discovery.enabled=false +spring.cloud.gateway.discovery.locator.enabled=true +spring.cloud.nacos.config.enabled=false \ No newline at end of file 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 aa01d756..5aa55c95 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 @@ -38,6 +38,10 @@ + + org.springframework.cloud + spring-cloud-starter-circuitbreaker-resilience4j + org.springframework.cloud spring-cloud-starter-bootstrap diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/consumer/src/main/resources/application.yaml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/consumer/src/main/resources/application.yaml new file mode 100644 index 00000000..2ab5384b --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/consumer/src/main/resources/application.yaml @@ -0,0 +1,32 @@ +#server: +# port: 65101 +# +#spring: +# application: +# name: service-consumer-2023 +# cloud: +# nacos: +# discovery: +# enabled: false +# server-addr: 127.0.0.1:8848 +# config: +# enabled: false +# serverAddr: 127.0.0.1:8848 +# username: 'nacos' +# password: 'nacos' +# main: +# allow-bean-definition-overriding: true +## config: +## import: +## - nacos:service-consumer-2023.properties?refreshEnabled=true +#management: +# endpoint: +# health: +# show-details: always +# endpoints: +# web: +# exposure: +# include: '*' +#logging: +# level: +# com.alibaba.cloud.nacos.configdata: debug \ No newline at end of file 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 eaeeb519..76dda92c 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 @@ -38,10 +38,10 @@ - - org.springframework.cloud - spring-cloud-starter-bootstrap - + + + + org.springframework.boot spring-boot-starter-web 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 new file mode 100644 index 00000000..649a698f --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/src/main/resources/application.yaml @@ -0,0 +1,32 @@ +server: + port: 65100 + +spring: + application: + name: service-provider-2023 + cloud: + nacos: + username: 'nacos' + password: 'nacos' + discovery: + enabled: false + server-addr: 127.0.0.1:8848 + config: + enabled: false + serverAddr: 127.0.0.1:8848 + username: 'nacos' + password: 'nacos' +# config: +# import: +# - nacos:service-provider-2023.properties?refreshEnabled=true +management: + endpoint: + health: + show-details: always + endpoints: + web: + exposure: + include: '*' +logging: + level: + com.alibaba.cloud.nacos.configdata: debug \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/src/main/resources/bootstrap.yaml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/src/main/resources/bootstrap.yaml index 649a698f..96483e5c 100644 --- a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/src/main/resources/bootstrap.yaml +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/provider/src/main/resources/bootstrap.yaml @@ -1,32 +1,32 @@ -server: - port: 65100 - -spring: - application: - name: service-provider-2023 - cloud: - nacos: - username: 'nacos' - password: 'nacos' - discovery: - enabled: false - server-addr: 127.0.0.1:8848 - config: - enabled: false - serverAddr: 127.0.0.1:8848 - username: 'nacos' - password: 'nacos' -# config: -# import: -# - nacos:service-provider-2023.properties?refreshEnabled=true -management: - endpoint: - health: - show-details: always - endpoints: - web: - exposure: - include: '*' -logging: - level: - com.alibaba.cloud.nacos.configdata: debug \ No newline at end of file +#server: +# port: 65100 +# +#spring: +# application: +# name: service-provider-2023 +# cloud: +# nacos: +# username: 'nacos' +# password: 'nacos' +# discovery: +# enabled: false +# server-addr: 127.0.0.1:8848 +# config: +# enabled: false +# serverAddr: 127.0.0.1:8848 +# username: 'nacos' +# password: 'nacos' +## config: +## import: +## - nacos:service-provider-2023.properties?refreshEnabled=true +#management: +# endpoint: +# health: +# show-details: always +# endpoints: +# web: +# exposure: +# include: '*' +#logging: +# level: +# com.alibaba.cloud.nacos.configdata: debug \ No newline at end of file diff --git a/polaris-agent-plugins/spring-cloud-plugins/pom.xml b/polaris-agent-plugins/spring-cloud-plugins/pom.xml index a983a22c..eff3cfe2 100644 --- a/polaris-agent-plugins/spring-cloud-plugins/pom.xml +++ b/polaris-agent-plugins/spring-cloud-plugins/pom.xml @@ -16,6 +16,7 @@ spring-cloud-2021-plugin spring-cloud-2020-plugin + spring-cloud-2022-plugin spring-cloud-hoxton-plugin spring-cloud-2023-plugin spring-cloud-plugin-common 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 new file mode 100644 index 00000000..e4455c4d --- /dev/null +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/pom.xml @@ -0,0 +1,470 @@ + + + + spring-cloud-plugins + com.tencent.polaris + ${revision} + ../pom.xml + + 4.0.0 + + spring-cloud-2022-plugin + + + 2022.0.4 + 1.14.0-2022.0.5-SNAPSHOT + 3.1.7 + 1.7.30 + 17 + ${env.JAVA_17_HOME} + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-dependencies + ${spring.boot.version} + pom + import + + + org.springframework.cloud + spring-cloud-starter-bootstrap + + + org.springframework.cloud + spring-cloud-dependencies + ${spring.cloud.version} + pom + import + + + com.tencent.cloud + spring-cloud-tencent-dependencies + ${spring.cloud.tencent.version} + pom + import + + + + + + + com.tencent.polaris + spring-cloud-plugin-common + ${project.version} + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + com.tencent.polaris + polaris-agent-core-extension + ${project.version} + + + com.tencent.polaris + polaris-agent-core-common + ${project.version} + + + org.slf4j + slf4j-api + ${slf4j.vesion} + provided + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + provided + + + org.springframework.cloud + spring-cloud-loadbalancer + provided + + + org.springframework.cloud + spring-cloud-context + provided + + + org.springframework.boot + spring-boot-starter-web + ${spring.boot.version} + provided + + + org.springframework.boot + spring-boot-starter-webflux + ${spring.boot.version} + provided + + + + + com.tencent.polaris + polaris-all + + + + + com.google.guava + guava + + + + + com.tencent.cloud + spring-cloud-tencent-polaris-context + + + com.tencent.cloud + spring-cloud-tencent-commons + + + + + + com.tencent.polaris + polaris-discovery-factory + + + + com.tencent.polaris + polaris-client + + + + com.tencent.polaris + polaris-plugin-api + + + + + + + + + com.tencent.polaris + connector-composite + + + + com.tencent.polaris + registry-memory + + + + com.tencent.polaris + flow-cache-expired + + + + com.tencent.polaris + polaris-router-factory + + + + com.tencent.polaris + loadbalancer-random + + + + com.tencent.polaris + loadbalancer-ringhash + + + + com.tencent.polaris + polaris-assembly-factory + + + + + com.tencent.cloud + spring-cloud-tencent-rpc-enhancement + + + com.tencent.polaris + stat-prometheus + + + + + com.tencent.cloud + spring-cloud-starter-tencent-polaris-discovery + ${spring.cloud.tencent.version} + + + com.tencent.cloud + spring-cloud-tencent-rpc-enhancement + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-webflux + + + org.springframework.cloud + spring-cloud-loadbalancer + + + com.tencent.cloud + spring-cloud-tencent-polaris-context + + + + + + com.tencent.cloud + spring-cloud-starter-tencent-polaris-config + ${spring.cloud.tencent.version} + + + org.springframework.cloud + spring-cloud-context + + + com.tencent.cloud + spring-cloud-tencent-polaris-context + + + com.tencent.polaris + polaris-configuration-factory + + + + + + com.tencent.cloud + spring-cloud-starter-tencent-polaris-contract + + + + com.tencent.cloud + spring-cloud-starter-tencent-polaris-router + ${spring.cloud.tencent.version} + + + com.tencent.cloud + spring-cloud-tencent-rpc-enhancement + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-webflux + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + com.tencent.cloud + spring-cloud-tencent-polaris-context + + + com.tencent.polaris + router-rule + + + com.tencent.polaris + router-metadata + + + com.tencent.polaris + router-nearby + + + + + + com.tencent.cloud + spring-cloud-starter-tencent-metadata-transfer + ${spring.cloud.tencent.version} + + + com.tencent.cloud + spring-cloud-tencent-polaris-context + + + + + com.tencent.cloud + spring-cloud-tencent-commons + ${spring.cloud.tencent.version} + + + com.tencent.polaris + polaris-model + + + com.tencent.polaris + polaris-metadata + + + com.tencent.polaris + polaris-threadlocal + + + + + + com.tencent.cloud + spring-cloud-tencent-lossless-plugin + ${spring.cloud.tencent.version} + + + com.tencent.cloud + spring-cloud-tencent-polaris-context + + + + com.tencent.cloud + spring-cloud-tencent-commons + + + + com.tencent.polaris + lossless-register + + + + com.tencent.polaris + lossless-deregister + + + + + + com.tencent.cloud + spring-cloud-starter-tencent-discovery-adapter-plugin + ${spring.cloud.tencent.version} + + + com.tencent.cloud + spring-cloud-starter-tencent-polaris-router + + + + + + com.tencent.cloud + spring-cloud-starter-tencent-polaris-circuitbreaker + ${spring.cloud.tencent.version} + + + com.tencent.cloud + spring-cloud-tencent-rpc-enhancement + + + com.tencent.polaris + polaris-circuitbreaker-factory + + + com.tencent.polaris + healthchecker-http + + + com.tencent.polaris + healthchecker-udp + + + com.tencent.polaris + healthchecker-tcp + + + + + + com.tencent.cloud + spring-cloud-starter-tencent-polaris-ratelimit + ${spring.cloud.tencent.version} + + + com.tencent.cloud + spring-cloud-tencent-rpc-enhancement + + + com.tencent.polaris + polaris-ratelimit-factory + + + + + com.tencent.cloud + spring-cloud-tencent-lossless-plugin + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + ${project.artifactId} + ${jdk.version} + + java.lang,java.lang.reflect + + + + + + maven-shade-plugin + ${maven.shaded.plugin.version} + + + package + + shade + + + true + false + + + + + + + *:* + + META-INF/spring.* + META-INF/*.xml + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + + + + + \ No newline at end of file diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/conf/plugin/spring-cloud-2022/application.properties b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/conf/plugin/spring-cloud-2022/application.properties new file mode 100644 index 00000000..adc85b8b --- /dev/null +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/conf/plugin/spring-cloud-2022/application.properties @@ -0,0 +1,45 @@ +# the application name for spring cloud, register as the service name in registry center +spring.application.name=service-provider-2022 +# polaris server address +spring.cloud.polaris.address=grpc\://106.55.74.24\:8091 +# switch for spring cloud polaris all features +spring.cloud.polaris.enabled=true +# 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 +# switch for polaris loadbalancer feature +spring.cloud.polaris.loadbalancer.enabled=true +# 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=true +# rejectHttpCode for polaris ratelimit, will be returned as limited +spring.cloud.polaris.ratelimit.rejectHttpCode=429 +# switch for circuitbreaker +spring.cloud.polaris.circuitbreaker.enabled=true +feign.hystrix.enabled=true +# maxQueuingTime for polaris ratelimit +spring.cloud.polaris.ratelimit.maxQueuingTime=1000 +# 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 +# path for polaris stat +spring.cloud.polaris.stat.path=/metrics + +logging.level.root=INFO \ No newline at end of file diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/MainPlugin.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/MainPlugin.java new file mode 100644 index 00000000..3eb1c820 --- /dev/null +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/MainPlugin.java @@ -0,0 +1,123 @@ +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 cn.polarismesh.agent.plugin.spring.cloud; + +import java.security.ProtectionDomain; + +import cn.polarismesh.agent.core.extension.AgentPlugin; +import cn.polarismesh.agent.core.extension.PluginContext; +import cn.polarismesh.agent.core.extension.instrument.InstrumentClass; +import cn.polarismesh.agent.core.extension.instrument.InstrumentMethod; +import cn.polarismesh.agent.core.extension.instrument.Instrumentor; +import cn.polarismesh.agent.core.extension.instrument.exception.InstrumentException; +import cn.polarismesh.agent.core.extension.transform.TransformCallback; +import cn.polarismesh.agent.core.extension.transform.TransformOperations; +import cn.polarismesh.agent.plugin.spring.cloud.common.Constant; +import cn.polarismesh.agent.plugin.spring.cloud.interceptor.ConfigurationParserInterceptor; +import cn.polarismesh.agent.plugin.spring.cloud.interceptor.ConfigurationPostProcessorInterceptor; +import cn.polarismesh.agent.plugin.spring.cloud.interceptor.RegisterBeanInterceptor; +import cn.polarismesh.agent.plugin.spring.cloud.interceptor.SpringFactoriesLoaderInterceptor; + +/** + * Polaris Spring Cloud hoxton Plugin + * + * @author shuhanliu + */ +public class MainPlugin implements AgentPlugin { + + public void init(PluginContext context) { + System.setProperty(Constant.AGENT_CONF_PATH, context.getAgentDirPath()); + TransformOperations operations = context.getTransformOperations(); + addPolarisTransformers(operations); + } + + /** + * add polaris transformers + */ + private void addPolarisTransformers(TransformOperations operations) { + + // 注入默认配置 + operations.transform(Constant.CONFIGURATION_CLAZZ_POST_PROCESSOR, ConfigurationPostProcessorTransform.class); + + // 注入bootstrap的bean定义 + operations.transform(Constant.CONFIGURATION_CLAZZ_PARSER, ConfigurationParserTransform.class); + + // 注入bean定义的调整设置 + operations.transform(Constant.BEAN_DEFINITION_REGISTRY, RegisterBeanDefinitionTransform.class); + + // 注入JNI定义 + operations.transform(Constant.SPRING_FACTORIES_LOADER, SpringFactoriesLoaderTransform.class); + } + + public static class ConfigurationParserTransform implements TransformCallback { + + @Override + public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classFileBuffer) throws InstrumentException { + InstrumentClass target = instrumentor.getInstrumentClass(classLoader, className, classFileBuffer); + InstrumentMethod constructMethod = target.getDeclaredMethod("parse", "java.util.Set"); + if (constructMethod != null) { + constructMethod.addInterceptor(ConfigurationParserInterceptor.class); + } + + return target.toBytecode(); + } + } + + public static class ConfigurationPostProcessorTransform implements TransformCallback { + + @Override + public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classFileBuffer) throws InstrumentException { + InstrumentClass target = instrumentor.getInstrumentClass(classLoader, className, classFileBuffer); + InstrumentMethod constructMethod = target.getDeclaredMethod("processConfigBeanDefinitions", "org.springframework.beans.factory.support.BeanDefinitionRegistry"); + if (constructMethod != null) { + constructMethod.addInterceptor(ConfigurationPostProcessorInterceptor.class); + } + + return target.toBytecode(); + } + } + + public static class RegisterBeanDefinitionTransform implements TransformCallback { + + @Override + public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classFileBuffer) throws InstrumentException { + InstrumentClass target = instrumentor.getInstrumentClass(classLoader, className, classFileBuffer); + InstrumentMethod constructMethod = target.getDeclaredMethod("registerBeanDefinition", "java.lang.String", "org.springframework.beans.factory.config.BeanDefinition"); + if (constructMethod != null) { + constructMethod.addInterceptor(RegisterBeanInterceptor.class); + } + + return target.toBytecode(); + } + } + + public static class SpringFactoriesLoaderTransform implements TransformCallback { + + @Override + public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classFileBuffer) throws InstrumentException { + InstrumentClass target = instrumentor.getInstrumentClass(classLoader, className, classFileBuffer); + InstrumentMethod constructMethod = target.getDeclaredMethod("loadSpringFactories", "java.lang.ClassLoader"); + if (constructMethod != null) { + constructMethod.addInterceptor(SpringFactoriesLoaderInterceptor.class); + } + + return target.toBytecode(); + } + } + +} \ No newline at end of file diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CircuitBreakerBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CircuitBreakerBeanInjector.java new file mode 100644 index 00000000..e2e4dd59 --- /dev/null +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CircuitBreakerBeanInjector.java @@ -0,0 +1,46 @@ +package cn.polarismesh.agent.plugin.spring.cloud.inject; + +import cn.polarismesh.agent.core.common.utils.ClassUtils; +import cn.polarismesh.agent.core.common.utils.ReflectionUtils; +import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.common.Constant; +import cn.polarismesh.agent.plugin.spring.cloud.common.Utils; +import com.tencent.cloud.polaris.circuitbreaker.config.*; +import com.tencent.cloud.polaris.circuitbreaker.endpoint.PolarisCircuitBreakerEndpointAutoConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +//import org.springframework.cloud.openfeign.PolarisFeignCircuitBreakerTargeterAutoConfiguration; +import org.springframework.core.env.Environment; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.concurrent.atomic.AtomicBoolean; + +public class CircuitBreakerBeanInjector implements BeanInjector { + + private static final Logger LOGGER = LoggerFactory.getLogger(CircuitBreakerBeanInjector.class); + + private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false); + + @Override + public String getModule() { + return "spring-cloud-starter-tencent-polaris-circuitbreaker"; + } + + @Override + public void onBootstrapStartup(Object configurationParser, Constructor configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) { + LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule()); + } + + @Override + public void onApplicationStartup(Object configurationParser, Constructor configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) { + Object polarisCircuitBreakerEndpointAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisCircuitBreakerEndpointAutoConfiguration.class, "polarisCircuitBreakerEndpointAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisCircuitBreakerEndpointAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisCircuitBreakerEndpointAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisCircuitBreakerEndpointAutoConfiguration.class).getBeanDefinition()); + LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule()); + } +} + diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CommonBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CommonBeanInjector.java new file mode 100644 index 00000000..9751bd63 --- /dev/null +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/CommonBeanInjector.java @@ -0,0 +1,83 @@ +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 cn.polarismesh.agent.plugin.spring.cloud.inject; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.concurrent.atomic.AtomicBoolean; + +import cn.polarismesh.agent.core.common.utils.ClassUtils; +import cn.polarismesh.agent.core.common.utils.ReflectionUtils; +import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.common.Utils; +import cn.polarismesh.agent.plugin.spring.cloud.common.Constant; +import com.tencent.cloud.common.metadata.config.MetadataAutoConfiguration; +import com.tencent.cloud.common.metadata.endpoint.PolarisMetadataEndpointAutoConfiguration; +import com.tencent.cloud.common.util.ApplicationContextAwareUtils; +import com.tencent.cloud.polaris.DiscoveryPropertiesAutoConfiguration; +import com.tencent.cloud.polaris.DiscoveryPropertiesBootstrapAutoConfiguration; +import com.tencent.cloud.polaris.config.PolarisConfigBootstrapAutoConfiguration; +import com.tencent.cloud.polaris.contract.config.PolarisContractPropertiesAutoConfiguration; +import com.tencent.cloud.polaris.router.config.FeignAutoConfiguration; +import com.tencent.cloud.polaris.router.config.RouterAutoConfiguration; +import com.tencent.cloud.polaris.router.config.RouterConfigModifierAutoConfiguration; +import com.tencent.cloud.polaris.router.config.properties.PolarisMetadataRouterProperties; +import com.tencent.cloud.polaris.router.config.properties.PolarisNearByRouterProperties; +import com.tencent.cloud.polaris.router.config.properties.PolarisRuleBasedRouterProperties; +import com.tencent.cloud.polaris.router.endpoint.PolarisRouterEndpointAutoConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.core.env.Environment; + +public class CommonBeanInjector implements BeanInjector { + + private static final Logger LOGGER = LoggerFactory.getLogger(CommonBeanInjector.class); + + private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false); + + @Override + public String getModule() { + return "spring-cloud-tencent-commons"; + } + + @Override + public void onApplicationStartup(Object configurationParser, Constructor configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) { + Object metadataAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, MetadataAutoConfiguration.class, "metadataAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, metadataAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("metadataAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + MetadataAutoConfiguration.class).getBeanDefinition()); + Object polarisMetadataEndpointAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisMetadataEndpointAutoConfiguration.class, "polarisMetadataEndpointAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisMetadataEndpointAutoConfiguration,Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisMetadataEndpointAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisMetadataEndpointAutoConfiguration.class).getBeanDefinition()); + Object applicationContextAwareUtils = ReflectionUtils.invokeConstructor(configClassCreator, ApplicationContextAwareUtils.class, "applicationContextAwareUtils"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, applicationContextAwareUtils, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("applicationContextAwareUtils", BeanDefinitionBuilder.genericBeanDefinition( + ApplicationContextAwareUtils.class).getBeanDefinition()); + 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) { + LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule()); + } +} diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/ConfigBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/ConfigBeanInjector.java new file mode 100644 index 00000000..d97b13b8 --- /dev/null +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/ConfigBeanInjector.java @@ -0,0 +1,78 @@ +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 cn.polarismesh.agent.plugin.spring.cloud.inject; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.concurrent.atomic.AtomicBoolean; + +import cn.polarismesh.agent.core.common.utils.ReflectionUtils; +import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.common.Constant; +import cn.polarismesh.agent.plugin.spring.cloud.common.Utils; +import com.tencent.cloud.polaris.config.PolarisConfigAutoConfiguration; +import com.tencent.cloud.polaris.config.PolarisConfigBootstrapAutoConfiguration; +import com.tencent.cloud.polaris.config.endpoint.PolarisConfigEndpointAutoConfiguration; +import com.tencent.cloud.polaris.contract.config.PolarisContractPropertiesAutoConfiguration; +import com.tencent.cloud.polaris.contract.config.PolarisContractProperties; +import com.tencent.cloud.polaris.contract.config.PolarisSwaggerAutoConfiguration; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.core.env.Environment; + +public class ConfigBeanInjector implements BeanInjector { + + private static final Logger LOGGER = LoggerFactory.getLogger(ConfigBeanInjector.class); + + private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false); + + @Override + public String getModule() { + return "spring-cloud-starter-tencent-polaris-config"; + } + + @Override + public void onBootstrapStartup(Object configurationParser, Constructor configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) { + LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule()); + } + + @Override + public void onApplicationStartup(Object configurationParser, Constructor configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) { + Object polarisConfigEndpointAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisConfigEndpointAutoConfiguration.class, "polarisConfigEndpointAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisConfigEndpointAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisConfigEndpointAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisConfigEndpointAutoConfiguration.class).getBeanDefinition()); + Object polarisContractProperties = ReflectionUtils.invokeConstructor(configClassCreator, PolarisContractProperties.class, "polarisContractProperties"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisContractProperties, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisContractProperties", BeanDefinitionBuilder.genericBeanDefinition( + PolarisContractProperties.class).getBeanDefinition()); + Object polarisConfigBootstrapAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisConfigBootstrapAutoConfiguration.class, "polarisConfigBootstrapAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisConfigBootstrapAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisConfigBootstrapAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisConfigBootstrapAutoConfiguration.class).getBeanDefinition()); + Object polarisConfigAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisConfigAutoConfiguration.class, "polarisConfigAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisConfigAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisConfigAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisConfigAutoConfiguration.class).getBeanDefinition()); + LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule()); + } +} diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LoadbalancerBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LoadbalancerBeanInjector.java new file mode 100644 index 00000000..2ed6ea6d --- /dev/null +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LoadbalancerBeanInjector.java @@ -0,0 +1,54 @@ +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 cn.polarismesh.agent.plugin.spring.cloud.inject; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.Map; + +import cn.polarismesh.agent.core.common.utils.ReflectionUtils; +import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.common.Constant; +import cn.polarismesh.agent.plugin.spring.cloud.common.Utils; +import com.tencent.cloud.polaris.loadbalancer.PolarisLoadBalancerAutoConfiguration; +import org.springframework.cloud.loadbalancer.config.LoadBalancerAutoConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.core.env.Environment; +import org.springframework.core.io.ClassPathResource; + +public class LoadbalancerBeanInjector implements BeanInjector { + + private static final Logger LOGGER = LoggerFactory.getLogger(LoadbalancerBeanInjector.class); + @Override + public String getModule() { + return "spring-cloud-tencent-polaris-loadbalancer"; + } + + @Override + public void onApplicationStartup(Object configurationParser, Constructor configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) { + Object polarisLoadBalancerAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisLoadBalancerAutoConfiguration.class, "polarisLoadBalancerAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisLoadBalancerAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisLoadBalancerAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisLoadBalancerAutoConfiguration.class).getBeanDefinition()); + LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule()); + } +} diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LosslessBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LosslessBeanInjector.java new file mode 100644 index 00000000..62cc0081 --- /dev/null +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/LosslessBeanInjector.java @@ -0,0 +1,68 @@ +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 cn.polarismesh.agent.plugin.spring.cloud.inject; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.concurrent.atomic.AtomicBoolean; + +import cn.polarismesh.agent.core.common.utils.ReflectionUtils; +import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.common.Constant; +import cn.polarismesh.agent.plugin.spring.cloud.common.Utils; +import com.tencent.cloud.plugin.lossless.config.LosslessAutoConfiguration; +import com.tencent.cloud.plugin.lossless.config.LosslessPropertiesAutoConfiguration; +import com.tencent.cloud.plugin.lossless.config.LosslessPropertiesBootstrapConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.core.env.Environment; + +public class LosslessBeanInjector implements BeanInjector { + + private static final Logger LOGGER = LoggerFactory.getLogger(LosslessBeanInjector.class); + + private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false); + + @Override + public String getModule() { + return "spring-cloud-tencent-lossless-plugin"; + } + + @Override + public void onBootstrapStartup(Object configurationParser, Constructor configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) { + Object losslessPropertiesBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, LosslessPropertiesBootstrapConfiguration.class, "losslessPropertiesBootstrapConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, losslessPropertiesBootstrapConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("losslessPropertiesBootstrapConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + LosslessPropertiesBootstrapConfiguration.class).getBeanDefinition()); + } + + @Override + public void onApplicationStartup(Object configurationParser, Constructor configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) { + Object losslessAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, LosslessAutoConfiguration.class, "losslessAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, losslessAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("losslessAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + LosslessAutoConfiguration.class).getBeanDefinition()); + Object losslessPropertiesAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, LosslessPropertiesAutoConfiguration.class, "losslessPropertiesAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, losslessPropertiesAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("losslessPropertiesAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + LosslessPropertiesAutoConfiguration.class).getBeanDefinition()); + } +} 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 new file mode 100644 index 00000000..8ae77b18 --- /dev/null +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/MetadataTransferBeanInjector.java @@ -0,0 +1,63 @@ +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 cn.polarismesh.agent.plugin.spring.cloud.inject; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.concurrent.atomic.AtomicBoolean; + +import cn.polarismesh.agent.core.common.utils.ReflectionUtils; +import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.common.Constant; +import cn.polarismesh.agent.plugin.spring.cloud.common.Utils; +import com.tencent.cloud.metadata.config.MetadataTransferAutoConfiguration; +import com.tencent.cloud.polaris.config.PolarisConfigBootstrapAutoConfiguration; +import com.tencent.cloud.common.metadata.config.MetadataAutoConfiguration; +import com.tencent.cloud.common.metadata.endpoint.PolarisMetadataEndpointAutoConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.core.env.Environment; + +public class MetadataTransferBeanInjector implements BeanInjector { + + private static final Logger LOGGER = LoggerFactory.getLogger(MetadataTransferBeanInjector.class); + + private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false); + + @Override + public String getModule() { + return "spring-cloud-starter-tencent-metadata-transfer"; + } + + @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()); + } + +} diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/PolarisContextBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/PolarisContextBeanInjector.java new file mode 100644 index 00000000..e79c8593 --- /dev/null +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/PolarisContextBeanInjector.java @@ -0,0 +1,85 @@ +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 cn.polarismesh.agent.plugin.spring.cloud.inject; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; + +import cn.polarismesh.agent.core.common.utils.ReflectionUtils; +import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.common.Constant; +import cn.polarismesh.agent.plugin.spring.cloud.common.Utils; +import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration; +import com.tencent.cloud.polaris.context.config.PolarisContextBootstrapAutoConfiguration; +import com.tencent.cloud.polaris.context.config.PolarisContextPostConfiguration; +import com.tencent.cloud.polaris.context.logging.PolarisLoggingApplicationListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.core.env.Environment; + +public class PolarisContextBeanInjector implements BeanInjector { + + private static final Logger LOGGER = LoggerFactory.getLogger(PolarisContextBeanInjector.class); + + private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false); + + @Override + public String getModule() { + return "spring-cloud-tencent-polaris-context"; + } + + @Override + public Map> getClassNameForType() { + Map> values = new HashMap<>(); + values.put("org.springframework.context.ApplicationListener", Collections.singletonList("com.tencent.cloud.polaris.context.logging.PolarisLoggingApplicationListener")); + return values; + } + + @Override + public void onBootstrapStartup(Object configurationParser, + Constructor configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) { + + LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule()); + } + + @Override + public void onApplicationStartup(Object configurationParser, + Constructor configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) { + Object polarisContextAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisContextAutoConfiguration.class, "polarisContextAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisContextAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisContextAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisContextAutoConfiguration.class).getBeanDefinition()); + Object polarisContextPostConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisContextPostConfiguration.class, "polarisContextPostConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisContextPostConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisContextPostConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisContextPostConfiguration.class).getBeanDefinition()); + Object polarisContextBootstrapAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisContextBootstrapAutoConfiguration.class, "polarisContextBootstrapAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisContextBootstrapAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisContextBootstrapAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisContextBootstrapAutoConfiguration.class).getBeanDefinition()); + LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule()); + } +} diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RateLimitBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RateLimitBeanInjector.java new file mode 100644 index 00000000..f45c328e --- /dev/null +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RateLimitBeanInjector.java @@ -0,0 +1,56 @@ +package cn.polarismesh.agent.plugin.spring.cloud.inject; + +import cn.polarismesh.agent.core.common.utils.ReflectionUtils; +import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.common.Constant; +import cn.polarismesh.agent.plugin.spring.cloud.common.Utils; +import com.tencent.cloud.polaris.ratelimit.config.PolarisRateLimitAutoConfiguration; +import com.tencent.cloud.polaris.ratelimit.config.PolarisRateLimitPropertiesAutoConfiguration; +import com.tencent.cloud.polaris.ratelimit.config.PolarisRateLimitPropertiesBootstrapConfiguration; +import com.tencent.cloud.polaris.ratelimit.endpoint.PolarisRateLimitRuleEndpointAutoConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.core.env.Environment; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.concurrent.atomic.AtomicBoolean; + +public class RateLimitBeanInjector implements BeanInjector { + + private static final Logger LOGGER = LoggerFactory.getLogger(RateLimitBeanInjector.class); + + private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false); + @Override + public String getModule() { + return "spring-cloud-starter-tencent-polaris-ratelimit"; + } + + @Override + public void onBootstrapStartup(Object configurationParser, Constructor configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) { + LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule()); + } + + @Override + public void onApplicationStartup(Object configurationParser, Constructor configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) { + Object polarisRateLimitAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisRateLimitAutoConfiguration.class, "polarisRateLimitAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisRateLimitAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisRateLimitAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisRateLimitAutoConfiguration.class).getBeanDefinition()); + Object polarisRateLimitRuleEndpointAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisRateLimitRuleEndpointAutoConfiguration.class, "polarisRateLimitRuleEndpointAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisRateLimitRuleEndpointAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisRateLimitRuleEndpointAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisRateLimitRuleEndpointAutoConfiguration.class).getBeanDefinition()); + Object polarisRateLimitPropertiesBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisRateLimitPropertiesBootstrapConfiguration.class, "polarisRateLimitPropertiesBootstrapConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisRateLimitPropertiesBootstrapConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisRateLimitPropertiesBootstrapConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisRateLimitPropertiesBootstrapConfiguration.class).getBeanDefinition()); + Object polarisRateLimitPropertiesAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisRateLimitPropertiesAutoConfiguration.class, "polarisRateLimitPropertiesAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisRateLimitPropertiesAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisRateLimitPropertiesAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisRateLimitPropertiesAutoConfiguration.class).getBeanDefinition()); + LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule()); + } +} diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RegistryBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RegistryBeanInjector.java new file mode 100644 index 00000000..beba7a91 --- /dev/null +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RegistryBeanInjector.java @@ -0,0 +1,108 @@ +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 cn.polarismesh.agent.plugin.spring.cloud.inject; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.concurrent.atomic.AtomicBoolean; + +import cn.polarismesh.agent.core.common.utils.ReflectionUtils; +import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.common.Constant; +import cn.polarismesh.agent.plugin.spring.cloud.common.Utils; +import com.tencent.cloud.common.metadata.config.MetadataLocalProperties; +import com.tencent.cloud.polaris.DiscoveryPropertiesAutoConfiguration; +import com.tencent.cloud.polaris.DiscoveryPropertiesBootstrapAutoConfiguration; +import com.tencent.cloud.polaris.discovery.PolarisDiscoveryAutoConfiguration; +import com.tencent.cloud.polaris.discovery.PolarisDiscoveryClientConfiguration; +import com.tencent.cloud.polaris.discovery.reactive.PolarisReactiveDiscoveryClientConfiguration; +import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties; +import com.tencent.polaris.api.config.Configuration; +import com.tencent.cloud.polaris.endpoint.PolarisDiscoveryEndpointAutoConfiguration; +import com.tencent.cloud.polaris.loadbalancer.PolarisLoadBalancerAutoConfiguration; +import com.tencent.cloud.polaris.registry.PolarisServiceRegistryAutoConfiguration; +import com.tencent.cloud.common.metadata.StaticMetadataManager; +import com.tencent.cloud.rpc.enhancement.stat.config.PolarisStatProperties; +import com.tencent.cloud.polaris.registry.PolarisAutoServiceRegistration; +import com.tencent.cloud.polaris.registry.PolarisRegistration; +import com.tencent.cloud.polaris.registry.PolarisServiceRegistry; +import com.tencent.polaris.client.api.SDKContext; +import com.tencent.cloud.polaris.discovery.refresh.PolarisRefreshConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.cloud.loadbalancer.config.LoadBalancerAutoConfiguration; +import org.springframework.core.env.Environment; + +public class RegistryBeanInjector implements BeanInjector { + + private static final Logger LOGGER = LoggerFactory.getLogger(RegistryBeanInjector.class); + + private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false); + + @Override + public String getModule() { + return "spring-cloud-starter-tencent-polaris-discovery"; + } + + @Override + public void onBootstrapStartup(Object configurationParser, Constructor configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) { + LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule()); + + } + + @Override + public void onApplicationStartup(Object configurationParser, Constructor configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) { + Object polarisDiscoveryAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisDiscoveryAutoConfiguration.class, "polarisDiscoveryAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisDiscoveryAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisDiscoveryAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisDiscoveryAutoConfiguration.class).getBeanDefinition()); + Object polarisDiscoveryClientConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisDiscoveryClientConfiguration.class, "polarisDiscoveryClientConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisDiscoveryClientConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisDiscoveryClientConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisDiscoveryClientConfiguration.class).getBeanDefinition()); + Object polarisReactiveDiscoveryClientConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisReactiveDiscoveryClientConfiguration.class, "polarisReactiveDiscoveryClientConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisReactiveDiscoveryClientConfiguration,Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisReactiveDiscoveryClientConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisReactiveDiscoveryClientConfiguration.class).getBeanDefinition()); + Object polarisRefreshConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisRefreshConfiguration.class, "polarisRefreshConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisRefreshConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisRefreshConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisRefreshConfiguration.class).getBeanDefinition()); + Object polarisServiceRegistryAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisServiceRegistryAutoConfiguration.class, "polarisServiceRegistryAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisServiceRegistryAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisServiceRegistryAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisServiceRegistryAutoConfiguration.class).getBeanDefinition()); + Object polarisDiscoveryEndpointAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisDiscoveryEndpointAutoConfiguration.class, "polarisDiscoveryEndpointAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisDiscoveryEndpointAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisDiscoveryEndpointAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisDiscoveryEndpointAutoConfiguration.class).getBeanDefinition()); + Object discoveryPropertiesAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, DiscoveryPropertiesAutoConfiguration.class, "discoveryPropertiesAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, discoveryPropertiesAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("discoveryPropertiesAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + DiscoveryPropertiesAutoConfiguration.class).getBeanDefinition()); + Object discoveryPropertiesBootstrapAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, DiscoveryPropertiesBootstrapAutoConfiguration.class, "discoveryPropertiesBootstrapAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, discoveryPropertiesBootstrapAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("discoveryPropertiesBootstrapAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + DiscoveryPropertiesBootstrapAutoConfiguration.class).getBeanDefinition()); + LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule()); + } +} + diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RouterBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RouterBeanInjector.java new file mode 100644 index 00000000..d5243b97 --- /dev/null +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RouterBeanInjector.java @@ -0,0 +1,131 @@ +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 cn.polarismesh.agent.plugin.spring.cloud.inject; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; + +import cn.polarismesh.agent.core.common.utils.ClassUtils; +import cn.polarismesh.agent.core.common.utils.ReflectionUtils; +import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.common.Constant; +import cn.polarismesh.agent.plugin.spring.cloud.common.Utils; +import com.tencent.cloud.polaris.DiscoveryPropertiesAutoConfiguration; +import com.tencent.cloud.polaris.circuitbreaker.config.PolarisCircuitBreakerAutoConfiguration; +import com.tencent.cloud.polaris.circuitbreaker.config.PolarisCircuitBreakerBootstrapConfiguration; +import com.tencent.cloud.polaris.circuitbreaker.config.PolarisCircuitBreakerFeignClientAutoConfiguration; +import com.tencent.cloud.polaris.circuitbreaker.config.ReactivePolarisCircuitBreakerAutoConfiguration; +import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration; +import com.tencent.cloud.polaris.contract.config.PolarisContractPropertiesAutoConfiguration; +import com.tencent.cloud.polaris.router.config.properties.PolarisNearByRouterProperties; +import com.tencent.cloud.polaris.DiscoveryPropertiesBootstrapAutoConfiguration; +import com.tencent.cloud.polaris.router.config.properties.PolarisRuleBasedRouterProperties; +import com.tencent.cloud.polaris.router.config.FeignAutoConfiguration; +import com.tencent.cloud.polaris.router.config.RouterAutoConfiguration; +import com.tencent.cloud.polaris.router.endpoint.PolarisRouterEndpointAutoConfiguration; +import com.tencent.cloud.polaris.router.config.properties.PolarisMetadataRouterProperties; +import com.tencent.cloud.polaris.router.config.RouterConfigModifierAutoConfiguration; +import com.tencent.cloud.rpc.enhancement.webclient.PolarisLoadBalancerClientRequestTransformer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.core.env.Environment; +import org.springframework.core.io.ClassPathResource; + +public class RouterBeanInjector implements BeanInjector { + + private static final Logger LOGGER = LoggerFactory.getLogger(RouterBeanInjector.class); + @Override + public String getModule() { + return "spring-cloud-starter-tencent-polaris-router"; + } + + private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false); + + @Override + public void onBootstrapStartup(Object configurationParser, Constructor configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) { + LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule()); + } + + + @Override + @SuppressWarnings("unchecked") + 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()); + if (null != ClassUtils.getClazz("feign.RequestInterceptor", + Thread.currentThread().getContextClassLoader())) { + Object feignAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, FeignAutoConfiguration.class, "feignAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, feignAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("feignAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + FeignAutoConfiguration.class).getBeanDefinition()); + } + Object routerAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, RouterAutoConfiguration.class, "routerAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, routerAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("routerAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + RouterAutoConfiguration.class).getBeanDefinition()); + Object polarisNearByRouterProperties = ReflectionUtils.invokeConstructor(configClassCreator, PolarisNearByRouterProperties.class, "polarisNearByRouterProperties"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisNearByRouterProperties, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisNearByRouterProperties", BeanDefinitionBuilder.genericBeanDefinition( + PolarisNearByRouterProperties.class).getBeanDefinition()); + Object polarisRuleBasedRouterProperties = ReflectionUtils.invokeConstructor(configClassCreator, PolarisRuleBasedRouterProperties.class, "polarisRuleBasedRouterProperties"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisRuleBasedRouterProperties, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisRuleBasedRouterProperties", BeanDefinitionBuilder.genericBeanDefinition( + PolarisRuleBasedRouterProperties.class).getBeanDefinition()); + Object routerConfigModifierAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, RouterConfigModifierAutoConfiguration.class, "routerConfigModifierAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, routerConfigModifierAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("routerConfigModifierAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + RouterConfigModifierAutoConfiguration.class).getBeanDefinition()); + Object polarisContractPropertiesAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisContractPropertiesAutoConfiguration.class, "polarisContractPropertiesAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisContractPropertiesAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisContractPropertiesAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisContractPropertiesAutoConfiguration.class).getBeanDefinition()); + Object polarisMetadataRouterProperties = ReflectionUtils.invokeConstructor(configClassCreator, PolarisMetadataRouterProperties.class, "polarisMetadataRouterProperties"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisMetadataRouterProperties, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisMetadataRouterProperties", BeanDefinitionBuilder.genericBeanDefinition( + PolarisMetadataRouterProperties.class).getBeanDefinition()); + Object polarisCircuitBreakerBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisCircuitBreakerBootstrapConfiguration.class, "polarisCircuitBreakerBootstrapConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisCircuitBreakerBootstrapConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisCircuitBreakerBootstrapConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisCircuitBreakerBootstrapConfiguration.class).getBeanDefinition()); + if (null != ClassUtils.getClazz("reactor.core.publisher.Mono", Thread.currentThread().getContextClassLoader()) + && null != ClassUtils.getClazz("reactor.core.publisher.Flux", Thread.currentThread() + .getContextClassLoader())) { + Object reactivePolarisCircuitBreakerAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, ReactivePolarisCircuitBreakerAutoConfiguration.class, "reactivePolarisCircuitBreakerAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, reactivePolarisCircuitBreakerAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("reactivePolarisCircuitBreakerAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + ReactivePolarisCircuitBreakerAutoConfiguration.class).getBeanDefinition()); + } + if (null != ClassUtils.getClazz("feign.Feign", Thread.currentThread().getContextClassLoader()) + && null != ClassUtils.getClazz("org.springframework.cloud.openfeign.FeignClientFactoryBean", Thread.currentThread() + .getContextClassLoader())) { + Object polarisCircuitBreakerFeignClientAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisCircuitBreakerFeignClientAutoConfiguration.class, "polarisCircuitBreakerFeignClientAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisCircuitBreakerFeignClientAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisCircuitBreakerFeignClientAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisCircuitBreakerFeignClientAutoConfiguration.class).getBeanDefinition()); + } + Object polarisCircuitBreakerAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisCircuitBreakerAutoConfiguration.class, "polarisCircuitBreakerAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisCircuitBreakerAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisCircuitBreakerAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisCircuitBreakerAutoConfiguration.class).getBeanDefinition()); + } + +} diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RpcEnhancementBeanInjector.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RpcEnhancementBeanInjector.java new file mode 100644 index 00000000..6061a417 --- /dev/null +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/inject/RpcEnhancementBeanInjector.java @@ -0,0 +1,77 @@ +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 cn.polarismesh.agent.plugin.spring.cloud.inject; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.concurrent.atomic.AtomicBoolean; + +import cn.polarismesh.agent.core.common.utils.ClassUtils; +import cn.polarismesh.agent.core.common.utils.ReflectionUtils; +import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.common.Constant; +import cn.polarismesh.agent.plugin.spring.cloud.common.Utils; +import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementAutoConfiguration; +import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementBootstrapConfiguration; +import com.tencent.cloud.rpc.enhancement.stat.config.PolarisStatPropertiesAutoConfiguration; +import com.tencent.cloud.rpc.enhancement.stat.config.PolarisStatPropertiesBootstrapConfiguration; +import com.tencent.cloud.rpc.enhancement.transformer.InstanceTransformer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.core.env.Environment; + +public class RpcEnhancementBeanInjector implements BeanInjector { + + private static final Logger LOGGER = LoggerFactory.getLogger(RpcEnhancementBeanInjector.class); + + private final AtomicBoolean bootstrapLoaded = new AtomicBoolean(false); + + @Override + public String getModule() { + return "spring-cloud-tencent-rpc-enhancement"; + } + + @Override + public void onBootstrapStartup(Object configurationParser, Constructor configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) { + LOGGER.info("[PolarisJavaAgent] success to inject bootstrap bean definitions for module {}", getModule()); + } + + @Override + public void onApplicationStartup(Object configurationParser, Constructor configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) { + Object polarisStatPropertiesBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisStatPropertiesBootstrapConfiguration.class, "polarisStatPropertiesBootstrapConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisStatPropertiesBootstrapConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisStatPropertiesBootstrapConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisStatPropertiesBootstrapConfiguration.class).getBeanDefinition()); + Object rpcEnhancementBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, RpcEnhancementBootstrapConfiguration.class, "rpcEnhancementBootstrapConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, rpcEnhancementBootstrapConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("rpcEnhancementBootstrapConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + RpcEnhancementBootstrapConfiguration.class).getBeanDefinition()); + Object polarisStatPropertiesAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisStatPropertiesAutoConfiguration.class, "polarisStatPropertiesAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisStatPropertiesAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("polarisStatPropertiesAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + PolarisStatPropertiesAutoConfiguration.class).getBeanDefinition()); + Object rpcEnhancementAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, RpcEnhancementAutoConfiguration.class, "rpcEnhancementAutoConfiguration"); + ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, rpcEnhancementAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER); + registry.registerBeanDefinition("rpcEnhancementAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition( + RpcEnhancementAutoConfiguration.class).getBeanDefinition()); + LOGGER.info("[PolarisJavaAgent] success to inject application bean definitions for module {}", getModule()); + } +} diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationParserInterceptor.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationParserInterceptor.java new file mode 100644 index 00000000..e0da174d --- /dev/null +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationParserInterceptor.java @@ -0,0 +1,160 @@ +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 cn.polarismesh.agent.plugin.spring.cloud.interceptor; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.function.Predicate; + +import cn.polarismesh.agent.core.common.utils.ClassUtils; +import cn.polarismesh.agent.core.common.utils.ReflectionUtils; +import cn.polarismesh.agent.core.extension.interceptor.Interceptor; +import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.common.PropertiesProvider; +import cn.polarismesh.agent.plugin.spring.cloud.common.Utils; +import cn.polarismesh.agent.plugin.spring.cloud.inject.CommonBeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.inject.ConfigBeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.inject.LoadbalancerBeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.inject.LosslessBeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.inject.MetadataTransferBeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.inject.PolarisContextBeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.inject.RegistryBeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.inject.RouterBeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.inject.RpcEnhancementBeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.inject.CircuitBreakerBeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.inject.RateLimitBeanInjector; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.config.BeanDefinitionHolder; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.Environment; +import org.springframework.core.env.MutablePropertySources; +import org.springframework.core.env.PropertiesPropertySource; + +public class ConfigurationParserInterceptor implements Interceptor { + + private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationParserInterceptor.class); + + private final List beanInjectors = new ArrayList<>(); + + private boolean judge = false; + + public ConfigurationParserInterceptor() { + beanInjectors.add(new CircuitBreakerBeanInjector()); + beanInjectors.add(new RateLimitBeanInjector()); + beanInjectors.add(new CommonBeanInjector()); + beanInjectors.add(new MetadataTransferBeanInjector()); + beanInjectors.add(new RegistryBeanInjector()); + beanInjectors.add(new RpcEnhancementBeanInjector()); + beanInjectors.add(new PolarisContextBeanInjector()); + beanInjectors.add(new RouterBeanInjector()); + beanInjectors.add(new LoadbalancerBeanInjector()); + beanInjectors.add(new ConfigBeanInjector()); + beanInjectors.add(new LosslessBeanInjector()); + } + + + private static boolean isMainBeanDefinition(BeanDefinitionHolder beanDefinitionHolder) { + BeanDefinition beanDefinition = beanDefinitionHolder.getBeanDefinition(); + if (beanDefinition instanceof AnnotatedGenericBeanDefinition) { + AnnotatedGenericBeanDefinition annotatedBeanDefinition = (AnnotatedGenericBeanDefinition)beanDefinition; + Class beanClass = annotatedBeanDefinition.getBeanClass(); + Annotation[] annotations = beanClass.getAnnotations(); + for (Annotation annotation : annotations) { + Class aClass = annotation.annotationType(); + if ("org.springframework.boot.autoconfigure.SpringBootApplication".equals(aClass.getCanonicalName())) { + return true; + } + } + } + return false; + } + + @Override + public void after(Object target, Object[] args, Object result, Throwable throwable) { + Set candidates = (Set) args[0]; + BeanDefinitionHolder beanDefinitionHolder = (BeanDefinitionHolder) candidates.iterator().next(); + if ("bootstrapImportSelectorConfiguration".equals(beanDefinitionHolder.getBeanName())) { + // bootstrap + Class clazz = ClassUtils.getClazz("org.springframework.context.annotation.ConfigurationClass", null); + Constructor constructor = ReflectionUtils.accessibleConstructor(clazz, Class.class, String.class); + Method processConfigurationClass = ReflectionUtils.findMethod(target.getClass(), "processConfigurationClass", clazz, Predicate.class); + ReflectionUtils.makeAccessible(processConfigurationClass); + + BeanDefinitionRegistry registry = (BeanDefinitionRegistry) ReflectionUtils.getObjectByFieldName(target, "registry"); + Environment environment = (Environment) ReflectionUtils.getObjectByFieldName(target, "environment"); + for (BeanInjector beanInjector : beanInjectors) { + LOGGER.info("[PolarisJavaAgent] start to inject bootstrap bean definitions in module {}", beanInjector.getModule()); + beanInjector.onBootstrapStartup(target, constructor, processConfigurationClass, registry, environment); + } + LOGGER.info("[PolarisJavaAgent] successfully injected spring cloud tencent bootstrap bean definitions"); + + } else if (isMainBeanDefinition(beanDefinitionHolder)) { + Class clazz = ClassUtils.getClazz("org.springframework.context.annotation.ConfigurationClass", null); + Constructor constructor = ReflectionUtils.accessibleConstructor(clazz, Class.class, String.class); + Method processConfigurationClass = ReflectionUtils.findMethod(target.getClass(), "processConfigurationClass", clazz, Predicate.class); + ReflectionUtils.makeAccessible(processConfigurationClass); + + BeanDefinitionRegistry registry = (BeanDefinitionRegistry) ReflectionUtils.getObjectByFieldName(target, "registry"); + Environment environment = (Environment) ReflectionUtils.getObjectByFieldName(target, "environment"); + for (BeanInjector beanInjector : beanInjectors) { + if (!(beanInjector instanceof RouterBeanInjector)) { + LOGGER.info("[PolarisJavaAgent] start to inject application bean definitions in module {}", beanInjector.getModule()); + beanInjector.onApplicationStartup(target, constructor, processConfigurationClass, registry, environment); + } + } + LOGGER.info("[PolarisJavaAgent] successfully injected spring cloud tencent application bean definitions"); + + } + } + + @Override + public void before(Object target, Object[] args) { + Set candidates = (Set) args[0]; + BeanDefinitionHolder beanDefinitionHolder = (BeanDefinitionHolder) candidates.iterator().next(); + if (isMainBeanDefinition(beanDefinitionHolder)) { + Class clazz = ClassUtils.getClazz("org.springframework.context.annotation.ConfigurationClass", null); + Constructor constructor = ReflectionUtils.accessibleConstructor(clazz, Class.class, String.class); + Method processConfigurationClass = ReflectionUtils.findMethod(target.getClass(), "processConfigurationClass", clazz, Predicate.class); + ReflectionUtils.makeAccessible(processConfigurationClass); + + BeanDefinitionRegistry registry = (BeanDefinitionRegistry) ReflectionUtils.getObjectByFieldName(target, "registry"); + Environment environment = (Environment) ReflectionUtils.getObjectByFieldName(target, "environment"); + for (BeanInjector beanInjector : beanInjectors) { + if ((beanInjector instanceof RouterBeanInjector)) { + LOGGER.info("[PolarisJavaAgent] start to inject application bean definitions in module {}", beanInjector.getModule()); + beanInjector.onApplicationStartup(target, constructor, processConfigurationClass, registry, environment); + } + } + LOGGER.info("[PolarisJavaAgent] successfully injected spring cloud tencent application bean definitions"); + + } + } + + +} + + diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationPostProcessorInterceptor.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationPostProcessorInterceptor.java new file mode 100644 index 00000000..b444ed27 --- /dev/null +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/ConfigurationPostProcessorInterceptor.java @@ -0,0 +1,55 @@ +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 cn.polarismesh.agent.plugin.spring.cloud.interceptor; + +import java.util.List; + +import cn.polarismesh.agent.core.common.utils.ReflectionUtils; +import cn.polarismesh.agent.core.extension.interceptor.Interceptor; +import cn.polarismesh.agent.plugin.spring.cloud.common.PropertiesProvider; +import cn.polarismesh.agent.plugin.spring.cloud.common.Utils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MutablePropertySources; +import org.springframework.core.env.PropertiesPropertySource; + +public class ConfigurationPostProcessorInterceptor implements Interceptor { + private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationPostProcessorInterceptor.class); + + @Override + public void before(Object target, Object[] args) { + ConfigurableEnvironment environment = (ConfigurableEnvironment) ReflectionUtils.getObjectByFieldName(target, "environment"); + if (!Utils.checkSpringApplicationNameExists(environment)) { + LOGGER.warn("[PolarisJavaAgent] skip inject polaris java agent configuration for no spring application name"); + return; + } + List propertySources = PropertiesProvider.loadPropertiesSource(); + MutablePropertySources mutablePropertySources = environment.getPropertySources(); + if (mutablePropertySources.contains(propertySources.get(0).getName())) { + return; + } + for (PropertiesPropertySource propertiesPropertySource : propertySources) { + LOGGER.info("[PolarisJavaAgent] start to add propertiesPropertySource {}", propertiesPropertySource.getName()); + environment.getPropertySources().addLast(propertiesPropertySource); + } + LOGGER.info("[PolarisJavaAgent] successfully injected agent properties into environment, size is " + propertySources.size()); + } + +} 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 new file mode 100644 index 00000000..ba15a1dc --- /dev/null +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/RegisterBeanInterceptor.java @@ -0,0 +1,49 @@ +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 cn.polarismesh.agent.plugin.spring.cloud.interceptor; + +import java.util.HashSet; +import java.util.Set; + +import cn.polarismesh.agent.core.extension.interceptor.Interceptor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.beans.factory.config.BeanDefinition; + +public class RegisterBeanInterceptor implements Interceptor { + + private static final Logger LOGGER = LoggerFactory.getLogger(RegisterBeanInterceptor.class); + + private final Set primaryBeanNames = new HashSet<>(); + + public RegisterBeanInterceptor() { +// primaryBeanNames.add("metadataTransferAutoConfiguratio"); + } + + @Override + public void before(Object target, Object[] args) { + String beanName = (String) args[0]; + if (!primaryBeanNames.contains(beanName)) { + return; + } + BeanDefinition beanDefinition = (BeanDefinition) args[1]; + beanDefinition.setPrimary(true); + LOGGER.info("[PolarisJavaAgent] bean {} has been made primary", beanName); + } +} diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java new file mode 100644 index 00000000..79f34908 --- /dev/null +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/interceptor/SpringFactoriesLoaderInterceptor.java @@ -0,0 +1,97 @@ +/* + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 cn.polarismesh.agent.plugin.spring.cloud.interceptor; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; + +import cn.polarismesh.agent.core.extension.interceptor.Interceptor; +import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.inject.CommonBeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.inject.ConfigBeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.inject.LoadbalancerBeanInjector; +//import cn.polarismesh.agent.plugin.spring.cloud.inject.LosslessBeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.inject.MetadataTransferBeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.inject.PolarisContextBeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.inject.RegistryBeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.inject.RouterBeanInjector; +import cn.polarismesh.agent.plugin.spring.cloud.inject.RpcEnhancementBeanInjector; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SpringFactoriesLoaderInterceptor implements Interceptor { + + private static final Logger LOGGER = LoggerFactory.getLogger(SpringFactoriesLoaderInterceptor.class); + + private final List beanInjectors = new ArrayList<>(); + + private final Map parsedClasses = new ConcurrentHashMap<>(); + + public SpringFactoriesLoaderInterceptor() { + beanInjectors.add(new RegistryBeanInjector()); + beanInjectors.add(new RpcEnhancementBeanInjector()); + beanInjectors.add(new PolarisContextBeanInjector()); + beanInjectors.add(new ConfigBeanInjector()); + beanInjectors.add(new RouterBeanInjector()); + beanInjectors.add(new CommonBeanInjector()); + beanInjectors.add(new MetadataTransferBeanInjector()); + beanInjectors.add(new LoadbalancerBeanInjector()); + } + + + @SuppressWarnings("unchecked") + @Override + public void after(Object target, Object[] args, Object result, Throwable throwable) { + if (args[0] == null) { + return; + } + ClassLoader classLoader = (ClassLoader)args[0]; + parsedClasses.computeIfAbsent(classLoader, new Function() { + @Override + public Boolean apply(ClassLoader classLoader) { + Map> loadedClasses = (Map>) result; + + for (BeanInjector beanInjector : beanInjectors) { + LOGGER.info("[PolarisJavaAgent] start to inject JNI definition in module {}", beanInjector.getModule()); + Map> classNames = beanInjector.getClassNameForType(); + if (classNames.isEmpty()) { + continue; + } + for (Map.Entry> entry : classNames.entrySet()) { + List existsValues = loadedClasses.get(entry.getKey()); + List toAddValues = entry.getValue(); + if (null != existsValues) { + for (String toAddValue : toAddValues) { + if (existsValues.contains(toAddValue)) { + continue; + } + existsValues.add(toAddValue); + } + } else { + classNames.put(entry.getKey(), toAddValues); + } + } + } + return true; + } + }); + } +} diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/resources/META-INF/services/cn.polarismesh.agent.core.extension.AgentPlugin b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/resources/META-INF/services/cn.polarismesh.agent.core.extension.AgentPlugin new file mode 100644 index 00000000..fc45706d --- /dev/null +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/resources/META-INF/services/cn.polarismesh.agent.core.extension.AgentPlugin @@ -0,0 +1 @@ +cn.polarismesh.agent.plugin.spring.cloud.MainPlugin \ No newline at end of file diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/resources/default-plugin.conf b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/resources/default-plugin.conf new file mode 100644 index 00000000..f37d0470 --- /dev/null +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/resources/default-plugin.conf @@ -0,0 +1,59 @@ +# 配置北极星服务端地址 +spring.cloud.polaris.enabled=true + +# 启用 Java Agent 的 Spring Cloud Tencent 注册发现能力 +spring.cloud.discovery.enabled=true +# 配置服务注册发现的命名空间信息 +spring.cloud.polaris.discovery.namespace=default +# 启用从北极星 +spring.cloud.polaris.discovery.enabled=true +spring.cloud.polaris.discovery.register=true + +# 是否启用北极星的 LoadBalancer +spring.cloud.polaris.loadbalancer.enabled=false + +# 是否启用北极星服务路由能力 +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 + +# 是否启用北极星的服务限流能力 +spring.cloud.polaris.ratelimit.enabled=false +# 设置触发限流时的提示信息 +# spring.cloud.polaris.ratelimit.rejectRequestTips="" +# 设置触发限流时的响应码 +spring.cloud.polaris.ratelimit.rejectHttpCode=429 +# 设置限流匀速排队最大排队时间 +spring.cloud.polaris.ratelimit.maxQueuingTime=1000 + +# 是否启用北极星的服务熔断能力 +spring.cloud.polaris.circuitbreaker.enabled=false + +## RPC 调用增强 +spring.cloud.tencent.rpc-enhancement.enabled=false + +# 开启 RPC 调用结果上报 +spring.cloud.tencent.rpc-enhancement.reporter.enabled=false + +# 配置北极星监控指标上报 +spring.cloud.polaris.stat.enabled=false +# 指标上报监听端口 +spring.cloud.polaris.stat.port=0 +# 指标上报暴露的 http path +spring.cloud.polaris.stat.path=/metrics + +# 启用北极星配置中心能力 +spring.cloud.polaris.config.enabled=true +# 是否开启配置监听刷新 +spring.cloud.polaris.config.auto-refresh=true + +# 启用优雅上下线功能 +spring.cloud.polaris.lossless.enabled=false +spring.cloud.polaris.lossless.port=28080 + +# 日志级别 +logging.level.root=INFO \ No newline at end of file diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/resources/polaris-log4j.xml b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/resources/polaris-log4j.xml new file mode 100644 index 00000000..f338d38a --- /dev/null +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/resources/polaris-log4j.xml @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/resources/polaris-log4j2.xml b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/resources/polaris-log4j2.xml new file mode 100644 index 00000000..81a556d3 --- /dev/null +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/resources/polaris-log4j2.xml @@ -0,0 +1,142 @@ + + + + + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n + + + + + + + + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n + + + + + + + + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n + + + + + + + + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n + + + + + + + + + + + + + %m|%d{yyyy-MM-dd HH:mm:ss.SSS}%n + + + + + + + + + + + + + %m|%d{yyyy-MM-dd HH:mm:ss.SSS}%n + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/resources/polaris-logback.xml b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/resources/polaris-logback.xml new file mode 100644 index 00000000..b0768896 --- /dev/null +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-2022-plugin/src/main/resources/polaris-logback.xml @@ -0,0 +1,163 @@ + + + + polaris + + + + ${polaris.log.home}/polaris.log + + + ${polaris.log.home}/polaris.log.%i + ${polaris.log.retain.count:-7} + + + + ${polaris.log.file.size:-10MB} + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n + + + + + ${polaris.log.home}/polaris-update-event.log + + + ${polaris.log.home}/polaris-update-event.log.%i + ${polaris.update.event.log.retain.count:-7} + + + + ${polaris.update.event.log.file.size:-10MB} + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n + + + + + ${polaris.log.home}/polaris-circuitbreaker-event.log + + + ${polaris.log.home}/polaris-circuitbreaker-event.log.%i + + ${polaris.circuitbreaker.event.log.retain.count:-7} + + + + ${polaris.circuitbreaker.event.log.file.size:-10MB} + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n + + + + + ${polaris.log.home}/polaris-healthcheck-event.log + + + ${polaris.log.home}/polaris-healthcheck-event.log.%i + + ${polaris.healthcheck.event.log.retain.count:-7} + + + + ${polaris.healthcheck.event.log.file.size:-10MB} + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n + + + + + ${polaris.log.home}/polaris-lossless-event.log + + + ${polaris.log.home}/polaris-lossless-event.log.%i + + ${polaris.lossless.event.log.retain.count:-7} + + + + ${polaris.lossless.event.log.file.size:-10MB} + + + + %m|%d{yyyy-MM-dd HH:mm:ss.SSS}%n + + + + + ${polaris.log.home}/polaris-instance-heartbeat.log + + + ${polaris.log.home}/polaris-instance-heartbeat.log.%i + + ${polaris.instance.heartbeat.log.retain.count:-7} + + + + ${polaris.instance.heartbeat.log.file.size:-10MB} + + + + %m|%d{yyyy-MM-dd HH:mm:ss.SSS}%n + + + + + 0 + 512 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-plugin-common/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/common/PropertiesProvider.java b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-plugin-common/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/common/PropertiesProvider.java index f07b9abc..542faee0 100644 --- a/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-plugin-common/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/common/PropertiesProvider.java +++ b/polaris-agent-plugins/spring-cloud-plugins/spring-cloud-plugin-common/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/common/PropertiesProvider.java @@ -57,7 +57,7 @@ public static List loadPropertiesSource() { String configPath = Paths.get(System.getProperty(Constant.AGENT_CONF_PATH), "conf").toString(); LOGGER.info("load property sources from config path " + configPath); Properties properties = new Properties(); - String confPath = Paths.get(configPath, "plugin", "spring-cloud-2023", "application.properties").toString(); + String confPath = Paths.get(configPath, "plugin", "spring-cloud-2022", "application.properties").toString(); String cmdVal = System.getProperty("polaris.agent.user.application.conf"); if (null != cmdVal && !cmdVal.isEmpty()) { confPath = cmdVal; diff --git a/pom.xml b/pom.xml index ee1b95c9..f9eaa296 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ https://github.com/polarismesh/polaris-java-agent - 1.7.0-RC3 + 1.7.0-RC4 1.15.5 32.0.1-jre UTF-8