Skip to content

Commit

Permalink
#564 Implemented adding a header for locality weighted load balancing…
Browse files Browse the repository at this point in the history
… (fixes)
  • Loading branch information
nastassia-dailidava committed Feb 6, 2024
1 parent b3a3987 commit ed5a712
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down Expand Up @@ -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"

Expand Down

0 comments on commit ed5a712

Please sign in to comment.