forked from polarismesh/polaris-java-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:support agent2022 (polarismesh#193)
* feat:support agent2022 * feat:support agent2022 --------- Co-authored-by: fredrikliu <[email protected]>
- Loading branch information
1 parent
7bcd419
commit 531cf60
Showing
59 changed files
with
3,604 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
plugins.enable=spring-cloud-2023-plugin | ||
plugins.enable=spring-cloud-2022-plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>spring-cloud-plugins-examples</artifactId> | ||
<groupId>com.tencent.polaris</groupId> | ||
<version>${revision}</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>spring-cloud-2022-examples</artifactId> | ||
|
||
<packaging>pom</packaging> | ||
|
||
<modules> | ||
<module>quickstart-examples</module> | ||
</modules> | ||
|
||
</project> |
29 changes: 29 additions & 0 deletions
29
...cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] |
48 changes: 48 additions & 0 deletions
48
...-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/deployment.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
105 changes: 105 additions & 0 deletions
105
...ng-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/consumer/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>3.1.8</version> | ||
<relativePath/> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.tencent.polaris</groupId> | ||
<artifactId>polaris-javaagent-demo-sc-quickstart-2022-consumer</artifactId> | ||
<packaging>jar</packaging> | ||
<version>1.7.0</version> | ||
|
||
<name>2022-consumer</name> | ||
<description>Demo Consumer Project For Spring Cloud Alibaba</description> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.alibaba.cloud</groupId> | ||
<artifactId>spring-cloud-alibaba-dependencies</artifactId> | ||
<version>2022.0.0.0</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-dependencies</artifactId> | ||
<version>2022.0.5</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<!-- 简单的 Spring Cloud Web 依赖 --> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-bootstrap</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-openfeign</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-webflux</artifactId> | ||
</dependency> | ||
|
||
<!-- 引入 Spring Cloud Alibaba 的服务注册发现依赖 --> | ||
<dependency> | ||
<groupId>com.alibaba.cloud</groupId> | ||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-loadbalancer</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
|
||
|
||
|
||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<configuration> | ||
<executable>true</executable> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>repackage</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
147 changes: 147 additions & 0 deletions
147
.../src/main/java/cn/polarismesh/agent/examples/alibaba/cloud/cloud/ConsumerApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <a href="mailto:[email protected]">liaochuntao</a> | ||
*/ | ||
@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<String> rest(@PathVariable String str) { | ||
ResponseEntity<String> 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(); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...loud-2022-examples/quickstart-examples/consumer/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
7 changes: 7 additions & 0 deletions
7
...-cloud-2022-examples/quickstart-examples/consumer/src/main/resources/bootstrap.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
8 changes: 8 additions & 0 deletions
8
...es/spring-cloud-2022-examples/quickstart-examples/consumer/src/main/resources/polaris.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
consumer: | ||
serviceRouter: | ||
plugin: | ||
# 设置就近路由插件配置 | ||
nearbyBasedRouter: | ||
# 描述:就近路由的最小匹配级别,需要显示设置 | ||
# 范围: zone(腾讯云地域信息,eg: ap-guangzhou)、campus(腾讯云可用区, eg: ap-guangzhou-3) | ||
matchLevel: campus |
Oops, something went wrong.