Skip to content

Commit

Permalink
Implemented locality weighted load balancing ( tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
nastassia-dailidava committed Jan 17, 2024
1 parent 918ccd5 commit 3498959
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ControlPlaneConfig {
): ControlPlane =
ControlPlane.builder(properties, meterRegistry)
.withMetrics(metrics)
.withCurrentZone(localDatacenter(consulProperties))
.withCurrentZone(localDatacenter(consulProperties, properties))
.withEnvoyHttpFilters(envoyHttpFilters)
.build(globalStateChanges.combined())

Expand Down Expand Up @@ -115,11 +115,12 @@ class ControlPlaneConfig {
fun localClusterStateChanges(
consulServiceChanges: ConsulServiceChanges,
consulProperties: ConsulProperties,
transformers: List<ServiceInstancesTransformer>
transformers: List<ServiceInstancesTransformer>,
envoyControlProperties: EnvoyControlProperties
): LocalClusterStateChanges = ConsulLocalClusterStateChanges(
consulServiceChanges,
Locality.LOCAL,
localDatacenter(consulProperties),
localDatacenter(consulProperties, envoyControlProperties),
transformers
)

Expand Down Expand Up @@ -173,7 +174,9 @@ class ControlPlaneConfig {
return EnvoyHttpFilters.defaultFilters(properties.envoy.snapshot)
}

fun localDatacenter(properties: ConsulProperties): String {
fun localDatacenter(properties: ConsulProperties, envoyControlProperties: EnvoyControlProperties): String {
logger.info("LoadBalancing priorities: ${envoyControlProperties.envoy
.snapshot.loadBalancing.priorities.zonePriorities}")
return (ConsulClient(properties.host, properties.port).agentSelf.value?.config?.datacenter ?: "local")
.also { logger.info("Resolved local datacenter name: $it") }
}
Expand Down

0 comments on commit 3498959

Please sign in to comment.