Skip to content

Commit

Permalink
review fixes #292
Browse files Browse the repository at this point in the history
  • Loading branch information
nastassia-dailidava committed Sep 25, 2023
1 parent 83ebfc5 commit f7ccbfc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ class EnvoyClustersFactory(

companion object {
private val logger by logger()

@JvmStatic
fun getSecondaryClusterName(serviceName: String, snapshotProperties: SnapshotProperties): String {
return "$serviceName-${snapshotProperties.loadBalancing.trafficSplitting.secondaryClusterPostfix}"
}

@JvmStatic
fun getAggregateClusterName(serviceName: String, snapshotProperties: SnapshotProperties): String {
return "$serviceName-${snapshotProperties.loadBalancing.trafficSplitting.aggregateClusterPostfix}"
}
}

fun getClustersForServices(
Expand Down Expand Up @@ -256,7 +266,7 @@ class EnvoyClustersFactory(
val secondaryCluster = createClusterForGroup(
dependencySettings,
cluster,
"${cluster.name}-${properties.loadBalancing.trafficSplitting.secondaryClusterPostfix}"
getSecondaryClusterName(cluster.name, properties)
)
val aggregateCluster =
createAggregateCluster(mainCluster.name, linkedSetOf(secondaryCluster.name, mainCluster.name))
Expand Down Expand Up @@ -349,7 +359,7 @@ class EnvoyClustersFactory(

private fun createAggregateCluster(clusterName: String, aggregatedClusters: Collection<String>): Cluster {
return Cluster.newBuilder()
.setName("$clusterName-${properties.loadBalancing.trafficSplitting.aggregateClusterPostfix}")
.setName(getAggregateClusterName(clusterName, properties))
.setConnectTimeout(Durations.fromMillis(properties.edsConnectionTimeout.toMillis()))
.setLbPolicy(Cluster.LbPolicy.CLUSTER_PROVIDED)
.setClusterType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ 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
Expand Down Expand Up @@ -90,10 +91,7 @@ class EnvoyEndpointsFactory(
.addAllEndpoints(assignment.endpointsList?.filter { e ->
e.locality.zone == properties.loadBalancing.trafficSplitting.zoneName
})
.setClusterName(
"${routeSpec.clusterName}-" + properties.loadBalancing
.trafficSplitting.secondaryClusterPostfix
)
.setClusterName(getSecondaryClusterName(routeSpec.clusterName, properties))
.build()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ 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.getAggregateClusterName
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.listeners.filters.ServiceTagFilterFactory
import pl.allegro.tech.servicemesh.envoycontrol.groups.RetryPolicy as EnvoyControlRetryPolicy

Expand Down Expand Up @@ -357,8 +358,7 @@ class EnvoyEgressRoutesFactory(
WeightedCluster.newBuilder()
.withClusterWeight(routeSpec.clusterName, routeSpec.clusterWeights.main)
.withClusterWeight(
"${routeSpec.clusterName}-" + properties.loadBalancing.trafficSplitting
.aggregateClusterPostfix,
getAggregateClusterName(routeSpec.clusterName, properties),
routeSpec.clusterWeights.secondary
)
)
Expand Down

0 comments on commit f7ccbfc

Please sign in to comment.