diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt index c7fe1136c..eb979c223 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt @@ -65,6 +65,8 @@ class ControlPlane private constructor( private var servicesDisposable: Disposable? = null companion object { + private val logger by logger() + fun builder( properties: EnvoyControlProperties, meterRegistry: MeterRegistry @@ -361,6 +363,7 @@ class ControlPlane private constructor( } fun withCurrentZone(zone: String): ControlPlaneBuilder { + logger.info("Setting zone to $zone") this.currentZone = zone return this } 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 e2986d832..5ba712e81 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 @@ -162,12 +162,12 @@ class EnvoyEndpointsFactory( zone: String, locality: Locality ): LocalityLbEndpoints { - val priority = toEnvoyPriority(zone, locality, serviceInstances?.serviceName) + val priority = toEnvoyPriority(zone, locality) return LocalityLbEndpoints.newBuilder() .setLocality(EnvoyProxyLocality.newBuilder().setZone(zone).build()) .addAllLbEndpoints(serviceInstances?.instances ?.map { - createLbEndpoint(it, serviceInstances.serviceName, locality, priority, zone) + createLbEndpoint(it, serviceInstances.serviceName, locality, priority) } ?: emptyList()) .setPriority(priority) .build() @@ -177,14 +177,13 @@ class EnvoyEndpointsFactory( serviceInstance: ServiceInstance, serviceName: String, locality: Locality, - priority: Int, - zone: String + priority: Int ): LbEndpoint { return LbEndpoint.newBuilder() .setEndpoint( buildEndpoint(serviceInstance) ) - .setMetadata(serviceInstance, serviceName, locality, priority, zone) + .setMetadata(serviceInstance, serviceName, locality, priority) .setLoadBalancingWeightFromInstance(serviceInstance) .build() } @@ -214,8 +213,7 @@ class EnvoyEndpointsFactory( instance: ServiceInstance, serviceName: String, locality: Locality, - priority: Int, - zone: String + priority: Int ): LbEndpoint.Builder { val lbMetadataKeys = Struct.newBuilder() val socketMatchMetadataKeys = Struct.newBuilder() @@ -242,16 +240,7 @@ class EnvoyEndpointsFactory( ) } val calcLocality = if (priority == 0) Locality.LOCAL.name else locality.name - if (serviceName == "service-mesh-service-first" || - serviceName == "service-mesh-service-second" - ) { - logger.info( - "Resolved metadata locality to $calcLocality with " + - "currentZone=$currentZone, locality: $locality priority $priority " + - ", serviceName: $serviceName, zone: $zone" + - "props=${properties.loadBalancing.priorities.zonePriorities}" - ) - } + lbMetadataKeys.putFields( properties.loadBalancing.localityMetadataKey, Value.newBuilder().setStringValue(calcLocality).build() @@ -282,21 +271,11 @@ class EnvoyEndpointsFactory( false -> this } - private fun toEnvoyPriority(zone: String, locality: Locality, serviceName: String?): Int { + private fun toEnvoyPriority(zone: String, locality: Locality): Int { val zonePriorities = properties.loadBalancing.priorities.zonePriorities return when (zonePriorities.isNotEmpty()) { true -> zonePriorities[currentZone]?.get(zone) ?: toEnvoyPriority(locality) false -> toEnvoyPriority(locality) - }.also { - if (serviceName == "service-mesh-service-first" || - serviceName == "service-mesh-service-second" - ) { - logger.debug( - "Resolved lb priority to $it with zone=$zone, " + - "currentZone=$currentZone, locality: $locality priority " + - "props=${properties.loadBalancing.priorities.zonePriorities}, serviceName: $serviceName" - ) - } } } 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 73aff39ef..2edc8b4da 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 @@ -75,7 +75,7 @@ class ControlPlaneConfig { ): ControlPlane = ControlPlane.builder(properties, meterRegistry) .withMetrics(metrics) - .withCurrentZone(localDatacenter(consulProperties, properties)) + .withCurrentZone(localDatacenter(consulProperties)) .withEnvoyHttpFilters(envoyHttpFilters) .build(globalStateChanges.combined()) @@ -115,12 +115,11 @@ class ControlPlaneConfig { fun localClusterStateChanges( consulServiceChanges: ConsulServiceChanges, consulProperties: ConsulProperties, - transformers: List, - envoyControlProperties: EnvoyControlProperties + transformers: List ): LocalClusterStateChanges = ConsulLocalClusterStateChanges( consulServiceChanges, Locality.LOCAL, - localDatacenter(consulProperties, envoyControlProperties), + localDatacenter(consulProperties), transformers ) @@ -174,9 +173,7 @@ class ControlPlaneConfig { return EnvoyHttpFilters.defaultFilters(properties.envoy.snapshot) } - fun localDatacenter(properties: ConsulProperties, envoyControlProperties: EnvoyControlProperties): String { - logger.info("LoadBalancing priorities: ${envoyControlProperties.envoy - .snapshot.loadBalancing.priorities.zonePriorities}") + fun localDatacenter(properties: ConsulProperties): String { return (ConsulClient(properties.host, properties.port).agentSelf.value?.config?.datacenter ?: "local") .also { logger.info("Resolved local datacenter name: $it") } }