spring-cloud / spring-cloud-netflix

Integration with Netflix OSS components
http://cloud.spring.io/spring-cloud-netflix/
Apache License 2.0
4.87k stars 2.44k forks source link

How to capture the host name of a request routed from Zuul? #2271

Closed indrabasak closed 7 years ago

indrabasak commented 7 years ago

I am using Dalston.SR3 for my Zuul server. The requests are routed using a Ribbon Client with Hystrix. Noticed that a server is allocated in LoadBalancerContext class for a given request. Is there a way to capture this host information? I am trying to keep track of in-flight requests per service ID and host.

ryanjbaxter commented 7 years ago

What do you want to do with the hostname?

indrabasak commented 7 years ago

We have the following requirements:

It will ensure that no in-flight transactions are lost while a host is being rebooted.

ryanjbaxter commented 7 years ago

You might want to look into using a ZuulFilter to capture the information you need.

indrabasak commented 7 years ago

I have looked at ZuulFilter. I have a route and a post filter to keep track of the number of requests and responses per service ID respectively. However, I have no way of retrieving the host information since the HTTP client request takes places inside the RibbonRoutingFilter.

ryanjbaxter commented 7 years ago

Have you tried something like this? https://github.com/spring-cloud/spring-cloud-netflix/blob/master/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/SimpleHostRoutingFilter.java#L232

indrabasak commented 7 years ago

@ryanjbaxter Thanks, I will take a look at it.