Skip to content

Commit

Permalink
#624 Set flat priority only for services with traffic splitting (adde…
Browse files Browse the repository at this point in the history
…d condition and condition for cluster)
  • Loading branch information
nastassia-dailidava committed Apr 5, 2024
1 parent 0cf42ea commit 6e820c8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ fun shouldEnableTrafficSplitting(
currentZone: String,
properties: SnapshotProperties
): Boolean {
return properties.loadBalancing.trafficSplitting.zonesAllowingTrafficSplitting.contains(currentZone) &&
acceptableEndpointsRatioBetweenZones(llbEndpointsList, currentZone, properties)
return properties.loadBalancing.trafficSplitting.zonesAllowingTrafficSplitting.contains(currentZone) &&
acceptableEndpointsRatioBetweenZones(llbEndpointsList, currentZone, properties)
}

fun acceptableEndpointsRatioBetweenZones(
Expand All @@ -29,8 +29,10 @@ fun acceptableEndpointsRatioBetweenZones(
properties: SnapshotProperties
): Boolean {
val localEndpoints = llbEndpointsList.filter { it.locality.zone == currentZone }
.flatMap { it.lbEndpointsList }
val trafficSplittingEndpoints = llbEndpointsList
.filter { it.locality.zone == properties.loadBalancing.trafficSplitting.zoneName }
.flatMap { it.lbEndpointsList }
return localEndpoints.isNotEmpty() && localEndpoints.size >= trafficSplittingEndpoints.size
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ import pl.allegro.tech.servicemesh.envoycontrol.utils.CLUSTER_NAME
import pl.allegro.tech.servicemesh.envoycontrol.utils.DEFAULT_CLUSTER_WEIGHTS
import pl.allegro.tech.servicemesh.envoycontrol.utils.DEFAULT_DISCOVERY_SERVICE_NAME
import pl.allegro.tech.servicemesh.envoycontrol.utils.DEFAULT_IDLE_TIMEOUT
import pl.allegro.tech.servicemesh.envoycontrol.utils.DEFAULT_PRIORITY
import pl.allegro.tech.servicemesh.envoycontrol.utils.DEFAULT_SERVICE_NAME
import pl.allegro.tech.servicemesh.envoycontrol.utils.EGRESS_HOST
import pl.allegro.tech.servicemesh.envoycontrol.utils.EGRESS_PORT
import pl.allegro.tech.servicemesh.envoycontrol.utils.HIGHEST_PRIORITY
import pl.allegro.tech.servicemesh.envoycontrol.utils.INGRESS_HOST
import pl.allegro.tech.servicemesh.envoycontrol.utils.INGRESS_PORT
import pl.allegro.tech.servicemesh.envoycontrol.utils.SNAPSHOT_PROPERTIES_WITH_WEIGHTS
Expand Down Expand Up @@ -275,13 +277,18 @@ class EnvoySnapshotFactoryTest {
assertThat(it.endpointsList)
.anySatisfy { e ->
e.locality.zone == TRAFFIC_SPLITTING_ZONE &&
e.loadBalancingWeight.value == DEFAULT_CLUSTER_WEIGHTS.weightByZone[TRAFFIC_SPLITTING_ZONE]
e.loadBalancingWeight.value == DEFAULT_CLUSTER_WEIGHTS.weightByZone[TRAFFIC_SPLITTING_ZONE] &&
e.priority == DEFAULT_PRIORITY
}.anySatisfy { e ->
e.locality.zone == TRAFFIC_SPLITTING_ZONE &&
e.loadBalancingWeight.value == DEFAULT_CLUSTER_WEIGHTS.weightByZone[TRAFFIC_SPLITTING_ZONE] &&
e.priority == HIGHEST_PRIORITY
}
.anySatisfy { e ->
e.locality.zone == CURRENT_ZONE &&
e.loadBalancingWeight.value == DEFAULT_CLUSTER_WEIGHTS.weightByZone[CURRENT_ZONE]
}
.hasSize(2)
.hasSize(3)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ fun createEndpoint(zone: String): LocalityLbEndpoints {
.build()
)
.addAllLbEndpoints(listOf(LbEndpoint.getDefaultInstance()))
.setPriority(DEFAULT_PRIORITY)
.build()
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const val CLUSTER_NAME1 = "cluster-1"
const val CLUSTER_NAME2 = "cluster-2"
const val TRAFFIC_SPLITTING_ZONE = "dc2"
const val CURRENT_ZONE = "dc1"
const val DEFAULT_PRIORITY = 1
const val HIGHEST_PRIORITY = 0

val DEFAULT_CLUSTER_WEIGHTS = zoneWeights(mapOf(CURRENT_ZONE to 60, TRAFFIC_SPLITTING_ZONE to 40))

Expand Down

0 comments on commit 6e820c8

Please sign in to comment.