Skip to content

Commit

Permalink
blacklisted clusters should be removed from sync process (#432)
Browse files Browse the repository at this point in the history
* blacklisted clusters should be removed from sync process

* fix linters

* changelog updated
  • Loading branch information
Ferdudas97 authored Sep 25, 2024
1 parent 71f6788 commit 58be4d6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ class SyncProperties {
var readTimeout: Duration = Duration.ofMillis(500)
var envoyControlAppName = "envoy-control"
var combineServiceChangesExperimentalFlow = false
var blackListedRemoteClusters: Set<String> = setOf()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 58be4d6

Please sign in to comment.