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 2e8a889de..134ca0da0 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,6 +158,8 @@ class CanaryProperties { class TrafficSplittingProperties { var zoneName = "" var serviceByWeightsProperties: Map = mapOf() + var secondaryClusterPostfix = "sec" + var aggregateClusterPostfix = "agg" } class ZoneWeights { diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/clusters/EnvoyClustersFactory.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/clusters/EnvoyClustersFactory.kt index f305bc4d8..407da6b9e 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/clusters/EnvoyClustersFactory.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/clusters/EnvoyClustersFactory.kt @@ -79,18 +79,6 @@ class EnvoyClustersFactory( companion object { private val logger by logger() - const val SECONDARY_CLUSTER_POSTFIX = "secondary" - const val AGGREGATE_CLUSTER_POSTFIX = "aggregate" - - @JvmStatic - fun getSecondaryClusterName(serviceName: String): String { - return "$serviceName-$SECONDARY_CLUSTER_POSTFIX" - } - - @JvmStatic - fun getAggregateClusterName(serviceName: String): String { - return "$serviceName-$AGGREGATE_CLUSTER_POSTFIX" - } } fun getClustersForServices( @@ -98,6 +86,11 @@ class EnvoyClustersFactory( communicationMode: CommunicationMode ): List { return services.map { edsCluster(it, communicationMode) } + .also { + it.forEach { cluster -> + logger.debug(" Created cluster config for services: ${cluster.name}") + } + } } fun getSecuredClusters(insecureClusters: List): List { @@ -264,7 +257,7 @@ class EnvoyClustersFactory( val secondaryCluster = createClusterForGroup( dependencySettings, cluster, - getSecondaryClusterName(cluster.name) + "${cluster.name}-${properties.loadBalancing.trafficSplitting.secondaryClusterPostfix}" ) val aggregateCluster = createAggregateCluster(mainCluster.name, linkedSetOf(secondaryCluster.name, mainCluster.name)) @@ -363,7 +356,7 @@ class EnvoyClustersFactory( private fun createAggregateCluster(clusterName: String, aggregatedClusters: Collection): Cluster { return Cluster.newBuilder() - .setName(getAggregateClusterName(clusterName)) + .setName("$clusterName-${properties.loadBalancing.trafficSplitting.aggregateClusterPostfix}") .setConnectTimeout(Durations.fromMillis(properties.edsConnectionTimeout.toMillis())) .setLbPolicy(Cluster.LbPolicy.CLUSTER_PROVIDED) .setClusterType( 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 9a8b84b5b..59916e474 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 @@ -20,7 +20,6 @@ import pl.allegro.tech.servicemesh.envoycontrol.services.ServiceInstances 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.Companion.getSecondaryClusterName import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.routes.ServiceTagMetadataGenerator typealias EnvoyProxyLocality = io.envoyproxy.envoy.config.core.v3.Locality @@ -91,7 +90,10 @@ class EnvoyEndpointsFactory( .addAllEndpoints(assignment.endpointsList?.filter { e -> e.locality.zone == properties.loadBalancing.trafficSplitting.zoneName }) - .setClusterName(getSecondaryClusterName(routeSpec.clusterName)) + .setClusterName( + "${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 7a0260810..3cad9893f 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 @@ -34,7 +34,6 @@ import pl.allegro.tech.servicemesh.envoycontrol.snapshot.RouteSpecification import pl.allegro.tech.servicemesh.envoycontrol.snapshot.SnapshotProperties import pl.allegro.tech.servicemesh.envoycontrol.snapshot.StandardRouteSpecification import pl.allegro.tech.servicemesh.envoycontrol.snapshot.WeightRouteSpecification -import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.clusters.EnvoyClustersFactory.Companion.getSecondaryClusterName import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.listeners.filters.ServiceTagFilterFactory import pl.allegro.tech.servicemesh.envoycontrol.groups.RetryPolicy as EnvoyControlRetryPolicy @@ -358,11 +357,13 @@ class EnvoyEgressRoutesFactory( WeightedCluster.newBuilder() .withClusterWeight(routeSpec.clusterName, routeSpec.clusterWeights.main) .withClusterWeight( - getSecondaryClusterName(routeSpec.clusterName), + "${routeSpec.clusterName}-" + + properties.loadBalancing.trafficSplitting.secondaryClusterPostfix, 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 314f504ae..bd1c6ff5c 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-secondary" - const val AGGREGATE_CLUSTER_NAME = "service-name-2-aggregate" + const val SECONDARY_CLUSTER_NAME = "service-name-2-sec" + const val AGGREGATE_CLUSTER_NAME = "service-name-2-agg" const val SERVICE_NAME_2 = "service-name-2" } 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 78fef6122..308251336 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-secondary" + private val secondaryClusterName = "service-one-sec" private val serviceName2 = "service-two"