From 2d9afcc4fb75e761d1c6e604ab85d2a2fe386579 Mon Sep 17 00:00:00 2001 From: Haotian Zhang <928016560@qq.com> Date: Wed, 15 Mar 2023 15:55:07 +0800 Subject: [PATCH] fix:remove the secondary report. (#900) --- CHANGELOG.md | 3 ++- .../feign/plugin/reporter/ExceptionPolarisReporter.java | 8 +++----- .../feign/plugin/reporter/SuccessPolarisReporter.java | 6 ++---- .../resttemplate/EnhancedRestTemplateReporter.java | 3 --- .../resttemplate/EnhancedRestTemplateReporterTest.java | 4 ++-- 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cf8b9d81..bfcd6c00b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # Change Log --- -- [fix: fix log feign response stream close bug.](https://github.com/Tencent/spring-cloud-tencent/pull/896) \ No newline at end of file +- [fix: fix log feign response stream close bug.](https://github.com/Tencent/spring-cloud-tencent/pull/896) +- [fix:remove the secondary report.](https://github.com/Tencent/spring-cloud-tencent/pull/900) diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/ExceptionPolarisReporter.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/ExceptionPolarisReporter.java index f0498fac6..a1496fa11 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/ExceptionPolarisReporter.java +++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/ExceptionPolarisReporter.java @@ -46,7 +46,7 @@ public class ExceptionPolarisReporter implements EnhancedFeignPlugin { private final ConsumerAPI consumerAPI; public ExceptionPolarisReporter(RpcEnhancementReporterProperties reporterProperties, - ConsumerAPI consumerAPI) { + ConsumerAPI consumerAPI) { this.reporterProperties = reporterProperties; this.consumerAPI = consumerAPI; } @@ -75,12 +75,10 @@ public class ExceptionPolarisReporter implements EnhancedFeignPlugin { if (exception instanceof SocketTimeoutException) { retStatus = RetStatus.RetTimeout; } - LOG.debug("Will report result of {}. Request=[{} {}]. Response=[{}].", retStatus.name(), request.httpMethod().name(), request.url(), response.status()); + LOG.debug("Will report result of {}. Request=[{} {}]. Response=[{}].", retStatus.name(), request.httpMethod() + .name(), request.url(), response.status()); ServiceCallResult resultRequest = ReporterUtils.createServiceCallResult(request, retStatus); consumerAPI.updateServiceCallResult(resultRequest); - // update result without method for service circuit break. - resultRequest.setMethod(""); - consumerAPI.updateServiceCallResult(resultRequest); } } diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/SuccessPolarisReporter.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/SuccessPolarisReporter.java index 933619766..cc009d1b8 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/SuccessPolarisReporter.java +++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/SuccessPolarisReporter.java @@ -72,12 +72,10 @@ public class SuccessPolarisReporter extends AbstractPolarisReporterAdapter imple if (apply(HttpStatus.resolve(response.status()))) { retStatus = RetStatus.RetFail; } - LOG.debug("Will report result of {}. Request=[{} {}]. Response=[{}].", retStatus.name(), request.httpMethod().name(), request.url(), response.status()); + LOG.debug("Will report result of {}. Request=[{} {}]. Response=[{}].", retStatus.name(), request.httpMethod() + .name(), request.url(), response.status()); ServiceCallResult resultRequest = ReporterUtils.createServiceCallResult(request, retStatus); consumerAPI.updateServiceCallResult(resultRequest); - // update result without method for service circuit break. - resultRequest.setMethod(""); - consumerAPI.updateServiceCallResult(resultRequest); } } diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporter.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporter.java index df1ec9907..b8f842e77 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporter.java +++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporter.java @@ -153,9 +153,6 @@ public class EnhancedRestTemplateReporter extends AbstractPolarisReporterAdapter LOGGER.debug("Will report result of {}. URL=[{}]. Response=[{}].", resultRequest.getRetStatus().name(), url, response); consumerAPI.updateServiceCallResult(resultRequest); - // update result without method for service circuit break. - resultRequest.setMethod(""); - consumerAPI.updateServiceCallResult(resultRequest); } catch (Exception e) { LOGGER.error("RestTemplate response reporter execute failed of {} url {}", response, url, e); diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporterTest.java b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporterTest.java index 2b54c25f0..a4395b8b6 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporterTest.java +++ b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporterTest.java @@ -147,7 +147,7 @@ public class EnhancedRestTemplateReporterTest { URI uri = mock(URI.class); enhancedRestTemplateReporter.handleError(uri, HttpMethod.GET, response); - verify(consumerAPI, times(2)).updateServiceCallResult(any()); + verify(consumerAPI, times(1)).updateServiceCallResult(any()); verify(delegate).handleError(uri, HttpMethod.GET, response); } @@ -162,7 +162,7 @@ public class EnhancedRestTemplateReporterTest { URI uri = mock(URI.class); enhancedRestTemplateReporter.handleError(uri, HttpMethod.GET, response); - verify(consumerAPI, times(2)).updateServiceCallResult(any()); + verify(consumerAPI, times(1)).updateServiceCallResult(any()); verify(delegate, times(0)).handleError(uri, HttpMethod.GET, response); }