feat: support custom quickstart circuitbreak delay time.

pull/1704/head
Fishtail 2 months ago committed by Haotian Zhang
parent ba181fc264
commit 902f7cdc79

@ -12,3 +12,4 @@
- [feat:support setting load balancing strategy per service.](https://github.com/Tencent/spring-cloud-tencent/pull/1701) - [feat:support setting load balancing strategy per service.](https://github.com/Tencent/spring-cloud-tencent/pull/1701)
- [feat: support shortest response time lb and least connection lb](https://github.com/Tencent/spring-cloud-tencent/pull/1702) - [feat: support shortest response time lb and least connection lb](https://github.com/Tencent/spring-cloud-tencent/pull/1702)
- [feat:support traffic mirroring.](https://github.com/Tencent/spring-cloud-tencent/pull/1703) - [feat:support traffic mirroring.](https://github.com/Tencent/spring-cloud-tencent/pull/1703)
- [feat: support custom quickstart circuitbreak delay time.](https://github.com/Tencent/spring-cloud-tencent/pull/1704)

@ -66,7 +66,7 @@ public class QuickstartCalleeController {
@Autowired @Autowired
private DataSourceProperties dataSourceProperties; private DataSourceProperties dataSourceProperties;
private boolean ifBadGateway = true; private boolean ifBadGateway = true;
private boolean ifDelay = false; private long delay = 0;
/** /**
* Get sum of two value. * Get sum of two value.
@ -119,16 +119,19 @@ public class QuickstartCalleeController {
@GetMapping("/circuitBreak") @GetMapping("/circuitBreak")
public ResponseEntity<String> circuitBreak() throws InterruptedException { public ResponseEntity<String> circuitBreak() throws InterruptedException {
if (ifBadGateway) { if (ifBadGateway) {
LOG.info("Quickstart Callee Service [{}:{}] is called wrong.", ip, port); String result = String.format("Quickstart Callee Service [%s:%s] is call failed.", ip, port);
return new ResponseEntity<>("failed for call quickstart callee service.", HttpStatus.BAD_GATEWAY); LOG.info(result);
return new ResponseEntity<>(result, HttpStatus.BAD_GATEWAY);
} }
if (ifDelay) { if (delay > 0) {
Thread.sleep(200); String result = String.format("Quickstart Callee Service [%s:%s] is called after %sms.", ip, port, delay);
LOG.info("Quickstart Callee Service [{}:{}] is called slow.", ip, port); Thread.sleep(delay);
return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is called slow.", ip, port), HttpStatus.OK); LOG.info(result);
return new ResponseEntity<>(result, HttpStatus.OK);
} }
LOG.info("Quickstart Callee Service [{}:{}] is called right.", ip, port); String result = String.format("Quickstart Callee Service [%s:%s] is called right.", ip, port);
return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is called right.", ip, port), HttpStatus.OK); LOG.info(result);
return new ResponseEntity<>(result, HttpStatus.OK);
} }
/** /**
@ -139,16 +142,19 @@ public class QuickstartCalleeController {
@GetMapping("/circuitBreak/wildcard/{uid}") @GetMapping("/circuitBreak/wildcard/{uid}")
public ResponseEntity<String> circuitBreakWildcard(@PathVariable String uid) throws InterruptedException { public ResponseEntity<String> circuitBreakWildcard(@PathVariable String uid) throws InterruptedException {
if (ifBadGateway) { if (ifBadGateway) {
LOG.info("Quickstart Callee Service with uid {} [{}:{}] is called wrong.", uid, ip, port); String result = String.format("Quickstart Callee Service uid %s [%s:%s] call failed.", uid, ip, port);
return new ResponseEntity<>("failed for call quickstart callee service wildcard.", HttpStatus.BAD_GATEWAY); LOG.info(result);
return new ResponseEntity<>(result, HttpStatus.BAD_GATEWAY);
} }
if (ifDelay) { if (delay > 0) {
Thread.sleep(200); String result = String.format("Quickstart Callee Service uid %s [%s:%s] is called after %sms.", uid, ip, port, delay);
LOG.info("Quickstart Callee Service uid {} [{}:{}] is called slow.", uid, ip, port); Thread.sleep(delay);
return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is called slow.", ip, port), HttpStatus.OK); LOG.info(result);
return new ResponseEntity<>(result, HttpStatus.OK);
} }
LOG.info("Quickstart Callee Service uid {} [{}:{}] is called right.", uid, ip, port); String result = String.format("Quickstart Callee Service uid %s [%s:%s] 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); LOG.info(result);
return new ResponseEntity<>(result, HttpStatus.OK);
} }
@GetMapping("/setBadGateway") @GetMapping("/setBadGateway")
@ -165,30 +171,35 @@ public class QuickstartCalleeController {
} }
@GetMapping("/setDelay") @GetMapping("/setDelay")
public String setDelay(@RequestParam boolean param) { public ResponseEntity<String> setDelay(@RequestParam long param) {
this.ifDelay = param; this.delay = param;
if (param) { if (param > 0) {
LOG.info("info is set to delay 200ms."); LOG.info("info is set to delay {}ms.", param);
return "info is set to delay 200ms."; return new ResponseEntity<>(String.format("info is set to delay %sms.", param), HttpStatus.OK);
} }
else { if (param == 0) {
LOG.info("info is set to no delay."); LOG.info("info is set to no delay.");
return "info is set to no delay."; return new ResponseEntity<>("info is set to no delay.", HttpStatus.OK);
} }
return new ResponseEntity<>("delay must be non-negative", HttpStatus.BAD_REQUEST);
} }
@GetMapping("/faultDetect") @GetMapping("/faultDetect")
public ResponseEntity<String> health() throws InterruptedException { public ResponseEntity<String> health() throws InterruptedException {
if (ifBadGateway) { if (ifBadGateway) {
LOG.info("Quickstart Callee Service [{}:{}] is detected wrong.", ip, port); String result = String.format("Quickstart Callee Service [%s:%s] call failed", ip, port);
return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is detected wrong.", ip, port), HttpStatus.BAD_GATEWAY); LOG.info(result);
return new ResponseEntity<>(result, HttpStatus.BAD_GATEWAY);
} }
if (ifDelay) { if (delay > 0) {
Thread.sleep(200); Thread.sleep(delay);
LOG.info("Quickstart Callee Service [{}:{}] is detected slow.", ip, port); String result = String.format("Quickstart Callee Service [%s:%s] is detected after %s.", ip, port, delay);
return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is detected slow.", ip, port), HttpStatus.OK); LOG.info(result);
return new ResponseEntity<>(result, HttpStatus.OK);
} }
LOG.info("Quickstart Callee Service [{}:{}] is detected right.", ip, port); String result = String.format("Quickstart Callee Service [%s:%s] is detected right.", ip, port);
return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is detected right.", ip, port), HttpStatus.OK); LOG.info(result);
return new ResponseEntity<>(result, HttpStatus.OK);
} }
} }

Loading…
Cancel
Save