From 58be4d6702680854152a51d3559872e43e45df8c Mon Sep 17 00:00:00 2001 From: Radek Chrzanowski Date: Wed, 25 Sep 2024 14:56:26 +0200 Subject: [PATCH] blacklisted clusters should be removed from sync process (#432) * blacklisted clusters should be removed from sync process * fix linters * changelog updated --- CHANGELOG.md | 4 +++ .../synchronization/SyncProperties.kt | 1 + .../infrastructure/SynchronizationConfig.kt | 15 ++++++---- .../EnvoyControlSynchronizationTest.kt | 29 +++++++++++++++++-- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f20435d91..06eb644f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ Lists all changes with user impact. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). +## [0.22.1] +### Changed +- Add blacklisted remote clusters to ignore them during sync + ## [0.22.0] ### Changed - Spring Boot update to 3.3.2 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..27b1849e4 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,16 +60,19 @@ 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( - consulProperties: ConsulProperties, - envoyControlProperties: EnvoyControlProperties + consulProperties: ConsulProperties, envoyControlProperties: EnvoyControlProperties ) = SimpleConsulInstanceFetcher( - ConsulClient(consulProperties.host, consulProperties.port), - envoyControlProperties.sync.envoyControlAppName + ConsulClient(consulProperties.host, consulProperties.port), envoyControlProperties.sync.envoyControlAppName ) } 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..887d7992d 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,19 @@ 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 @@ -131,10 +152,14 @@ internal class EnvoyControlSynchronizationTest { 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()