diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt index c7fe1136c..6905f9f3a 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt @@ -167,7 +167,7 @@ class ControlPlane private constructor( val snapshotsVersions = SnapshotsVersions() val snapshotProperties = properties.envoy.snapshot val envoySnapshotFactory = EnvoySnapshotFactory( - ingressRoutesFactory = EnvoyIngressRoutesFactory(snapshotProperties, envoyHttpFilters), + ingressRoutesFactory = EnvoyIngressRoutesFactory(snapshotProperties, envoyHttpFilters, currentZone), egressRoutesFactory = EnvoyEgressRoutesFactory(snapshotProperties), clustersFactory = EnvoyClustersFactory(snapshotProperties), endpointsFactory = EnvoyEndpointsFactory( diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/EnvoyDefaultFilters.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/EnvoyDefaultFilters.kt index 85d6aa305..e4475043d 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/EnvoyDefaultFilters.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/EnvoyDefaultFilters.kt @@ -10,8 +10,7 @@ import pl.allegro.tech.servicemesh.envoycontrol.snapshot.SnapshotProperties class EnvoyDefaultFilters( private val snapshotProperties: SnapshotProperties, - private val customLuaMetadata: LuaMetadataProperty.StructPropertyLua, - private val currentZone: String + private val customLuaMetadata: LuaMetadataProperty.StructPropertyLua ) { private val rbacFilterFactory = RBACFilterFactory( snapshotProperties.incomingPermissions, @@ -117,7 +116,7 @@ class EnvoyDefaultFilters( return preFilters + filters.toList() + postFilters } - val defaultIngressMetadata = { group: Group -> + val defaultIngressMetadata = { group: Group, currentZone: String -> luaFilterFactory.ingressScriptsMetadata(group, customLuaMetadata, currentZone) } diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/EnvoyHttpFilters.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/EnvoyHttpFilters.kt index 8f073051f..2b8081652 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/EnvoyHttpFilters.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/EnvoyHttpFilters.kt @@ -1,6 +1,7 @@ package pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.listeners.filters import io.envoyproxy.envoy.config.core.v3.Metadata +import pl.allegro.tech.servicemesh.envoycontrol.groups.Group import pl.allegro.tech.servicemesh.envoycontrol.snapshot.SnapshotProperties import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.listeners.HttpFilterFactory import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.routes.IngressMetadataFactory @@ -8,17 +9,16 @@ import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.routes.Ingress class EnvoyHttpFilters( val ingressFilters: List, val egressFilters: List, - val ingressMetadata: IngressMetadataFactory = { _ -> Metadata.getDefaultInstance() } + val ingressMetadata: IngressMetadataFactory = { _: Group, _: String -> Metadata.getDefaultInstance() } ) { companion object { - val emptyFilters = EnvoyHttpFilters(listOf(), listOf()) { Metadata.getDefaultInstance() } + val emptyFilters = EnvoyHttpFilters(listOf(), listOf()) { _, _ -> Metadata.getDefaultInstance() } fun defaultFilters( snapshotProperties: SnapshotProperties, - localDatacenter: String, customLuaMetadata: LuaMetadataProperty.StructPropertyLua = LuaMetadataProperty.StructPropertyLua() ): EnvoyHttpFilters { - val defaultFilters = EnvoyDefaultFilters(snapshotProperties, customLuaMetadata, localDatacenter) + val defaultFilters = EnvoyDefaultFilters(snapshotProperties, customLuaMetadata) return EnvoyHttpFilters( defaultFilters.ingressFilters(), defaultFilters.defaultEgressFilters, diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/routes/EnvoyIngressRoutesFactory.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/routes/EnvoyIngressRoutesFactory.kt index 40b076417..f92fe7fce 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/routes/EnvoyIngressRoutesFactory.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/routes/EnvoyIngressRoutesFactory.kt @@ -30,11 +30,12 @@ import pl.allegro.tech.servicemesh.envoycontrol.snapshot.SnapshotProperties import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.getRuleId import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.listeners.filters.EnvoyHttpFilters -typealias IngressMetadataFactory = (node: Group) -> Metadata +typealias IngressMetadataFactory = (node: Group, currentZone: String) -> Metadata class EnvoyIngressRoutesFactory( private val properties: SnapshotProperties, - envoyHttpFilters: EnvoyHttpFilters = EnvoyHttpFilters.emptyFilters + envoyHttpFilters: EnvoyHttpFilters = EnvoyHttpFilters.emptyFilters, + private val currentZone: String ) { private val allClients = setOf( @@ -187,7 +188,7 @@ class EnvoyIngressRoutesFactory( .setRoute(clusterRouteActionWithRetryPolicy(retryPolicy, localRouteAction)) } return (retryRoutes + nonRetryRoute).map { builder -> - builder.setMetadata(filterMetadata(group)).build() + builder.setMetadata(filterMetadata(group, currentZone)).build() } } diff --git a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoySnapshotFactoryTest.kt b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoySnapshotFactoryTest.kt index c59c5fbbe..5ba51e613 100644 --- a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoySnapshotFactoryTest.kt +++ b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoySnapshotFactoryTest.kt @@ -35,7 +35,6 @@ import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.routes.EnvoyIn import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.routes.ServiceTagMetadataGenerator import pl.allegro.tech.servicemesh.envoycontrol.snapshot.serviceDependencies import pl.allegro.tech.servicemesh.envoycontrol.utils.CLUSTER_NAME -import pl.allegro.tech.servicemesh.envoycontrol.utils.CURRENT_ZONE import pl.allegro.tech.servicemesh.envoycontrol.utils.DEFAULT_CLUSTER_WEIGHTS import pl.allegro.tech.servicemesh.envoycontrol.utils.DEFAULT_DISCOVERY_SERVICE_NAME import pl.allegro.tech.servicemesh.envoycontrol.utils.DEFAULT_IDLE_TIMEOUT @@ -54,6 +53,7 @@ import pl.allegro.tech.servicemesh.envoycontrol.utils.zoneWeights class EnvoySnapshotFactoryTest { companion object { const val SERVICE_NAME_2 = "service-name-2" + const val CURRENT_ZONE = "dc1" } @Test @@ -453,12 +453,13 @@ class EnvoySnapshotFactoryTest { SnapshotProperties(), EnvoyHttpFilters( emptyList(), emptyList() - ) { Metadata.getDefaultInstance() } + ) { _, _ -> Metadata.getDefaultInstance() }, + CURRENT_ZONE ) val egressRoutesFactory = EnvoyEgressRoutesFactory(properties) val clustersFactory = EnvoyClustersFactory(properties) val endpointsFactory = EnvoyEndpointsFactory(properties, ServiceTagMetadataGenerator(), CURRENT_ZONE) - val envoyHttpFilters = EnvoyHttpFilters.defaultFilters(properties, "dc1") + val envoyHttpFilters = EnvoyHttpFilters.defaultFilters(properties) val listenersFactory = EnvoyListenersFactory(properties, envoyHttpFilters) val snapshotsVersions = SnapshotsVersions() val meterRegistry: MeterRegistry = SimpleMeterRegistry() diff --git a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/SnapshotUpdaterTest.kt b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/SnapshotUpdaterTest.kt index 84a541131..916357f72 100644 --- a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/SnapshotUpdaterTest.kt +++ b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/SnapshotUpdaterTest.kt @@ -89,6 +89,7 @@ class SnapshotUpdaterTest { ) private val uninitializedSnapshot = null + private const val CURRENT_ZONE = "dc1" } val groupWithProxy = AllServicesGroup( @@ -1309,11 +1310,11 @@ class SnapshotUpdaterTest { private fun snapshotFactory(snapshotProperties: SnapshotProperties, meterRegistry: MeterRegistry) = EnvoySnapshotFactory( - ingressRoutesFactory = EnvoyIngressRoutesFactory(snapshotProperties), + ingressRoutesFactory = EnvoyIngressRoutesFactory(snapshotProperties, currentZone = CURRENT_ZONE), egressRoutesFactory = EnvoyEgressRoutesFactory(snapshotProperties), clustersFactory = EnvoyClustersFactory(snapshotProperties), endpointsFactory = EnvoyEndpointsFactory( - snapshotProperties, ServiceTagMetadataGenerator(snapshotProperties.routing.serviceTags), "dc1" + snapshotProperties, ServiceTagMetadataGenerator(snapshotProperties.routing.serviceTags), CURRENT_ZONE ), listenersFactory = EnvoyListenersFactory( snapshotProperties, diff --git a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/EnvoyDefaultFiltersTest.kt b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/EnvoyDefaultFiltersTest.kt index f1503ea1d..1cb4fa90b 100644 --- a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/EnvoyDefaultFiltersTest.kt +++ b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/EnvoyDefaultFiltersTest.kt @@ -13,8 +13,7 @@ class EnvoyDefaultFiltersTest { private val defaultFilters = EnvoyDefaultFilters( SnapshotProperties(), - LuaMetadataProperty.StructPropertyLua(), - "dc1" + LuaMetadataProperty.StructPropertyLua() ) @Test diff --git a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/routes/EnvoyIngressRoutesFactoryTest.kt b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/routes/EnvoyIngressRoutesFactoryTest.kt index 35737e1f3..d769379c4 100644 --- a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/routes/EnvoyIngressRoutesFactoryTest.kt +++ b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/routes/EnvoyIngressRoutesFactoryTest.kt @@ -79,6 +79,7 @@ internal class EnvoyIngressRoutesFactoryTest { adminRoute(), adminRedirectRoute() ) + private val currentZone = "dc1" @Test fun `should create route config with health check and response timeout defined`() { @@ -94,7 +95,7 @@ internal class EnvoyIngressRoutesFactoryTest { pathPrefix = "/config_dump" method = "GET" }) - }) + }, currentZone = currentZone) val responseTimeout = Durations.fromSeconds(777) val idleTimeout = Durations.fromSeconds(61) val connectionIdleTimeout = Durations.fromSeconds(120) @@ -107,12 +108,18 @@ internal class EnvoyIngressRoutesFactoryTest { permissionsEnabled = true, timeoutPolicy = TimeoutPolicy(idleTimeout, responseTimeout, connectionIdleTimeout), rateLimitEndpoints = listOf( - IncomingRateLimitEndpoint("/hello", PathMatchingType.PATH_PREFIX, setOf("GET", "POST"), - setOf(ClientWithSelector.create("client-1", "selector")), "100/s"), - IncomingRateLimitEndpoint("/banned", PathMatchingType.PATH, setOf("GET"), - setOf(ClientWithSelector.create("*")), "0/m"), - IncomingRateLimitEndpoint("/a/.*", PathMatchingType.PATH_REGEX, emptySet(), - setOf(ClientWithSelector.create("client-2")), "0/m") + IncomingRateLimitEndpoint( + "/hello", PathMatchingType.PATH_PREFIX, setOf("GET", "POST"), + setOf(ClientWithSelector.create("client-1", "selector")), "100/s" + ), + IncomingRateLimitEndpoint( + "/banned", PathMatchingType.PATH, setOf("GET"), + setOf(ClientWithSelector.create("*")), "0/m" + ), + IncomingRateLimitEndpoint( + "/a/.*", PathMatchingType.PATH_REGEX, emptySet(), + setOf(ClientWithSelector.create("client-2")), "0/m" + ) ) ) ) @@ -185,7 +192,7 @@ internal class EnvoyIngressRoutesFactoryTest { ingress.headersToRemove = mutableListOf("x-via-vip", "x-special-case-header") ingress.addServiceNameHeaderToResponse = true ingress.addRequestedAuthorityHeaderToResponse = true - }) + }, currentZone = currentZone) val proxySettingsOneEndpoint = ProxySettings( incoming = Incoming( healthCheck = HealthCheck( diff --git a/envoy-control-runner/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/infrastructure/ControlPlaneConfig.kt b/envoy-control-runner/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/infrastructure/ControlPlaneConfig.kt index 3801bff3e..6845fcb5a 100644 --- a/envoy-control-runner/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/infrastructure/ControlPlaneConfig.kt +++ b/envoy-control-runner/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/infrastructure/ControlPlaneConfig.kt @@ -163,10 +163,9 @@ class ControlPlaneConfig { @Bean @ConditionalOnMissingBean(EnvoyHttpFilters::class) fun envoyHttpFilters( - properties: EnvoyControlProperties, - consulProperties: ConsulProperties + properties: EnvoyControlProperties ): EnvoyHttpFilters { - return EnvoyHttpFilters.defaultFilters(properties.envoy.snapshot, localDatacenter(consulProperties)) + return EnvoyHttpFilters.defaultFilters(properties.envoy.snapshot) } fun localDatacenter(properties: ConsulProperties) =