Change RpcEnhancementProperties default values .

pull/424/head
misselvexu 3 years ago
parent 5ac7cb1070
commit 5f31c81b17

@ -9,3 +9,4 @@
- [Optimize: add EncodeTransferMedataRestTemplateInterceptor to RestTemplate](https://github.com/Tencent/spring-cloud-tencent/pull/434) - [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) - [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) - [Optimize: Specification apollo code reference notes](https://github.com/Tencent/spring-cloud-tencent/pull/442)
- [Optimize feign & rest-template circuit-breaker logic](https://github.com/Tencent/spring-cloud-tencent/pull/424)

@ -17,6 +17,8 @@
package com.tencent.cloud.rpc.enhancement; package com.tencent.cloud.rpc.enhancement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -27,7 +29,18 @@ import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import static org.springframework.http.HttpStatus.BAD_GATEWAY;
import static org.springframework.http.HttpStatus.BANDWIDTH_LIMIT_EXCEEDED;
import static org.springframework.http.HttpStatus.GATEWAY_TIMEOUT;
import static org.springframework.http.HttpStatus.HTTP_VERSION_NOT_SUPPORTED;
import static org.springframework.http.HttpStatus.INSUFFICIENT_STORAGE;
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
import static org.springframework.http.HttpStatus.LOOP_DETECTED;
import static org.springframework.http.HttpStatus.NETWORK_AUTHENTICATION_REQUIRED;
import static org.springframework.http.HttpStatus.NOT_EXTENDED;
import static org.springframework.http.HttpStatus.NOT_IMPLEMENTED;
import static org.springframework.http.HttpStatus.SERVICE_UNAVAILABLE;
import static org.springframework.http.HttpStatus.VARIANT_ALSO_NEGOTIATES;
/** /**
* Abstract Polaris Reporter Adapter . * Abstract Polaris Reporter Adapter .
@ -40,6 +53,10 @@ public abstract class AbstractPolarisReporterAdapter {
protected final RpcEnhancementProperties properties; protected final RpcEnhancementProperties properties;
private static final List<HttpStatus> HTTP_STATUSES = toList(NOT_IMPLEMENTED, BAD_GATEWAY,
SERVICE_UNAVAILABLE, GATEWAY_TIMEOUT, HTTP_VERSION_NOT_SUPPORTED, VARIANT_ALSO_NEGOTIATES,
INSUFFICIENT_STORAGE, LOOP_DETECTED, BANDWIDTH_LIMIT_EXCEEDED, NOT_EXTENDED, NETWORK_AUTHENTICATION_REQUIRED);
/** /**
* Constructor With {@link RpcEnhancementProperties} . * Constructor With {@link RpcEnhancementProperties} .
* *
@ -49,6 +66,18 @@ public abstract class AbstractPolarisReporterAdapter {
this.properties = properties; this.properties = properties;
} }
/**
* Convert items to List.
*
* @param items item arrays
* @param <T> Object Generics.
* @return list
*/
@SafeVarargs
private static <T> List<T> toList(T... items) {
return new ArrayList<>(Arrays.asList(items));
}
/** /**
* Callback after completion of request processing, Check if business meltdown reporting is required. * Callback after completion of request processing, Check if business meltdown reporting is required.
* *
@ -70,7 +99,7 @@ public abstract class AbstractPolarisReporterAdapter {
return false; return false;
} }
if (series.isEmpty()) { if (series.isEmpty()) {
return false; return HTTP_STATUSES.contains(httpStatus);
} }
else { else {
try { try {

@ -24,18 +24,6 @@ import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import static org.springframework.http.HttpStatus.BAD_GATEWAY;
import static org.springframework.http.HttpStatus.BANDWIDTH_LIMIT_EXCEEDED;
import static org.springframework.http.HttpStatus.GATEWAY_TIMEOUT;
import static org.springframework.http.HttpStatus.HTTP_VERSION_NOT_SUPPORTED;
import static org.springframework.http.HttpStatus.INSUFFICIENT_STORAGE;
import static org.springframework.http.HttpStatus.LOOP_DETECTED;
import static org.springframework.http.HttpStatus.NETWORK_AUTHENTICATION_REQUIRED;
import static org.springframework.http.HttpStatus.NOT_EXTENDED;
import static org.springframework.http.HttpStatus.NOT_IMPLEMENTED;
import static org.springframework.http.HttpStatus.SERVICE_UNAVAILABLE;
import static org.springframework.http.HttpStatus.VARIANT_ALSO_NEGOTIATES;
/** /**
* Properties of Polaris CircuitBreaker . * Properties of Polaris CircuitBreaker .
* *
@ -52,9 +40,7 @@ public class RpcEnhancementProperties {
/** /**
* Specify the Http status code(s) that needs to be fused. * Specify the Http status code(s) that needs to be fused.
*/ */
private List<HttpStatus> statuses = toList(NOT_IMPLEMENTED, BAD_GATEWAY, private List<HttpStatus> statuses = new ArrayList<>();
SERVICE_UNAVAILABLE, GATEWAY_TIMEOUT, HTTP_VERSION_NOT_SUPPORTED, VARIANT_ALSO_NEGOTIATES,
INSUFFICIENT_STORAGE, LOOP_DETECTED, BANDWIDTH_LIMIT_EXCEEDED, NOT_EXTENDED, NETWORK_AUTHENTICATION_REQUIRED);
/** /**
* Specify List of HTTP status series. * Specify List of HTTP status series.
@ -79,7 +65,6 @@ public class RpcEnhancementProperties {
return new ArrayList<>(Arrays.asList(items)); return new ArrayList<>(Arrays.asList(items));
} }
public List<HttpStatus> getStatuses() { public List<HttpStatus> getStatuses() {
return statuses; return statuses;
} }

@ -84,7 +84,7 @@ public class AbstractPolarisReporterAdapterTest {
// Assert // Assert
Assertions.assertThat(adapter.apply(HttpStatus.OK)).isEqualTo(false); Assertions.assertThat(adapter.apply(HttpStatus.OK)).isEqualTo(false);
Assertions.assertThat(adapter.apply(HttpStatus.INTERNAL_SERVER_ERROR)).isEqualTo(false); Assertions.assertThat(adapter.apply(HttpStatus.INTERNAL_SERVER_ERROR)).isEqualTo(false);
Assertions.assertThat(adapter.apply(HttpStatus.BAD_GATEWAY)).isEqualTo(false); Assertions.assertThat(adapter.apply(HttpStatus.BAD_GATEWAY)).isEqualTo(true);
} }
@Test @Test

Loading…
Cancel
Save