mirror of https://github.com/grpc/grpc-java.git
netty: use FINE log for pure IOExceptions
This commit is contained in:
parent
03c75e180c
commit
c166ec2c4e
|
|
@ -19,7 +19,6 @@ package io.grpc.netty;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.base.MoreObjects;
|
||||||
import com.google.common.base.Preconditions;
|
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.ListenableFuture;
|
||||||
import com.google.common.util.concurrent.SettableFuture;
|
import com.google.common.util.concurrent.SettableFuture;
|
||||||
import io.grpc.InternalChannelz.SocketStats;
|
import io.grpc.InternalChannelz.SocketStats;
|
||||||
|
|
@ -50,11 +49,6 @@ class NettyServerTransport implements ServerTransport {
|
||||||
// connectionLog is for connection related messages only
|
// connectionLog is for connection related messages only
|
||||||
private static final Logger connectionLog = Logger.getLogger(
|
private static final Logger connectionLog = Logger.getLogger(
|
||||||
String.format("%s.connections", NettyServerTransport.class.getName()));
|
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 InternalLogId logId;
|
||||||
private final Channel channel;
|
private final Channel channel;
|
||||||
|
|
@ -184,13 +178,9 @@ class NettyServerTransport implements ServerTransport {
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static Level getLogLevel(Throwable t) {
|
static Level getLogLevel(Throwable t) {
|
||||||
if (t instanceof IOException && t.getMessage() != null) {
|
if (t.getClass().equals(IOException.class)) {
|
||||||
for (String msg : QUIET_ERRORS) {
|
|
||||||
if (t.getMessage().contains(msg)) {
|
|
||||||
return Level.FINE;
|
return Level.FINE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return Level.INFO;
|
return Level.INFO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package io.grpc.netty;
|
package io.grpc.netty;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static io.grpc.netty.NettyServerTransport.getLogLevel;
|
import static io.grpc.netty.NettyServerTransport.getLogLevel;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
|
@ -34,27 +35,25 @@ public class NettyServerTransportTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void quiet() {
|
public void ioException() {
|
||||||
assertEquals(Level.FINE, getLogLevel(new IOException("Connection reset by peer")));
|
assertEquals(Level.FINE, getLogLevel(new IOException("Connection reset by peer")));
|
||||||
assertEquals(Level.FINE, getLogLevel(new IOException(
|
assertEquals(Level.FINE, getLogLevel(new IOException(
|
||||||
"An existing connection was forcibly closed by the remote host")));
|
"An existing connection was forcibly closed by the remote host")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void quiet_prefixed() {
|
public void ioException_nullMessage() {
|
||||||
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() {
|
|
||||||
IOException e = new IOException();
|
IOException e = new IOException();
|
||||||
assertNull(e.getMessage());
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue