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-3528: Improving Observability in Asynchronous Processing #3558

Merged
merged 2 commits into from
Oct 16, 2024

Conversation

sobychacko
Copy link
Contributor

…bleFuture, Mono)

Fixes: #3528

#3528

  • Improve spring-kafka observability for failures in async consumer tasks when listener methods return CompletableFuture or Mono and throw errors during async execution
  • Refactoring code in KafkaMessageListenerContainer and MessagingMessageListenerAdapter around observability
  • Adding tests to verify
  • Add @nullable annotations to relevant methods for better null safety

…ssing

Fixes: spring-projects#3528

spring-projects#3528

- Improve spring-kafka observability for failures in async consumer tasks
  when listener methods return CompletableFuture<?> or Mono<?> and throw
  errors during async execution
- Refactoring code in KafkaMessageListenerContainer and MessagingMessageListenerAdapter
  around observability
- Adding tests to verify
- Add @nullable annotations to relevant methods for better null safety
@sobychacko sobychacko changed the title GH-3528: Improving Observability in Asynchronous Processing (Completa… GH-3528: Improving Observability in Asynchronous Processing Oct 15, 2024
catch (RuntimeException e) {
failureTimer(sample, cRecord);
recordInterceptAfter(cRecord, e);
if (!(this.listener instanceof MessagingMessageListenerAdapter<?, ?>)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if for consistency this condition has also to be against RecordMessagingMessageListenerAdapter...

}
}
finally {
if (!(this.listener instanceof MessagingMessageListenerAdapter<?, ?>)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DITTO

this.logger.warn("Container 'Acknowledgment' must be async ack for Mono<?> return type " +
"(or Kotlin suspend function); otherwise the container will ack the message immediately");
}
result = mono.toFuture();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not OK to re-assign method argument.
I don't remember SonarCube rule, but we definitely must not override them.
So, you have to introduce internal CompletableFuture<?> variable and deal with it instead.

@@ -870,6 +899,10 @@ private boolean rawByParameterIsType(Type parameterType, Type type) {
return parameterType instanceof ParameterizedType pType && pType.getRawType().equals(type);
}

public void setObservationRegistry(ObservationRegistry observationRegistry) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setter is in wrong place.
Has to be somewhere after ctor with the rest of setters.
And the method might deserve JavaDoc since it is public.

@artembilan artembilan merged commit c878099 into spring-projects:main Oct 16, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improving Observability in Asynchronous Processing (CompletableFuture, Mono)
2 participants