Skip to content

Commit 2454f9b

Browse files
authored
feat: Add support for upstream PreconnectPolicy (#7288)
* preconnect policy Signed-off-by: jukie <[email protected]> * adjust fields Signed-off-by: jukie <[email protected]> * lint Signed-off-by: jukie <[email protected]> * descriptions, naming, and perEndpointPercent min vs max Signed-off-by: jukie <[email protected]> * test case and description tweak Signed-off-by: jukie <[email protected]> --------- Signed-off-by: jukie <[email protected]> Signed-off-by: Isaac <[email protected]>
1 parent 4b79591 commit 2454f9b

27 files changed

+2829
-0
lines changed

api/v1alpha1/connection_types.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,45 @@ type BackendConnection struct {
7070
// +optional
7171
// +notImplementedHide
7272
SocketBufferLimit *resource.Quantity `json:"socketBufferLimit,omitempty"`
73+
74+
// Preconnect configures proactive upstream connections to reduce latency by establishing
75+
// connections before they’re needed and avoiding connection establishment overhead.
76+
//
77+
// If unset, Envoy will fetch connections as needed to serve in-flight requests.
78+
//
79+
// +optional
80+
Preconnect *PreconnectPolicy `json:"preconnect,omitempty"`
81+
}
82+
83+
// Preconnect configures proactive upstream connections to avoid
84+
// connection establishment overhead and reduce latency.
85+
type PreconnectPolicy struct {
86+
// PerEndpointPercent configures how many additional connections to maintain per
87+
// upstream endpoint, useful for high-QPS or latency sensitive services. Expressed as a
88+
// percentage of the connections required by active streams
89+
// (e.g. 100 = preconnect disabled, 105 = 1.05x connections per-endpoint, 200 = 2.00×).
90+
//
91+
// Allowed value range is between 100-300. When both PerEndpointPercent and
92+
// PredictivePercent are set, Envoy ensures both are satisfied (max of the two).
93+
//
94+
// +kubebuilder:validation:Minimum=100
95+
// +kubebuilder:validation:Maximum=300
96+
// +optional
97+
PerEndpointPercent *uint32 `json:"perEndpointPercent,omitempty"`
98+
99+
// PredictivePercent configures how many additional connections to maintain
100+
// across the cluster by anticipating which upstream endpoint the load balancer
101+
// will select next, useful for low-QPS services. Relies on deterministic
102+
// loadbalancing and is only supported with Random or RoundRobin.
103+
// Expressed as a percentage of the connections required by active streams
104+
// (e.g. 100 = 1.0 (no preconnect), 105 = 1.05× connections across the cluster, 200 = 2.00×).
105+
//
106+
// Minimum allowed value is 100. When both PerEndpointPercent and PredictivePercent are
107+
// set Envoy ensures both are satisfied per host (max of the two).
108+
//
109+
// +kubebuilder:validation:Minimum=100
110+
// +optional
111+
PredictivePercent *uint32 `json:"predictivePercent,omitempty"`
73112
}
74113

75114
type ConnectionLimit struct {

api/v1alpha1/shared_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,8 @@ type BackendCluster struct {
585585

586586
// ClusterSettings provides the various knobs that can be set to control how traffic to a given
587587
// backend will be configured.
588+
//
589+
// +kubebuilder:validation:XValidation:rule="!((has(self.connection) && has(self.connection.preconnect) && has(self.connection.preconnect.predictivePercent)) && !(has(self.loadBalancer) && has(self.loadBalancer.type) && self.loadBalancer.type in ['Random', 'RoundRobin']))",message="predictivePercent in preconnect policy only works with RoundRobin or Random load balancers"
588590
type ClusterSettings struct {
589591
// LoadBalancer policy to apply when routing traffic from the gateway to
590592
// the backend endpoints. Defaults to `LeastRequest`.

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,41 @@ spec:
191191
For example, 20Mi, 1Gi, 256Ki etc.
192192
Note: that when the suffix is not provided, the value is interpreted as bytes.
193193
x-kubernetes-int-or-string: true
194+
preconnect:
195+
description: |-
196+
Preconnect configures proactive upstream connections to reduce latency by establishing
197+
connections before they’re needed and avoiding connection establishment overhead.
198+
199+
If unset, Envoy will fetch connections as needed to serve in-flight requests.
200+
properties:
201+
perEndpointPercent:
202+
description: |-
203+
PerEndpointPercent configures how many additional connections to maintain per
204+
upstream endpoint, useful for high-QPS or latency sensitive services. Expressed as a
205+
percentage of the connections required by active streams
206+
(e.g. 100 = preconnect disabled, 105 = 1.05x connections per-endpoint, 200 = 2.00×).
207+
208+
Allowed value range is between 100-300. When both PerEndpointPercent and
209+
PredictivePercent are set, Envoy ensures both are satisfied (max of the two).
210+
format: int32
211+
maximum: 300
212+
minimum: 100
213+
type: integer
214+
predictivePercent:
215+
description: |-
216+
PredictivePercent configures how many additional connections to maintain
217+
across the cluster by anticipating which upstream endpoint the load balancer
218+
will select next, useful for low-QPS services. Relies on deterministic
219+
loadbalancing and is only supported with Random or RoundRobin.
220+
Expressed as a percentage of the connections required by active streams
221+
(e.g. 100 = 1.0 (no preconnect), 105 = 1.05× connections across the cluster, 200 = 2.00×).
222+
223+
Minimum allowed value is 100. When both PerEndpointPercent and PredictivePercent are
224+
set Envoy ensures both are satisfied per host (max of the two).
225+
format: int32
226+
minimum: 100
227+
type: integer
228+
type: object
194229
socketBufferLimit:
195230
allOf:
196231
- pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
@@ -2265,6 +2300,12 @@ spec:
22652300
: true'
22662301
- message: either compression or compressor can be set, not both
22672302
rule: '!has(self.compression) || !has(self.compressor)'
2303+
- message: predictivePercent in preconnect policy only works with RoundRobin
2304+
or Random load balancers
2305+
rule: '!((has(self.connection) && has(self.connection.preconnect) &&
2306+
has(self.connection.preconnect.predictivePercent)) && !(has(self.loadBalancer)
2307+
&& has(self.loadBalancer.type) && self.loadBalancer.type in [''Random'',
2308+
''RoundRobin'']))'
22682309
status:
22692310
description: status defines the current status of BackendTrafficPolicy.
22702311
properties:

charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_envoyextensionpolicies.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,41 @@ spec:
302302
For example, 20Mi, 1Gi, 256Ki etc.
303303
Note: that when the suffix is not provided, the value is interpreted as bytes.
304304
x-kubernetes-int-or-string: true
305+
preconnect:
306+
description: |-
307+
Preconnect configures proactive upstream connections to reduce latency by establishing
308+
connections before they’re needed and avoiding connection establishment overhead.
309+
310+
If unset, Envoy will fetch connections as needed to serve in-flight requests.
311+
properties:
312+
perEndpointPercent:
313+
description: |-
314+
PerEndpointPercent configures how many additional connections to maintain per
315+
upstream endpoint, useful for high-QPS or latency sensitive services. Expressed as a
316+
percentage of the connections required by active streams
317+
(e.g. 100 = preconnect disabled, 105 = 1.05x connections per-endpoint, 200 = 2.00×).
318+
319+
Allowed value range is between 100-300. When both PerEndpointPercent and
320+
PredictivePercent are set, Envoy ensures both are satisfied (max of the two).
321+
format: int32
322+
maximum: 300
323+
minimum: 100
324+
type: integer
325+
predictivePercent:
326+
description: |-
327+
PredictivePercent configures how many additional connections to maintain
328+
across the cluster by anticipating which upstream endpoint the load balancer
329+
will select next, useful for low-QPS services. Relies on deterministic
330+
loadbalancing and is only supported with Random or RoundRobin.
331+
Expressed as a percentage of the connections required by active streams
332+
(e.g. 100 = 1.0 (no preconnect), 105 = 1.05× connections across the cluster, 200 = 2.00×).
333+
334+
Minimum allowed value is 100. When both PerEndpointPercent and PredictivePercent are
335+
set Envoy ensures both are satisfied per host (max of the two).
336+
format: int32
337+
minimum: 100
338+
type: integer
339+
type: object
305340
socketBufferLimit:
306341
allOf:
307342
- pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
@@ -1059,6 +1094,13 @@ spec:
10591094
type: object
10601095
type: object
10611096
type: object
1097+
x-kubernetes-validations:
1098+
- message: predictivePercent in preconnect policy only works
1099+
with RoundRobin or Random load balancers
1100+
rule: '!((has(self.connection) && has(self.connection.preconnect)
1101+
&& has(self.connection.preconnect.predictivePercent)) &&
1102+
!(has(self.loadBalancer) && has(self.loadBalancer.type)
1103+
&& self.loadBalancer.type in [''Random'', ''RoundRobin'']))'
10621104
failOpen:
10631105
default: false
10641106
description: |-

0 commit comments

Comments
 (0)