spring-cloud-gateway
spring-cloud-gateway copied to clipboard
Setting timeouts via metadata per-route doesn't work with Spring Cloud kubernetes discovery
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)
This pull request will resolve the issue: pull request
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.
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.