spring-cloud-gateway icon indicating copy to clipboard operation
spring-cloud-gateway copied to clipboard

Setting timeouts via metadata per-route doesn't work with Spring Cloud kubernetes discovery

Open claitonp opened this issue 2 years ago • 1 comments

Hi,

In upgrading to Spring Cloud Gateway 3.1.1 version, I'm having problems with 'per-route timeouts' settings, 'connect-timeout' and 'response-timeout' metadata values always return as String in SCG, I use discovery Spring Cloud Kubernetes.

Kubernetes labels and annotations are by definition String, I made several attempts and could not set the metadata values as number.

apiVersion: v1
kind: Service
metadata:
  annotations:
    meta.helm.sh/release-name: app
  creationTimestamp: "2022-04-18T14:55:39Z"
  labels:
    connect-timeout: "2000"
    response-timeout: "10000"

The change that could be the source of the problem, a condition '&& responseTimeoutAttr instanceof Number' was added in the NettyRoutingFilter class:

private Duration getResponseTimeout(Route route) {
	Object responseTimeoutAttr = route.getMetadata().get(RESPONSE_TIMEOUT_ATTR);	
	if (responseTimeoutAttr != null && responseTimeoutAttr instanceof Number) {
	...
	}
}

Commit: https://github.com/spring-cloud/spring-cloud-gateway/commit/9efafe8d9cb83c3e3f5bba40064f89e992d814a2 (Disable per route response timeout with negative number)

claitonp avatar May 09 '22 17:05 claitonp

This pull request will resolve the issue: pull request

claitonp avatar May 19 '22 11:05 claitonp

Hi, It would be good to make this simple adjustment, as it is harming those who use Spring Cloud Kubernetes discovery with the labels.

In NettyRoutingFilter.java

Today: if (responseTimeoutAttr != null && responseTimeoutAttr instanceof Number) { ...

For: if (responseTimeoutAttr != null && responseTimeoutAttr.toString().matches("[0-9]+")) { ...

As labels in kubernetes are by nature 'String' the condition is not satisfied.

claitonp avatar Feb 26 '23 13:02 claitonp

Hi, I'm having the same problem with per-route timeouts. Due to this problem it's not possible to set a specific timeout per route, I'm having to have a single timeout value for all routes.

rafaelpivetta avatar Feb 28 '23 18:02 rafaelpivetta