From 33e080ea70f79418c8b7c0534a69de86cca03cf1 Mon Sep 17 00:00:00 2001 From: andrew shan <45474304+andrewshan@users.noreply.github.com> Date: Thu, 25 Jul 2024 21:59:27 +0800 Subject: [PATCH] fix: memory cost too many when using wildcard feign calls (#1356) --- CHANGELOG.md | 3 ++- .../callee/QuickstartCalleeController.java | 12 +++++++++++ .../callee/QuickstartCalleeController.java | 21 +++++++++++++++++++ .../CircuitBreakerController.java | 19 +++++++++++++++++ ...CircuitBreakerQuickstartCalleeService.java | 9 ++++++++ ...reakerQuickstartCalleeServiceFallback.java | 5 +++++ ...erQuickstartCalleeServiceWithFallback.java | 9 ++++++++ 7 files changed, 77 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35bbb6c1e..a855ed60a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,4 +23,5 @@ - [fix: fix lossless test case unstable issues.](https://github.com/Tencent/spring-cloud-tencent/pull/1324) - [feat:support consul service update task.](https://github.com/Tencent/spring-cloud-tencent/pull/1329) - [fix:fix app starting failed when user using custom OpenAPI bean.](https://github.com/Tencent/spring-cloud-tencent/pull/1330) -- [fix: move ConditionalOnTsfEnabled to spring-cloud-tencent-commons and fix PolarisInetUtilsAutoConfiguration.](https://github.com/Tencent/spring-cloud-tencent/pull/1330) \ No newline at end of file +- [fix: move ConditionalOnTsfEnabled to spring-cloud-tencent-commons and fix PolarisInetUtilsAutoConfiguration.](https://github.com/Tencent/spring-cloud-tencent/pull/1354) +- [fix: memory cost too many when using wildcard feign calls](https://github.com/Tencent/spring-cloud-tencent/pull/1356) diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java index 072255d85..2370d4c17 100644 --- a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java +++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java @@ -28,6 +28,7 @@ import org.slf4j.LoggerFactory; 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.PathVariable; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -106,6 +107,17 @@ public class QuickstartCalleeController { return String.format("Quickstart Callee Service [%s:%s] is called right.", ip, port); } + /** + * Check circuit break. + * + * @return circuit break info + */ + @GetMapping("/circuitBreak/wildcard/{uid}") + public String circuitBreakWildcard(@PathVariable String uid) throws InterruptedException { + LOG.info("Quickstart Callee Service uid {} [{}:{}] is called right.", uid, ip, port); + return String.format("Quickstart Callee Service %s [%s:%s] is called right.", uid, ip, port); + } + @GetMapping("/faultDetect") public String health() { LOG.info("Quickstart Callee Service [{}:{}] is detected right.", ip, port); diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java index d4de94f3d..9f923950a 100644 --- a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java +++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java @@ -30,6 +30,7 @@ import org.springframework.beans.factory.annotation.Value; 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.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -119,6 +120,26 @@ public class QuickstartCalleeController { return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is called right.", ip, port), HttpStatus.OK); } + /** + * Check circuit break. + * + * @return circuit break info + */ + @GetMapping("/circuitBreak/wildcard/{uid}") + public ResponseEntity circuitBreakWildcard(@PathVariable String uid) throws InterruptedException { + if (ifBadGateway) { + LOG.info("Quickstart Callee Service with uid {} [{}:{}] is called wrong.", uid, ip, port); + return new ResponseEntity<>("failed for call quickstart callee service wildcard.", HttpStatus.BAD_GATEWAY); + } + if (ifDelay) { + Thread.sleep(200); + LOG.info("Quickstart Callee Service uid {} [{}:{}] is called slow.", uid, ip, port); + return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is called slow.", ip, port), HttpStatus.OK); + } + LOG.info("Quickstart Callee Service uid {} [{}:{}] is called right.", uid, ip, port); + return new ResponseEntity<>(String.format("Quickstart Callee Service %s [%s:%s] is called right.", uid, ip, port), HttpStatus.OK); + } + @GetMapping("/setBadGateway") public String setBadGateway(@RequestParam boolean param) { this.ifBadGateway = param; diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerController.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerController.java index 4d902aaa2..5b348144b 100644 --- a/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerController.java +++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerController.java @@ -25,6 +25,7 @@ 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.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; @@ -84,6 +85,24 @@ public class CircuitBreakerController { return circuitBreakerQuickstartCalleeServiceWithFallback.circuitBreak(); } + /** + * Feign circuit breaker with fallback from Polaris. + * @return circuit breaker information of callee + */ + @GetMapping("/feign/fallbackFromPolaris/wildcard/{uid}") + public String circuitBreakFeignFallbackFromPolarisWildcard(@PathVariable String uid) { + return circuitBreakerQuickstartCalleeService.circuitBreakWildcard(uid); + } + + /** + * Feign circuit breaker with fallback from Polaris. + * @return circuit breaker information of callee + */ + @GetMapping("/feign/fallbackFromCode/wildcard/{uid}") + public String circuitBreakFeignFallbackFromCodeWildcard(@PathVariable String uid) { + return circuitBreakerQuickstartCalleeServiceWithFallback.circuitBreakWildcard(uid); + } + /** * RestTemplate circuit breaker. * @return circuit breaker information of callee diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeService.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeService.java index 64821b9a9..b96052840 100644 --- a/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeService.java +++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeService.java @@ -19,6 +19,7 @@ package com.tencent.cloud.quickstart.caller.circuitbreaker; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; /** * Circuit breaker example callee provider. @@ -35,4 +36,12 @@ public interface CircuitBreakerQuickstartCalleeService { */ @GetMapping("/quickstart/callee/circuitBreak") String circuitBreak(); + + /** + * Check circuit break with uid. + * @param uid uid variable + * @return circuit break info + */ + @GetMapping("/quickstart/callee/circuitBreak/wildcard/{uid}") + String circuitBreakWildcard(@PathVariable String uid); } diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeServiceFallback.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeServiceFallback.java index 06a2df366..dbc2b9af8 100644 --- a/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeServiceFallback.java +++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeServiceFallback.java @@ -31,4 +31,9 @@ public class CircuitBreakerQuickstartCalleeServiceFallback implements CircuitBre public String circuitBreak() { return "fallback: trigger the refuse for service callee."; } + + @Override + public String circuitBreakWildcard(String uid) { + return String.format("fallback: trigger the refuse for service callee %s.", uid); + } } diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeServiceWithFallback.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeServiceWithFallback.java index f71a7650e..fe4a9daf8 100644 --- a/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeServiceWithFallback.java +++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeServiceWithFallback.java @@ -19,6 +19,7 @@ package com.tencent.cloud.quickstart.caller.circuitbreaker; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; /** * CircuitBreakerQuickstartCalleeServiceWithFallback. @@ -35,4 +36,12 @@ public interface CircuitBreakerQuickstartCalleeServiceWithFallback { */ @GetMapping("/quickstart/callee/circuitBreak") String circuitBreak(); + + /** + * Check circuit break with uid. + * @param uid uid variable + * @return circuit break info + */ + @GetMapping("/circuitBreak/wildcard/{uid}") + String circuitBreakWildcard(@PathVariable String uid); }