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

Fix metric disable when using the constructor injection of the Grpc Client #907

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

SOOHYUN-LIM
Copy link

�Issue: https://github.com/yidongnan/grpc-spring-boot-starter/issues/859

According to the order of registering Spring beans, there is an issue with the constructor injection of the Grpc Client. When creating the GrpcClientBeanPostProcessor bean, the constructor injection of the "Grpc Client" is performed by the @PostConstruct. During this process, when creating the GlobalGrpcClientInterceptor and its associated beans (MetricsBeanPostProcessor, Prometheus, etc.), the initialized "BeanPostProcessor" is not yet registered (nonOrdered), causing metrics to not be properly registered.

Therefore, it is necessary to change the order of bean registration by using InternalPostProcessors, similar to the AutowiredAnnotationBeanPostProcessor in Spring and the PersistenceAnnotationBeanPostProcessor in JPA. The task has been carried out along with the same validation as Spring's dependency injection, and it allows for identifying more specific errors.

@ST-DDT
Copy link
Collaborator

ST-DDT commented Jun 12, 2023

Can you please add a test for this?

@SOOHYUN-LIM
Copy link
Author

I have modified the code to ensure that each dependency injection method works correctly, taking into consideration the Spring lifecycle. Also added test code to verify if metric information registration is done successfully.

@ST-DDT
Copy link
Collaborator

ST-DDT commented Jun 19, 2023

Thanks, I will have a look when I have some spare time.

@ST-DDT ST-DDT added this to the 2.15.0 milestone Jun 19, 2023
@ST-DDT ST-DDT added the enhancement A feature request or improvement label Jun 19, 2023
@ST-DDT ST-DDT self-requested a review June 19, 2023 18:43
@abhathal
Copy link

hey @ST-DDT @SOOHYUN-LIM I know this PR might potentially be out of date now, but any update on getting this fix in?

@SOOHYUN-LIM
Copy link
Author

@abhathal No, I haven't received any feedback yet.
@ST-DDT When can �i expect confirmation?

@ST-DDT
Copy link
Collaborator

ST-DDT commented Nov 17, 2023

Could you please resolve the merge conflict?

@SOOHYUN-LIM
Copy link
Author

@ST-DDT I resolved the merge conflict

@ST-DDT
Copy link
Collaborator

ST-DDT commented Nov 22, 2023

@ST-DDT I resolved the merge conflict

Thanks, I will get to it shortly.

@ST-DDT
Copy link
Collaborator

ST-DDT commented Nov 22, 2023

It looks like there is a compile error.

@SOOHYUN-LIM
Copy link
Author

@ST-DDT Sorry, Please build it again

Copy link
Collaborator

@ST-DDT ST-DDT left a comment

Choose a reason for hiding this comment

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

I tested the changes and to make the test pass, all that is needed is moving the initGrpClientConstructorInjections() call, the other changes to the GrpcClientBeanPostProcessor seem to do nothing in the given test.

Could you please explain what the other code's purpose is?
I have a rough guess, that it might be an optimization for the normal field/method injection, but it calls the entire field/method processing for every field and method once again.
With these changes it might be possible to avoid requiring the @PostConstruct workaround entirely. Should we move that refactoring to a future/different PR?

@@ -149,8 +152,7 @@ List<GrpcChannelConfigurer> defaultChannelConfigurers() {
"io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder"})
@Bean
@Lazy
GrpcChannelFactory shadedNettyGrpcChannelFactory(
final GrpcChannelsProperties properties,
GrpcChannelFactory shadedNettyGrpcChannelFactory(final GrpcChannelsProperties properties,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please revert these unrelated formatting changes.

@msajawalsial
Copy link

Is there an estimated timeline for merging this pull request? In addition to metrics, it is also affecting tracing.

@SOOHYUN-LIM SOOHYUN-LIM force-pushed the fix-GrpcClientBeanPostProcessor branch from b07e9a2 to 3f3bd29 Compare April 23, 2024 06:02
@SOOHYUN-LIM
Copy link
Author

Sorry for the delay.
@ST-DDT As you mentioned, relocating initGrpClientConstructorInjections() would resolve the issue. However, given the potential for bugs due to the order of bean registrations, I proceeded with improvement efforts.

During the initialization of LoadTimeWeaverAware (LTW), I performed the initialization of the grpc client BEAN. This ensures that at that point of initialization, any potential issues arising from other associated beans being registered in unintended orders are prevented.

It has been confirmed that initialization occurs only once. Could you please provide an explanation once again?

Copy link
Collaborator

@ST-DDT ST-DDT left a comment

Choose a reason for hiding this comment

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

Code wise, this looks good to me, but I don't have a project/the time to verify it

@Benji1109
Copy link

@ST-DDT @SOOHYUN-LIM
Is there an estimated timeline for merging this pull request?

@ST-DDT
Copy link
Collaborator

ST-DDT commented May 17, 2024

If somebody else approves it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A feature request or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants