add feature-env examples (#450)

pull/452/head
lepdou 2 years ago committed by GitHub
parent 7f27e79d5d
commit 528fa2b3b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,6 +6,7 @@
- [Feature: Optimized configuration update](https://github.com/Tencent/spring-cloud-tencent/pull/423)
- [[Optimize] improve load-balance ut and support configurable heartbeat interval](https://github.com/Tencent/spring-cloud-tencent/pull/427)
- [Feature: add feature-env plugin & add spring cloud gateway staining plugin](https://github.com/Tencent/spring-cloud-tencent/pull/428)
- [Feature: add feature env examples](https://github.com/Tencent/spring-cloud-tencent/pull/450)
- [Optimize: add EncodeTransferMedataRestTemplateInterceptor to RestTemplate](https://github.com/Tencent/spring-cloud-tencent/pull/434)
- [feat:enhance Feign and RestTemplate and support Polaris monitor.](https://github.com/Tencent/spring-cloud-tencent/pull/435)
- [Optimize: Specification apollo code reference notes](https://github.com/Tencent/spring-cloud-tencent/pull/442)

@ -107,6 +107,7 @@ public class PolarisLoadBalancerCompositeRule extends AbstractLoadBalancerRule {
return null;
}
ILoadBalancer loadBalancer = new SimpleLoadBalancer();
// 2. filter by router
if (key instanceof PolarisRouterContext) {
PolarisRouterContext routerContext = (PolarisRouterContext) key;
@ -114,10 +115,12 @@ public class PolarisLoadBalancerCompositeRule extends AbstractLoadBalancerRule {
// 3. filter by load balance.
// A LoadBalancer needs to be regenerated for each request,
// because the list of servers may be different after filtered by router
ILoadBalancer loadBalancer = new SimpleLoadBalancer();
loadBalancer.addServers(serversAfterRouter);
delegateRule.setLoadBalancer(loadBalancer);
}
else {
loadBalancer.addServers(allServers);
}
delegateRule.setLoadBalancer(loadBalancer);
return delegateRule.choose(key);
}

@ -103,16 +103,10 @@ public class RouterLabelFeignInterceptor implements RequestInterceptor, Ordered
}
// labels from downstream
Map<String, String> transitiveLabels = MetadataContextHolder.get()
.getFragmentContext(MetadataContext.FRAGMENT_TRANSITIVE);
Map<String, String> transitiveLabels = MetadataContextHolder.get().getFragmentContext(MetadataContext.FRAGMENT_TRANSITIVE);
labels.putAll(transitiveLabels);
// pass label by header
if (labels.size() == 0) {
requestTemplate.header(RouterConstants.ROUTER_LABEL_HEADER);
return;
}
String encodedLabelsContent;
try {
encodedLabelsContent = URLEncoder.encode(JacksonUtils.serialize2Json(labels), UTF_8);

@ -0,0 +1,152 @@
# 多测试环境样例说明
## 一、部署结构
<img src="./imgs/structs.png"/>
如上图所示,一共有三个环境:
1. 基线环境,包含 FrontService、MiddleService、BackendService
2. feature1 环境,包含 MiddleService、BackendService
3. feature2 环境,包含 FrontService、BackendService
并且在入口处,部署网关服务。
三条请求链路:
1. 基线环境链路Gateway -> FrontService(基线) -> MiddleService(基线) -> BackendService(基线)
2. feature1 环境链路Gateway -> FrontService(基线) -> MiddleService(feature1) -> BackendService(feature1)
3. feature2 环境链路Gateway -> FrontService(feature2) -> MiddleService(基线) -> BackendService(feature2)
## 二、运行样例
无需任何代码变更,直接启动 base、feature1、feature2、featureenv-gateway 下所有应用即可。
应用默认指向北极星官方的体验环境,启动成功后可直接到体验站点查看服务注册数据。
- 管控台地址: http://14.116.241.63:8080/
- 账号polaris
- 密码polaris
## 三、测试
### 方式一:客户端打标
#### 基线环境链路
````
curl http://127.0.0.1:9999/featureenv-front-example/router/rest
````
响应结果base 表示基线环境)
````
featureenv-front-example[base] -> featureenv-middle-example[base] -> featureenv-backend-example[base]
````
#### feature1 环境链路
通过 X-Polaris-Metadata-Transitive-featureenv 请求头指定特性环境。
````
curl -H'X-Polaris-Metadata-Transitive-featureenv:feature1' http://127.0.0.1:9999/featureenv-front-example/router/rest
````
响应结果
````
featureenv-front-example[base] -> featureenv-middle-example[feature1] -> featureenv-backend-example[feature1]
````
#### feature2 环境链路
通过 X-Polaris-Metadata-Transitive-featureenv 请求头指定特性环境。
````
curl -H'X-Polaris-Metadata-Transitive-featureenv:feature2' http://127.0.0.1:9999/featureenv-front-example/router/rest
````
响应结果
````
featureenv-front-example[feature2] -> featureenv-middle-example[base] -> featureenv-backend-example[feature2]
````
### 方式二:网关流量染色
模拟一种实际的场景,假设客户端请求有一个 uid 请求参数,期望:
1. uid=1000 的请求打到 feature1 环境
2. uid=2000 的请求打到 feature2 环境
3. 其它 uid 的请求打到基线环境
**配置染色规则**
配置地址http://14.116.241.63:8080/#/filegroup-detail?group=featureenv-gateway&namespace=default
修改 rule/staining.json 配置文件,填写以下规则:
````json
{
"rules":[
{
"conditions":[
{
"key":"${http.query.uid}",
"values":["1000"],
"operation":"EQUAL"
}
],
"labels":[
{
"key":"featureenv",
"value":"feature1"
}
]
},
{
"conditions":[
{
"key":"${http.query.uid}",
"values":["2000"],
"operation":"EQUAL"
}
],
"labels":[
{
"key":"featureenv",
"value":"feature2"
}
]
}
]
}
````
填写完后发布配置即可。
#### 基线环境链路
````
curl http://127.0.0.1:9999/featureenv-front-example/router/rest?uid=3000
````
响应结果base 表示基线环境)
````
featureenv-front-example[base] -> featureenv-middle-example[base] -> featureenv-backend-example[base]
````
#### feature1 环境链路
通过 X-Polaris-Metadata-Transitive-featureenv 请求头指定特性环境。
````
curl http://127.0.0.1:9999/featureenv-front-example/router/rest?uid=1000
````
响应结果
````
featureenv-front-example[base] -> featureenv-middle-example[feature1] -> featureenv-backend-example[feature1]
````
#### feature2 环境链路
通过 X-Polaris-Metadata-Transitive-featureenv 请求头指定特性环境。
````
curl http://127.0.0.1:9999/featureenv-front-example/router/rest?uid=2000
````
响应结果
````
featureenv-front-example[feature2] -> featureenv-middle-example[base] -> featureenv-backend-example[feature2]
````

@ -0,0 +1,16 @@
<?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>polaris-router-featureenv-base</artifactId>
<groupId>com.tencent.cloud</groupId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>base-backend</artifactId>
</project>

@ -0,0 +1,44 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent 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 com.tencent.cloud.polaris.router.featureenv.basebackend;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author lepdou 2022-07-20
*/
@RestController
@RequestMapping("/router")
public class BackendController {
@Value("${spring.application.name}")
private String appName;
/**
* Get information of callee.
* @return information of callee
*/
@GetMapping("/rest")
public String rest() {
return appName + "[base]";
}
}

@ -0,0 +1,34 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent 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 com.tencent.cloud.polaris.router.featureenv.basebackend;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* @author lepdou 2022-07-20
*/
@SpringBootApplication
@EnableFeignClients
public class BaseBackendApplication {
public static void main(String[] args) {
SpringApplication.run(BaseBackendApplication.class, args);
}
}

@ -0,0 +1,15 @@
server:
session-timeout: 1800
port: 10002
spring:
application:
name: featureenv-backend-example
cloud:
polaris:
address: grpc://183.47.111.80:8091
namespace: default
enabled: true
logging:
level:
org.springframework.cloud.gateway: info
com.tencent.cloud.polaris: debug

@ -0,0 +1,16 @@
<?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>polaris-router-featureenv-base</artifactId>
<groupId>com.tencent.cloud</groupId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>base-front</artifactId>
</project>

@ -0,0 +1,34 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent 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 com.tencent.cloud.polaris.router.featureenv.basefront;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* @author lepdou 2022-07-20
*/
@SpringBootApplication
@EnableFeignClients
public class BaseFrontApplication {
public static void main(String[] args) {
SpringApplication.run(BaseFrontApplication.class, args);
}
}

@ -0,0 +1,51 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent 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 com.tencent.cloud.polaris.router.featureenv.basefront;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author lepdou 2022-07-20
*/
@RestController
@RequestMapping("/router")
public class FrontController {
@Value("${spring.application.name}")
private String appName;
@Autowired
private MiddleService middleService;
/**
* Get information of callee.
* @return information of callee
*/
@GetMapping("/rest")
public String rest() {
String curName = appName + "[base]";
String resp = middleService.rest();
return curName + " -> " + resp;
}
}

@ -0,0 +1,33 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent 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 com.tencent.cloud.polaris.router.featureenv.basefront;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
/**
* @author lepdou 2022-07-20
*/
@FeignClient("featureenv-middle-example")
public interface MiddleService {
@GetMapping("/router/rest")
String rest();
}

@ -0,0 +1,15 @@
server:
session-timeout: 1800
port: 10000
spring:
application:
name: featureenv-front-example
cloud:
polaris:
address: grpc://183.47.111.80:8091
namespace: default
enabled: true
logging:
level:
org.springframework.cloud.gateway: info
com.tencent.cloud.polaris: debug

@ -0,0 +1,18 @@
<?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>polaris-router-featureenv-base</artifactId>
<groupId>com.tencent.cloud</groupId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>base-middle</artifactId>
</project>

@ -0,0 +1,33 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent 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 com.tencent.cloud.polaris.router.featureenv.basemiddle;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
/**
* @author lepdou 2022-07-20
*/
@FeignClient("featureenv-backend-example")
public interface BackendService {
@GetMapping("/router/rest")
String rest();
}

@ -0,0 +1,34 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent 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 com.tencent.cloud.polaris.router.featureenv.basemiddle;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* @author lepdou 2022-07-20
*/
@SpringBootApplication
@EnableFeignClients
public class BaseMiddleApplication {
public static void main(String[] args) {
SpringApplication.run(BaseMiddleApplication.class, args);
}
}

@ -0,0 +1,51 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent 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 com.tencent.cloud.polaris.router.featureenv.basemiddle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author lepdou 2022-07-20
*/
@RestController
@RequestMapping("/router")
public class MiddleController {
@Value("${spring.application.name}")
private String appName;
@Autowired
private BackendService backendService;
/**
* Get information of callee.
* @return information of callee
*/
@GetMapping("/rest")
public String rest() {
String curName = appName + "[base]";
String resp = backendService.rest();
return curName + " -> " + resp;
}
}

@ -0,0 +1,15 @@
server:
session-timeout: 1800
port: 10001
spring:
application:
name: featureenv-middle-example
cloud:
polaris:
address: grpc://183.47.111.80:8091
namespace: default
enabled: true
logging:
level:
org.springframework.cloud.gateway: info
com.tencent.cloud.polaris: debug

@ -0,0 +1,33 @@
<?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>polaris-router-featureenv-example</artifactId>
<groupId>com.tencent.cloud</groupId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>polaris-router-featureenv-base</artifactId>
<packaging>pom</packaging>
<modules>
<module>base-front</module>
<module>base-middle</module>
<module>base-backend</module>
</modules>
<dependencies>
<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>
</dependencies>
</project>

@ -0,0 +1,16 @@
<?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>feature1</artifactId>
<groupId>com.tencent.cloud</groupId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>feature1-backend</artifactId>
</project>

@ -0,0 +1,51 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent 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 com.tencent.cloud.polaris.router.featureenv.feature1backend;
import com.tencent.cloud.common.metadata.StaticMetadataManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author lepdou 2022-07-20
*/
@RestController
@RequestMapping("/router")
public class BackendController {
@Autowired
private StaticMetadataManager staticMetadataManager;
@Value("${spring.application.name}")
private String appName;
/**
* Get information of callee.
* @return information of callee
*/
@GetMapping("/rest")
public String rest() {
String featureEnv = staticMetadataManager.getMergedStaticMetadata().get("featureenv");
return appName + "[" + featureEnv + "]";
}
}

@ -0,0 +1,34 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent 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 com.tencent.cloud.polaris.router.featureenv.feature1backend;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* @author lepdou 2022-07-20
*/
@SpringBootApplication
@EnableFeignClients
public class Feature1BackendApplication {
public static void main(String[] args) {
SpringApplication.run(Feature1BackendApplication.class, args);
}
}

@ -0,0 +1,19 @@
server:
session-timeout: 1800
port: 11002
spring:
application:
name: featureenv-backend-example
cloud:
polaris:
address: grpc://183.47.111.80:8091
namespace: default
enabled: true
tencent:
metadata:
content:
featureenv: feature1
logging:
level:
org.springframework.cloud.gateway: info
com.tencent.cloud.polaris: debug

@ -0,0 +1,16 @@
<?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>feature1</artifactId>
<groupId>com.tencent.cloud</groupId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>feature1-middle</artifactId>
</project>

@ -0,0 +1,33 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent 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 com.tencent.cloud.polaris.router.featureenv.feature1middle;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
/**
* @author lepdou 2022-07-20
*/
@FeignClient("featureenv-backend-example")
public interface BackendService {
@GetMapping("/router/rest")
String rest();
}

@ -0,0 +1,34 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent 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 com.tencent.cloud.polaris.router.featureenv.feature1middle;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* @author lepdou 2022-07-20
*/
@SpringBootApplication
@EnableFeignClients
public class Feature1MiddleApplication {
public static void main(String[] args) {
SpringApplication.run(Feature1MiddleApplication.class, args);
}
}

@ -0,0 +1,58 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent 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 com.tencent.cloud.polaris.router.featureenv.feature1middle;
import com.tencent.cloud.common.metadata.StaticMetadataManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author lepdou 2022-07-20
*/
@RestController
@RequestMapping("/router")
public class MiddleController {
@Value("${spring.application.name}")
private String appName;
@Autowired
private BackendService backendService;
@Autowired
private StaticMetadataManager staticMetadataManager;
/**
* Get information of callee.
* @return information of callee
*/
@GetMapping("/rest")
public String rest() {
String featureEnv = staticMetadataManager.getMergedStaticMetadata().get("featureenv");
String curName = appName + "[" + featureEnv + "]";
String resp = backendService.rest();
return curName + " -> " + resp;
}
}

@ -0,0 +1,19 @@
server:
session-timeout: 1800
port: 11001
spring:
application:
name: featureenv-middle-example
cloud:
polaris:
address: grpc://183.47.111.80:8091
namespace: default
enabled: true
tencent:
metadata:
content:
featureenv: feature1
logging:
level:
org.springframework.cloud.gateway: info
com.tencent.cloud.polaris: debug

@ -0,0 +1,32 @@
<?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>polaris-router-featureenv-example</artifactId>
<groupId>com.tencent.cloud</groupId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>feature1</artifactId>
<packaging>pom</packaging>
<modules>
<module>feature1-middle</module>
<module>feature1-backend</module>
</modules>
<dependencies>
<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>
</dependencies>
</project>

@ -0,0 +1,16 @@
<?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>feature2</artifactId>
<groupId>com.tencent.cloud</groupId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>feature2-backend</artifactId>
</project>

@ -0,0 +1,51 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent 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 com.tencent.cloud.polaris.router.featureenv.feature2backend;
import com.tencent.cloud.common.metadata.StaticMetadataManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author lepdou 2022-07-20
*/
@RestController
@RequestMapping("/router")
public class BackendController {
@Autowired
private StaticMetadataManager staticMetadataManager;
@Value("${spring.application.name}")
private String appName;
/**
* Get information of callee.
* @return information of callee
*/
@GetMapping("/rest")
public String rest() {
String featureEnv = staticMetadataManager.getMergedStaticMetadata().get("featureenv");
return appName + "[" + featureEnv + "]";
}
}

@ -0,0 +1,34 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent 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 com.tencent.cloud.polaris.router.featureenv.feature2backend;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* @author lepdou 2022-07-20
*/
@SpringBootApplication
@EnableFeignClients
public class Feature2BackendApplication {
public static void main(String[] args) {
SpringApplication.run(Feature2BackendApplication.class, args);
}
}

@ -0,0 +1,19 @@
server:
session-timeout: 1800
port: 12002
spring:
application:
name: featureenv-backend-example
cloud:
polaris:
address: grpc://183.47.111.80:8091
namespace: default
enabled: true
tencent:
metadata:
content:
featureenv: feature2
logging:
level:
org.springframework.cloud.gateway: info
com.tencent.cloud.polaris: debug

@ -0,0 +1,17 @@
<?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>feature2</artifactId>
<groupId>com.tencent.cloud</groupId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>feature2-front</artifactId>
</project>

@ -0,0 +1,34 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent 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 com.tencent.cloud.polaris.router.featureenv.feature2front;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* @author lepdou 2022-07-20
*/
@SpringBootApplication
@EnableFeignClients
public class Feature2FrontApplication {
public static void main(String[] args) {
SpringApplication.run(Feature2FrontApplication.class, args);
}
}

@ -0,0 +1,58 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent 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 com.tencent.cloud.polaris.router.featureenv.feature2front;
import com.tencent.cloud.common.metadata.StaticMetadataManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author lepdou 2022-07-20
*/
@RestController
@RequestMapping("/router")
public class FrontController {
@Autowired
private StaticMetadataManager staticMetadataManager;
@Value("${spring.application.name}")
private String appName;
@Autowired
private MiddleService middleService;
/**
* Get information of callee.
* @return information of callee
*/
@GetMapping("/rest")
public String rest() {
String featureEnv = staticMetadataManager.getMergedStaticMetadata().get("featureenv");
String curName = appName + "[" + featureEnv + "]";
String resp = middleService.rest();
return curName + " -> " + resp;
}
}

@ -0,0 +1,33 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent 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 com.tencent.cloud.polaris.router.featureenv.feature2front;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
/**
* @author lepdou 2022-07-20
*/
@FeignClient("featureenv-middle-example")
public interface MiddleService {
@GetMapping("/router/rest")
String rest();
}

@ -0,0 +1,19 @@
server:
session-timeout: 1800
port: 12000
spring:
application:
name: featureenv-front-example
cloud:
polaris:
address: grpc://183.47.111.80:8091
namespace: default
enabled: true
tencent:
metadata:
content:
featureenv: feature2
logging:
level:
org.springframework.cloud.gateway: info
com.tencent.cloud.polaris: debug

@ -0,0 +1,32 @@
<?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>polaris-router-featureenv-example</artifactId>
<groupId>com.tencent.cloud</groupId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>feature2</artifactId>
<packaging>pom</packaging>
<modules>
<module>feature2-front</module>
<module>feature2-backend</module>
</modules>
<dependencies>
<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>
</dependencies>
</project>

@ -0,0 +1,30 @@
<?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>polaris-router-featureenv-example</artifactId>
<groupId>com.tencent.cloud</groupId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>featureenv-gateway</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-gateway-plugin</artifactId>
</dependency>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-featureenv-plugin</artifactId>
</dependency>
</dependencies>
</project>

@ -0,0 +1,33 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent 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 com.tencent.cloud.polaris.featureenv.gateway;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author lepdou 2022-07-20
*/
@SpringBootApplication
public class FeatureEnvScgApplication {
public static void main(String[] args) {
SpringApplication.run(FeatureEnvScgApplication.class, args);
}
}

@ -0,0 +1,68 @@
server:
session-timeout: 1800
port: 9999
spring:
application:
name: featureenv-gateway
cloud:
tencent:
plugin:
scg:
staining:
enabled: true
rule-staining:
enabled: true
router:
feature-env:
enabled: true
polaris:
address: grpc://183.47.111.80:8091
namespace: default
enabled: true
gateway:
discovery:
locator:
enabled: true
'predicates[0]':
name: Path
args:
patterns: '''/'' + serviceId + ''/**'''
'filters[0]':
name: RewritePath
args:
regexp: '''/'' + serviceId + ''/(?<remaining>.*)'''
replacement: '''/$\{remaining}'''
'filters[1]':
name: Retry
args:
retries: 3
exceptions:
'[0]': '''java.net.ConnectException'''
'[1]': '''java.io.IOException'''
statuses:
'[0]': '''BAD_GATEWAY'''
'[1]': '''SERVICE_UNAVAILABLE'''
series:
'[0]': '''CLIENT_ERROR'''
methods:
'[0]': '''GET'''
'[1]': '''POST'''
'[2]': '''PUT'''
'[3]': '''DELETE'''
backoff:
firstBackoff: '''100ms'''
maxBackoff: '''500ms'''
factor: 2
basedOnPreviousValue: false
routes:
- id: featureenv-front-example
uri: lb://featureenv-front-example
predicates:
- Path=/featureenv-front-example/**
filters:
- StripPrefix=1
logging:
level:
org.springframework.cloud.gateway: info
com.tencent.cloud.polaris: debug

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

@ -0,0 +1,34 @@
<?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-tencent-examples</artifactId>
<groupId>com.tencent.cloud</groupId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>polaris-router-featureenv-example</artifactId>
<packaging>pom</packaging>
<modules>
<module>base</module>
<module>feature1</module>
<module>feature2</module>
<module>featureenv-gateway</module>
</modules>
<dependencies>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-discovery</artifactId>
</dependency>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-featureenv-plugin</artifactId>
</dependency>
</dependencies>
</project>

@ -24,6 +24,7 @@
<module>polaris-router-example</module>
<module>metadata-transfer-example</module>
<module>polaris-router-grayrelease-example</module>
<module>polaris-router-featureenv-example</module>
</modules>
<properties>

Loading…
Cancel
Save