Skip to content

Commit 4872e53

Browse files
authored
fix(gatewayapi): http retry without backoff (#9238)
* fix http retry without backoff Signed-off-by: zirain <zirain2009@gmail.com> * release notes Signed-off-by: zirain <zirain2009@gmail.com> --------- Signed-off-by: zirain <zirain2009@gmail.com>
1 parent 8280f00 commit 4872e53

4 files changed

Lines changed: 89 additions & 10 deletions

File tree

internal/gatewayapi/route.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -542,18 +542,22 @@ func processRouteRetry(irRoute *ir.HTTPRoute, rule *gwapiv1.HTTPRouteRule) {
542542
if retry.Backoff != nil {
543543
backoff, err := time.ParseDuration(string(*retry.Backoff))
544544
if err == nil {
545-
res.PerRetry = &ir.PerRetryPolicy{
546-
BackOff: &ir.BackOffPolicy{
547-
BaseInterval: ir.MetaV1DurationPtr(backoff),
548-
},
545+
if res.PerRetry == nil {
546+
res.PerRetry = &ir.PerRetryPolicy{}
549547
}
550-
// xref: https://gateway-api.sigs.k8s.io/geps/gep-1742/#timeout-values
551-
if rule.Timeouts != nil && rule.Timeouts.BackendRequest != nil {
552-
backendRequestTimeout, err := time.ParseDuration(string(*rule.Timeouts.BackendRequest))
553-
if err == nil {
554-
res.PerRetry.Timeout = ir.MetaV1DurationPtr(backendRequestTimeout)
555-
}
548+
res.PerRetry.BackOff = &ir.BackOffPolicy{
549+
BaseInterval: ir.MetaV1DurationPtr(backoff),
550+
}
551+
}
552+
}
553+
// xref: https://gateway-api.sigs.k8s.io/geps/gep-1742/#timeout-values
554+
if rule.Timeouts != nil && rule.Timeouts.BackendRequest != nil {
555+
backendRequestTimeout, err := time.ParseDuration(string(*rule.Timeouts.BackendRequest))
556+
if err == nil {
557+
if res.PerRetry == nil {
558+
res.PerRetry = &ir.PerRetryPolicy{}
556559
}
560+
res.PerRetry.Timeout = ir.MetaV1DurationPtr(backendRequestTimeout)
557561
}
558562
}
559563
if len(retry.Codes) > 0 {

internal/gatewayapi/testdata/httproute-retry.in.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ httpRoutes:
5454
backendRefs:
5555
- name: service-1
5656
port: 8080
57+
- matches:
58+
- path:
59+
value: "/v2"
60+
retry:
61+
attempts: 3
62+
timeouts:
63+
backendRequest: 3s
64+
backendRefs:
65+
- name: service-1
66+
port: 8080
5767
backendTrafficPolicies:
5868
- apiVersion: gateway.envoyproxy.io/v1alpha1
5969
kind: BackendTrafficPolicy

internal/gatewayapi/testdata/httproute-retry.out.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,16 @@ httpRoutes:
188188
- 500
189189
timeouts:
190190
backendRequest: 3s
191+
- backendRefs:
192+
- name: service-1
193+
port: 8080
194+
matches:
195+
- path:
196+
value: /v2
197+
retry:
198+
attempts: 3
199+
timeouts:
200+
backendRequest: 3s
191201
status:
192202
parents:
193203
- conditions:
@@ -330,6 +340,60 @@ xdsIR:
330340
mergeSlashes: true
331341
port: 10080
332342
routes:
343+
- destination:
344+
metadata:
345+
kind: HTTPRoute
346+
name: httproute-1
347+
namespace: default
348+
name: httproute/default/httproute-1/rule/1
349+
settings:
350+
- addressType: IP
351+
endpoints:
352+
- host: 7.7.7.7
353+
port: 8080
354+
metadata:
355+
kind: Service
356+
name: service-1
357+
namespace: default
358+
sectionName: "8080"
359+
name: httproute/default/httproute-1/rule/1/backend/0
360+
protocol: HTTP
361+
weight: 1
362+
hostname: gateway.envoyproxy.io
363+
isHTTP2: false
364+
metadata:
365+
kind: HTTPRoute
366+
name: httproute-1
367+
namespace: default
368+
policies:
369+
- kind: BackendTrafficPolicy
370+
name: policy-for-route
371+
namespace: default
372+
name: httproute/default/httproute-1/rule/1/match/0/gateway_envoyproxy_io
373+
pathMatch:
374+
distinct: false
375+
name: ""
376+
prefix: /v2
377+
retry:
378+
numRetries: 3
379+
perRetry:
380+
timeout: 3s
381+
traffic:
382+
retry:
383+
numAttemptsPerPriority: 1
384+
numRetries: 5
385+
perRetry:
386+
backOff:
387+
baseInterval: 100ms
388+
maxInterval: 10s
389+
timeout: 250ms
390+
retryOn:
391+
httpStatusCodes:
392+
- 429
393+
- 503
394+
triggers:
395+
- connect-failure
396+
- retriable-status-codes
333397
- destination:
334398
metadata:
335399
kind: HTTPRoute

release-notes/current.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ bug fixes: |
4747
Fixed upstream PROXY protocol clusters to preserve generated HTTP protocol options, including auto protocol detection for Backend TLS.
4848
Fixed EnvoyGateway config hot-reload to apply defaults before validation, so validators always run against a fully-defaulted struct on both the startup and reload paths.
4949
Fixed deduplicate CA certificates in ClientTrafficPolicy mTLS.
50+
Fixed HTTPRoute per-retry timeout (derived from `rule.timeouts.backendRequest`) not being applied when no retry backoff was configured.
5051
Fixed shared global rate limit rules with a `cost` field not working as expected.
5152
5253
# Enhancements that improve performance.

0 commit comments

Comments
 (0)