From ed5a712389a8905e80eda5b4ede5313c975631a1 Mon Sep 17 00:00:00 2001 From: "nastassia.dailidava" Date: Tue, 6 Feb 2024 11:31:57 +0100 Subject: [PATCH] #564 Implemented adding a header for locality weighted load balancing (fixes) --- .../main/resources/lua/ingress_current_zone_header.lua | 6 +++--- .../envoycontrol/infrastructure/ControlPlaneConfig.kt | 9 ++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/envoy-control-core/src/main/resources/lua/ingress_current_zone_header.lua b/envoy-control-core/src/main/resources/lua/ingress_current_zone_header.lua index ba18457c0..7d2b7d673 100644 --- a/envoy-control-core/src/main/resources/lua/ingress_current_zone_header.lua +++ b/envoy-control-core/src/main/resources/lua/ingress_current_zone_header.lua @@ -1,10 +1,10 @@ function envoy_on_request(handle) - local header_name = handle:metadata():get("traffic_splitting_zone_header_name") or "" + local traffic_splitting_zone_header_name = handle:metadata():get("traffic_splitting_zone_header_name") or "" local current_zone = handle:metadata():get("current_zone") or "" - if header_name == "" then + if traffic_splitting_zone_header_name == "" then return end - handle:headers():add(header_name, current_zone) + handle:headers():add(traffic_splitting_zone_header_name, current_zone) end function envoy_on_response(handle) diff --git a/envoy-control-runner/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/infrastructure/ControlPlaneConfig.kt b/envoy-control-runner/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/infrastructure/ControlPlaneConfig.kt index 2470b39e1..3801bff3e 100644 --- a/envoy-control-runner/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/infrastructure/ControlPlaneConfig.kt +++ b/envoy-control-runner/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/infrastructure/ControlPlaneConfig.kt @@ -66,11 +66,11 @@ class ControlPlaneConfig { globalStateChanges: GlobalStateChanges, metrics: EnvoyControlMetrics, envoyHttpFilters: EnvoyHttpFilters, - localDatacenter: String + consulProperties: ConsulProperties ): ControlPlane = ControlPlane.builder(properties, meterRegistry) .withMetrics(metrics) - .withCurrentZone(localDatacenter) + .withCurrentZone(localDatacenter(consulProperties)) .withEnvoyHttpFilters(envoyHttpFilters) .build(globalStateChanges.combined()) @@ -164,12 +164,11 @@ class ControlPlaneConfig { @ConditionalOnMissingBean(EnvoyHttpFilters::class) fun envoyHttpFilters( properties: EnvoyControlProperties, - localDatacenter: String + consulProperties: ConsulProperties ): EnvoyHttpFilters { - return EnvoyHttpFilters.defaultFilters(properties.envoy.snapshot, localDatacenter) + return EnvoyHttpFilters.defaultFilters(properties.envoy.snapshot, localDatacenter(consulProperties)) } - @Bean fun localDatacenter(properties: ConsulProperties) = ConsulClient(properties.host, properties.port).agentSelf.value?.config?.datacenter ?: "local"