Reputation: 61
Hi I have configured Zuul (spring-cloud-netflix) to work with ribbon.
I was able to see which request is coming to zuul and what requests is being sent to related endpoint in the logs before adding the ribbon to it.
At some point I have added ribbon & load balancing feature.
Now I can not see outgoing req(from zuul to real endpoint) request in the logs. Things are working fine . There is no error . But I need to know/log incomingReq->outgoingReq information inside the Zuul proxy. I mean I need the route path information (especially with ip information) .
Is there any way to see/get this information ? I want to log it in a filter if possible ?
Upvotes: 1
Views: 1429
Reputation: 61
I found a way to do it something like that .. Hope it helps somebody else too.
import com.netflix.client.IResponse;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.net.URI;
@Component
public class PostFilter extends ZuulFilter {
Logger auditLogger = LoggerFactory.getLogger("auditLogger");
@Override
public String filterType() {
return "post";
}
@Override
public int filterOrder() {
return 1;
}
@Override
public boolean shouldFilter() {
return true;
}
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
URI ribbonResponseURI = ((IResponse) ctx.get("ribbonResponse")).getRequestedURI();
AuditBean auditBean = (AuditBean) RequestContext.getCurrentContext().get("auditBean");
auditBean.setIncomingURI(ctx.getRequest().getRequestURL().toString());
auditBean.setOutgoingURI(ribbonResponseURI.toString());
auditLogger.info("{}", auditBean.toJson());
return null;
}
}
Upvotes: 2