Remove some unnecessary loggings from the proxy

We confirmed that the retry is working. Instead of logging the messages them
selves, we only need to log the message hash to ensure that the same message is
retried.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=208883712
This commit is contained in:
jianglai 2018-08-15 14:31:31 -07:00
parent 3dba385213
commit 301301cafe
3 changed files with 18 additions and 14 deletions

View file

@ -93,6 +93,7 @@ public class ProxyServer implements Runnable {
inboundChannel.attr(PROTOCOL_KEY).set(inboundProtocol);
inboundChannel.attr(RELAY_BUFFER_KEY).set(new ArrayDeque<>());
addHandlers(inboundChannel.pipeline(), inboundProtocol.handlerProviders());
logger.atInfo().log("Connection established: %s %s", inboundProtocol.name(), inboundChannel);
if (!inboundProtocol.hasBackend()) {
// If the frontend has no backend to relay to (health check, web WHOIS redirect, etc), start
@ -146,10 +147,9 @@ public class ProxyServer implements Runnable {
.get()
.forEach(
msg -> {
// TODO (jianglai): do not log the message once retry behavior is
// confirmed.
logger.atWarning().log(
"Unfinished relay for connection %s: %s", inboundChannel, msg);
"Unfinished relay for connection %s\nHASH: %s",
inboundChannel, msg.hashCode());
ReferenceCountUtil.release(msg);
});
});
@ -194,14 +194,13 @@ public class ProxyServer implements Runnable {
Object[] messages = relayBuffer.toArray();
relayBuffer.clear();
for (Object msg : messages) {
// TODO (jianglai): do not log the message once retry behavior is confirmed.
logger.atInfo().log(
"Relay retried: %s <-> %s\nFRONTEND: %s\nBACKEND: %s\nMESSAGE: %s",
"Relay retried: %s <-> %s\nFRONTEND: %s\nBACKEND: %s\nHASH: %s",
inboundProtocol.name(),
outboundProtocol.name(),
inboundChannel,
outboundChannel,
msg);
msg.hashCode());
writeToRelayChannel(inboundChannel, outboundChannel, msg, true);
}
// When this outbound connection is closed, try reconnecting if the inbound connection
@ -220,6 +219,13 @@ public class ProxyServer implements Runnable {
outboundChannel);
connectOutboundChannel(
bootstrap, inboundProtocol, outboundProtocol, inboundChannel);
} else {
logger.atInfo().log(
"Relay terminated: %s <-> %s\nFRONTEND: %s\nBACKEND: %s",
inboundProtocol.name(),
outboundProtocol.name(),
inboundChannel,
outboundChannel);
}
});
} else {

View file

@ -79,7 +79,8 @@ public class BackendMetricsHandler extends ChannelDuplexHandler {
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
// Backend channel is always established after a frontend channel is connected, so this
// Backend channel is always established after a frontend channel is connected, so this call
// should always return a non-null relay channel.
relayedChannel = ctx.channel().attr(RELAY_CHANNEL_KEY).get();
checkNotNull(relayedChannel, "No frontend channel found.");
relayedProtocolName = relayedChannel.attr(PROTOCOL_KEY).get().name();

View file

@ -101,14 +101,13 @@ public class RelayHandler<I> extends SimpleChannelInboundHandler<I> {
.addListener(
future -> {
if (!future.isSuccess()) {
// TODO (jianglai): do not log the message once retry behavior is confirmed.
logger.atWarning().withCause(future.cause()).log(
"Relay failed: %s --> %s\nINBOUND: %s\nOUTBOUND: %s\nMESSAGE: %s",
"Relay failed: %s --> %s\nINBOUND: %s\nOUTBOUND: %s\nHASH: %s",
channel.attr(PROTOCOL_KEY).get().name(),
relayChannel.attr(PROTOCOL_KEY).get().name(),
channel,
relayChannel,
msg);
msg.hashCode());
// If we cannot write to the relay channel and the originating channel has
// a relay buffer (i. e. we tried to relay the frontend to the backend), store
// the message in the buffer for retry later. The relay channel (backend) should
@ -129,15 +128,13 @@ public class RelayHandler<I> extends SimpleChannelInboundHandler<I> {
ChannelFuture unusedFuture2 = relayChannel.close();
} else {
if (retry) {
// TODO (jianglai): do not log the message once retry behavior is confirmed.
logger.atInfo().log(
"Relay retry succeeded: %s --> %s\nINBOUND: %s\nOUTBOUND: %s\n"
+ "MESSAGE: %s",
"Relay retry succeeded: %s --> %s\nINBOUND: %s\nOUTBOUND: %s\nHASH: %s",
channel.attr(PROTOCOL_KEY).get().name(),
relayChannel.attr(PROTOCOL_KEY).get().name(),
channel,
relayChannel,
msg);
msg.hashCode());
}
// If the write is successful, we know that no retry is needed. This function
// will decrement the reference count if the message is reference counted,