本文总结Spring Cloud Gateway的排错、调试技巧。

第一式:Actuator监控端点

借助Actuator的监控端点,可分析全局过滤器、过滤器工厂、路由详情。详见:Spring Cloud Gateway监控

第二式:日志

加日志,按需将如下包的日志级别设置成 debug 或 trace ,总有一款对你有用。

  • org.springframework.cloud.gateway
  • org.springframework.http.server.reactive
  • org.springframework.web.reactive
  • org.springframework.boot.autoconfigure.web
  • reactor.netty
  • redisratelimiter
    配置示例:
logging:
level:
org.springframework.cloud.gateway: trace

第三式:Wiretap【从Greenwich SR3及更高版本才会支持】

Reactor Netty HttpClient 以及 HttpServer 可启用 Wiretap 。将reactor.netty 包设置成 debug 或 trace ,然后设置如下属性:

  • spring.cloud.gateway.httpserver.wiretap=true
  • spring.cloud.gateway.httpclient.wiretap=true
    分别开启HttpServer及HttpClient的Wiretap。

然后,就可以分析日志啦。

TIPS

相关Issue: https://github.com/spring-cloud/spring-cloud-gateway/issues/1194

wiretap其实是Reactor Netty的概念,作用是,打印对端之间的流量详情,相关文档:

HttpClient的Wire Logger

HttpServer的Wire Logger

Q.E.D.


爱调味品的大哥