Skip to content

Commit f7ccbfc

Browse files
review fixes #292
1 parent 83ebfc5 commit f7ccbfc

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ class EnvoyClustersFactory(
7979

8080
companion object {
8181
private val logger by logger()
82+
83+
@JvmStatic
84+
fun getSecondaryClusterName(serviceName: String, snapshotProperties: SnapshotProperties): String {
85+
return "$serviceName-${snapshotProperties.loadBalancing.trafficSplitting.secondaryClusterPostfix}"
86+
}
87+
88+
@JvmStatic
89+
fun getAggregateClusterName(serviceName: String, snapshotProperties: SnapshotProperties): String {
90+
return "$serviceName-${snapshotProperties.loadBalancing.trafficSplitting.aggregateClusterPostfix}"
91+
}
8292
}
8393

8494
fun getClustersForServices(
@@ -256,7 +266,7 @@ class EnvoyClustersFactory(
256266
val secondaryCluster = createClusterForGroup(
257267
dependencySettings,
258268
cluster,
259-
"${cluster.name}-${properties.loadBalancing.trafficSplitting.secondaryClusterPostfix}"
269+
getSecondaryClusterName(cluster.name, properties)
260270
)
261271
val aggregateCluster =
262272
createAggregateCluster(mainCluster.name, linkedSetOf(secondaryCluster.name, mainCluster.name))
@@ -349,7 +359,7 @@ class EnvoyClustersFactory(
349359

350360
private fun createAggregateCluster(clusterName: String, aggregatedClusters: Collection<String>): Cluster {
351361
return Cluster.newBuilder()
352-
.setName("$clusterName-${properties.loadBalancing.trafficSplitting.aggregateClusterPostfix}")
362+
.setName(getAggregateClusterName(clusterName, properties))
353363
.setConnectTimeout(Durations.fromMillis(properties.edsConnectionTimeout.toMillis()))
354364
.setLbPolicy(Cluster.LbPolicy.CLUSTER_PROVIDED)
355365
.setClusterType(

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ 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
2324
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.routes.ServiceTagMetadataGenerator
2425

2526
typealias EnvoyProxyLocality = io.envoyproxy.envoy.config.core.v3.Locality
@@ -90,10 +91,7 @@ class EnvoyEndpointsFactory(
9091
.addAllEndpoints(assignment.endpointsList?.filter { e ->
9192
e.locality.zone == properties.loadBalancing.trafficSplitting.zoneName
9293
})
93-
.setClusterName(
94-
"${routeSpec.clusterName}-" + properties.loadBalancing
95-
.trafficSplitting.secondaryClusterPostfix
96-
)
94+
.setClusterName(getSecondaryClusterName(routeSpec.clusterName, properties))
9795
.build()
9896
}
9997
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ 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.getAggregateClusterName
3738
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.listeners.filters.ServiceTagFilterFactory
3839
import pl.allegro.tech.servicemesh.envoycontrol.groups.RetryPolicy as EnvoyControlRetryPolicy
3940

@@ -357,8 +358,7 @@ class EnvoyEgressRoutesFactory(
357358
WeightedCluster.newBuilder()
358359
.withClusterWeight(routeSpec.clusterName, routeSpec.clusterWeights.main)
359360
.withClusterWeight(
360-
"${routeSpec.clusterName}-" + properties.loadBalancing.trafficSplitting
361-
.aggregateClusterPostfix,
361+
getAggregateClusterName(routeSpec.clusterName, properties),
362362
routeSpec.clusterWeights.secondary
363363
)
364364
)

0 commit comments

Comments
 (0)