feat: support custom quickstart circuitbreak delay time. (#1666)

pull/1674/head
Fishtail 2 months ago committed by Haotian Zhang
parent 826443aee4
commit a568f22856

@ -11,3 +11,4 @@
- [refactor: optimize log](https://github.com/Tencent/spring-cloud-tencent/pull/1671)
- [feat: support shortest response time lb and least connection lb](https://github.com/Tencent/spring-cloud-tencent/pull/1637)
- [feat:support traffic mirroring.](https://github.com/Tencent/spring-cloud-tencent/pull/1647)
- [feat: support custom quickstart circuitbreak delay time.](https://github.com/Tencent/spring-cloud-tencent/pull/1666)

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

Loading…
Cancel
Save