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

GH-3690: Fix observation leak in the KafkaMessageListenerContainer #3694

Merged
merged 1 commit into from
Dec 23, 2024
Merged
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 @@ -966,8 +966,8 @@ else if (listener instanceof MessageListener) {
this.wasIdlePartition = new HashMap<>();
this.kafkaAdmin = obtainAdmin();

if (this.listener instanceof RecordMessagingMessageListenerAdapter<?, ?> rmmla) {
rmmla.setObservationRegistry(observationRegistry);
if (isListenerAdapterObservationAware()) {
((RecordMessagingMessageListenerAdapter<?, ?>) this.listener).setObservationRegistry(observationRegistry);
}
}

Expand Down Expand Up @@ -1228,6 +1228,10 @@ else if (timeout instanceof String str) {
}
}

private boolean isListenerAdapterObservationAware() {
return this.listener != null && RecordMessagingMessageListenerAdapter.class.equals(this.listener.getClass());
}

private void subscribeOrAssignTopics(final Consumer<? super K, ? super V> subscribingConsumer) {
if (KafkaMessageListenerContainer.this.topicPartitions == null) {
ConsumerRebalanceListener rebalanceListener = new ListenerConsumerRebalanceListener();
Expand Down Expand Up @@ -2772,7 +2776,7 @@ private RuntimeException doInvokeRecordListener(final ConsumerRecord<K, V> cReco
catch (RuntimeException e) {
failureTimer(sample, cRecord);
recordInterceptAfter(cRecord, e);
if (!(this.listener instanceof RecordMessagingMessageListenerAdapter<K, V>)) {
if (!isListenerAdapterObservationAware()) {
observation.error(e);
}
if (this.commonErrorHandler == null) {
Expand Down Expand Up @@ -2800,7 +2804,7 @@ private RuntimeException doInvokeRecordListener(final ConsumerRecord<K, V> cReco
}
}
finally {
if (!(this.listener instanceof RecordMessagingMessageListenerAdapter<K, V>)) {
if (!isListenerAdapterObservationAware()) {
observation.stop();
}
observationScope.close();
Expand Down
Loading