Skip to content

Commit

Permalink
changed postfix #292
Browse files Browse the repository at this point in the history
  • Loading branch information
nastassia-dailidava committed Sep 15, 2023
1 parent d0e912a commit bc8fa73
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ class CanaryProperties {
class TrafficSplittingProperties {
var zoneName = ""
var serviceByWeightsProperties: Map<String, ZoneWeights> = mapOf()
var secondaryClusterPostfix = "sec"
var aggregateClusterPostfix = "agg"
}

class ZoneWeights {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,18 @@ 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(
services: Collection<ClusterConfiguration>,
communicationMode: CommunicationMode
): List<Cluster> {
return services.map { edsCluster(it, communicationMode) }
.also {
it.forEach { cluster ->
logger.debug(" Created cluster config for services: ${cluster.name}")
}
}
}

fun getSecuredClusters(insecureClusters: List<Cluster>): List<Cluster> {
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -363,7 +356,7 @@ class EnvoyClustersFactory(

private fun createAggregateCluster(clusterName: String, aggregatedClusters: Collection<String>): 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit bc8fa73

Please sign in to comment.