Add a log filter for spurious warnings about unsupported channel options

This commit is contained in:
Jon Chambers
2024-06-07 19:11:55 -04:00
committed by Jon Chambers
parent ad5ef76e8e
commit 0871d6ebc1
4 changed files with 46 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
package org.whispersystems.textsecuregcm.util.logging;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.filter.Filter;
import ch.qos.logback.core.spi.FilterReply;
/**
* Filters spurious warnings about setting a very specific channel option on local channels.
* <p/>
* gRPC unconditionally tries to set the {@code SO_KEEPALIVE} option on all of its channels, but local channels, which
* are used by the Noise-over-WebSocket tunnel, do not support {@code SO_KEEPALIVE} and log a warning on each new
* channel. We don't want to filter <em>all</em> warnings from the relevant logger, and so this custom filter denies
* attempts to log the specific spurious message.
*/
public class UnknownKeepaliveOptionFilter extends Filter<ILoggingEvent> {
private static final String MESSAGE_PREFIX = "Unknown channel option 'SO_KEEPALIVE'";
@Override
public FilterReply decide(final ILoggingEvent event) {
final boolean loggerNameMatches = "io.netty.bootstrap.Bootstrap".equals(event.getLoggerName()) ||
"io.netty.bootstrap.ServerBootstrap".equals(event.getLoggerName());
return loggerNameMatches && event.getMessage().startsWith(MESSAGE_PREFIX) ? FilterReply.DENY : FilterReply.NEUTRAL;
}
}

View File

@@ -0,0 +1,15 @@
package org.whispersystems.textsecuregcm.util.logging;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.filter.Filter;
import com.fasterxml.jackson.annotation.JsonTypeName;
import io.dropwizard.logging.common.filter.FilterFactory;
@JsonTypeName("unknownKeepaliveOption")
public class UnknownKeepaliveOptionFilterFactory implements FilterFactory<ILoggingEvent> {
@Override
public Filter<ILoggingEvent> build() {
return new UnknownKeepaliveOptionFilter();
}
}