feat:rename the configuration of reporter. (#465)

* docs:rename the configuration of reporter.

* junit:add junit of reporter.

* docs:update CHANGELOG.md.
pull/466/head
Haotian Zhang 2 years ago committed by GitHub
parent 3884f29d4c
commit 741c0eb6ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,3 +17,4 @@
- [Optimize: rename opertion EQUAL to EQUALS](https://github.com/Tencent/spring-cloud-tencent/pull/457) - [Optimize: rename opertion EQUAL to EQUALS](https://github.com/Tencent/spring-cloud-tencent/pull/457)
- [Docs: Add featureenv example readme(en) file](https://github.com/Tencent/spring-cloud-tencent/pull/460) - [Docs: Add featureenv example readme(en) file](https://github.com/Tencent/spring-cloud-tencent/pull/460)
- [docs:update configuration metadata.](https://github.com/Tencent/spring-cloud-tencent/pull/463) - [docs:update configuration metadata.](https://github.com/Tencent/spring-cloud-tencent/pull/463)
- [feat:rename the configuration of reporter.](https://github.com/Tencent/spring-cloud-tencent/pull/465)

@ -13,12 +13,13 @@ spring:
stat: stat:
enabled: true enabled: true
port: 28081 port: 28081
# tencent: tencent:
# rpc-enhancement: rpc-enhancement:
# enabled: true enabled: true
# ignore-internal-server-error: true reporter:
# series: server_error ignore-internal-server-error: true
# statuses: gateway_timeout, bad_gateway, service_unavailable series: server_error
statuses: gateway_timeout, bad_gateway, service_unavailable
feign: feign:
hystrix: hystrix:

@ -22,7 +22,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects; 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -50,19 +50,17 @@ import static org.springframework.http.HttpStatus.VARIANT_ALSO_NEGOTIATES;
public abstract class AbstractPolarisReporterAdapter { public abstract class AbstractPolarisReporterAdapter {
private static final Logger LOG = LoggerFactory.getLogger(AbstractPolarisReporterAdapter.class); 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, private static final List<HttpStatus> HTTP_STATUSES = toList(NOT_IMPLEMENTED, BAD_GATEWAY,
SERVICE_UNAVAILABLE, GATEWAY_TIMEOUT, HTTP_VERSION_NOT_SUPPORTED, VARIANT_ALSO_NEGOTIATES, SERVICE_UNAVAILABLE, GATEWAY_TIMEOUT, HTTP_VERSION_NOT_SUPPORTED, VARIANT_ALSO_NEGOTIATES,
INSUFFICIENT_STORAGE, LOOP_DETECTED, BANDWIDTH_LIMIT_EXCEEDED, NOT_EXTENDED, NETWORK_AUTHENTICATION_REQUIRED); 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; this.properties = properties;
} }

@ -49,7 +49,7 @@ import static org.springframework.core.Ordered.HIGHEST_PRECEDENCE;
*/ */
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(value = "spring.cloud.tencent.rpc-enhancement.enabled", havingValue = "true", matchIfMissing = true) @ConditionalOnProperty(value = "spring.cloud.tencent.rpc-enhancement.enabled", havingValue = "true", matchIfMissing = true)
@EnableConfigurationProperties(RpcEnhancementProperties.class) @EnableConfigurationProperties(RpcEnhancementReporterProperties.class)
@AutoConfigureAfter(PolarisContextAutoConfiguration.class) @AutoConfigureAfter(PolarisContextAutoConfiguration.class)
public class RpcEnhancementAutoConfiguration { public class RpcEnhancementAutoConfiguration {
@ -75,7 +75,7 @@ public class RpcEnhancementAutoConfiguration {
static class PolarisReporterConfig { static class PolarisReporterConfig {
@Bean @Bean
public SuccessPolarisReporter successPolarisReporter(RpcEnhancementProperties properties) { public SuccessPolarisReporter successPolarisReporter(RpcEnhancementReporterProperties properties) {
return new SuccessPolarisReporter(properties); return new SuccessPolarisReporter(properties);
} }
@ -98,7 +98,7 @@ public class RpcEnhancementAutoConfiguration {
@Bean @Bean
public EnhancedRestTemplateReporter polarisRestTemplateResponseErrorHandler( public EnhancedRestTemplateReporter polarisRestTemplateResponseErrorHandler(
RpcEnhancementProperties properties, RpcEnhancementReporterProperties properties,
ConsumerAPI consumerAPI) { ConsumerAPI consumerAPI) {
return new EnhancedRestTemplateReporter(properties, consumerAPI); return new EnhancedRestTemplateReporter(properties, consumerAPI);
} }

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

@ -18,7 +18,7 @@
package com.tencent.cloud.rpc.enhancement.feign.plugin.reporter; package com.tencent.cloud.rpc.enhancement.feign.plugin.reporter;
import com.tencent.cloud.rpc.enhancement.AbstractPolarisReporterAdapter; 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.EnhancedFeignContext;
import com.tencent.cloud.rpc.enhancement.feign.plugin.EnhancedFeignPlugin; import com.tencent.cloud.rpc.enhancement.feign.plugin.EnhancedFeignPlugin;
import com.tencent.cloud.rpc.enhancement.feign.plugin.EnhancedFeignPluginType; 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 { public class SuccessPolarisReporter extends AbstractPolarisReporterAdapter implements EnhancedFeignPlugin {
private static final Logger LOG = LoggerFactory.getLogger(SuccessPolarisReporter.class); 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); super(properties);
} }
@Autowired(required = false)
private ConsumerAPI consumerAPI;
@Override @Override
public String getName() { public String getName() {
return SuccessPolarisReporter.class.getName(); return SuccessPolarisReporter.class.getName();

@ -25,7 +25,7 @@ import java.net.URL;
import com.tencent.cloud.common.metadata.MetadataContext; import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.util.ReflectionUtils; import com.tencent.cloud.common.util.ReflectionUtils;
import com.tencent.cloud.rpc.enhancement.AbstractPolarisReporterAdapter; 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.core.ConsumerAPI;
import com.tencent.polaris.api.pojo.RetStatus; import com.tencent.polaris.api.pojo.RetStatus;
import com.tencent.polaris.api.pojo.ServiceKey; import com.tencent.polaris.api.pojo.ServiceKey;
@ -52,7 +52,7 @@ public class EnhancedRestTemplateReporter extends AbstractPolarisReporterAdapter
private final ConsumerAPI consumerAPI; private final ConsumerAPI consumerAPI;
public EnhancedRestTemplateReporter(RpcEnhancementProperties properties, ConsumerAPI consumerAPI) { public EnhancedRestTemplateReporter(RpcEnhancementReporterProperties properties, ConsumerAPI consumerAPI) {
super(properties); super(properties);
this.consumerAPI = consumerAPI; this.consumerAPI = consumerAPI;
} }

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

@ -17,7 +17,7 @@
package com.tencent.cloud.rpc.enhancement; 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.assertj.core.api.Assertions;
import org.junit.Test; import org.junit.Test;
@ -32,7 +32,7 @@ public class AbstractPolarisReporterAdapterTest {
@Test @Test
public void testApplyWithDefaultConfig() { public void testApplyWithDefaultConfig() {
RpcEnhancementProperties properties = new RpcEnhancementProperties(); RpcEnhancementReporterProperties properties = new RpcEnhancementReporterProperties();
// Mock Condition // Mock Condition
SimplePolarisReporterAdapter adapter = new SimplePolarisReporterAdapter(properties); SimplePolarisReporterAdapter adapter = new SimplePolarisReporterAdapter(properties);
@ -44,7 +44,7 @@ public class AbstractPolarisReporterAdapterTest {
@Test @Test
public void testApplyWithoutIgnoreInternalServerError() { public void testApplyWithoutIgnoreInternalServerError() {
RpcEnhancementProperties properties = new RpcEnhancementProperties(); RpcEnhancementReporterProperties properties = new RpcEnhancementReporterProperties();
// Mock Condition // Mock Condition
properties.getStatuses().clear(); properties.getStatuses().clear();
properties.setIgnoreInternalServerError(false); properties.setIgnoreInternalServerError(false);
@ -59,7 +59,7 @@ public class AbstractPolarisReporterAdapterTest {
@Test @Test
public void testApplyWithIgnoreInternalServerError() { public void testApplyWithIgnoreInternalServerError() {
RpcEnhancementProperties properties = new RpcEnhancementProperties(); RpcEnhancementReporterProperties properties = new RpcEnhancementReporterProperties();
// Mock Condition // Mock Condition
properties.getStatuses().clear(); properties.getStatuses().clear();
properties.setIgnoreInternalServerError(true); properties.setIgnoreInternalServerError(true);
@ -74,7 +74,7 @@ public class AbstractPolarisReporterAdapterTest {
@Test @Test
public void testApplyWithoutSeries() { public void testApplyWithoutSeries() {
RpcEnhancementProperties properties = new RpcEnhancementProperties(); RpcEnhancementReporterProperties properties = new RpcEnhancementReporterProperties();
// Mock Condition // Mock Condition
properties.getStatuses().clear(); properties.getStatuses().clear();
properties.getSeries().clear(); properties.getSeries().clear();
@ -89,7 +89,7 @@ public class AbstractPolarisReporterAdapterTest {
@Test @Test
public void testApplyWithSeries() { public void testApplyWithSeries() {
RpcEnhancementProperties properties = new RpcEnhancementProperties(); RpcEnhancementReporterProperties properties = new RpcEnhancementReporterProperties();
// Mock Condition // Mock Condition
properties.getStatuses().clear(); properties.getStatuses().clear();
properties.getSeries().clear(); properties.getSeries().clear();
@ -109,7 +109,7 @@ public class AbstractPolarisReporterAdapterTest {
*/ */
public static class SimplePolarisReporterAdapter extends AbstractPolarisReporterAdapter { public static class SimplePolarisReporterAdapter extends AbstractPolarisReporterAdapter {
public SimplePolarisReporterAdapter(RpcEnhancementProperties properties) { public SimplePolarisReporterAdapter(RpcEnhancementReporterProperties properties) {
super(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.URI;
import java.net.URL; 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 com.tencent.polaris.api.core.ConsumerAPI;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -49,7 +49,7 @@ public class EnhancedRestTemplateReporterTest {
public void handleError() throws Exception { public void handleError() throws Exception {
ConsumerAPI consumerAPI = mock(ConsumerAPI.class); ConsumerAPI consumerAPI = mock(ConsumerAPI.class);
EnhancedRestTemplateReporter enhancedRestTemplateReporter = EnhancedRestTemplateReporter enhancedRestTemplateReporter =
new EnhancedRestTemplateReporter(mock(RpcEnhancementProperties.class), consumerAPI); new EnhancedRestTemplateReporter(mock(RpcEnhancementReporterProperties.class), consumerAPI);
URI uri = mock(URI.class); URI uri = mock(URI.class);
when(uri.getPath()).thenReturn("/test"); when(uri.getPath()).thenReturn("/test");
when(uri.getHost()).thenReturn("host"); when(uri.getHost()).thenReturn("host");

@ -1,3 +1,8 @@
spring.cloud.polaris.stat.enabled=true spring.cloud.polaris.stat.enabled=true
spring.cloud.polaris.stat.port=20000 spring.cloud.polaris.stat.port=20000
spring.cloud.polaris.stat.path=/xxx 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