Skip to content

Commit

Permalink
Outgoing dependencies fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nastassia-dailidava committed Nov 23, 2023
1 parent 1abb570 commit 4897d1e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ class EnvoySnapshotFactory(
)
}
val listeners = if (properties.dynamicListeners.enabled) {
listenersFactory.createListeners(group, globalSnapshot)
listenersFactory.createListeners(group, globalSnapshot, egressServiceRouteSpecification)
} else {
emptyList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ import pl.allegro.tech.servicemesh.envoycontrol.groups.Dependency
import pl.allegro.tech.servicemesh.envoycontrol.groups.DomainDependency
import pl.allegro.tech.servicemesh.envoycontrol.groups.Group
import pl.allegro.tech.servicemesh.envoycontrol.groups.ListenersConfig
import pl.allegro.tech.servicemesh.envoycontrol.groups.ServiceDependency
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.EnvoySnapshotFactory.Companion.DEFAULT_HTTP_PORT
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.GlobalSnapshot
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.RouteSpecification
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.SnapshotProperties
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.WeightRouteSpecification
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.clusters.EnvoyClustersFactory
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.listeners.filters.EnvoyHttpFilters
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.listeners.filters.HttpConnectionManagerFactory
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.listeners.filters.TcpProxyFilterFactory
Expand Down Expand Up @@ -120,7 +124,11 @@ class EnvoyListenersFactory(
TLS("tls")
}

fun createListeners(group: Group, globalSnapshot: GlobalSnapshot): List<Listener> {
fun createListeners(
group: Group,
globalSnapshot: GlobalSnapshot,
routes: Collection<RouteSpecification>
): List<Listener> {
if (group.listenersConfig == null) {
return listOf()
}
Expand All @@ -130,7 +138,7 @@ class EnvoyListenersFactory(
createEgressListener(group, listenersConfig, globalSnapshot)
)
return if (group.listenersConfig?.useTransparentProxy == true) {
listeners + createEgressVirtualListeners(group, globalSnapshot)
listeners + createEgressVirtualListeners(group, globalSnapshot, routes)
} else {
listeners
}
Expand Down Expand Up @@ -196,19 +204,26 @@ class EnvoyListenersFactory(
return listener.build()
}

private fun createEgressVirtualListeners(group: Group, globalSnapshot: GlobalSnapshot): List<Listener> {
private fun createEgressVirtualListeners(
group: Group,
globalSnapshot: GlobalSnapshot,
routes: Collection<RouteSpecification>
): List<Listener> {
val tcpProxy = group.proxySettings.outgoing.getDomainDependencies().filter {
it.useSsl()
}.groupBy(
{ it.getPort() }, { it }
).toMap()

val httpProxy = (group.proxySettings.outgoing.getDomainDependencies() +
group.proxySettings.outgoing.getServiceDependencies()).filter {
!it.useSsl()
}.groupBy(
{ it.getPort() }, { it }
).toMutableMap()
val httpProxy = (
group.proxySettings.outgoing.getDomainDependencies() +
group.proxySettings.outgoing.getServiceDependencies() +
getTrafficSplittingDependencies(group, routes)
).filter {
!it.useSsl()
}.groupBy(
{ it.getPort() }, { it }
).toMutableMap()

if (group.proxySettings.outgoing.allServicesDependencies) {
httpProxy[DEFAULT_HTTP_PORT] = group.proxySettings.outgoing.getServiceDependencies()
Expand All @@ -218,6 +233,23 @@ class EnvoyListenersFactory(
createEgressHttpProxyVirtualListener(httpProxy.toMap(), group, globalSnapshot)
}

private fun getTrafficSplittingDependencies(
group: Group,
routes: Collection<RouteSpecification>
): List<ServiceDependency> {
val clusters = routes.filterIsInstance<WeightRouteSpecification>()
.map { it.clusterName }
.toList()
return group.proxySettings.outgoing.getServiceDependencies()
.filter { clusters.contains(it.service) }
.map {
it.copy(
service = EnvoyClustersFactory.getAggregateClusterName(it.service, snapshotProperties),
settings = it.settings
)
}
}

private fun createEgressFilter(
group: Group,
globalSnapshot: GlobalSnapshot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package pl.allegro.tech.servicemesh.envoycontrol.metrics

import io.micrometer.core.instrument.simple.SimpleMeterRegistry
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import pl.allegro.tech.servicemesh.envoycontrol.ControlPlane
import pl.allegro.tech.servicemesh.envoycontrol.EnvoyControlProperties
import pl.allegro.tech.servicemesh.envoycontrol.server.ExecutorType
import reactor.core.publisher.Flux

@Disabled
class ThreadPoolMetricTest {

@Test
Expand Down

0 comments on commit 4897d1e

Please sign in to comment.