From 8c88a92c45adb3c166a7cc5c0ef1d56f339683fd Mon Sep 17 00:00:00 2001 From: "Shanyou Yu (Sean Yu)" Date: Wed, 15 Mar 2023 12:54:21 +0800 Subject: [PATCH] fix: fix log feign response stream close bug (#898) --- CHANGELOG.md | 1 + .../feign/plugin/reporter/ExceptionPolarisReporter.java | 2 +- .../feign/plugin/reporter/SuccessPolarisReporter.java | 2 +- .../feign/plugin/reporter/ExceptionPolarisReporterTest.java | 4 +++- .../feign/plugin/reporter/SuccessPolarisReporterTest.java | 4 +++- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06c1f8175..36c992a2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ # Change Log --- +- [fix: fix log feign response stream close bug.](https://github.com/Tencent/spring-cloud-tencent/pull/898) \ No newline at end of file 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 0e1b2c87a..f0498fac6 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 @@ -75,7 +75,7 @@ public class ExceptionPolarisReporter implements EnhancedFeignPlugin { if (exception instanceof SocketTimeoutException) { retStatus = RetStatus.RetTimeout; } - LOG.debug("Will report result of {}. Request=[{}]. Response=[{}].", retStatus.name(), request, response); + 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. 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 2fefd6dcf..933619766 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,7 +72,7 @@ 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, response); + 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. diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/ExceptionPolarisReporterTest.java b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/ExceptionPolarisReporterTest.java index a123e8490..997f9b37f 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/ExceptionPolarisReporterTest.java +++ b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/ExceptionPolarisReporterTest.java @@ -17,6 +17,8 @@ package com.tencent.cloud.rpc.enhancement.feign.plugin.reporter; +import java.util.HashMap; + 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.EnhancedFeignPluginType; @@ -83,7 +85,7 @@ public class ExceptionPolarisReporterTest { @Test public void testRun() { // mock request - Request request = mock(Request.class); + Request request = Request.create(Request.HttpMethod.GET, "/", new HashMap<>(), null, null, null); // mock response Response response = mock(Response.class); diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/SuccessPolarisReporterTest.java b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/SuccessPolarisReporterTest.java index 841592986..2970baa8c 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/SuccessPolarisReporterTest.java +++ b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/SuccessPolarisReporterTest.java @@ -17,6 +17,8 @@ package com.tencent.cloud.rpc.enhancement.feign.plugin.reporter; +import java.util.HashMap; + 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.EnhancedFeignPluginType; @@ -83,7 +85,7 @@ public class SuccessPolarisReporterTest { @Test public void testRun() { // mock request - Request request = mock(Request.class); + Request request = Request.create(Request.HttpMethod.GET, "/", new HashMap<>(), null, null, null); // mock response Response response = mock(Response.class); doReturn(502).when(response).status();