I'm currently using Zuul as a reverse proxy, Ribbon as a load balancer and Eureka as service discovery.
Is it possible to get the request's response time using only a Zuul post filter? Can I also get the timestamps of a request entering and leaving the gateway?
i guess thats possible, but it would involve combination of filters, restTemplate interceptor and servlet Filter classes
i wud have given the diagram had their been a plantuml plugin for stackoverflow
idea is , create a preFilter lets say TimeTrackerFilter that would add entry point time stamp "time-start-id" in the request header, a userContextFilter which will intercept all incoming HTTP request and map HTTP request to a userContext class , UserContextClass consists of a getter/setter method that retrieves and stores values from java.lang.ThreadLocal
UserContextHolder.java to store the UserContext in a ThreadLocal variable that is accessible in any method being invoked by the thread processing the user’s request
UserContextINterceptor class to inject the "time-start-id" to any outgoing http based service request executed from a rest template
a post filter that will actually get the time-start-id from request context, calculate time diff and add a new header "time taken " with value being time diff to the response
in case you dont want to see the start time id in other services being called, using only pre and post filter should suffice (ignore userContext, and interceptors in that case)
note: when you want to add a value to the HTTP request headers, you use the RequestContext’s addZuulRequestHeader() method. This method will maintain a separate map of HTTP headers that were added while a request was flowing through the filters with your Zuul server. The data con- tained within the ZuulRequestHeader map will be merged when the target service is invoked by your Zuul server.