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

Allow configuring observation registry directly #3643

Conversation

cfredri4
Copy link
Contributor

This changes allows configuring the observation registry directly, instead of it being fetched from the application context. This is to allow observability when KafkaTemplate/KafkaMessageListenerContainer are used without an application context.

@sobychacko
Copy link
Contributor

@ cfredri4 I think this needs more discussion. These changes modify the behavior of setting the default NOOP observation registry for both KafkaTemplate and the listener container. Why do you need to provide the ObservationRegistry as a non-bean, and why is the application context absent? Since there are some design changes in the PR, we will discuss this internally soon, but you can just give some more context around the changes. Thanks.

@cfredri4
Copy link
Contributor Author

@cfredri4 I think this needs more discussion. These changes modify the behavior of setting the default NOOP observation registry for both KafkaTemplate and the listener container.

This was for simplicity's sake as the registry is nullable and null and NOOP are treated the same. But I can change back to NOOP if desired.

Why do you need to provide the ObservationRegistry as a non-bean, and why is the application context absent? Since there are some design changes in the PR, we will discuss this internally soon, but you can just give some more context around the changes. Thanks.

I have two situations where this change would be beneficial:

  1. We sometimes use Spring Kafka in applications which are not Spring applications, i.e. they do not have a Spring application context. Here we need to create a mock ApplicationContext which implements getBeanProvider to return the registry; this is messy and fragile as it's dependent on internal logic in how KafkaTemplate/KafkaMessageListenerContainer works.

  2. We sometimes have the need to use a different observation registry for Spring Kafka than what is in the application context. Here we need to do similar to # 1 above but then also make sure that this is done after Spring has already initialized KafkaTemplate/KafkaMessageListenerContainer as this time they are Spring beans.

Both of these situations would be trivial had it been possible to configure the observation registry directly.
Exactly the same thing can already be done for the KafkaAdmin, so to me it makes sense to allow it also for the observation registry.

@sobychacko
Copy link
Contributor

@cfredri4 We are ok with the changes. However, could you re-work your solution so we don't break any existing behavior? Specifically, the default ObservationRegistry.NOOP should be restored in both KafkaTemplate and KafkaMessageListenerContainer. Thanks!

@sobychacko
Copy link
Contributor

Also, please add the author tag with your name in all the classes you changed. Thanks!

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

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

Please, consider to address reviews by tomorrow.
We have release on Monday, so might be great to have this in.

Thank you!

@cfredri4 cfredri4 force-pushed the allow-configuring-observation-registry-directly branch from c378bc1 to b8027b7 Compare December 13, 2024 08:55
@cfredri4
Copy link
Contributor Author

I have pushed some updates, please check.

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

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

Well, sorry for the noise, but apparently there are some Checkstyle violations:

Error: eckstyle] [ERROR] /home/runner/work/spring-kafka/spring-kafka/spring-kafka/src/main/java/org/springframework/kafka/core/KafkaTemplate.java:496: Line matches the illegal pattern 'Trailing whitespace'. [Regexp]

Error: eckstyle] [ERROR] /home/runner/work/spring-kafka/spring-kafka/spring-kafka/src/main/java/org/springframework/kafka/listener/ContainerProperties.java:45:1: Wrong order for 'io.micrometer.observation.ObservationRegistry' import. [ImportOrder]
> Task :spring-kafka:checkstyleMain
Error: eckstyle] [ERROR] /home/runner/work/spring-kafka/spring-kafka/spring-kafka/src/main/java/org/springframework/kafka/listener/KafkaMessageListenerContainer.java:81:8: Unused import - org.springframework.beans.factory.ObjectProvider. [UnusedImports]

Please, consider to use Gradle check task before pushing commits to the PR.

Thanks

This changes allows configuring the observation registry directly, instead of it being fetched from the application context.
This is to allow observability when KafkaTemplate/KafkaMessageListenerContainer are used without an application context.
@cfredri4 cfredri4 force-pushed the allow-configuring-observation-registry-directly branch from b8027b7 to 16f251c Compare December 13, 2024 20:20
@cfredri4
Copy link
Contributor Author

Fixed.

@artembilan artembilan added this to the 3.3.1 milestone Dec 16, 2024
@artembilan artembilan merged commit 3cd6c9c into spring-projects:main Dec 16, 2024
3 checks passed
@cfredri4 cfredri4 deleted the allow-configuring-observation-registry-directly branch December 17, 2024 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants