Skip to content

Commit

Permalink
#624 Added track_remaining setting
Browse files Browse the repository at this point in the history
  • Loading branch information
nastassia-dailidava committed Mar 26, 2024
1 parent 8e902af commit 71be5f8
Showing 1 changed file with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,16 @@ class EnvoyEndpointsFactory(
routeSpec: RouteSpecification,
loadAssignment: ClusterLoadAssignment
): ClusterLoadAssignment {
return if (routeSpec is WeightRouteSpecification) {
ClusterLoadAssignment.newBuilder(loadAssignment)
.clearEndpoints()
.addAllEndpoints(assignWeights(loadAssignment.endpointsList, routeSpec.clusterWeights))
.setClusterName(routeSpec.clusterName)
.build()
} else loadAssignment

val endpointsWithWeights = if (routeSpec is WeightRouteSpecification) {
assignWeights(loadAssignment.endpointsList, routeSpec.clusterWeights)
} else assignWeightsForUnlistedClusters(loadAssignment.endpointsList)

return ClusterLoadAssignment.newBuilder(loadAssignment)
.clearEndpoints()
.addAllEndpoints(endpointsWithWeights)
.setClusterName(routeSpec.clusterName)
.build()
}

private fun assignWeights(
Expand All @@ -103,6 +106,19 @@ class EnvoyEndpointsFactory(
}
}

private fun assignWeightsForUnlistedClusters(
llbEndpointsList: List<LocalityLbEndpoints>
): List<LocalityLbEndpoints> {
return llbEndpointsList
.map {
if (properties.loadBalancing.trafficSplitting.zoneName == it.locality.zone) {
LocalityLbEndpoints.newBuilder(it)
.setLoadBalancingWeight(UInt32Value.of(0))
.build()
} else it
}
}

private fun filterEndpoints(loadAssignment: ClusterLoadAssignment, tag: String): ClusterLoadAssignment? {
var allEndpointMatched = true
val filteredEndpoints = loadAssignment.endpointsList.mapNotNull { localityLbEndpoint ->
Expand Down

0 comments on commit 71be5f8

Please sign in to comment.