From b0c10516901f86be64e417408aa8ab600a12e373 Mon Sep 17 00:00:00 2001 From: "radoslaw.chrzanowski" Date: Tue, 24 Sep 2024 13:51:12 +0200 Subject: [PATCH] blacklisted clusters should be removed from sync process --- .../synchronization/SyncProperties.kt | 1 + .../infrastructure/SynchronizationConfig.kt | 11 +++++- .../EnvoyControlSynchronizationTest.kt | 38 ++++++++++++++++++- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/synchronization/SyncProperties.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/synchronization/SyncProperties.kt index 53f9a929a..0d34abec7 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/synchronization/SyncProperties.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/synchronization/SyncProperties.kt @@ -11,4 +11,5 @@ class SyncProperties { var readTimeout: Duration = Duration.ofMillis(500) var envoyControlAppName = "envoy-control" var combineServiceChangesExperimentalFlow = false + var blackListedRemoteClusters: Set = setOf() } diff --git a/envoy-control-runner/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/infrastructure/SynchronizationConfig.kt b/envoy-control-runner/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/infrastructure/SynchronizationConfig.kt index 934e40d91..bafbec09c 100644 --- a/envoy-control-runner/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/infrastructure/SynchronizationConfig.kt +++ b/envoy-control-runner/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/infrastructure/SynchronizationConfig.kt @@ -60,8 +60,15 @@ class SynchronizationConfig { } @Bean - fun remoteClusters(consulDatacenterReader: ConsulDatacenterReader) = - RemoteClusters(consulDatacenterReader.knownDatacenters() - consulDatacenterReader.localDatacenter()) + fun remoteClusters( + consulDatacenterReader: ConsulDatacenterReader, + properties: EnvoyControlProperties + ): RemoteClusters = + RemoteClusters( + consulDatacenterReader.knownDatacenters() + - consulDatacenterReader.localDatacenter() + - properties.sync.blackListedRemoteClusters + ) @Bean fun instanceFetcher( diff --git a/envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoyControlSynchronizationTest.kt b/envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoyControlSynchronizationTest.kt index cc163f075..b5e5b2aa7 100644 --- a/envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoyControlSynchronizationTest.kt +++ b/envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoyControlSynchronizationTest.kt @@ -31,6 +31,7 @@ internal class EnvoyControlSynchronizationTest { val properties = mapOf( "envoy-control.envoy.snapshot.stateSampleDuration" to stateSampleDuration, "envoy-control.sync.enabled" to true, + "envoy-control.sync.blackListedRemoteClusters" to setOf("dc3"), "envoy-control.sync.polling-interval" to pollingInterval.seconds ) @@ -41,6 +42,9 @@ internal class EnvoyControlSynchronizationTest { @JvmField @RegisterExtension val envoyControlDc2 = EnvoyControlClusteredExtension(consulClusters.serverSecond, dependencies = listOf(consulClusters)) + @JvmField + @RegisterExtension + val envoyControlDc3 = EnvoyControlClusteredExtension(consulClusters.serverThird, dependencies = listOf(consulClusters)) @JvmField @RegisterExtension @@ -53,13 +57,17 @@ internal class EnvoyControlSynchronizationTest { @JvmField @RegisterExtension val serviceRemote = EchoServiceExtension() + + @JvmField + @RegisterExtension + val serviceRemote3 = EchoServiceExtension() } @Test fun `should prefer services from local dc and fallback to remote dc when needed`() { // given: local and remote instances - registerServiceInRemoteDc("echo", serviceRemote) + registerServiceInRemoteDc2("echo", serviceRemote) val serviceId = registerServiceInLocalDc("echo", serviceLocal) // then: local called @@ -78,6 +86,22 @@ internal class EnvoyControlSynchronizationTest { waitServiceOkAndFrom("echo", serviceLocal) } + + @Test + fun `should not synchronize blacklisted remote clusters`() { + + // given: local and remote instances + registerServiceInRemoteDc3("echo", serviceRemote3) + registerServiceInRemoteDc2("echo", serviceRemote) + + // when: dc2 is synchronized + envoy.waitForClusterEndpointHealthy("echo", serviceRemote.container().ipAddress()) + + // when: instances from dc3 are absent + envoy.waitForClusterEndpointNotHealthy("echo", serviceRemote3.container().ipAddress()) + + + } @Test fun `latency between service registration in local dc and being able to access it via envoy should be less than 0,5s + stateSampleDuration`() { // when @@ -127,14 +151,24 @@ internal class EnvoyControlSynchronizationTest { } } + private fun waitServiceUnhealthy(name: String, echoServiceExtension: EchoServiceExtension) { + untilAsserted { + envoy.waitForClusterEndpointNotHealthy(name, echoServiceExtension.container().ipAddress()) + } + } + fun registerServiceInLocalDc(name: String, target: EchoServiceExtension): String { return consulClusters.serverFirst.operations.registerService(target, name = name) } - fun registerServiceInRemoteDc(name: String, target: EchoServiceExtension): String { + fun registerServiceInRemoteDc2(name: String, target: EchoServiceExtension): String { return consulClusters.serverSecond.operations.registerService(target, name = name) } + fun registerServiceInRemoteDc3(name: String, target: EchoServiceExtension): String { + return consulClusters.serverThird.operations.registerService(target, name = name) + } + private class LatencySummary(private val timer: Timer) { private fun nanosToMillis(nanos: Long) = Duration.ofNanos(nanos).toMillis()