Skip to content

Commit

Permalink
fix: memory not released while using wildcard api call with circuitbr…
Browse files Browse the repository at this point in the history
…eaker enabled (#1335)
  • Loading branch information
andrewshan committed Jul 18, 2024
1 parent f354fcf commit 8454f73
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
- [fix:fix the ratelimit bug for hoxton](https://github.com/Tencent/spring-cloud-tencent/pull/1301)
- [feat:upgrade jacoco version.](https://github.com/Tencent/spring-cloud-tencent/pull/1306)
- [fix:fix no registry when lossless is disabled.](https://github.com/Tencent/spring-cloud-tencent/pull/1313)
- [fix: memory not released while using wildcard api call with circuitbreaker enabled](https://github.com/Tencent/spring-cloud-tencent/pull/1335)
2 changes: 1 addition & 1 deletion spring-cloud-tencent-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<revision>1.14.0-Hoxton.SR12-RC3</revision>

<!-- Polaris SDK version -->
<polaris.version>1.15.5</polaris.version>
<polaris.version>2.0.0.0-SNAPSHOT</polaris.version>

<!-- Dependencies -->
<guava.version>32.0.1-jre</guava.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ public String circuitBreak() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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;
Expand Down Expand Up @@ -119,6 +120,26 @@ public ResponseEntity<String> circuitBreak() throws InterruptedException {
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<String> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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;
Expand Down Expand Up @@ -84,6 +85,24 @@ public String circuitBreakFeignFallbackFromCode() {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

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.
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
* CircuitBreakerQuickstartCalleeServiceWithFallback.
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void testRegister() {
assertThat(OkHttpUtil.checkUrl(HOST, LOSSLESS_PORT_1, "/online", Collections.EMPTY_MAP)).isFalse();
}).doesNotThrowAnyException();
// delay register after 5s
Thread.sleep(5000);
Thread.sleep(10000);
PolarisServiceRegistry registry = context.getBean(PolarisServiceRegistry.class);
PolarisRegistration registration = context.getBean(PolarisRegistration.class);

Expand Down
78 changes: 78 additions & 0 deletions spring-cloud-tencent-polaris-context/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,84 @@
</exclusions>
</dependency>

<dependency>
<groupId>com.tencent.polaris</groupId>
<artifactId>polaris-circuitbreaker-factory</artifactId>
<exclusions>
<exclusion>
<groupId>com.tencent.polaris</groupId>
<artifactId>router-rule</artifactId>
</exclusion>
<exclusion>
<groupId>com.tencent.polaris</groupId>
<artifactId>router-nearby</artifactId>
</exclusion>
<exclusion>
<groupId>com.tencent.polaris</groupId>
<artifactId>router-metadata</artifactId>
</exclusion>
<exclusion>
<groupId>com.tencent.polaris</groupId>
<artifactId>circuitbreaker-errrate</artifactId>
</exclusion>
<exclusion>
<groupId>com.tencent.polaris</groupId>
<artifactId>circuitbreaker-errcount</artifactId>
</exclusion>
<exclusion>
<groupId>com.tencent.polaris</groupId>
<artifactId>circuitbreaker-composite</artifactId>
</exclusion>
<exclusion>
<groupId>com.tencent.polaris</groupId>
<artifactId>stat-prometheus</artifactId>
</exclusion>
<exclusion>
<groupId>com.tencent.polaris</groupId>
<artifactId>healthchecker-http</artifactId>
</exclusion>
<exclusion>
<groupId>com.tencent.polaris</groupId>
<artifactId>healthchecker-tcp</artifactId>
</exclusion>
<exclusion>
<groupId>com.tencent.polaris</groupId>
<artifactId>healthchecker-udp</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>com.tencent.polaris</groupId>
<artifactId>polaris-ratelimit-factory</artifactId>
<exclusions>
<exclusion>
<groupId>com.tencent.polaris</groupId>
<artifactId>router-rule</artifactId>
</exclusion>
<exclusion>
<groupId>com.tencent.polaris</groupId>
<artifactId>router-nearby</artifactId>
</exclusion>
<exclusion>
<groupId>com.tencent.polaris</groupId>
<artifactId>router-metadata</artifactId>
</exclusion>
<exclusion>
<groupId>com.tencent.polaris</groupId>
<artifactId>ratelimiter-reject</artifactId>
</exclusion>
<exclusion>
<groupId>com.tencent.polaris</groupId>
<artifactId>ratelimiter-unirate</artifactId>
</exclusion>
<exclusion>
<groupId>com.tencent.polaris</groupId>
<artifactId>stat-prometheus</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>com.tencent.polaris</groupId>
<artifactId>polaris-client</artifactId>
Expand Down

0 comments on commit 8454f73

Please sign in to comment.