From commits-return-44813-archive-asf-public=cust-asf.ponee.io@nifi.apache.org Wed Jun 23 15:35:52 2021 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mxout1-he-de.apache.org (mxout1-he-de.apache.org [95.216.194.37]) by mx-eu-01.ponee.io (Postfix) with ESMTPS id 708AC180636 for ; Wed, 23 Jun 2021 17:35:52 +0200 (CEST) Received: from mail.apache.org (mailroute1-lw-us.apache.org [207.244.88.153]) by mxout1-he-de.apache.org (ASF Mail Server at mxout1-he-de.apache.org) with SMTP id 711A661C00 for ; Wed, 23 Jun 2021 15:35:51 +0000 (UTC) Received: (qmail 72806 invoked by uid 500); 23 Jun 2021 15:35:50 -0000 Mailing-List: contact commits-help@nifi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@nifi.apache.org Delivered-To: mailing list commits@nifi.apache.org Received: (qmail 72797 invoked by uid 99); 23 Jun 2021 15:35:50 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Jun 2021 15:35:50 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 7B7B2821E0; Wed, 23 Jun 2021 15:35:50 +0000 (UTC) Date: Wed, 23 Jun 2021 15:35:50 +0000 To: "commits@nifi.apache.org" Subject: [nifi] branch main updated: NIFI-4344: Improve bulletin messages with exception details. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <162446254958.15438.17737573346921132887@gitbox.apache.org> From: tpalfy@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: nifi X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Oldrev: 8e5ce46f6c4d20c57ed6e315bfe262550b6b2671 X-Git-Newrev: 0c748a5a2b366990c544e0580ca8626f0b9e3ed1 X-Git-Rev: 0c748a5a2b366990c544e0580ca8626f0b9e3ed1 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. tpalfy pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/nifi.git The following commit(s) were added to refs/heads/main by this push: new 0c748a5 NIFI-4344: Improve bulletin messages with exception details. 0c748a5 is described below commit 0c748a5a2b366990c544e0580ca8626f0b9e3ed1 Author: Lehel Boér AuthorDate: Wed Mar 31 20:58:26 2021 +0200 NIFI-4344: Improve bulletin messages with exception details. This closes #5093. Signed-off-by: Tamas Palfy --- .../logging/repository/StandardLogRepository.java | 4 +-- .../apache/nifi/processor/SimpleProcessLogger.java | 26 +++++++++++++---- .../nifi/processor/TestSimpleProcessLogger.java | 34 +++++++++++++--------- .../nifi/controller/tasks/ConnectableTask.java | 4 +-- 4 files changed, 43 insertions(+), 25 deletions(-) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/logging/repository/StandardLogRepository.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/logging/repository/StandardLogRepository.java index dde2a8c..687cfec 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/logging/repository/StandardLogRepository.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/logging/repository/StandardLogRepository.java @@ -34,8 +34,6 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; public class StandardLogRepository implements LogRepository { - public static final int DEFAULT_MAX_CAPACITY_PER_LEVEL = 10; - private final Map> observers = new HashMap<>(); private final Map observerLookup = new HashMap<>(); @@ -82,7 +80,7 @@ public class StandardLogRepository implements LogRepository { addLogMessage(level, formattedMessage, t); } - private void replaceThrowablesWithMessage(Object[] params) { + private void replaceThrowablesWithMessage(final Object[] params) { for (int i = 0; i < params.length; i++) { if(params[i] instanceof Throwable) { params[i] = ((Throwable) params[i]).getLocalizedMessage(); diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/processor/SimpleProcessLogger.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/processor/SimpleProcessLogger.java index e82309b..0c55241 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/processor/SimpleProcessLogger.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/processor/SimpleProcessLogger.java @@ -24,8 +24,14 @@ import org.apache.nifi.logging.LogRepositoryFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.LinkedList; +import java.util.stream.Collectors; + public class SimpleProcessLogger implements ComponentLog { + public static final String NEW_LINE_ARROW = "\u21B3"; + public static final String CAUSES = NEW_LINE_ARROW + " causes: "; + private final Logger logger; private final LogRepository logRepository; private final Object component; @@ -58,7 +64,7 @@ public class SimpleProcessLogger implements ComponentLog { } msg = "{} " + msg; - final Object[] os = {component, t.toString(), t}; + final Object[] os = {component, getCauses(t), t}; logger.warn(msg, os); logRepository.addLogMessage(LogLevel.WARN, msg, os, t); } @@ -110,7 +116,7 @@ public class SimpleProcessLogger implements ComponentLog { } msg = "{} " + msg; - final Object[] os = {component, t.toString(), t}; + final Object[] os = {component, getCauses(t), t}; logger.trace(msg, os); logRepository.addLogMessage(LogLevel.TRACE, msg, os, t); } @@ -184,7 +190,7 @@ public class SimpleProcessLogger implements ComponentLog { } msg = "{} " + msg; - final Object[] os = {component, t.toString()}; + final Object[] os = {component, getCauses(t)}; logger.info(msg, os); if (logger.isDebugEnabled()) { @@ -245,12 +251,12 @@ public class SimpleProcessLogger implements ComponentLog { if (t == null) { msg = "{} " + msg; - final Object[] os = new Object[] {component}; + final Object[] os = new Object[]{component}; logger.error(msg, os); logRepository.addLogMessage(LogLevel.ERROR, msg, os); } else { msg = "{} " + msg + ": {}"; - final Object[] os = new Object[] {component, t.toString(), t}; + final Object[] os = new Object[]{component, getCauses(t), t}; logger.error(msg, os); logRepository.addLogMessage(LogLevel.ERROR, msg, os, t); } @@ -301,7 +307,7 @@ public class SimpleProcessLogger implements ComponentLog { modifiedArgs = new Object[os.length + 3]; modifiedArgs[0] = component.toString(); System.arraycopy(os, 0, modifiedArgs, 1, os.length); - modifiedArgs[modifiedArgs.length - 2] = t.toString(); + modifiedArgs[modifiedArgs.length - 2] = getCauses(t); modifiedArgs[modifiedArgs.length - 1] = t; } @@ -448,4 +454,12 @@ public class SimpleProcessLogger implements ComponentLog { } } + private String getCauses(final Throwable throwable) { + final LinkedList causes = new LinkedList<>(); + for (Throwable t = throwable; t != null; t = t.getCause()) { + causes.push(t.toString()); + } + return causes.stream().collect(Collectors.joining(System.lineSeparator() + CAUSES)); + } + } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/processor/TestSimpleProcessLogger.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/processor/TestSimpleProcessLogger.java index 2307470..6d2bd1c 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/processor/TestSimpleProcessLogger.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/processor/TestSimpleProcessLogger.java @@ -16,6 +16,15 @@ */ package org.apache.nifi.processor; +import org.apache.nifi.logging.LogLevel; +import org.apache.nifi.reporting.ReportingTask; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; + +import java.lang.reflect.Field; + +import static org.apache.nifi.processor.SimpleProcessLogger.NEW_LINE_ARROW; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; @@ -24,16 +33,13 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import java.lang.reflect.Field; +public class TestSimpleProcessLogger { -import org.apache.nifi.logging.LogLevel; -import org.apache.nifi.reporting.ReportingTask; -import org.junit.Before; -import org.junit.Test; -import org.slf4j.Logger; + private static final String EXPECTED_CAUSES = "java.lang.RuntimeException: third" + System.lineSeparator() + + NEW_LINE_ARROW + " causes: java.lang.RuntimeException: second" + System.lineSeparator() + + NEW_LINE_ARROW + " causes: java.lang.RuntimeException: first"; -public class TestSimpleProcessLogger { - private final Exception e = new RuntimeException("intentional"); + private final Exception e = new RuntimeException("first", new RuntimeException("second", new RuntimeException("third"))); private ReportingTask task; @@ -68,7 +74,7 @@ public class TestSimpleProcessLogger { @Test public void validateDelegateLoggerReceivesThrowableToStringOnError() { componentLog.error("Hello {}", e); - verify(logger, times(1)).error(anyString(), eq(task), eq(e.toString()), eq(e)); + verify(logger, times(1)).error(anyString(), eq(task), eq(EXPECTED_CAUSES), eq(e)); } @Test @@ -80,24 +86,24 @@ public class TestSimpleProcessLogger { @Test public void validateDelegateLoggerReceivesThrowableToStringOnTrace() { componentLog.trace("Hello {}", e); - verify(logger, times(1)).trace(anyString(), eq(task), eq(e.toString()), eq(e)); + verify(logger, times(1)).trace(anyString(), eq(task), eq(EXPECTED_CAUSES), eq(e)); } @Test public void validateDelegateLoggerReceivesThrowableToStringOnWarn() { componentLog.warn("Hello {}", e); - verify(logger, times(1)).warn(anyString(), eq(task), eq(e.toString()), eq(e)); + verify(logger, times(1)).warn(anyString(), eq(task), eq(EXPECTED_CAUSES), eq(e)); } @Test public void validateDelegateLoggerReceivesThrowableToStringOnLogWithLevel() { componentLog.log(LogLevel.WARN, "Hello {}", e); - verify(logger, times(1)).warn(anyString(), eq(task), eq(e.toString()), eq(e)); + verify(logger, times(1)).warn(anyString(), eq(task), eq(EXPECTED_CAUSES), eq(e)); componentLog.log(LogLevel.ERROR, "Hello {}", e); - verify(logger, times(1)).error(anyString(), eq(task), eq(e.toString()), eq(e)); + verify(logger, times(1)).error(anyString(), eq(task), eq(EXPECTED_CAUSES), eq(e)); componentLog.log(LogLevel.INFO, "Hello {}", e); verify(logger, times(1)).info(anyString(), eq(e)); componentLog.log(LogLevel.TRACE, "Hello {}", e); - verify(logger, times(1)).trace(anyString(), eq(task), eq(e.toString()), eq(e)); + verify(logger, times(1)).trace(anyString(), eq(task), eq(EXPECTED_CAUSES), eq(e)); } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/tasks/ConnectableTask.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/tasks/ConnectableTask.java index 83dc8f1..916d9a3 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/tasks/ConnectableTask.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/tasks/ConnectableTask.java @@ -251,8 +251,8 @@ public class ConnectableTask { } catch (final Throwable t) { // Use ComponentLog to log the event so that a bulletin will be created for this processor final ComponentLog procLog = new SimpleProcessLogger(connectable.getIdentifier(), connectable.getRunnableComponent()); - procLog.error("{} failed to process session due to {}; Processor Administratively Yielded for {}", - new Object[] {connectable.getRunnableComponent(), t, schedulingAgent.getAdministrativeYieldDuration()}, t); + procLog.error("Failed to process session due to {}; Processor Administratively Yielded for {}", + new Object[] {t, schedulingAgent.getAdministrativeYieldDuration()}, t); logger.warn("Administratively Yielding {} due to uncaught Exception: {}", connectable.getRunnableComponent(), t.toString(), t); connectable.yield(schedulingAgent.getAdministrativeYieldDuration(TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS);