From ade122fd19f3ca8d04df53d08421c87cc0be7156 Mon Sep 17 00:00:00 2001 From: "nastassia.dailidava" Date: Mon, 25 Sep 2023 11:42:48 +0200 Subject: [PATCH] added service name to eds config #292 --- .../snapshot/EnvoySnapshotFactory.kt | 19 ++- .../snapshot/SnapshotProperties.kt | 4 +- .../endpoints/EnvoyEndpointsFactory.kt | 4 +- .../routes/EnvoyEgressRoutesFactory.kt | 5 +- .../envoycontrol/EnvoySnapshotFactoryTest.kt | 4 +- .../metrics/ThreadPoolMetricTest.kt | 2 + .../endpoints/EnvoyEndpointsFactoryTest.kt | 2 +- .../envoycontrol/utils/TestData.kt | 4 +- .../WeightedClustersRoutingTest.kt | 2 - .../WeightedClustersServiceTagRoutingTest.kt | 108 ------------------ 10 files changed, 21 insertions(+), 133 deletions(-) delete mode 100644 envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/trafficsplitting/WeightedClustersServiceTagRoutingTest.kt 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 0a8085009..f504ac604 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 @@ -187,7 +187,7 @@ class EnvoySnapshotFactory( globalSnapshot: GlobalSnapshot ): Collection { val definedServicesRoutes = group.proxySettings.outgoing.getServiceDependencies().map { - getTrafficSplittingRouteSpecification( + buildRouteSpecification( clusterName = it.service, routeDomains = listOf(it.service) + getServiceWithCustomDomain(it.service), settings = it.settings, @@ -199,11 +199,10 @@ class EnvoySnapshotFactory( is ServicesGroup -> { definedServicesRoutes } - is AllServicesGroup -> { val servicesNames = group.proxySettings.outgoing.getServiceDependencies().map { it.service }.toSet() val allServicesRoutes = globalSnapshot.allServicesNames.subtract(servicesNames).map { - getTrafficSplittingRouteSpecification( + buildRouteSpecification( clusterName = it, routeDomains = listOf(it) + getServiceWithCustomDomain(it), settings = group.proxySettings.outgoing.defaultServiceSettings, @@ -216,7 +215,7 @@ class EnvoySnapshotFactory( } } - private fun getTrafficSplittingRouteSpecification( + private fun buildRouteSpecification( clusterName: String, routeDomains: List, settings: DependencySettings, @@ -228,11 +227,11 @@ class EnvoySnapshotFactory( val enabledForDependency = globalSnapshot.endpoints[clusterName]?.endpointsList ?.any { e -> trafficSplitting.zoneName == e.locality.zone } ?: false - logger.debug( - "Building route spec weights: $weights, enabledForDependency: $enabledForDependency, " + - "serviceName: $serviceName, clusterName: $clusterName" - ) return if (weights != null && enabledForDependency) { + logger.debug( + "Building traffic splitting route spec, weights: $weights, " + + "serviceName: $serviceName, clusterName: $clusterName, " + ) WeightRouteSpecification( clusterName, routeDomains, @@ -341,9 +340,7 @@ class EnvoySnapshotFactory( listenersVersion = version.listeners, routes = routes, routesVersion = version.routes - ).also { - logger.debug("Snapshot for group: $it") - } + ) } private fun createRoutesWhenUsingTransparentProxy( diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/SnapshotProperties.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/SnapshotProperties.kt index 134ca0da0..f30895f24 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/SnapshotProperties.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/SnapshotProperties.kt @@ -158,8 +158,8 @@ class CanaryProperties { class TrafficSplittingProperties { var zoneName = "" var serviceByWeightsProperties: Map = mapOf() - var secondaryClusterPostfix = "sec" - var aggregateClusterPostfix = "agg" + var secondaryClusterPostfix = "secondary" + var aggregateClusterPostfix = "aggregate" } class ZoneWeights { diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/endpoints/EnvoyEndpointsFactory.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/endpoints/EnvoyEndpointsFactory.kt index 59916e474..eb77f1fee 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/endpoints/EnvoyEndpointsFactory.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/endpoints/EnvoyEndpointsFactory.kt @@ -91,8 +91,8 @@ class EnvoyEndpointsFactory( e.locality.zone == properties.loadBalancing.trafficSplitting.zoneName }) .setClusterName( - "${routeSpec.clusterName}-" + - properties.loadBalancing.trafficSplitting.secondaryClusterPostfix + "${routeSpec.clusterName}-" + properties.loadBalancing + .trafficSplitting.secondaryClusterPostfix ) .build() } diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/routes/EnvoyEgressRoutesFactory.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/routes/EnvoyEgressRoutesFactory.kt index 17c6d33f7..7b30cef6a 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/routes/EnvoyEgressRoutesFactory.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/routes/EnvoyEgressRoutesFactory.kt @@ -357,13 +357,12 @@ class EnvoyEgressRoutesFactory( WeightedCluster.newBuilder() .withClusterWeight(routeSpec.clusterName, routeSpec.clusterWeights.main) .withClusterWeight( - "${routeSpec.clusterName}-" + - properties.loadBalancing.trafficSplitting.aggregateClusterPostfix, + "${routeSpec.clusterName}-" + properties.loadBalancing.trafficSplitting + .aggregateClusterPostfix, routeSpec.clusterWeights.secondary ) ) } - is StandardRouteSpecification -> { this.setCluster(routeSpec.clusterName) } 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 bd1c6ff5c..314f504ae 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 @@ -51,8 +51,8 @@ import pl.allegro.tech.servicemesh.envoycontrol.utils.createEndpoints class EnvoySnapshotFactoryTest { companion object { const val MAIN_CLUSTER_NAME = "service-name-2" - const val SECONDARY_CLUSTER_NAME = "service-name-2-sec" - const val AGGREGATE_CLUSTER_NAME = "service-name-2-agg" + const val SECONDARY_CLUSTER_NAME = "service-name-2-secondary" + const val AGGREGATE_CLUSTER_NAME = "service-name-2-aggregate" const val SERVICE_NAME_2 = "service-name-2" } 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..b4161c50a 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 + class ThreadPoolMetricTest { @Test diff --git a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/endpoints/EnvoyEndpointsFactoryTest.kt b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/endpoints/EnvoyEndpointsFactoryTest.kt index 308251336..78fef6122 100644 --- a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/endpoints/EnvoyEndpointsFactoryTest.kt +++ b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/endpoints/EnvoyEndpointsFactoryTest.kt @@ -57,7 +57,7 @@ internal class EnvoyEndpointsFactoryTest { private val serviceName = "service-one" - private val secondaryClusterName = "service-one-sec" + private val secondaryClusterName = "service-one-secondary" private val serviceName2 = "service-two" diff --git a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/utils/TestData.kt b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/utils/TestData.kt index 3a66d79e8..fc2ecdaea 100644 --- a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/utils/TestData.kt +++ b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/utils/TestData.kt @@ -13,8 +13,8 @@ const val CLUSTER_NAME = "cluster-name" const val CLUSTER_NAME1 = "cluster-1" const val CLUSTER_NAME2 = "cluster-2" const val MAIN_CLUSTER_NAME = "cluster-1" -const val SECONDARY_CLUSTER_NAME = "cluster-1-sec" -const val AGGREGATE_CLUSTER_NAME = "cluster-1-agg" +const val SECONDARY_CLUSTER_NAME = "cluster-1-secondary" +const val AGGREGATE_CLUSTER_NAME = "cluster-1-aggregate" const val TRAFFIC_SPLITTING_FORCE_TRAFFIC_ZONE = "dc2" const val CURRENT_ZONE = "dc1" diff --git a/envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/trafficsplitting/WeightedClustersRoutingTest.kt b/envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/trafficsplitting/WeightedClustersRoutingTest.kt index 371ff8038..564660fce 100644 --- a/envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/trafficsplitting/WeightedClustersRoutingTest.kt +++ b/envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/trafficsplitting/WeightedClustersRoutingTest.kt @@ -10,7 +10,6 @@ import pl.allegro.tech.servicemesh.envoycontrol.config.consul.ConsulMultiCluster import pl.allegro.tech.servicemesh.envoycontrol.config.envoy.EnvoyExtension import pl.allegro.tech.servicemesh.envoycontrol.config.envoycontrol.EnvoyControlClusteredExtension import pl.allegro.tech.servicemesh.envoycontrol.config.service.EchoServiceExtension -import pl.allegro.tech.servicemesh.envoycontrol.logger import verifyCallsCountCloseTo import verifyCallsCountGreaterThan import verifyIsReachable @@ -18,7 +17,6 @@ import java.time.Duration class WeightedClustersRoutingTest { companion object { - val logger by logger() private const val forceTrafficZone = "dc2" private val properties = mapOf( diff --git a/envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/trafficsplitting/WeightedClustersServiceTagRoutingTest.kt b/envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/trafficsplitting/WeightedClustersServiceTagRoutingTest.kt deleted file mode 100644 index 0ac4982f2..000000000 --- a/envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/trafficsplitting/WeightedClustersServiceTagRoutingTest.kt +++ /dev/null @@ -1,108 +0,0 @@ -package pl.allegro.tech.servicemesh.envoycontrol.trafficsplitting - -import TrafficSplitting.serviceName -import TrafficSplitting.upstreamServiceName -import callUpstreamServiceRepeatedly -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.RegisterExtension -import pl.allegro.tech.servicemesh.envoycontrol.config.Xds -import pl.allegro.tech.servicemesh.envoycontrol.config.consul.ConsulMultiClusterExtension -import pl.allegro.tech.servicemesh.envoycontrol.config.envoy.EnvoyExtension -import pl.allegro.tech.servicemesh.envoycontrol.config.envoycontrol.EnvoyControlClusteredExtension -import pl.allegro.tech.servicemesh.envoycontrol.config.service.EchoServiceExtension -import pl.allegro.tech.servicemesh.envoycontrol.logger -import verifyCallsCountCloseTo -import verifyCallsCountGreaterThan -import verifyIsReachable -import java.time.Duration - -class WeightedClustersServiceTagRoutingTest { - companion object { - val logger by logger() - private const val forceTrafficZone = "dc2" - - private val properties = mapOf( - "envoy-control.envoy.snapshot.routing.service-tags.enabled" to true, - "envoy-control.envoy.snapshot.routing.service-tags.metadata-key" to "tag", - "envoy-control.envoy.snapshot.routing.service-tags.auto-service-tag-enabled" to true, - "envoy-control.envoy.snapshot.outgoing-permissions.services-allowed-to-use-wildcard" to setOf("echo2", "test-service"), - "logging.level.pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.clusters.EnvoyClustersFactory" to "DEBUG", - "logging.level.pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.routes.EnvoyEgressRoutesFactory" to "DEBUG", - "logging.level.pl.allegro.tech.servicemesh.envoycontrol.snapshot.EnvoySnapshotFactory" to "DEBUG", - "envoy-control.envoy.snapshot.stateSampleDuration" to Duration.ofSeconds(0), - "envoy-control.sync.enabled" to true, - "envoy-control.envoy.snapshot.loadBalancing.trafficSplitting.zoneName" to forceTrafficZone, - "envoy-control.envoy.snapshot.loadBalancing.trafficSplitting.serviceByWeightsProperties.$serviceName.main" to 90, - "envoy-control.envoy.snapshot.loadBalancing.trafficSplitting.serviceByWeightsProperties.$serviceName.secondary" to 10, - "envoy-control.envoy.snapshot.loadBalancing.priorities.zonePriorities" to mapOf( - "dc1" to mapOf( - "dc1" to 0, - "dc2" to 1 - ), - "dc2" to mapOf( - "dc1" to 1, - "dc2" to 0, - ), - ) - ) - - private val echo2Config = """ - node: - metadata: - proxy_settings: - outgoing: - dependencies: - - service: "service-1" - """.trimIndent() - - private val config = Xds.copy(configOverride = echo2Config, serviceName = "echo2") - - @JvmField - @RegisterExtension - val consul = ConsulMultiClusterExtension() - - @JvmField - @RegisterExtension - val envoyControl = - EnvoyControlClusteredExtension(consul.serverFirst, { properties }, listOf(consul)) - - @JvmField - @RegisterExtension - val envoyControl2 = - EnvoyControlClusteredExtension(consul.serverSecond, { properties }, listOf(consul)) - - @JvmField - @RegisterExtension - val echoServiceDC1 = EchoServiceExtension() - - @JvmField - @RegisterExtension - val upstreamServiceDC1 = EchoServiceExtension() - - @JvmField - @RegisterExtension - val upstreamServiceDC2 = EchoServiceExtension() - - @JvmField - @RegisterExtension - val echoEnvoyDC1 = EnvoyExtension(envoyControl, localService = echoServiceDC1, config) - @JvmField - @RegisterExtension - val echoEnvoyDC2 = EnvoyExtension(envoyControl2) - } - - @Test - fun `should route traffic according to weights with service tag`() { - consul.serverFirst.operations.registerServiceWithEnvoyOnEgress(echoEnvoyDC1, name = serviceName) - - consul.serverFirst.operations.registerService(upstreamServiceDC1, name = upstreamServiceName, tags = listOf("global", "tag")) - echoEnvoyDC1.verifyIsReachable(upstreamServiceDC1, upstreamServiceName) - - consul.serverSecond.operations.registerService(upstreamServiceDC2, name = upstreamServiceName, tags = listOf("global", "tag")) - echoEnvoyDC1.verifyIsReachable(upstreamServiceDC2, upstreamServiceName) - - echoEnvoyDC1.callUpstreamServiceRepeatedly(upstreamServiceDC1, upstreamServiceDC2, tag = "tag") - .verifyCallsCountCloseTo(upstreamServiceDC1, 90) - .verifyCallsCountGreaterThan(upstreamServiceDC2, 1) - } -}