Skip to content

Commit

Permalink
blacklisted clusters should be removed from sync process
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferdudas97 committed Sep 24, 2024
1 parent 71f6788 commit b0c1051
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
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,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(
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,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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit b0c1051

Please sign in to comment.