Skip to content

Commit

Permalink
Avoid log pollution while waiting for consumer to close (#821)
Browse files Browse the repository at this point in the history
* Inhibit TRACE messages for a while to avoid polluting the logs

* Set test log level to TRACE
  • Loading branch information
guillermocalvo authored Aug 17, 2023
1 parent 44d7b8f commit b0d144b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@

import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -328,8 +329,22 @@ public void close() {
consumerState.kafkaConsumer.wakeup();
}
for (ConsumerState consumerState : consumers.values()) {
while (consumerState.closedState == ConsumerCloseState.POLLING) {
LOG.trace("consumer not closed yet");
if (consumerState.closedState == ConsumerCloseState.POLLING) {
final Instant start = Instant.now();
Instant silentTime = start;
do {
if (LOG.isTraceEnabled()) {
final Instant now = Instant.now();
if (now.isAfter(silentTime)) {
LOG.trace("Consumer {} is not closed yet (waiting {})", consumerState.clientId, Duration.between(start, now));
// Inhibit TRACE messages for a while to avoid polluting the logs
silentTime = now.plusSeconds(5);
}
}
} while (consumerState.closedState == ConsumerCloseState.POLLING);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Consumer {} is closed", consumerState.clientId);
}
}
consumers.clear();
Expand Down
2 changes: 1 addition & 1 deletion kafka/src/test/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
<!--<logger name="org.apache.kafka" level="TRACE" />-->
<!-- <logger name="io.micronaut.context" level="TRACE"/>-->
<!--<logger name="io.micronaut.configuration.kafka.processor" level="TRACE"/>-->
<!-- <logger name="io.micronaut.configuration.kafka " level="TRACE" />-->
<logger name="io.micronaut.configuration.kafka" level="TRACE" />
</configuration>

0 comments on commit b0d144b

Please sign in to comment.