Skip to content

Commit

Permalink
Fix Weighted Invalid Backend Logic (envoyproxy#4911)
Browse files Browse the repository at this point in the history
* Fix Weighted Invaid Backend Logic

We were not adding valid clusters where there was a invalid cluster

Regression from envoyproxy#3246

Signed-off-by: Arko Dasgupta <[email protected]>

* add release note

Signed-off-by: Arko Dasgupta <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
  • Loading branch information
arkodg authored Dec 13, 2024
1 parent 1843a61 commit b9ff29c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
36 changes: 15 additions & 21 deletions internal/xds/translator/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,39 +244,33 @@ func buildXdsWeightedRouteAction(backendWeights *ir.BackendWeights, settings []*
Weight: &wrapperspb.UInt32Value{Value: backendWeights.Invalid},
}
weightedClusters = append(weightedClusters, invalidCluster)
return &routev3.RouteAction{
// Intentionally route to a non-existent cluster and return a 500 error when it is not found
ClusterNotFoundResponseCode: routev3.RouteAction_INTERNAL_SERVER_ERROR,
ClusterSpecifier: &routev3.RouteAction_WeightedClusters{
WeightedClusters: &routev3.WeightedCluster{
Clusters: weightedClusters,
},
},
}
}

for _, destinationSetting := range settings {
if destinationSetting.Filters != nil {
if len(destinationSetting.Endpoints) > 0 {
validCluster := &routev3.WeightedCluster_ClusterWeight{
Name: backendWeights.Name,
Weight: &wrapperspb.UInt32Value{Value: *destinationSetting.Weight},
}

if len(destinationSetting.Filters.AddRequestHeaders) > 0 {
validCluster.RequestHeadersToAdd = append(validCluster.RequestHeadersToAdd, buildXdsAddedHeaders(destinationSetting.Filters.AddRequestHeaders)...)
}
if destinationSetting.Filters != nil {
if len(destinationSetting.Filters.AddRequestHeaders) > 0 {
validCluster.RequestHeadersToAdd = append(validCluster.RequestHeadersToAdd, buildXdsAddedHeaders(destinationSetting.Filters.AddRequestHeaders)...)
}

if len(destinationSetting.Filters.RemoveRequestHeaders) > 0 {
validCluster.RequestHeadersToRemove = append(validCluster.RequestHeadersToRemove, destinationSetting.Filters.RemoveRequestHeaders...)
}
if len(destinationSetting.Filters.RemoveRequestHeaders) > 0 {
validCluster.RequestHeadersToRemove = append(validCluster.RequestHeadersToRemove, destinationSetting.Filters.RemoveRequestHeaders...)
}

if len(destinationSetting.Filters.AddResponseHeaders) > 0 {
validCluster.ResponseHeadersToAdd = append(validCluster.ResponseHeadersToAdd, buildXdsAddedHeaders(destinationSetting.Filters.AddResponseHeaders)...)
}
if len(destinationSetting.Filters.AddResponseHeaders) > 0 {
validCluster.ResponseHeadersToAdd = append(validCluster.ResponseHeadersToAdd, buildXdsAddedHeaders(destinationSetting.Filters.AddResponseHeaders)...)
}

if len(destinationSetting.Filters.RemoveResponseHeaders) > 0 {
validCluster.ResponseHeadersToRemove = append(validCluster.ResponseHeadersToRemove, destinationSetting.Filters.RemoveResponseHeaders...)
if len(destinationSetting.Filters.RemoveResponseHeaders) > 0 {
validCluster.ResponseHeadersToRemove = append(validCluster.ResponseHeadersToRemove, destinationSetting.Filters.RemoveResponseHeaders...)
}
}

weightedClusters = append(weightedClusters, validCluster)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
clusters:
- name: invalid-backend-cluster
weight: 1
- name: first-route-dest
weight: 1
1 change: 1 addition & 0 deletions release-notes/current.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ bug fixes: |
Fixed reference grant from EnvoyExtensionPolicy to referenced ext-proc backend not respected
Fixed BackendTrafficPolicy not applying to Gateway Route when Route has a Request Timeout defined
Fixed proxies connected to the secondary EG were not receiving xDS configuration
Fixed traffic splitting when some backends were invalid
# Enhancements that improve performance.
performance improvements: |
Expand Down

0 comments on commit b9ff29c

Please sign in to comment.