netty: use FINE log for pure IOExceptions

This commit is contained in:
Jihun Cho 2019-10-24 14:06:16 -07:00
parent 03c75e180c
commit c166ec2c4e
2 changed files with 15 additions and 26 deletions

View File

@ -19,7 +19,6 @@ 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,11 +49,6 @@ class NettyServerTransport implements ServerTransport {
// connectionLog is for connection related messages only
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_ERRORS = ImmutableList.of(
"Connection reset by peer",
"An existing connection was forcibly closed by the remote host",
"An established connection was aborted by the software in your host machine");
private final InternalLogId logId;
private final Channel channel;
@ -184,12 +178,8 @@ class NettyServerTransport implements ServerTransport {
*/
@VisibleForTesting
static Level getLogLevel(Throwable t) {
if (t instanceof IOException && t.getMessage() != null) {
for (String msg : QUIET_ERRORS) {
if (t.getMessage().contains(msg)) {
return Level.FINE;
}
}
if (t.getClass().equals(IOException.class)) {
return Level.FINE;
}
return Level.INFO;
}

View File

@ -16,6 +16,7 @@
package io.grpc.netty;
import static com.google.common.truth.Truth.assertThat;
import static io.grpc.netty.NettyServerTransport.getLogLevel;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
@ -34,27 +35,25 @@ public class NettyServerTransportTest {
}
@Test
public void quiet() {
public void ioException() {
assertEquals(Level.FINE, getLogLevel(new IOException("Connection reset by peer")));
assertEquals(Level.FINE, getLogLevel(new IOException(
"An existing connection was forcibly closed by the remote host")));
}
@Test
public void quiet_prefixed() {
assertEquals(Level.FINE, getLogLevel(new IOException(
"syscall:read(..) failed: Connection reset by peer")));
}
@Test
public void nonquiet() {
assertEquals(Level.INFO, getLogLevel(new IOException("foo")));
}
@Test
public void nullMessage() {
public void ioException_nullMessage() {
IOException e = new IOException();
assertNull(e.getMessage());
assertEquals(Level.INFO, getLogLevel(e));
assertEquals(Level.FINE, getLogLevel(e));
}
@Test
public void extendedIoException() {
class ExtendedIoException extends IOException {}
ExtendedIoException e = new ExtendedIoException();
assertThat(e.getMessage()).isNull();
assertThat(getLogLevel(e)).isEqualTo(Level.INFO);
}
}