[ 
https://issues.apache.org/jira/browse/SCB-911?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16616979#comment-16616979
 ] 

ASF GitHub Bot commented on SCB-911:
------------------------------------

liubao68 closed pull request #907: [SCB-911]Timeout scenario print too many logs
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/907
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/ExceptionUtils.java
 
b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/ExceptionUtils.java
new file mode 100644
index 000000000..acf0b452f
--- /dev/null
+++ 
b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/ExceptionUtils.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 org.apache.servicecomb.foundation.common.utils;
+
+public class ExceptionUtils {
+  private static final int DEPTH = 5;
+
+  private ExceptionUtils() {
+
+  }
+
+  public static String getExceptionMessageWithoutTrace(Throwable e) {
+    StringBuilder result = new StringBuilder();
+    appendExceptionInfo(e, result);
+    Throwable cause = e.getCause();
+    int depth = DEPTH;
+    while (cause != null && depth-- > 0) {
+      result.append(";");
+      appendExceptionInfo(cause, result);
+      cause = cause.getCause();
+    }
+    return result.toString();
+  }
+
+  private static void appendExceptionInfo(Throwable e, StringBuilder result) {
+    result.append("cause:");
+    result.append(e.getClass().getSimpleName());
+    result.append(",message:");
+    result.append(e.getMessage());
+  }
+}
diff --git 
a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/utils/TestExceptionUtils.java
 
b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/utils/TestExceptionUtils.java
new file mode 100644
index 000000000..1d075444b
--- /dev/null
+++ 
b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/utils/TestExceptionUtils.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 org.apache.servicecomb.foundation.common.utils;
+
+import java.io.IOException;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestExceptionUtils {
+  @Test
+  public void testExceptionUtils() {
+    Exception e = new Exception("Hello");
+    Assert.assertEquals("cause:Exception,message:Hello", 
ExceptionUtils.getExceptionMessageWithoutTrace(e));
+    Exception e2 = new Exception("FAIL", new IOException("IO"));
+    
Assert.assertEquals("cause:Exception,message:FAIL;cause:IOException,message:IO",
+        ExceptionUtils.getExceptionMessageWithoutTrace(e2));
+  }
+}
diff --git 
a/handlers/handler-bizkeeper/src/main/java/org/apache/servicecomb/bizkeeper/BizkeeperHandler.java
 
b/handlers/handler-bizkeeper/src/main/java/org/apache/servicecomb/bizkeeper/BizkeeperHandler.java
index bf6f91140..a79741f01 100644
--- 
a/handlers/handler-bizkeeper/src/main/java/org/apache/servicecomb/bizkeeper/BizkeeperHandler.java
+++ 
b/handlers/handler-bizkeeper/src/main/java/org/apache/servicecomb/bizkeeper/BizkeeperHandler.java
@@ -19,6 +19,7 @@
 
 import org.apache.servicecomb.core.Handler;
 import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.foundation.common.utils.ExceptionUtils;
 import org.apache.servicecomb.swagger.invocation.AsyncResponse;
 import org.apache.servicecomb.swagger.invocation.Response;
 import org.slf4j.Logger;
@@ -51,7 +52,7 @@
       HystrixPlugins.getInstance().registerCommandExecutionHook(new 
HystrixCommandExecutionHook() {
         @Override
         public <T> Exception onExecutionError(HystrixInvokable<T> 
commandInstance, Exception e) {
-          LOG.warn("bizkeeper execution error", e);
+          LOG.warn("bizkeeper execution error, info={}", 
ExceptionUtils.getExceptionMessageWithoutTrace(e));
           return e; //by default, just pass through
         }
       });
diff --git 
a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToResponseConverters.java
 
