Skip to content

Commit bc8fa73

Browse files
changed postfix #292
1 parent d0e912a commit bc8fa73

File tree

6 files changed

+19
-21
lines changed

6 files changed

+19
-21
lines changed

envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/SnapshotProperties.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ class CanaryProperties {
158158
class TrafficSplittingProperties {
159159
var zoneName = ""
160160
var serviceByWeightsProperties: Map<String, ZoneWeights> = mapOf()
161+
var secondaryClusterPostfix = "sec"
162+
var aggregateClusterPostfix = "agg"
161163
}
162164

163165
class ZoneWeights {

envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/clusters/EnvoyClustersFactory.kt

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,18 @@ class EnvoyClustersFactory(
7979

8080
companion object {
8181
private val logger by logger()
82-
const val SECONDARY_CLUSTER_POSTFIX = "secondary"
83-
const val AGGREGATE_CLUSTER_POSTFIX = "aggregate"
84-
85-
@JvmStatic
86-
fun getSecondaryClusterName(serviceName: String): String {
87-
return "$serviceName-$SECONDARY_CLUSTER_POSTFIX"
88-
}
89-
90-
@JvmStatic
91-
fun getAggregateClusterName(serviceName: String): String {
92-
return "$serviceName-$AGGREGATE_CLUSTER_POSTFIX"
93-
}
9482
}
9583

9684
fun getClustersForServices(
9785
services: Collection<ClusterConfiguration>,
9886
communicationMode: CommunicationMode
9987
): List<Cluster> {
10088
return services.map { edsCluster(it, communicationMode) }
89+
.also {
90+
it.forEach { cluster ->
91+
logger.debug(" Created cluster config for services: ${cluster.name}")
92+
}
93+
}
10194
}
10295

10396
fun getSecuredClusters(insecureClusters: List<Cluster>): List<Cluster> {
@@ -264,7 +257,7 @@ class EnvoyClustersFactory(
264257
val secondaryCluster = createClusterForGroup(
265258
dependencySettings,
266259
cluster,
267-
getSecondaryClusterName(cluster.name)
260+
"${cluster.name}-${properties.loadBalancing.trafficSplitting.secondaryClusterPostfix}"
268261
)
269262
val aggregateCluster =
270263
createAggregateCluster(mainCluster.name, linkedSetOf(secondaryCluster.name, mainCluster.name))
@@ -363,7 +356,7 @@ class EnvoyClustersFactory(
363356

364357
private fun createAggregateCluster(clusterName: String, aggregatedClusters: Collection<String>): Cluster {
365358
return Cluster.newBuilder()
366-
.setName(getAggregateClusterName(clusterName))
359+
.setName("$clusterName-${properties.loadBalancing.trafficSplitting.aggregateClusterPostfix}")
367360
.setConnectTimeout(Durations.fromMillis(properties.edsConnectionTimeout.toMillis()))
368361
.setLbPolicy(Cluster.LbPolicy.CLUSTER_PROVIDED)
369362
.setClusterType(

envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/endpoints/EnvoyEndpointsFactory.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import pl.allegro.tech.servicemesh.envoycontrol.services.ServiceInstances
2020
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.RouteSpecification
2121
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.SnapshotProperties
2222
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.WeightRouteSpecification
23-
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.clusters.EnvoyClustersFactory.Companion.getSecondaryClusterName
2423
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.routes.ServiceTagMetadataGenerator
2524

2625
typealias EnvoyProxyLocality = io.envoyproxy.envoy.config.core.v3.Locality
@@ -91,7 +90,10 @@ class EnvoyEndpointsFactory(
9190
.addAllEndpoints(assignment.endpointsList?.filter { e ->
9291
e.locality.zone == properties.loadBalancing.trafficSplitting.zoneName
9392
})
94-
.setClusterName(getSecondaryClusterName(routeSpec.clusterName))
93+
.setClusterName(
94+
"${routeSpec.clusterName}-" +
95+
properties.loadBalancing.trafficSplitting.secondaryClusterPostfix
96+
)
9597
.build()
9698
}
9799
}

envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/routes/EnvoyEgressRoutesFactory.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import pl.allegro.tech.servicemesh.envoycontrol.snapshot.RouteSpecification
3434
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.SnapshotProperties
3535
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.StandardRouteSpecification
3636
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.WeightRouteSpecification
37-
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.clusters.EnvoyClustersFactory.Companion.getSecondaryClusterName
3837
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.listeners.filters.ServiceTagFilterFactory
3938
import pl.allegro.tech.servicemesh.envoycontrol.groups.RetryPolicy as EnvoyControlRetryPolicy
4039

@@ -358,11 +357,13 @@ class EnvoyEgressRoutesFactory(
358357
WeightedCluster.newBuilder()
359358
.withClusterWeight(routeSpec.clusterName, routeSpec.clusterWeights.main)
360359
.withClusterWeight(
361-
getSecondaryClusterName(routeSpec.clusterName),
360+
"${routeSpec.clusterName}-" +
361+
properties.loadBalancing.trafficSplitting.secondaryClusterPostfix,
362362
routeSpec.clusterWeights.secondary
363363
)
364364
)
365365
}
366+
366367
is StandardRouteSpecification -> {
367368
this.setCluster(routeSpec.clusterName)
368369
}

envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoySnapshotFactoryTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ import pl.allegro.tech.servicemesh.envoycontrol.utils.createEndpoints
5151
class EnvoySnapshotFactoryTest {
5252
companion object {
5353
const val MAIN_CLUSTER_NAME = "service-name-2"
54-
const val SECONDARY_CLUSTER_NAME = "service-name-2-secondary"
55-
const val AGGREGATE_CLUSTER_NAME = "service-name-2-aggregate"
54+
const val SECONDARY_CLUSTER_NAME = "service-name-2-sec"
55+
const val AGGREGATE_CLUSTER_NAME = "service-name-2-agg"
5656
const val SERVICE_NAME_2 = "service-name-2"
5757
}
5858

envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/endpoints/EnvoyEndpointsFactoryTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ internal class EnvoyEndpointsFactoryTest {
5757

5858
private val serviceName = "service-one"
5959

60-
private val secondaryClusterName = "service-one-secondary"
60+
private val secondaryClusterName = "service-one-sec"
6161

6262
private val serviceName2 = "service-two"
6363

0 commit comments

Comments
 (0)