From 7b936f2a87564f97dc85978e835780af9b999e06 Mon Sep 17 00:00:00 2001 From: kares Date: Wed, 16 Jun 2021 13:18:56 +0200 Subject: [PATCH 1/4] Fix: reduce error logging on connection resets --- .../java/org/logstash/beats/BeatsHandler.java | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/logstash/beats/BeatsHandler.java b/src/main/java/org/logstash/beats/BeatsHandler.java index 16564222..6cbe1fa0 100644 --- a/src/main/java/org/logstash/beats/BeatsHandler.java +++ b/src/main/java/org/logstash/beats/BeatsHandler.java @@ -2,10 +2,10 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.util.AttributeKey; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.io.IOException; import java.net.InetSocketAddress; import javax.net.ssl.SSLHandshakeException; @@ -40,7 +40,7 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception { @Override - public void channelRead0(ChannelHandlerContext ctx, Batch batch) throws Exception { + public void channelRead0(ChannelHandlerContext ctx, Batch batch) { if(logger.isDebugEnabled()) { logger.debug(format("Received a new payload")); } @@ -81,19 +81,37 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E if (!(cause instanceof SSLHandshakeException)) { messageListener.onException(ctx, cause); } - final Throwable realCause = extractCause(cause, 0); - if (logger.isDebugEnabled()){ - logger.debug(format("Handling exception: " + cause + " (caused by: " + realCause + ")"), cause); + if (silentException(cause)) { + if (logger.isDebugEnabled()) { + logger.debug(format("closing"), cause); + } else { + logger.info(format("closing (" + cause.getMessage() + ")")); + } } else { - logger.info(format("Handling exception: " + cause + " (caused by: " + realCause + ")")); + final Throwable realCause = extractCause(cause, 0); + if (logger.isDebugEnabled()){ + logger.debug(format("Handling exception: " + cause + " (caused by: " + realCause + ")"), cause); + } else { + logger.info(format("Handling exception: " + cause + " (caused by: " + realCause + ")")); + } + super.exceptionCaught(ctx, cause); } - } finally{ - super.exceptionCaught(ctx, cause); + } finally { ctx.flush(); ctx.close(); } } + private boolean silentException(final Throwable ex) { + if (ex instanceof IOException) { + final String message = ex.getMessage(); + if ("Connection reset by peer".equals(message)) { + return true; + } + } + return false; + } + private boolean needAck(Message message) { return message.getSequence() == message.getBatch().getHighestSequence(); } From 64ab5d8460d1a324e719d74114a4aaf9132b0c1c Mon Sep 17 00:00:00 2001 From: kares Date: Wed, 16 Jun 2021 13:35:52 +0200 Subject: [PATCH 2/4] keep detailed reset log entry an info level --- src/main/java/org/logstash/beats/BeatsHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/logstash/beats/BeatsHandler.java b/src/main/java/org/logstash/beats/BeatsHandler.java index 6cbe1fa0..71a38f2b 100644 --- a/src/main/java/org/logstash/beats/BeatsHandler.java +++ b/src/main/java/org/logstash/beats/BeatsHandler.java @@ -83,7 +83,7 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E } if (silentException(cause)) { if (logger.isDebugEnabled()) { - logger.debug(format("closing"), cause); + logger.info(format("closing"), cause); } else { logger.info(format("closing (" + cause.getMessage() + ")")); } From 7c264b7764c483145817f81475c72609b74ec985 Mon Sep 17 00:00:00 2001 From: kares Date: Wed, 16 Jun 2021 13:38:33 +0200 Subject: [PATCH 3/4] bump + changelog --- CHANGELOG.md | 3 +++ VERSION | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91df1e32..818683b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 6.1.4 + - Fix: reduce error logging on connection resets [#424](https://github.com/logstash-plugins/logstash-input-beats/pull/424) + ## 6.1.3 - Fix: safe-guard byte buf allocation [#420](https://github.com/logstash-plugins/logstash-input-beats/pull/420) - Updated Jackson dependencies diff --git a/VERSION b/VERSION index 88d06f10..c0f25bae 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.1.3 +6.1.4 From dba1148da93b299b79864eb70604402cc35cc480 Mon Sep 17 00:00:00 2001 From: kares Date: Thu, 17 Jun 2021 06:41:34 +0200 Subject: [PATCH 4/4] Review: use consistent level + better method name --- src/main/java/org/logstash/beats/BeatsHandler.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/logstash/beats/BeatsHandler.java b/src/main/java/org/logstash/beats/BeatsHandler.java index 71a38f2b..9e96bcf3 100644 --- a/src/main/java/org/logstash/beats/BeatsHandler.java +++ b/src/main/java/org/logstash/beats/BeatsHandler.java @@ -81,7 +81,7 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E if (!(cause instanceof SSLHandshakeException)) { messageListener.onException(ctx, cause); } - if (silentException(cause)) { + if (isNoisyException(cause)) { if (logger.isDebugEnabled()) { logger.info(format("closing"), cause); } else { @@ -90,7 +90,7 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E } else { final Throwable realCause = extractCause(cause, 0); if (logger.isDebugEnabled()){ - logger.debug(format("Handling exception: " + cause + " (caused by: " + realCause + ")"), cause); + logger.info(format("Handling exception: " + cause + " (caused by: " + realCause + ")"), cause); } else { logger.info(format("Handling exception: " + cause + " (caused by: " + realCause + ")")); } @@ -102,7 +102,7 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E } } - private boolean silentException(final Throwable ex) { + private boolean isNoisyException(final Throwable ex) { if (ex instanceof IOException) { final String message = ex.getMessage(); if ("Connection reset by peer".equals(message)) {