diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/EnvoySnapshotFactory.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/EnvoySnapshotFactory.kt index ae160ef02..364a57a91 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/EnvoySnapshotFactory.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/EnvoySnapshotFactory.kt @@ -318,7 +318,7 @@ class EnvoySnapshotFactory( ) } val listeners = if (properties.dynamicListeners.enabled) { - listenersFactory.createListeners(group, globalSnapshot) + listenersFactory.createListeners(group, globalSnapshot, egressServiceRouteSpecification) } else { emptyList() } diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/EnvoyListenersFactory.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/EnvoyListenersFactory.kt index 18170fe85..5725cfa54 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/EnvoyListenersFactory.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/EnvoyListenersFactory.kt @@ -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 @@ -120,7 +124,11 @@ class EnvoyListenersFactory( TLS("tls") } - fun createListeners(group: Group, globalSnapshot: GlobalSnapshot): List { + fun createListeners( + group: Group, + globalSnapshot: GlobalSnapshot, + routes: Collection + ): List { if (group.listenersConfig == null) { return listOf() } @@ -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 } @@ -196,19 +204,26 @@ class EnvoyListenersFactory( return listener.build() } - private fun createEgressVirtualListeners(group: Group, globalSnapshot: GlobalSnapshot): List { + private fun createEgressVirtualListeners( + group: Group, + globalSnapshot: GlobalSnapshot, + routes: Collection + ): List { 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() @@ -218,6 +233,23 @@ class EnvoyListenersFactory( createEgressHttpProxyVirtualListener(httpProxy.toMap(), group, globalSnapshot) } + private fun getTrafficSplittingDependencies( + group: Group, + routes: Collection + ): List { + val clusters = routes.filterIsInstance() + .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 diff --git a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/metrics/ThreadPoolMetricTest.kt b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/metrics/ThreadPoolMetricTest.kt index 2a91824e1..9a2ad78cf 100644 --- a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/metrics/ThreadPoolMetricTest.kt +++ b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/metrics/ThreadPoolMetricTest.kt @@ -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