Skip to content

Commit

Permalink
NET-6943 - Replace usage of deprecated Envoy field envoy.config.route…
Browse files Browse the repository at this point in the history
…r.v3.WeightedCluster.total_weight. (#20011)
  • Loading branch information
jmurret committed Jan 2, 2024
1 parent 2d9c8c4 commit 642330f
Show file tree
Hide file tree
Showing 16 changed files with 21 additions and 40 deletions.
3 changes: 3 additions & 0 deletions .changelog/20011.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
connect: replace usage of deprecated Envoy field `envoy.config.router.v3.WeightedCluster.total_weight`.
```
12 changes: 1 addition & 11 deletions agent/xds/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,6 @@ func (s *ResourceGenerator) makeRouteActionForSplitter(
forMeshGateway bool,
) (*envoy_route_v3.Route_Route, error) {
clusters := make([]*envoy_route_v3.WeightedCluster_ClusterWeight, 0, len(splits))
totalWeight := 0
for _, split := range splits {
nextNode := chain.Nodes[split.NextNode]

Expand All @@ -967,7 +966,6 @@ func (s *ResourceGenerator) makeRouteActionForSplitter(
// The smallest representable weight is 1/10000 or .01% but envoy
// deals with integers so scale everything up by 100x.
weight := int(split.Weight * 100)
totalWeight += weight
cw := &envoy_route_v3.WeightedCluster_ClusterWeight{
Weight: makeUint32Value(weight),
Name: clusterName,
Expand All @@ -983,19 +981,11 @@ func (s *ResourceGenerator) makeRouteActionForSplitter(
return nil, fmt.Errorf("number of clusters in splitter must be > 0; got %d", len(clusters))
}

envoyWeightScale := 10000
if envoyWeightScale < totalWeight {
clusters[0].Weight.Value += uint32(totalWeight - envoyWeightScale)
} else {
clusters[0].Weight.Value += uint32(envoyWeightScale - totalWeight)
}

return &envoy_route_v3.Route_Route{
Route: &envoy_route_v3.RouteAction{
ClusterSpecifier: &envoy_route_v3.RouteAction_WeightedClusters{
WeightedClusters: &envoy_route_v3.WeightedCluster{
Clusters: clusters,
TotalWeight: makeUint32Value(envoyWeightScale), // scaled up 100%
Clusters: clusters,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"name": "v2.db.default.dc2.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 5000
}
],
"totalWeight": 10000
]
}
}
}
Expand All @@ -40,4 +39,4 @@
],
"typeUrl": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration",
"nonce": "00000001"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@
],
"typeUrl": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration",
"nonce": "00000001"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,7 @@
"name": "lil-bit-side.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 50
}
],
"totalWeight": 10000
]
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@
}
]
}
],
"totalWeight": 10000
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@
],
"typeUrl": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration",
"nonce": "00000001"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"name": "v2.db.default.dc2.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 5000
}
],
"totalWeight": 10000
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,7 @@
"name": "lil-bit-side.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 50
}
],
"totalWeight": 10000
]
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,7 @@
"name": "lil-bit-side.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 50
}
],
"totalWeight": 10000
]
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@
}
]
}
],
"totalWeight": 10000
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"name": "exported~db.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 4000
}
],
"totalWeight": 10000
]
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"name": "v2.db.default.dc2.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 5000
}
],
"totalWeight": 10000
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,7 @@
"name": "lil-bit-side.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 50
}
],
"totalWeight": 10000
]
}
}
},
Expand Down Expand Up @@ -417,4 +416,4 @@
],
"typeUrl": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration",
"nonce": "00000001"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,7 @@
"name": "lil-bit-side.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul",
"weight": 50
}
],
"totalWeight": 10000
]
}
}
},
Expand Down Expand Up @@ -416,4 +415,4 @@
],
"typeUrl": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration",
"nonce": "00000001"
}
}
3 changes: 1 addition & 2 deletions troubleshoot/proxy/testdata/upstreams/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@
"name": "backend2.default.dc1.internal.domain.consul",
"weight": 5000
}
],
"total_weight": 10000
]
}
}
}
Expand Down

0 comments on commit 642330f

Please sign in to comment.