Skip to content

Commit

Permalink
feat(translator): implement max requests per connection (envoyproxy#2539
Browse files Browse the repository at this point in the history
)

implement max requests per connection

Signed-off-by: Guy Daich <guy.daich@sap.com>
  • Loading branch information
guydc authored Jan 31, 2024
1 parent 241e838 commit b090182
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ backendTrafficPolicies:
maxConnections: 2048
maxPendingRequests: 1
maxParallelRequests: 4294967295
maxRequestsPerConnection: 1
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: BackendTrafficPolicy
metadata:
Expand All @@ -93,3 +94,4 @@ backendTrafficPolicies:
maxConnections: 42
maxPendingRequests: 42
maxParallelRequests: 42
maxRequestsPerConnection: 42
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ backendTrafficPolicies:
maxConnections: 42
maxParallelRequests: 42
maxPendingRequests: 42
maxRequestsPerConnection: 42
targetRef:
group: gateway.networking.k8s.io
kind: HTTPRoute
Expand All @@ -33,6 +34,7 @@ backendTrafficPolicies:
maxConnections: 2048
maxParallelRequests: 4294967295
maxPendingRequests: 1
maxRequestsPerConnection: 1
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
Expand Down
3 changes: 3 additions & 0 deletions internal/ir/xds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions internal/ir/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 17 additions & 8 deletions internal/xds/translator/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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,
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ http:
maxConnections: 1
maxPendingRequests: 1
maxParallelRequests: 1
maxRequestsPerConnection: 10
destination:
name: "first-route-dest"
settings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}

0 comments on commit b090182

Please sign in to comment.