From b5646e6f4f7954392fefa8f396e616a6b6cdef24 Mon Sep 17 00:00:00 2001 From: "nastassia.dailidava" Date: Mon, 22 Jan 2024 13:48:32 +0100 Subject: [PATCH] Implemented locality weighted load balancing ( added conditional log) --- .../resource/endpoints/EnvoyEndpointsFactory.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/endpoints/EnvoyEndpointsFactory.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/endpoints/EnvoyEndpointsFactory.kt index f27d1dc12..2a9461cf7 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/endpoints/EnvoyEndpointsFactory.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/endpoints/EnvoyEndpointsFactory.kt @@ -176,7 +176,7 @@ class EnvoyEndpointsFactory( } createLbEndpoint(it, serviceInstances.serviceName, locality) } ?: emptyList()) - .setPriority(toEnvoyPriority(zone, locality)) + .setPriority(toEnvoyPriority(zone, locality, serviceInstances?.serviceName)) .build() } @@ -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" + ) + } } }