grpc-spring icon indicating copy to clipboard operation
grpc-spring copied to clipboard

How to access the managed channels?

Open hsalem7 opened this issue 3 years ago • 8 comments

Hello, I am trying to access the managed channels in order to warm up the DNS resolver.

I mean I want the channel to resolve the service host after the application is started. But I couldn't access the managed channels in any way!

So is there a way to do so? or is there any workaround?

Many thanks

hsalem7 avatar Sep 12 '22 22:09 hsalem7

Currently, there is no way to access the ManagaedChannels directly. It is planned though.

Why do you wish to warmup the dns resolvers?

One way to do that (per channel) is to send a request to the channel. E.g. a health request.

ST-DDT avatar Sep 13 '22 08:09 ST-DDT

That is a good idea. But the problem is that the service doesn't have health check methods! (Unless there is another way 🙈 ) And the actual endpoints require some user context that I don't want to access during the service startup.

hsalem7 avatar Sep 13 '22 13:09 hsalem7

You dont have to use an existing method/valid input. Just create the stub call it and discard the result (error). Like normal http you can call any url and the browser will resolve the hostname/show an error. That way, the dns is initialized.

ST-DDT avatar Sep 13 '22 13:09 ST-DDT

The problem is that we have many interceptors that check some data and I don't want to bypass those, so if I provide the wrong data, the call will not happen, that is why it is not an option for me.

And regarding your statement:

Currently, there is no way to access the ManagaedChannels directly. It is planned though

Can I help somehow with that implementation? I can dedicate time to that.

hsalem7 avatar Sep 14 '22 09:09 hsalem7

There are two parts that I would like to do.

  • Extract the injection logic from the bean post processor, so that it can be injected itself
    • The injector is also responsible to apply the interceptors, removing this task from the channel factory
    • If possible, it should also split the injection step from channel factory (using a lazy forwarding channel; that way there is no longer a dependency between the InProcessChannel and Server)
  • Replace the different ManagedChannel/ServerFactories with something that are just use grpc native builder factory + configurer to build the instance, all configuration logic should be moved from the factories to configurers

From an architectural perspective it should look somewhat like this:

grafik

Which part do you wish to tackle?

  • Split GrpcClientBeanPostProcessor into GrpcClientInjector
  • Rewrite ManagedChannelFactory

ST-DDT avatar Sep 14 '22 18:09 ST-DDT

I would start with the first one Split GrpcClientBeanPostProcessor into GrpcClientInjector

hsalem7 avatar Sep 15 '22 04:09 hsalem7

Awesome. The public API of the injector should be somewhat like this:

  • <T> T get(String name, Class<T> type)
  • <T> T get(@GrpcClient client, Class<T> type)

Where T is the type of the field and @GrpcClient the annotation on that field. The name variant is a simplification for manual use where you dont want to set any additional options. Feel free to adjust the method signature to your liking/implementation needs.

ST-DDT avatar Sep 15 '22 07:09 ST-DDT

My case is integration test. I need to inspect some behaviour and signup to ManagedChannel.notifyWhenStateChanged. I very need this feature.

slogic avatar Feb 15 '23 10:02 slogic