feat:update configuration metadata. (#474)

pull/483/head
Haotian Zhang 2 years ago committed by GitHub
parent 0f32fb47e6
commit 1f4b59b8b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,3 +8,4 @@
- [feat:enhance Feign and RestTemplate and support Polaris monitor.](https://github.com/Tencent/spring-cloud-tencent/pull/447)
- [Optimize feign & rest-template circuit-breaker logic](https://github.com/Tencent/spring-cloud-tencent/pull/454)
- [Feature: Add disposable metadata transfer support](https://github.com/Tencent/spring-cloud-tencent/pull/459)
- [docs:update configuration metadata.](https://github.com/Tencent/spring-cloud-tencent/pull/474)

@ -18,6 +18,7 @@
package com.tencent.cloud.polaris.discovery;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@ -29,6 +30,7 @@ import com.tencent.polaris.api.pojo.ServiceInstances;
import com.tencent.polaris.api.rpc.InstancesResponse;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.util.CollectionUtils;
/**
* @author Haotian Zhang, Andrew Shan, Jie Cheng
@ -63,7 +65,10 @@ public class PolarisServiceDiscovery {
* @throws PolarisException polarisException
*/
public List<String> getServices() throws PolarisException {
return polarisDiscoveryHandler.GetServices().getServices().stream().map(ServiceInfo::getService)
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(polarisDiscoveryHandler.GetServices().getServices())) {
return Collections.emptyList();
}
return polarisDiscoveryHandler.GetServices().getServices().stream()
.map(ServiceInfo::getService).collect(Collectors.toList());
}
}

@ -24,6 +24,12 @@
"defaultValue": true,
"description": "enable polaris registration or not."
},
{
"name": "spring.cloud.polaris.discovery.heartbeat-interval",
"type": "java.lang.Integer",
"defaultValue": "5000",
"description": "Millis interval of Heart beat. Default: 5000."
},
{
"name": "spring.cloud.polaris.discovery.health-check-url",
"type": "java.lang.String",

@ -9,6 +9,11 @@
"name": "spring.cloud.tencent.metadata.transitive",
"type": "java.util.List",
"description": "Custom transitive metadata key list."
},
{
"name": "spring.cloud.tencent.metadata.disposable",
"type": "java.util.List",
"description": "Custom disposable metadata key list."
}
]
}

@ -73,7 +73,7 @@
<revision>1.7.0-2021.0.3-SNAPSHOT</revision>
<!-- Dependencies -->
<polaris.version>1.7.1</polaris.version>
<polaris.version>1.7.2</polaris.version>
<guava.version>31.0.1-jre</guava.version>
<logback.version>1.2.11</logback.version>
<mocktio.version>4.5.1</mocktio.version>

@ -15,12 +15,14 @@ spring:
port: 28081
loadbalancer:
configurations: polaris
# tencent:
# rpc-enhancement:
# enabled: true
# ignore-internal-server-error: true
# series: server_error
# statuses: gateway_timeout, bad_gateway, service_unavailable
tencent:
rpc-enhancement:
enabled: true
reporter:
ignore-internal-server-error: true
series: server_error
statuses: gateway_timeout, bad_gateway, service_unavailable
feign:
circuitbreaker:
enabled: true

@ -22,7 +22,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementProperties;
import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementReporterProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -50,19 +50,17 @@ import static org.springframework.http.HttpStatus.VARIANT_ALSO_NEGOTIATES;
public abstract class AbstractPolarisReporterAdapter {
private static final Logger LOG = LoggerFactory.getLogger(AbstractPolarisReporterAdapter.class);
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);
protected final RpcEnhancementReporterProperties properties;
/**
* Constructor With {@link RpcEnhancementProperties} .
* Constructor With {@link RpcEnhancementReporterProperties} .
*
* @param properties instance of {@link RpcEnhancementProperties}.
* @param properties instance of {@link RpcEnhancementReporterProperties}.
*/
protected AbstractPolarisReporterAdapter(RpcEnhancementProperties properties) {
protected AbstractPolarisReporterAdapter(RpcEnhancementReporterProperties properties) {
this.properties = properties;
}

@ -50,7 +50,7 @@ import static org.springframework.core.Ordered.HIGHEST_PRECEDENCE;
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(value = "spring.cloud.tencent.rpc-enhancement.enabled", havingValue = "true", matchIfMissing = true)
@EnableConfigurationProperties(RpcEnhancementProperties.class)
@EnableConfigurationProperties(RpcEnhancementReporterProperties.class)
@AutoConfigureAfter(PolarisContextAutoConfiguration.class)
public class RpcEnhancementAutoConfiguration {
@ -76,7 +76,7 @@ public class RpcEnhancementAutoConfiguration {
static class PolarisReporterConfig {
@Bean
public SuccessPolarisReporter successPolarisReporter(RpcEnhancementProperties properties) {
public SuccessPolarisReporter successPolarisReporter(RpcEnhancementReporterProperties properties) {
return new SuccessPolarisReporter(properties);
}
@ -99,15 +99,15 @@ public class RpcEnhancementAutoConfiguration {
@Bean
public EnhancedRestTemplateReporter polarisRestTemplateResponseErrorHandler(
RpcEnhancementProperties properties, ConsumerAPI consumerAPI,
RpcEnhancementReporterProperties properties, ConsumerAPI consumerAPI,
@Autowired(required = false) PolarisResponseErrorHandler polarisResponseErrorHandler) {
return new EnhancedRestTemplateReporter(properties, consumerAPI, polarisResponseErrorHandler);
}
@Bean
public EnhancedRestTemplateModifier polarisRestTemplateBeanPostProcessor(
EnhancedRestTemplateReporter enhancedRestTemplateReporter) {
return new EnhancedRestTemplateModifier(enhancedRestTemplateReporter);
EnhancedRestTemplateReporter restTemplateResponseErrorHandler) {
return new EnhancedRestTemplateModifier(restTemplateResponseErrorHandler);
}
}
}

@ -29,27 +29,22 @@ import org.springframework.http.HttpStatus;
*
* @author <a href="mailto:iskp.me@gmail.com">Elve.Xu</a> 2022-07-08
*/
@ConfigurationProperties("spring.cloud.tencent.rpc-enhancement")
public class RpcEnhancementProperties {
@ConfigurationProperties("spring.cloud.tencent.rpc-enhancement.reporter")
public class RpcEnhancementReporterProperties {
/**
* If circuit-breaker enabled.
*/
private boolean enabled = true;
/**
* Specify the Http status code(s) that needs to be fused.
* Specify the Http status code(s) that needs to be reported as FAILED.
*/
private List<HttpStatus> statuses = new ArrayList<>();
/**
* Specify List of HTTP status series.
* Specify List of HTTP status series that needs to be reported as FAILED when status list is empty.
*/
private List<HttpStatus.Series> series = toList(HttpStatus.Series.SERVER_ERROR);
/**
* Ignore Internal Server Error Http Status Code,
* Only takes effect if the attribute {@link RpcEnhancementProperties#series} is not empty.
* If ignore "Internal Server Error Http Status Code (500)",
* Only takes effect if the attribute {@link RpcEnhancementReporterProperties#series} is not empty.
*/
private boolean ignoreInternalServerError = true;
@ -81,14 +76,6 @@ public class RpcEnhancementProperties {
this.series = series;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public boolean isIgnoreInternalServerError() {
return ignoreInternalServerError;
}

@ -18,7 +18,7 @@
package com.tencent.cloud.rpc.enhancement.feign.plugin.reporter;
import com.tencent.cloud.rpc.enhancement.AbstractPolarisReporterAdapter;
import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementProperties;
import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementReporterProperties;
import com.tencent.cloud.rpc.enhancement.feign.plugin.EnhancedFeignContext;
import com.tencent.cloud.rpc.enhancement.feign.plugin.EnhancedFeignPlugin;
import com.tencent.cloud.rpc.enhancement.feign.plugin.EnhancedFeignPluginType;
@ -42,14 +42,13 @@ import org.springframework.http.HttpStatus;
public class SuccessPolarisReporter extends AbstractPolarisReporterAdapter implements EnhancedFeignPlugin {
private static final Logger LOG = LoggerFactory.getLogger(SuccessPolarisReporter.class);
@Autowired(required = false)
private ConsumerAPI consumerAPI;
public SuccessPolarisReporter(RpcEnhancementProperties properties) {
public SuccessPolarisReporter(RpcEnhancementReporterProperties properties) {
super(properties);
}
@Autowired(required = false)
private ConsumerAPI consumerAPI;
@Override
public String getName() {
return SuccessPolarisReporter.class.getName();

@ -26,7 +26,7 @@ import java.util.Objects;
import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.util.ReflectionUtils;
import com.tencent.cloud.rpc.enhancement.AbstractPolarisReporterAdapter;
import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementProperties;
import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementReporterProperties;
import com.tencent.polaris.api.core.ConsumerAPI;
import com.tencent.polaris.api.pojo.RetStatus;
import com.tencent.polaris.api.pojo.ServiceKey;
@ -55,7 +55,7 @@ public class EnhancedRestTemplateReporter extends AbstractPolarisReporterAdapter
private final PolarisResponseErrorHandler polarisResponseErrorHandler;
public EnhancedRestTemplateReporter(RpcEnhancementProperties properties, ConsumerAPI consumerAPI,
public EnhancedRestTemplateReporter(RpcEnhancementReporterProperties properties, ConsumerAPI consumerAPI,
PolarisResponseErrorHandler polarisResponseErrorHandler) {
super(properties);
this.consumerAPI = consumerAPI;

@ -1,5 +1,29 @@
{
"properties": [
{
"name": "spring.cloud.tencent.rpc-enhancement.enabled",
"type": "java.lang.Boolean",
"defaultValue": true,
"description": "If rpc enhancement enabled."
},
{
"name": "spring.cloud.tencent.rpc-enhancement.reporter.ignore-internal-server-error",
"type": "java.lang.Boolean",
"defaultValue": true,
"description": "If ignore \"Internal Server Error Http Status Code (500)\"."
},
{
"name": "spring.cloud.tencent.rpc-enhancement.reporter.series",
"type": "java.util.List<org.springframework.http.HttpStatus.Series>",
"defaultValue": "HttpStatus.Series.SERVER_ERROR",
"description": "Specify List of HTTP status series that needs to be reported as FAILED when status list is empty."
},
{
"name": "spring.cloud.tencent.rpc-enhancement.reporter.statuses",
"type": "java.util.List<org.springframework.http.HttpStatus>",
"defaultValue": "",
"description": "Specify the Http status code(s) that needs to be reported as FAILED."
},
{
"name": "spring.cloud.polaris.stat.enabled",
"type": "java.lang.Boolean",

@ -17,7 +17,7 @@
package com.tencent.cloud.rpc.enhancement;
import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementProperties;
import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementReporterProperties;
import org.assertj.core.api.Assertions;
import org.junit.Test;
@ -32,7 +32,7 @@ public class AbstractPolarisReporterAdapterTest {
@Test
public void testApplyWithDefaultConfig() {
RpcEnhancementProperties properties = new RpcEnhancementProperties();
RpcEnhancementReporterProperties properties = new RpcEnhancementReporterProperties();
// Mock Condition
SimplePolarisReporterAdapter adapter = new SimplePolarisReporterAdapter(properties);
@ -44,7 +44,7 @@ public class AbstractPolarisReporterAdapterTest {
@Test
public void testApplyWithoutIgnoreInternalServerError() {
RpcEnhancementProperties properties = new RpcEnhancementProperties();
RpcEnhancementReporterProperties properties = new RpcEnhancementReporterProperties();
// Mock Condition
properties.getStatuses().clear();
properties.setIgnoreInternalServerError(false);
@ -59,7 +59,7 @@ public class AbstractPolarisReporterAdapterTest {
@Test
public void testApplyWithIgnoreInternalServerError() {
RpcEnhancementProperties properties = new RpcEnhancementProperties();
RpcEnhancementReporterProperties properties = new RpcEnhancementReporterProperties();
// Mock Condition
properties.getStatuses().clear();
properties.setIgnoreInternalServerError(true);
@ -74,7 +74,7 @@ public class AbstractPolarisReporterAdapterTest {
@Test
public void testApplyWithoutSeries() {
RpcEnhancementProperties properties = new RpcEnhancementProperties();
RpcEnhancementReporterProperties properties = new RpcEnhancementReporterProperties();
// Mock Condition
properties.getStatuses().clear();
properties.getSeries().clear();
@ -89,7 +89,7 @@ public class AbstractPolarisReporterAdapterTest {
@Test
public void testApplyWithSeries() {
RpcEnhancementProperties properties = new RpcEnhancementProperties();
RpcEnhancementReporterProperties properties = new RpcEnhancementReporterProperties();
// Mock Condition
properties.getStatuses().clear();
properties.getSeries().clear();
@ -109,7 +109,7 @@ public class AbstractPolarisReporterAdapterTest {
*/
public static class SimplePolarisReporterAdapter extends AbstractPolarisReporterAdapter {
public SimplePolarisReporterAdapter(RpcEnhancementProperties properties) {
public SimplePolarisReporterAdapter(RpcEnhancementReporterProperties properties) {
super(properties);
}
}

@ -0,0 +1,64 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.tencent.cloud.rpc.enhancement.config;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.http.HttpStatus.MOVED_PERMANENTLY;
import static org.springframework.http.HttpStatus.MULTIPLE_CHOICES;
import static org.springframework.http.HttpStatus.Series.CLIENT_ERROR;
import static org.springframework.http.HttpStatus.Series.SERVER_ERROR;
/**
* Test For {@link RpcEnhancementReporterProperties}.
*
* @author Haotian Zhang
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = RpcEnhancementReporterPropertiesTest.TestApplication.class)
@ActiveProfiles("test")
public class RpcEnhancementReporterPropertiesTest {
@Autowired
private RpcEnhancementReporterProperties rpcEnhancementReporterProperties;
@Test
public void testDefaultInitialization() {
assertThat(rpcEnhancementReporterProperties).isNotNull();
assertThat(rpcEnhancementReporterProperties.isIgnoreInternalServerError()).isFalse();
assertThat(rpcEnhancementReporterProperties.getSeries()).isNotEmpty();
assertThat(rpcEnhancementReporterProperties.getSeries().get(0)).isEqualTo(CLIENT_ERROR);
assertThat(rpcEnhancementReporterProperties.getSeries().get(1)).isEqualTo(SERVER_ERROR);
assertThat(rpcEnhancementReporterProperties.getStatuses()).isNotEmpty();
assertThat(rpcEnhancementReporterProperties.getStatuses().get(0)).isEqualTo(MULTIPLE_CHOICES);
assertThat(rpcEnhancementReporterProperties.getStatuses().get(1)).isEqualTo(MOVED_PERMANENTLY);
}
@SpringBootApplication
protected static class TestApplication {
}
}

@ -22,7 +22,7 @@ import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementProperties;
import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementReporterProperties;
import com.tencent.polaris.api.core.ConsumerAPI;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -49,7 +49,7 @@ public class EnhancedRestTemplateReporterTest {
public void handleError() throws Exception {
ConsumerAPI consumerAPI = mock(ConsumerAPI.class);
EnhancedRestTemplateReporter enhancedRestTemplateReporter =
new EnhancedRestTemplateReporter(mock(RpcEnhancementProperties.class), consumerAPI, null);
new EnhancedRestTemplateReporter(mock(RpcEnhancementReporterProperties.class), consumerAPI, null);
URI uri = mock(URI.class);
when(uri.getPath()).thenReturn("/test");
when(uri.getHost()).thenReturn("host");

@ -1,3 +1,8 @@
spring.cloud.polaris.stat.enabled=true
spring.cloud.polaris.stat.port=20000
spring.cloud.polaris.stat.path=/xxx
spring.cloud.tencent.rpc-enhancement.reporter.ignore-internal-server-error=false
spring.cloud.tencent.rpc-enhancement.reporter.series[0]=CLIENT_ERROR
spring.cloud.tencent.rpc-enhancement.reporter.series[1]=SERVER_ERROR
spring.cloud.tencent.rpc-enhancement.reporter.statuses[0]=MULTIPLE_CHOICES
spring.cloud.tencent.rpc-enhancement.reporter.statuses[1]=MOVED_PERMANENTLY

Loading…
Cancel
Save