Điểm:0

Spring cloud gateway deployed in GCP App engine flexible causes infinite redirect loop

lá cờ mx

I have a two services running in GCP app engine; let's say service A and B, and then I deployed a spring cloud gateway service to route external traffic to these two services based on path predicates. service A and B are deployed in app engine flexible. initially I had the gateway deployed in app engine flexible and it was working perfectly well. because we have some batch services which has response time of more than 10 mins (app engine standard has max-response-timeout of 10 mins), we had to decide to migrate the gateway to app engine flexible.

The gateway service is dockerized and runs in the port 8080. My app.yaml looks like this:

runtime: custom
env: flex

service: beta-gateway

env_variables:
  SPRING_PROFILES_ACTIVE: "beta"

resources:
  cpu: 1
  memory_gb: 2

liveness_check:
  path: "/actuator/health"
  check_interval_sec: 30
  timeout_sec: 4
  failure_threshold: 2
  success_threshold: 2
  initial_delay_sec: 300

readiness_check:
  path: "/actuator/health"
  check_interval_sec: 5
  timeout_sec: 4
  failure_threshold: 2
  success_threshold: 2
  app_start_timeout_sec: 300

The service gets deployed correctly, the actuator endpoints works perfectly, I call /actuator/gateway/routes end point and the routing config looks good (And I route it to the services A and B using the appshot dns uri; Not the best approach should use a service registry in future).

The Problem: The problem is that for any endpoint other that the actuator endpoint, the request goes in to a redirect(302) loop and eventually fails.

What I tried:

As mentioned above, I invoked the /actuator/gateway/routes end point and the routing config looks good. I enabled TRACE logging for gateway and I see that the routing is getting matched correctly to service A or B's appspot dns url. The looks looks like this:

2022-06-02 16:10:22.030 PDT
spring.cloud.gateway.requests tags: [tag(httpMethod=GET),tag(httpStatusCode=302),tag(outcome=REDIRECTION),tag(routeId=web_api_route),tag(routeUri=https://my-service-dot-my-project.appspot.com:443),tag(status=FOUND)]
2022-06-02 16:10:22.029 PDT
NettyWriteResponseFilter start inbound: 2ad7457b, outbound: [67187409-456]
2022-06-02 16:10:22.019 PDT
outbound route: 2ad7457b, inbound: [67187409-456]
2022-06-02 16:10:22.016 PDT
RouteToRequestUrlFilter start
2022-06-02 16:10:22.016 PDT
Sorted gatewayFilterFactories: [[GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.RemoveCachedBodyFilter@1e4d3ce5}, order = -2147483648], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.AdaptCachedBodyGlobalFilter@21d03963}, order = -2147482648], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.NettyWriteResponseFilter@4b5189ac}, order = -1], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.ForwardPathFilter@379614be}, order = 0], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.GatewayMetricsFilter@1e81f160}, order = 0], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter@3ddc6915}, order = 10000], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.config.GatewayNoLoadBalancerClientAutoConfiguration$NoLoadBalancerClientFilter@1acaf3d}, order = 10150], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.WebsocketRoutingFilter@404bbcbd}, order = 2147483646], GatewayFilterAdapter{delegate=org.company.gatewayapi.configs.FilterConfiguration$$Lambda$397/503642634@27508c5d}, [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.NettyRoutingFilter@4f704591}, order = 2147483647], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.ForwardRoutingFilter@704deff2}, order = 2147483647]]
2022-06-02 16:10:22.016 PDT
[67187409-456] Mapped to org.springframework.cloud.gateway.handler.FilteringWebHandler@1f570ea9
2022-06-02 16:10:22.015 PDT
Mapping [Exchange: GET http://my-gateway-dot-my-project.uc.r.appspot.com/favicon.ico] to Route{id='web_api_route', uri=https://my-service-dot-my-project.appspot.com:443, order=0, predicate=Paths: [/**], match trailing slash: true, gatewayFilters=[], metadata={}}
2022-06-02 16:10:22.015 PDT
Route matched: web_api_route
2022-06-02 16:10:22.015 PDT
Pattern "/**" matches against value "/favicon.ico"
2022-06-02 16:10:22.015 PDT
Pattern "[/api/import-auphan/**, /api/import-speedline/**, /api/import-heartland/**, /api/import-clover/**, /api/import-toast/**]" does not match against value "/favicon.ico"
2022-06-02 16:10:22.015 PDT
Pattern "[/api/cloudprint/**]" does not match against value "/favicon.ico"

2022-06-02 16:10:22.015 PDT
Pattern "[/api/jobs/**]" does not match against value "/favicon.ico"
2022-06-02 16:10:22.014 PDT
Pattern "[/api/webhooks/**]" does not match against value "/favicon.ico"

I am not very sure if it is relevant, but I initially did a deployment with network setting specifying port binding

network:
  name: default
  forwarded_ports:
    - 80:8080

I then learned that the binding to 8080 is done be default and removed it.

Any advice will be highly appreciated. Thank you!

Đăng câu trả lời

Hầu hết mọi người không hiểu rằng việc đặt nhiều câu hỏi sẽ mở ra cơ hội học hỏi và cải thiện mối quan hệ giữa các cá nhân. Ví dụ, trong các nghiên cứu của Alison, mặc dù mọi người có thể nhớ chính xác có bao nhiêu câu hỏi đã được đặt ra trong các cuộc trò chuyện của họ, nhưng họ không trực giác nhận ra mối liên hệ giữa câu hỏi và sự yêu thích. Qua bốn nghiên cứu, trong đó những người tham gia tự tham gia vào các cuộc trò chuyện hoặc đọc bản ghi lại các cuộc trò chuyện của người khác, mọi người có xu hướng không nhận ra rằng việc đặt câu hỏi sẽ ảnh hưởng—hoặc đã ảnh hưởng—mức độ thân thiện giữa những người đối thoại.