Skip to content

Commit

Permalink
netty: log NativeIoException as FINE level (#6477)
Browse files Browse the repository at this point in the history
resolves #6478
  • Loading branch information
creamsoup committed Dec 3, 2019
1 parent 54b7847 commit 1573e0d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion netty/src/main/java/io/grpc/netty/NettyServerTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -178,7 +183,8 @@ Channel channel() {
*/
@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,13 @@ class ExtendedIoException extends IOException {}
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);
}
}

0 comments on commit 1573e0d

Please sign in to comment.