Skip to content

Commit

Permalink
fix: Configure idle timeout when timeout is set on HTTPRoute (envoypr…
Browse files Browse the repository at this point in the history
…oxy#2708)

* Configure idle timeout when timeout is set on HTTPRoute

Signed-off-by: David Alger <davidmalger@gmail.com>

* Adjust logic

Signed-off-by: David Alger <davidmalger@gmail.com>

---------

Signed-off-by: David Alger <davidmalger@gmail.com>
  • Loading branch information
davidalger authored Feb 27, 2024
1 parent efedbd1 commit 698e6f1
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 3 deletions.
30 changes: 27 additions & 3 deletions internal/xds/translator/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package translator
import (
"errors"
"strings"
"time"

corev3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
routev3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
Expand Down Expand Up @@ -62,7 +63,7 @@ func buildXdsRoute(httpRoute *ir.HTTPRoute) (*routev3.Route, error) {
// If there are invalid backends then a weighted cluster is required for the route
routeAction = buildXdsWeightedRouteAction(httpRoute)
} else {
routeAction = buildXdsRouteAction(httpRoute.Destination.Name)
routeAction = buildXdsRouteAction(httpRoute)
}
if httpRoute.Mirrors != nil {
routeAction.RequestMirrorPolicies = buildXdsRequestMirrorPolicies(httpRoute.Mirrors)
Expand Down Expand Up @@ -207,11 +208,12 @@ func buildXdsStringMatcher(irMatch *ir.StringMatch) *matcherv3.StringMatcher {
return stringMatcher
}

func buildXdsRouteAction(destName string) *routev3.RouteAction {
func buildXdsRouteAction(httpRoute *ir.HTTPRoute) *routev3.RouteAction {
return &routev3.RouteAction{
ClusterSpecifier: &routev3.RouteAction_Cluster{
Cluster: destName,
Cluster: httpRoute.Destination.Name,
},
IdleTimeout: idleTimeout(httpRoute),
}
}

Expand Down Expand Up @@ -239,9 +241,31 @@ func buildXdsWeightedRouteAction(httpRoute *ir.HTTPRoute) *routev3.RouteAction {
Clusters: clusters,
},
},
IdleTimeout: idleTimeout(httpRoute),
}
}

func idleTimeout(httpRoute *ir.HTTPRoute) *durationpb.Duration {
if httpRoute.Timeout != nil && httpRoute.Timeout.HTTP != nil {
if httpRoute.Timeout.HTTP.RequestTimeout != nil {
timeout := time.Hour // Default to 1 hour

// Ensure is not less than the request timeout
if timeout < httpRoute.Timeout.HTTP.RequestTimeout.Duration {
timeout = httpRoute.Timeout.HTTP.RequestTimeout.Duration
}

// Disable idle timeout when request timeout is disabled
if httpRoute.Timeout.HTTP.RequestTimeout.Duration == 0 {
timeout = 0
}

return durationpb.New(timeout)
}
}
return nil
}

func buildXdsRedirectAction(redirection *ir.Redirect) *routev3.RedirectAction {
routeAction := &routev3.RedirectAction{}

Expand Down
22 changes: 22 additions & 0 deletions internal/xds/translator/testdata/in/xds-ir/http-route-timeout.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,25 @@ http:
- endpoints:
- host: "1.2.3.4"
port: 50000
- name: "second-route"
hostname: "*"
timeout:
http:
requestTimeout: 4000s
destination:
name: "second-route-dest"
settings:
- endpoints:
- host: "1.2.3.4"
port: 50001
- name: "third-route"
hostname: "*"
timeout:
http:
requestTimeout: 0s
destination:
name: "third-route-dest"
settings:
- endpoints:
- host: "1.2.3.4"
port: 50002
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,31 @@
outlierDetection: {}
perConnectionBufferLimitBytes: 32768
type: EDS
- commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 10s
dnsLookupFamily: V4_ONLY
edsClusterConfig:
edsConfig:
ads: {}
resourceApiVersion: V3
serviceName: second-route-dest
lbPolicy: LEAST_REQUEST
name: second-route-dest
outlierDetection: {}
perConnectionBufferLimitBytes: 32768
type: EDS
- commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 10s
dnsLookupFamily: V4_ONLY
edsClusterConfig:
edsConfig:
ads: {}
resourceApiVersion: V3
serviceName: third-route-dest
lbPolicy: LEAST_REQUEST
name: third-route-dest
outlierDetection: {}
perConnectionBufferLimitBytes: 32768
type: EDS
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,27 @@
loadBalancingWeight: 1
locality:
region: first-route-dest/backend/0
- clusterName: second-route-dest
endpoints:
- lbEndpoints:
- endpoint:
address:
socketAddress:
address: 1.2.3.4
portValue: 50001
loadBalancingWeight: 1
loadBalancingWeight: 1
locality:
region: second-route-dest/backend/0
- clusterName: third-route-dest
endpoints:
- lbEndpoints:
- endpoint:
address:
socketAddress:
address: 1.2.3.4
portValue: 50002
loadBalancingWeight: 1
loadBalancingWeight: 1
locality:
region: third-route-dest/backend/0
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@
name: first-route
route:
cluster: first-route-dest
idleTimeout: 3600s
timeout: 5s
upgradeConfigs:
- upgradeType: websocket
- match:
prefix: /
name: second-route
route:
cluster: second-route-dest
idleTimeout: 4000s
timeout: 4000s
upgradeConfigs:
- upgradeType: websocket
- match:
prefix: /
name: third-route
route:
cluster: third-route-dest
idleTimeout: 0s
timeout: 0s
upgradeConfigs:
- upgradeType: websocket

0 comments on commit 698e6f1

Please sign in to comment.