I'd like to track every requests' response time in some load balancing tests and I found that I can add a listener on LoadBalancerCommand. But the LoadBalancerCommand was instanced by its Builder and the Builder was called in AbstractLoadBalancerAwareClient. The AbstractLoadBalancerAwareClient has prepared a method named customizeLoadBalancerCommandBuilder to add additional configure LoadBalancerCommand.
I have checked one of the sub-classes named AbstractLoadBalancingClient. In this class, it has overrided the method customizeLoadBalancerCommandBuilder which added a ServerLocatorKey.
I found the sub-class RibbonLoadBalancingHttpClient which extends AbstractLoadBalancingClient was instanced in HttpClientRibbonConfiguration.ribbonLoadBalancingHttpClient. This bean will be instanced when there is no Beans with class AbstractLoadBalancerAwareClient. But if I write my own configure class to instance my LoadBalancingClient, I will get an exception said that there is no bean with type IClientConfig. After tracking the call stack, I found the method HttpClientRibbonConfiguration.ribbonLoadBalancingHttpClient was call in SpringClientFactory. I also tried to create my HttpClientRibbonCommandFactory but I got an error NoSuchMethodException said there is no method MyRibbonLoadBalancingHttpClient.
I want to know if there is any interface that I can track ervery requests' response time or how can I add a custom LoadBalancingHttpClient that can add listeners on the LoadBalanceCommand to track the time.
Comment From: spencergibb
We don't use ribbonLoadBalancingHttpClient and don't provide any support for it. There is a RibbonStatsRecorder that is used by RetryableRibbonLoadBalancingHttpClient and RetryableOkHttpLoadBalancingClient
Comment From: jerry-yuan
Thanks for your reply. I have checked the RibbonStatsRecorder and unfortunately it doesn't support for tracking requests ether (It was called by HttpClient directly and can not be replaced by its sub-class). But after checked the beans organized by Spring Cloud, I found the objects not found is managed by a sub-context and with some efforts I put my RibbonLoadBalancingHttpClient into sub-context and found it work well. After override the methods, I have successfully add an ExecutionListener to the LoadBalancingCommand.
By the way, there probaly some bugs in server statistic modules when the ribbon works with Spring Cloud Gateway.