From b090182c74a02f485e3d40f4caae9d4b87941569 Mon Sep 17 00:00:00 2001 From: Guy Daich Date: Tue, 30 Jan 2024 21:00:11 -0600 Subject: [PATCH] feat(translator): implement max requests per connection (#2539) implement max requests per connection Signed-off-by: Guy Daich --- ...trafficpolicy-with-circuitbreakers.in.yaml | 2 ++ ...rafficpolicy-with-circuitbreakers.out.yaml | 2 ++ internal/ir/xds.go | 3 +++ internal/ir/zz_generated.deepcopy.go | 5 ++++ internal/xds/translator/cluster.go | 25 +++++++++++++------ .../testdata/in/xds-ir/circuit-breaker.yaml | 1 + .../out/xds-ir/circuit-breaker.clusters.yaml | 7 ++++++ 7 files changed, 37 insertions(+), 8 deletions(-) diff --git a/internal/gatewayapi/testdata/backendtrafficpolicy-with-circuitbreakers.in.yaml b/internal/gatewayapi/testdata/backendtrafficpolicy-with-circuitbreakers.in.yaml index babae4b3650..8bd4067f17b 100644 --- a/internal/gatewayapi/testdata/backendtrafficpolicy-with-circuitbreakers.in.yaml +++ b/internal/gatewayapi/testdata/backendtrafficpolicy-with-circuitbreakers.in.yaml @@ -78,6 +78,7 @@ backendTrafficPolicies: maxConnections: 2048 maxPendingRequests: 1 maxParallelRequests: 4294967295 + maxRequestsPerConnection: 1 - apiVersion: gateway.envoyproxy.io/v1alpha1 kind: BackendTrafficPolicy metadata: @@ -93,3 +94,4 @@ backendTrafficPolicies: maxConnections: 42 maxPendingRequests: 42 maxParallelRequests: 42 + maxRequestsPerConnection: 42 diff --git a/internal/gatewayapi/testdata/backendtrafficpolicy-with-circuitbreakers.out.yaml b/internal/gatewayapi/testdata/backendtrafficpolicy-with-circuitbreakers.out.yaml index 4b17ac19de0..bcb293af7e3 100644 --- a/internal/gatewayapi/testdata/backendtrafficpolicy-with-circuitbreakers.out.yaml +++ b/internal/gatewayapi/testdata/backendtrafficpolicy-with-circuitbreakers.out.yaml @@ -10,6 +10,7 @@ backendTrafficPolicies: maxConnections: 42 maxParallelRequests: 42 maxPendingRequests: 42 + maxRequestsPerConnection: 42 targetRef: group: gateway.networking.k8s.io kind: HTTPRoute @@ -33,6 +34,7 @@ backendTrafficPolicies: maxConnections: 2048 maxParallelRequests: 4294967295 maxPendingRequests: 1 + maxRequestsPerConnection: 1 targetRef: group: gateway.networking.k8s.io kind: Gateway diff --git a/internal/ir/xds.go b/internal/ir/xds.go index 65bad668b15..d06bb0ce000 100644 --- a/internal/ir/xds.go +++ b/internal/ir/xds.go @@ -1313,6 +1313,9 @@ type CircuitBreaker struct { // The maximum number of parallel requests that Envoy will make. MaxParallelRequests *uint32 `json:"maxParallelRequests,omitempty" yaml:"maxParallelRequests,omitempty"` + + // The maximum number of parallel requests that Envoy will make. + MaxRequestsPerConnection *uint32 `json:"maxRequestsPerConnection,omitempty" yaml:"maxRequestsPerConnection,omitempty"` } // HealthCheck defines health check settings diff --git a/internal/ir/zz_generated.deepcopy.go b/internal/ir/zz_generated.deepcopy.go index f6b57c02a88..882c6b125f0 100644 --- a/internal/ir/zz_generated.deepcopy.go +++ b/internal/ir/zz_generated.deepcopy.go @@ -161,6 +161,11 @@ func (in *CircuitBreaker) DeepCopyInto(out *CircuitBreaker) { *out = new(uint32) **out = **in } + if in.MaxRequestsPerConnection != nil { + in, out := &in.MaxRequestsPerConnection, &out.MaxRequestsPerConnection + *out = new(uint32) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CircuitBreaker. diff --git a/internal/xds/translator/cluster.go b/internal/xds/translator/cluster.go index fbbdb0029f8..126534794fd 100644 --- a/internal/xds/translator/cluster.go +++ b/internal/xds/translator/cluster.go @@ -324,8 +324,9 @@ func buildTypedExtensionProtocolOptions(args *xdsClusterArgs) map[string]*anypb. } } - requiresCommonHTTPOptions := args.timeout != nil && args.timeout.HTTP != nil && - (args.timeout.HTTP.MaxConnectionDuration != nil || args.timeout.HTTP.ConnectionIdleTimeout != nil) + requiresCommonHTTPOptions := (args.timeout != nil && args.timeout.HTTP != nil && + (args.timeout.HTTP.MaxConnectionDuration != nil || args.timeout.HTTP.ConnectionIdleTimeout != nil)) || + (args.circuitBreaker != nil && args.circuitBreaker.MaxRequestsPerConnection != nil) requiresHTTP1Options := args.http1Settings != nil && (args.http1Settings.EnableTrailers || args.http1Settings.PreserveHeaderCase) @@ -338,14 +339,22 @@ func buildTypedExtensionProtocolOptions(args *xdsClusterArgs) map[string]*anypb. if requiresCommonHTTPOptions { protocolOptions.CommonHttpProtocolOptions = &corev3.HttpProtocolOptions{} - if args.timeout.HTTP.ConnectionIdleTimeout != nil { - protocolOptions.CommonHttpProtocolOptions.IdleTimeout = - durationpb.New(args.timeout.HTTP.ConnectionIdleTimeout.Duration) + if args.timeout != nil && args.timeout.HTTP != nil { + if args.timeout.HTTP.ConnectionIdleTimeout != nil { + protocolOptions.CommonHttpProtocolOptions.IdleTimeout = + durationpb.New(args.timeout.HTTP.ConnectionIdleTimeout.Duration) + } + + if args.timeout.HTTP.MaxConnectionDuration != nil { + protocolOptions.CommonHttpProtocolOptions.MaxConnectionDuration = + durationpb.New(args.timeout.HTTP.MaxConnectionDuration.Duration) + } } - if args.timeout.HTTP.MaxConnectionDuration != nil { - protocolOptions.CommonHttpProtocolOptions.MaxConnectionDuration = - durationpb.New(args.timeout.HTTP.MaxConnectionDuration.Duration) + if args.circuitBreaker != nil && args.circuitBreaker.MaxRequestsPerConnection != nil { + protocolOptions.CommonHttpProtocolOptions.MaxRequestsPerConnection = &wrapperspb.UInt32Value{ + Value: *args.circuitBreaker.MaxRequestsPerConnection, + } } } diff --git a/internal/xds/translator/testdata/in/xds-ir/circuit-breaker.yaml b/internal/xds/translator/testdata/in/xds-ir/circuit-breaker.yaml index caf0d373f89..cb693fc583e 100644 --- a/internal/xds/translator/testdata/in/xds-ir/circuit-breaker.yaml +++ b/internal/xds/translator/testdata/in/xds-ir/circuit-breaker.yaml @@ -14,6 +14,7 @@ http: maxConnections: 1 maxPendingRequests: 1 maxParallelRequests: 1 + maxRequestsPerConnection: 10 destination: name: "first-route-dest" settings: diff --git a/internal/xds/translator/testdata/out/xds-ir/circuit-breaker.clusters.yaml b/internal/xds/translator/testdata/out/xds-ir/circuit-breaker.clusters.yaml index 59a43e91a45..9bae95db486 100644 --- a/internal/xds/translator/testdata/out/xds-ir/circuit-breaker.clusters.yaml +++ b/internal/xds/translator/testdata/out/xds-ir/circuit-breaker.clusters.yaml @@ -17,3 +17,10 @@ outlierDetection: {} perConnectionBufferLimitBytes: 32768 type: EDS + typedExtensionProtocolOptions: + envoy.extensions.upstreams.http.v3.HttpProtocolOptions: + '@type': type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions + commonHttpProtocolOptions: + maxRequestsPerConnection: 10 + explicitHttpConfig: + httpProtocolOptions: {}