From 48aa39e0749c2764e12373b932a405d152fb5e50 Mon Sep 17 00:00:00 2001 From: "maciej.moscicki" Date: Thu, 18 Jan 2024 16:52:45 +0100 Subject: [PATCH] allow tasks to be rejected --- .../hermes/frontend/producer/BrokerLatencyReporter.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hermes-frontend/src/main/java/pl/allegro/tech/hermes/frontend/producer/BrokerLatencyReporter.java b/hermes-frontend/src/main/java/pl/allegro/tech/hermes/frontend/producer/BrokerLatencyReporter.java index f999ed64fa..797d5e6a8f 100644 --- a/hermes-frontend/src/main/java/pl/allegro/tech/hermes/frontend/producer/BrokerLatencyReporter.java +++ b/hermes-frontend/src/main/java/pl/allegro/tech/hermes/frontend/producer/BrokerLatencyReporter.java @@ -12,6 +12,7 @@ import java.time.Duration; import java.util.Optional; import java.util.concurrent.ExecutorService; +import java.util.concurrent.RejectedExecutionException; import java.util.function.Supplier; public class BrokerLatencyReporter { @@ -39,7 +40,12 @@ public void report(HermesTimerContext timerContext, @Nullable Supplier produceMetadata) { Duration duration = timerContext.closeAndGet(); if (perBrokerLatencyEnabled) { - reporterExecutorService.submit(() -> doReport(duration, message.getId(), ack, produceMetadata)); + try { + reporterExecutorService.submit(() -> doReport(duration, message.getId(), ack, produceMetadata)); + } catch (RejectedExecutionException ignored) { + // don't propagate the exception - allow metrics to be dropped if executor is overloaded + // executor service should already be instrumented to meter rejected executions so no action is needed + } } }