Skip to content

Commit

Permalink
Implemented locality weighted load balancing ( added conditional log)
Browse files Browse the repository at this point in the history
  • Loading branch information
nastassia-dailidava committed Jan 22, 2024
1 parent c6a9263 commit b5646e6
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class EnvoyEndpointsFactory(
}
createLbEndpoint(it, serviceInstances.serviceName, locality)
} ?: emptyList())
.setPriority(toEnvoyPriority(zone, locality))
.setPriority(toEnvoyPriority(zone, locality, serviceInstances?.serviceName))
.build()
}

Expand Down Expand Up @@ -274,16 +274,21 @@ class EnvoyEndpointsFactory(
false -> this
}

private fun toEnvoyPriority(zone: String, locality: Locality): Int {
private fun toEnvoyPriority(zone: String, locality: Locality, serviceName: String?): Int {
val zonePriorities = properties.loadBalancing.priorities.zonePriorities
return when (zonePriorities.isNotEmpty()) {
true -> zonePriorities[currentZone]?.get(zone) ?: toEnvoyPriority(locality)
false -> toEnvoyPriority(locality)
}.also {
logger.debug(
"Resolved lb priority to {} with zone={}, currentZone={}, priority props={}",
it, zone, currentZone, zonePriorities
)
if (serviceName == "service-mesh-service-first" ||
serviceName == "service-mesh-service-second"
) {
logger.info(
"Resolved lb priority to $it with zone=$zone, " +
"currentZone=$currentZone, locality: $locality priority " +
"props=${properties.loadBalancing.priorities.zonePriorities}, serviceName: $serviceName"
)
}
}
}

Expand Down

0 comments on commit b5646e6

Please sign in to comment.