b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToResponseConverters.java
index 60706a900..997b75c75 100644
--- 
a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToResponseConverters.java
+++ 
b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/exception/ExceptionToResponseConverters.java
@@ -33,7 +33,9 @@
   public ExceptionToResponseConverters() {
     
SPIServiceUtils.getSortedService(ExceptionToResponseConverter.class).forEach(converter
 -> {
       if (converter.getExceptionClass() == null) {
-        defaultConverter = converter;
+        if (defaultConverter == null) {
+          defaultConverter = converter;
+        }
         return;
       }
 
@@ -42,8 +44,18 @@ public ExceptionToResponseConverters() {
   }
 
   public Response convertExceptionToResponse(SwaggerInvocation 
swaggerInvocation, Throwable e) {
-    ExceptionToResponseConverter<Throwable> converter =
-        exceptionToResponseConverters.getOrDefault(e.getClass(), 
defaultConverter);
+    ExceptionToResponseConverter<Throwable> converter = null;
+    Class<?> clazz = e.getClass();
+    while (converter == null) {
+      converter = exceptionToResponseConverters.get(clazz);
+      if (clazz == Throwable.class) {
+        break;
+      }
+      clazz = clazz.getSuperclass();
+    }
+    if (converter == null) {
+      converter = defaultConverter;
+    }
     return converter.convert(swaggerInvocation, e);
   }
 }
diff --git 
a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/exception/TestExceptionToResponseConverters.java
 
b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/exception/TestExceptionToResponseConverters.java
index 022ff8ced..d2d6d6da4 100644
--- 
a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/exception/TestExceptionToResponseConverters.java
+++ 
b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/exception/TestExceptionToResponseConverters.java
@@ -16,8 +16,11 @@
  */
 package org.apache.servicecomb.swagger.invocation.exception;
 
+import java.io.IOException;
 import java.util.Arrays;
 
+import javax.ws.rs.core.Response.Status;
+
 import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
 import org.apache.servicecomb.swagger.invocation.Response;
 import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
@@ -34,8 +37,7 @@ public void convertExceptionToResponse(@Mocked 
ExceptionToResponseConverter c1,
       @Mocked Response r1,
       @Mocked ExceptionToResponseConverter c2,
       @Mocked Response r2,
-      @Mocked ExceptionToResponseConverter cDef,
-      @Mocked Response rDef) {
+      @Mocked ExceptionToResponseConverter cDef) {
     new Expectations(SPIServiceUtils.class) {
       {
         SPIServiceUtils.getSortedService(ExceptionToResponseConverter.class);
@@ -53,8 +55,6 @@ public void convertExceptionToResponse(@Mocked 
ExceptionToResponseConverter c1,
 
         cDef.getExceptionClass();
         result = null;
-        cDef.convert((SwaggerInvocation) any, (Throwable) any);
-        result = rDef;
       }
     };
 
@@ -64,8 +64,54 @@ public void convertExceptionToResponse(@Mocked 
ExceptionToResponseConverter c1,
         
exceptionToResponseConverters.convertExceptionToResponse((SwaggerInvocation) 
null, new Throwable()));
     Assert.assertSame(r2,
         
exceptionToResponseConverters.convertExceptionToResponse((SwaggerInvocation) 
null, new Exception()));
-    Assert.assertSame(rDef,
+    Assert.assertSame(r2,
         
exceptionToResponseConverters.convertExceptionToResponse((SwaggerInvocation) 
null,
             new IllegalStateException()));
   }
+
+  @SuppressWarnings({"rawtypes", "unchecked"})
+  @Test
+  public void convertExceptionToResponse2(@Mocked ExceptionToResponseConverter 
c1,
+      @Mocked Response r1,
+      @Mocked ExceptionToResponseConverter c2,
+      @Mocked Response r2,
+      @Mocked ExceptionToResponseConverter cDef,
+      @Mocked Response rDef,
+      @Mocked ExceptionToResponseConverter cDef2) {
+    new Expectations(SPIServiceUtils.class) {
+      {
+        SPIServiceUtils.getSortedService(ExceptionToResponseConverter.class);
+        result = Arrays.asList(c1, c2, cDef, cDef2);
+
+        c1.getExceptionClass();
+        result = RuntimeException.class;
+        c1.convert((SwaggerInvocation) any, (Throwable) any);
+        result = r1;
+
+        c2.getExceptionClass();
+        result = InvocationException.class;
+        c2.convert((SwaggerInvocation) any, (Throwable) any);
+        result = r2;
+
+        cDef.getExceptionClass();
+        result = null;
+        cDef.convert((SwaggerInvocation) any, (Throwable) any);
+        result = rDef;
+
+        cDef2.getExceptionClass();
+        result = null;
+      }
+    };
+
+    ExceptionToResponseConverters exceptionToResponseConverters = new 
ExceptionToResponseConverters();
+
+    Assert.assertSame(r2,
+        exceptionToResponseConverters
+            .convertExceptionToResponse((SwaggerInvocation) null, new 
InvocationException(Status.UNAUTHORIZED, "")));
+    Assert.assertSame(r1,
+        
exceptionToResponseConverters.convertExceptionToResponse((SwaggerInvocation) 
null, new RuntimeException()));
+    Assert.assertSame(rDef,
+        
exceptionToResponseConverters.convertExceptionToResponse((SwaggerInvocation) 
null,
+            new IOException()));
+  }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Timeout scenario print too many logs
> ------------------------------------
>
>                 Key: SCB-911
>                 URL: https://issues.apache.org/jira/browse/SCB-911
>             Project: Apache ServiceComb
>          Issue Type: Improvement
>          Components: Java-Chassis
>            Reporter: liubao
>            Assignee: liubao
>            Priority: Major
>
> In some scenario, timeout is very normal. customers do not want print too 
> much logs in this situation. 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to