Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid log pollution while waiting for consumer to close #821

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>