From 6ad4d4f1cfc9eefd3a92a18e9a265dc27e0893ed Mon Sep 17 00:00:00 2001 From: Katharina Schmid Date: Mon, 29 Jan 2024 16:18:29 +0100 Subject: [PATCH] Remove additional process reports --- CHANGES.md | 5 ++ .../reporting/DefaultProcessReport.java | 43 +++++++---- .../reporting/FlusswerkProcessReport.java | 60 --------------- .../reporting/SilentProcessReport.java | 20 ----- .../reporting/StructuredProcessReport.java | 74 ------------------- .../reporting/SilentProcessReportTest.java | 64 ---------------- 6 files changed, 34 insertions(+), 232 deletions(-) delete mode 100644 framework/src/main/java/com/github/dbmdz/flusswerk/framework/reporting/FlusswerkProcessReport.java delete mode 100644 framework/src/main/java/com/github/dbmdz/flusswerk/framework/reporting/SilentProcessReport.java delete mode 100644 framework/src/main/java/com/github/dbmdz/flusswerk/framework/reporting/StructuredProcessReport.java delete mode 100644 framework/src/test/java/com/github/dbmdz/flusswerk/framework/reporting/SilentProcessReportTest.java diff --git a/CHANGES.md b/CHANGES.md index e285703b..8383779d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Outgoing routes may now include a list of topics instead of a single topic. A `Route` can be used to send a message to several topics at once. +- The `DefaultFlusswerkReport` logs tracing information. + +### Removed +- `FlusswerkProcessReport`, `StructuredProcessReport` and `SilentProcessReport` have been removed. Users who would like to customize their process report can subclass [DefaultProcessReport](framework/src/main/java/com/github/dbmdz/flusswerk/framework/reporting/DefaultProcessReport.java) +or implement the [ProcessReport](framework/src/main/java/com/github/dbmdz/flusswerk/framework/reporting/ProcessReport.java) interface. ## [6.0.1] - 2023-12-06 diff --git a/framework/src/main/java/com/github/dbmdz/flusswerk/framework/reporting/DefaultProcessReport.java b/framework/src/main/java/com/github/dbmdz/flusswerk/framework/reporting/DefaultProcessReport.java index 8d348edb..8ad937a7 100644 --- a/framework/src/main/java/com/github/dbmdz/flusswerk/framework/reporting/DefaultProcessReport.java +++ b/framework/src/main/java/com/github/dbmdz/flusswerk/framework/reporting/DefaultProcessReport.java @@ -5,46 +5,55 @@ import com.github.dbmdz.flusswerk.framework.exceptions.RetryProcessingException; import com.github.dbmdz.flusswerk.framework.exceptions.StopProcessingException; +import com.github.dbmdz.flusswerk.framework.model.Envelope; import com.github.dbmdz.flusswerk.framework.model.Message; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class DefaultProcessReport implements ProcessReport { - private static final Logger LOGGER = LoggerFactory.getLogger(DefaultProcessReport.class); - + private final FlusswerkLogger logger; private final String name; - private final Tracing tracing; public DefaultProcessReport(String name, Tracing tracing) { this.name = requireNonNull(name); - this.tracing = requireNonNull(tracing); + FlusswerkLoggerFactory loggerFactory = new FlusswerkLoggerFactory(requireNonNull(tracing)); + this.logger = loggerFactory.getFlusswerkLogger(DefaultProcessReport.class); + } + + public DefaultProcessReport(String name, FlusswerkLogger logger) { + this.name = requireNonNull(name); + this.logger = requireNonNull(logger); } @Override public void reportSuccess(Message message) { - LOGGER.info("{} successful", name, keyValue("tracing", tracing.tracingPath())); + getLogger().info("{} successful", name); } @Override public void reportFail(Message message, StopProcessingException e) { + Envelope envelope = message.getEnvelope(); getLogger() .error( "{} failed terminally: {}", name, e.getMessage(), - keyValue("amqp_message", message.toString()), + keyValue("will_retry", false), + keyValue("incoming_queue", envelope.getSource()), + keyValue("retries", envelope.getRetries()), e); } @Override public void reportFailAfterMaxRetries(Message message, Exception e) { + Envelope envelope = message.getEnvelope(); getLogger() .error( "{} failed after maximum number of retries: {}", name, e.getMessage(), - keyValue("amqp_message", message.toString()), + keyValue("will_retry", false), + keyValue("incoming_queue", envelope.getSource()), + keyValue("retries", envelope.getRetries()), e); } @@ -58,12 +67,15 @@ public void reportReject(Message message, Exception e) { @Override public void reportRetry(Message message, RuntimeException e) { + Envelope envelope = message.getEnvelope(); getLogger() .warn( "{} rejected for retry: {}", name, e.getMessage(), - keyValue("amqp_message", message.toString()), + keyValue("will_retry", true), + keyValue("incoming_queue", envelope.getSource()), + keyValue("retries", envelope.getRetries()), e); } @@ -71,6 +83,7 @@ public void reportRetry(Message message, RuntimeException e) { public void reportComplexRetry(Message message, RetryProcessingException e) { int newMessagesToRetry = e.getMessagesToRetry().size(); int messagesSent = e.getMessagesToSend().size(); + Envelope envelope = message.getEnvelope(); getLogger() .warn( "{} rejected for retry with ({} new, {} sent) and : {}", @@ -78,16 +91,18 @@ public void reportComplexRetry(Message message, RetryProcessingException e) { newMessagesToRetry, messagesSent, e.getMessage(), - keyValue("amqp_message", message.toString()), + keyValue("will_retry", true), + keyValue("incoming_queue", envelope.getSource()), + keyValue("retries", envelope.getRetries()), e); } @Override public void reportSkip(Message message, Exception skip) { - LOGGER.info("Skipped: {}", skip.getMessage()); + getLogger().info("Skipped: {}", skip.getMessage()); } - protected Logger getLogger() { - return LOGGER; + protected FlusswerkLogger getLogger() { + return logger; } } diff --git a/framework/src/main/java/com/github/dbmdz/flusswerk/framework/reporting/FlusswerkProcessReport.java b/framework/src/main/java/com/github/dbmdz/flusswerk/framework/reporting/FlusswerkProcessReport.java deleted file mode 100644 index 35d02e9e..00000000 --- a/framework/src/main/java/com/github/dbmdz/flusswerk/framework/reporting/FlusswerkProcessReport.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.github.dbmdz.flusswerk.framework.reporting; - -import static java.util.Objects.requireNonNull; -import static net.logstash.logback.argument.StructuredArguments.keyValue; - -import com.github.dbmdz.flusswerk.framework.exceptions.StopProcessingException; -import com.github.dbmdz.flusswerk.framework.model.Envelope; -import com.github.dbmdz.flusswerk.framework.model.Message; - -public class FlusswerkProcessReport implements ProcessReport { - - protected final FlusswerkLogger logger; - protected final String name; - - public FlusswerkProcessReport(String name, FlusswerkLogger logger) { - this.name = requireNonNull(name); - this.logger = requireNonNull(logger); - } - - @Override - public void reportSuccess(Message message) { - // should be default, so no need to log anything and spam the logs - } - - @Override - public void reportFail(Message message, StopProcessingException e) { - Envelope envelope = message.getEnvelope(); - logger.error( - "{} failed, will not retry", - name, - keyValue("will_retry", false), - keyValue("incoming_queue", envelope.getSource()), - keyValue("retries", envelope.getRetries()), - e); - } - - @Override - public void reportFailAfterMaxRetries(Message message, Exception e) { - Envelope envelope = message.getEnvelope(); - logger.error( - "{} failed after max retries", - name, - keyValue("will_retry", false), - keyValue("incoming_queue", envelope.getSource()), - keyValue("retries", envelope.getRetries()), - e); - } - - @Override - public void reportReject(Message message, Exception e) { - Envelope envelope = message.getEnvelope(); - logger.error( - "{} failed, but will retry later", - name, - keyValue("will_retry", true), - keyValue("incoming_queue", envelope.getSource()), - keyValue("retries", envelope.getRetries()), - e); - } -} diff --git a/framework/src/main/java/com/github/dbmdz/flusswerk/framework/reporting/SilentProcessReport.java b/framework/src/main/java/com/github/dbmdz/flusswerk/framework/reporting/SilentProcessReport.java deleted file mode 100644 index 49d089f0..00000000 --- a/framework/src/main/java/com/github/dbmdz/flusswerk/framework/reporting/SilentProcessReport.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.dbmdz.flusswerk.framework.reporting; - -import com.github.dbmdz.flusswerk.framework.exceptions.StopProcessingException; -import com.github.dbmdz.flusswerk.framework.model.Message; - -/** Empty implementation for unit tests that reports nothing. */ -public class SilentProcessReport implements ProcessReport { - - @Override - public void reportSuccess(Message message) {} - - @Override - public void reportFail(Message message, StopProcessingException e) {} - - @Override - public void reportFailAfterMaxRetries(Message message, Exception e) {} - - @Override - public void reportReject(Message message, Exception e) {} -} diff --git a/framework/src/main/java/com/github/dbmdz/flusswerk/framework/reporting/StructuredProcessReport.java b/framework/src/main/java/com/github/dbmdz/flusswerk/framework/reporting/StructuredProcessReport.java deleted file mode 100644 index ca4d0199..00000000 --- a/framework/src/main/java/com/github/dbmdz/flusswerk/framework/reporting/StructuredProcessReport.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.github.dbmdz.flusswerk.framework.reporting; - -import static java.util.Objects.requireNonNull; -import static net.logstash.logback.argument.StructuredArguments.keyValue; - -import com.github.dbmdz.flusswerk.framework.exceptions.StopProcessingException; -import com.github.dbmdz.flusswerk.framework.model.Envelope; -import com.github.dbmdz.flusswerk.framework.model.Message; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class StructuredProcessReport implements ProcessReport { - - private static final Logger LOGGER = LoggerFactory.getLogger(StructuredProcessReport.class); - - private final String name; - private final Tracing tracing; - - public StructuredProcessReport(String name, Tracing tracing) { - this.name = requireNonNull(name); - this.tracing = requireNonNull(tracing); - } - - @Override - public void reportSuccess(Message message) { - // should be default, so no need to log anything and spam the logs - } - - @Override - public void reportFail(Message message, StopProcessingException e) { - Envelope envelope = message.getEnvelope(); - getLogger() - .error( - "{} failed, will not retry", - name, - keyValue("will_retry", false), - keyValue("incoming_queue", envelope.getSource()), - keyValue("retries", envelope.getRetries()), - keyValue("tracing", tracing.tracingPath()), - e); - } - - @Override - public void reportFailAfterMaxRetries(Message message, Exception e) { - Envelope envelope = message.getEnvelope(); - getLogger() - .error( - "{} failed after max retries", - name, - keyValue("will_retry", false), - keyValue("incoming_queue", envelope.getSource()), - keyValue("retries", envelope.getRetries()), - keyValue("tracing", tracing.tracingPath()), - e); - } - - @Override - public void reportReject(Message message, Exception e) { - Envelope envelope = message.getEnvelope(); - getLogger() - .error( - "{} failed, but will retry later", - name, - keyValue("will_retry", true), - keyValue("incoming_queue", envelope.getSource()), - keyValue("retries", envelope.getRetries()), - keyValue("tracing", tracing.tracingPath()), - e); - } - - protected Logger getLogger() { - return LOGGER; - } -} diff --git a/framework/src/test/java/com/github/dbmdz/flusswerk/framework/reporting/SilentProcessReportTest.java b/framework/src/test/java/com/github/dbmdz/flusswerk/framework/reporting/SilentProcessReportTest.java deleted file mode 100644 index 1e88d96a..00000000 --- a/framework/src/test/java/com/github/dbmdz/flusswerk/framework/reporting/SilentProcessReportTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.github.dbmdz.flusswerk.framework.reporting; - -import static org.assertj.core.api.Assertions.assertThat; - -import ch.qos.logback.classic.Level; -import ch.qos.logback.classic.Logger; -import ch.qos.logback.classic.LoggerContext; -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.read.ListAppender; -import com.github.dbmdz.flusswerk.framework.exceptions.RetryProcessingException; -import com.github.dbmdz.flusswerk.framework.exceptions.StopProcessingException; -import com.github.dbmdz.flusswerk.framework.model.Message; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.slf4j.LoggerFactory; - -@DisplayName("The SilentProcessReport") -class SilentProcessReportTest { - - private SilentProcessReport silentProcessReport; - private ListAppender listAppender; - - @BeforeEach - void setUp() { - Logger logger = (Logger) LoggerFactory.getLogger(DefaultProcessReport.class); - logger.setLevel(Level.DEBUG); - listAppender = new ListAppender<>(); - listAppender.setContext((LoggerContext) LoggerFactory.getILoggerFactory()); - listAppender.start(); - logger.addAppender(listAppender); - silentProcessReport = new SilentProcessReport(); - } - - @DisplayName("should report nothing on success") - @Test - void reportSuccess() { - Message message = new Message(); - silentProcessReport.reportSuccess(message); - assertThat(listAppender.list).isEmpty(); - } - - @DisplayName("should report nothing on fail") - @Test - void reportFail() { - silentProcessReport.reportFail(new Message(), new StopProcessingException("stop now")); - assertThat(listAppender.list).isEmpty(); - } - - @DisplayName("should report nothing on fail after too many retries") - @Test - void reportFailAfterMaxRetries() { - silentProcessReport.reportFailAfterMaxRetries( - new Message(), new StopProcessingException("stop now")); - assertThat(listAppender.list).isEmpty(); - } - - @DisplayName("should report nothing on fail with retries") - @Test - void reportReject() { - silentProcessReport.reportReject(new Message(), new RetryProcessingException("stop now")); - assertThat(listAppender.list).isEmpty(); - } -}