Repository: kumahq/kuma
Pull request #1275 (2020-12-03 18:38:49)

chore(*) disable timeout on route level
### Summary

Disable Route timeout to ensure longlived and streaming connections
https://www.envoyproxy.io/docs/envoy/latest/faq/configuration/timeouts#route-timeouts

This shall be replaced by a proper timeout management resource.

### Documentation

- [ ] Link to the website [documentation PR](https://github.com/kumahq/kuma-website/pull/XXX)



Patch:
diff --git a/pkg/api-server/index_endpoints.go b/pkg/api-server/index_endpoints.go
index dab04e1de..cd9ce796b 100644
--- a/pkg/api-server/index_endpoints.go
+++ b/pkg/api-server/index_endpoints.go
@@ -9,20 +9,29 @@ import (
 	kuma_version "github.com/kumahq/kuma/pkg/version"
 )
 
+var APIIndexResponseFn = kumaAPIIndexResponse
+
 func addIndexWsEndpoints(ws *restful.WebService) error {
-	hostname, err := os.Hostname()
+	response, err := APIIndexResponseFn()
 	if err != nil {
 		return err
 	}
 	ws.Route(ws.GET("/").To(func(req *restful.Request, resp *restful.Response) {
-		response := types.IndexResponse{
-			Hostname: hostname,
-			Tagline:  kuma_version.Product,
-			Version:  kuma_version.Build.Version,
-		}
 		if err := resp.WriteAsJson(response); err != nil {
 			log.Error(err, "Could not write the index response")
 		}
 	}))
 	return nil
 }
+
+func kumaAPIIndexResponse() (interface{}, error) {
+	hostname, err := os.Hostname()
+	if err != nil {
+		return nil, err
+	}
+	return types.IndexResponse{
+		Hostname: hostname,
+		Tagline:  kuma_version.Product,
+		Version:  kuma_version.Build.Version,
+	}, nil
+}
diff --git a/pkg/xds/envoy/routes/default_route_configurer.go b/pkg/xds/envoy/routes/default_route_configurer.go
index b077caf1c..017d129fe 100644
--- a/pkg/xds/envoy/routes/default_route_configurer.go
+++ b/pkg/xds/envoy/routes/default_route_configurer.go
@@ -1,6 +1,7 @@
 package routes
 
 import (
+	"github.com/golang/protobuf/ptypes/duration"
 	"github.com/golang/protobuf/ptypes/wrappers"
 
 	envoy_route "github.com/envoyproxy/go-control-plane/envoy/api/v2/route"
@@ -43,7 +44,11 @@ type RouteConfigurer struct {
 }
 
 func (c RouteConfigurer) routeAction() *envoy_route.RouteAction {
-	routeAction := envoy_route.RouteAction{}
+	routeAction := envoy_route.RouteAction{
+		// This disable the timeout of the response. As Envoy docs suggest
+		// disabling this solves problems with long lived and streaming requests.
+		Timeout: &duration.Duration{Seconds: 0, Nanos: 0},
+	}
 	if len(c.subsets) == 1 {
 		routeAction.ClusterSpecifier = &envoy_route.RouteAction_Cluster{
 			Cluster: c.subsets[0].ClusterName,


Test patch:
diff --git a/pkg/xds/envoy/listeners/http_inbound_route_configurer_test.go b/pkg/xds/envoy/listeners/http_inbound_route_configurer_test.go
index 86827688f..d650a0179 100644
--- a/pkg/xds/envoy/listeners/http_inbound_route_configurer_test.go
+++ b/pkg/xds/envoy/listeners/http_inbound_route_configurer_test.go
@@ -76,6 +76,7 @@ var _ = Describe("HttpInboundRouteConfigurer", func() {
                           prefix: /
                         route:
                           cluster: localhost:8080
+                          timeout: 0s
                   statPrefix: localhost_8080
 `,
 		}),
diff --git a/pkg/xds/envoy/listeners/http_outbound_route_configurer_test.go b/pkg/xds/envoy/listeners/http_outbound_route_configurer_test.go
index fb9934350..82bc6decc 100644
--- a/pkg/xds/envoy/listeners/http_outbound_route_configurer_test.go
+++ b/pkg/xds/envoy/listeners/http_outbound_route_configurer_test.go
@@ -112,6 +112,7 @@ var _ = Describe("HttpOutboundRouteConfigurer", func() {
                               name: backend
                               weight: 80
                             totalWeight: 100
+                          timeout: 0s
                   statPrefix: "127_0_0_1_18080"
             name: outbound:127.0.0.1:18080
             trafficDirection: OUTBOUND`,
diff --git a/pkg/xds/envoy/routes/default_route_configurer_test.go b/pkg/xds/envoy/routes/default_route_configurer_test.go
index 092de78e5..2224bfef8 100644
--- a/pkg/xds/envoy/routes/default_route_configurer_test.go
+++ b/pkg/xds/envoy/routes/default_route_configurer_test.go
@@ -44,6 +44,7 @@ var _ = Describe("DefaultRouteConfigurer", func() {
                 prefix: /
               route:
                 cluster: backend
+                timeout: 0s
 `,
 		}),
 		Entry("basic VirtualHost with weighted destination clusters", testCase{
@@ -71,6 +72,7 @@ var _ = Describe("DefaultRouteConfigurer", func() {
                     name: backend
                     weight: 70
                   totalWeight: 100
+                timeout: 0s
 `,
 		}),
 		Entry("basic VirtualHost with weighted destination clusters with totalWeight less than 100", testCase{
@@ -98,6 +100,7 @@ var _ = Describe("DefaultRouteConfigurer", func() {
                     name: backend
                     weight: 60
                   totalWeight: 90
+                timeout: 0s
 `,
 		}),
 	)
diff --git a/pkg/xds/generator/testdata/inbound-proxy/3-envoy-config.golden.yaml b/pkg/xds/generator/testdata/inbound-proxy/3-envoy-config.golden.yaml
index b23daec07..d2bb5932e 100644
--- a/pkg/xds/generator/testdata/inbound-proxy/3-envoy-config.golden.yaml
+++ b/pkg/xds/generator/testdata/inbound-proxy/3-envoy-config.golden.yaml
@@ -141,6 +141,7 @@ resources:
                             prefix: /
                           route:
                             cluster: localhost:8080
+                            timeout: 0s
                 statPrefix: localhost_8080
           transportSocket:
             name: envoy.transport_sockets.tls
@@ -270,6 +271,7 @@ resources:
                             prefix: /
                           route:
                             cluster: localhost:8080
+                            timeout: 0s
                 statPrefix: localhost_8080
           transportSocket:
             name: envoy.transport_sockets.tls
diff --git a/pkg/xds/generator/testdata/inbound-proxy/4-envoy-config.golden.yaml b/pkg/xds/generator/testdata/inbound-proxy/4-envoy-config.golden.yaml
index ab1d492f5..0013801fa 100644
--- a/pkg/xds/generator/testdata/inbound-proxy/4-envoy-config.golden.yaml
+++ b/pkg/xds/generator/testdata/inbound-proxy/4-envoy-config.golden.yaml
@@ -145,6 +145,7 @@ resources:
                             prefix: /
                           route:
                             cluster: localhost:8080
+                            timeout: 0s
                 statPrefix: localhost_8080
           transportSocket:
             name: envoy.transport_sockets.tls
@@ -278,6 +279,7 @@ resources:
                             prefix: /
                           route:
                             cluster: localhost:8080
+                            timeout: 0s
                 statPrefix: localhost_8080
           transportSocket:
             name: envoy.transport_sockets.tls
diff --git a/pkg/xds/generator/testdata/outbound-proxy/03.envoy.golden.yaml b/pkg/xds/generator/testdata/outbound-proxy/03.envoy.golden.yaml
index 7affb20a1..6c76b3b44 100644
--- a/pkg/xds/generator/testdata/outbound-proxy/03.envoy.golden.yaml
+++ b/pkg/xds/generator/testdata/outbound-proxy/03.envoy.golden.yaml
@@ -269,6 +269,7 @@ resources:
                             prefix: /
                           route:
                             cluster: api-http
+                            timeout: 0s
                 statPrefix: api-http
       name: outbound:127.0.0.1:40001
       trafficDirection: OUTBOUND
@@ -329,6 +330,7 @@ resources:
                             prefix: /
                           route:
                             cluster: api-http2
+                            timeout: 0s
                 statPrefix: api-http2
       name: outbound:127.0.0.1:40003
       trafficDirection: OUTBOUND
@@ -367,6 +369,7 @@ resources:
                             prefix: /
                           route:
                             cluster: api-grpc
+                            timeout: 0s
                 statPrefix: api-grpc
       name: outbound:127.0.0.1:40004
       trafficDirection: OUTBOUND
diff --git a/pkg/xds/generator/testdata/outbound-proxy/04.envoy.golden.yaml b/pkg/xds/generator/testdata/outbound-proxy/04.envoy.golden.yaml
index e65cae484..e017342a2 100644
--- a/pkg/xds/generator/testdata/outbound-proxy/04.envoy.golden.yaml
+++ b/pkg/xds/generator/testdata/outbound-proxy/04.envoy.golden.yaml
@@ -404,6 +404,7 @@ resources:
                             prefix: /
                           route:
                             cluster: api-http
+                            timeout: 0s
                 statPrefix: api-http
       name: outbound:127.0.0.1:40001
       trafficDirection: OUTBOUND
diff --git a/pkg/xds/generator/testdata/outbound-proxy/05.envoy.golden.yaml b/pkg/xds/generator/testdata/outbound-proxy/05.envoy.golden.yaml
index 8604adc21..3d4f67c37 100644
--- a/pkg/xds/generator/testdata/outbound-proxy/05.envoy.golden.yaml
+++ b/pkg/xds/generator/testdata/outbound-proxy/05.envoy.golden.yaml
@@ -63,6 +63,7 @@ resources:
                               filterMetadata:
                                 envoy.lb:
                                   kuma.io/protocol: http
+                            timeout: 0s
                 statPrefix: es
       name: outbound:127.0.0.1:18081
       trafficDirection: OUTBOUND
diff --git a/pkg/xds/generator/testdata/outbound-proxy/06.envoy.golden.yaml b/pkg/xds/generator/testdata/outbound-proxy/06.envoy.golden.yaml
index 581e7b40a..83c673d52 100644
--- a/pkg/xds/generator/testdata/outbound-proxy/06.envoy.golden.yaml
+++ b/pkg/xds/generator/testdata/outbound-proxy/06.envoy.golden.yaml
@@ -64,6 +64,7 @@ resources:
                               filterMetadata:
                                 envoy.lb:
                                   kuma.io/protocol: http2
+                            timeout: 0s
                 statPrefix: es2
       name: outbound:127.0.0.1:18082
       trafficDirection: OUTBOUND
diff --git a/pkg/xds/generator/testdata/profile-source/3-envoy-config.golden.yaml b/pkg/xds/generator/testdata/profile-source/3-envoy-config.golden.yaml
index 15c389018..67217c581 100644
--- a/pkg/xds/generator/testdata/profile-source/3-envoy-config.golden.yaml
+++ b/pkg/xds/generator/testdata/profile-source/3-envoy-config.golden.yaml
@@ -192,6 +192,7 @@ resources:
                             prefix: /
                           route:
                             cluster: localhost:8080
+                            timeout: 0s
                 statPrefix: localhost_8080
           transportSocket:
             name: envoy.transport_sockets.tls
diff --git a/pkg/xds/generator/testdata/profile-source/4-envoy-config.golden.yaml b/pkg/xds/generator/testdata/profile-source/4-envoy-config.golden.yaml
index 397b1b1c2..89cb53ca1 100644
--- a/pkg/xds/generator/testdata/profile-source/4-envoy-config.golden.yaml
+++ b/pkg/xds/generator/testdata/profile-source/4-envoy-config.golden.yaml
@@ -214,6 +214,7 @@ resources:
                             prefix: /
                           route:
                             cluster: localhost:8080
+                            timeout: 0s
                 statPrefix: localhost_8080
           transportSocket:
             name: envoy.transport_sockets.tls