netty: log NativeIoException as FINE level (#6477)

resolves #6478
This commit is contained in:
Jihun Cho 2019-12-03 13:05:04 -08:00 committed by GitHub
parent 54b7847a7f
commit 1573e0d400
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -19,6 +19,7 @@ package io.grpc.netty;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import io.grpc.InternalChannelz.SocketStats;
@ -50,6 +51,10 @@ class NettyServerTransport implements ServerTransport {
private static final Logger connectionLog = Logger.getLogger(
String.format("%s.connections", NettyServerTransport.class.getName()));
// Some exceptions are not very useful and add too much noise to the log
private static final ImmutableList<String> QUIET_EXCEPTIONS = ImmutableList.of(
"NativeIoException" /* Netty exceptions */);
private final InternalLogId logId;
private final Channel channel;
private final ChannelPromise channelUnused;
@ -178,7 +183,8 @@ class NettyServerTransport implements ServerTransport {
*/
@VisibleForTesting
static Level getLogLevel(Throwable t) {
if (t.getClass().equals(IOException.class)) {
if (t.getClass().equals(IOException.class)
|| QUIET_EXCEPTIONS.contains(t.getClass().getSimpleName())) {
return Level.FINE;
}
return Level.INFO;

View File

@ -56,4 +56,13 @@ public class NettyServerTransportTest {
assertThat(e.getMessage()).isNull();
assertThat(getLogLevel(e)).isEqualTo(Level.INFO);
}
@Test
public void fakeNettyNativeIoException() {
class NativeIoException extends IOException {}
NativeIoException fakeNativeIoException = new NativeIoException();
assertThat(getLogLevel(fakeNativeIoException)).isEqualTo(Level.FINE);
}
}