Skip to content

Commit 41c0c9b

Browse files
added postfix, added service name
Added logs Ignored failing test #292
1 parent 332e94d commit 41c0c9b

File tree

14 files changed

+183
-51
lines changed

14 files changed

+183
-51
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class EnvoySnapshotFactory(
113113
val removedClusters = previous - current.keys
114114
current + removedClusters
115115
}
116+
116117
false -> current
117118
}
118119
}
@@ -198,6 +199,7 @@ class EnvoySnapshotFactory(
198199
is ServicesGroup -> {
199200
definedServicesRoutes
200201
}
202+
201203
is AllServicesGroup -> {
202204
val servicesNames = group.proxySettings.outgoing.getServiceDependencies().map { it.service }.toSet()
203205
val allServicesRoutes = globalSnapshot.allServicesNames.subtract(servicesNames).map {
@@ -226,6 +228,10 @@ class EnvoySnapshotFactory(
226228
val enabledForDependency = globalSnapshot.endpoints[clusterName]?.endpointsList
227229
?.any { e -> trafficSplitting.zoneName == e.locality.zone }
228230
?: false
231+
logger.debug(
232+
"Building route spec weights: $weights, enabledForDependency: $enabledForDependency, " +
233+
"serviceName: $serviceName, clusterName: $clusterName"
234+
)
229235
return if (weights != null && enabledForDependency) {
230236
WeightRouteSpecification(
231237
clusterName,
@@ -335,7 +341,9 @@ class EnvoySnapshotFactory(
335341
listenersVersion = version.listeners,
336342
routes = routes,
337343
routesVersion = version.routes
338-
)
344+
).also {
345+
logger.debug("Snapshot for group: $it")
346+
}
339347
}
340348

341349
private fun createRoutesWhenUsingTransparentProxy(

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: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,6 @@ 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(
@@ -239,8 +227,8 @@ class EnvoyClustersFactory(
239227

240228
private fun getDependencySettings(dependency: ServiceDependency?, group: Group): DependencySettings {
241229
return if (dependency != null && dependency.settings.timeoutPolicy.connectionIdleTimeout != null) {
242-
dependency.settings
243-
} else group.proxySettings.outgoing.defaultServiceSettings
230+
dependency.settings
231+
} else group.proxySettings.outgoing.defaultServiceSettings
244232
}
245233

246234
private fun createClusterForGroup(
@@ -253,6 +241,10 @@ class EnvoyClustersFactory(
253241
return Cluster.newBuilder(cluster)
254242
.setCommonHttpProtocolOptions(HttpProtocolOptions.newBuilder().setIdleTimeout(idleTimeoutPolicy))
255243
.setName(clusterName)
244+
.setEdsClusterConfig(
245+
Cluster.EdsClusterConfig.newBuilder(cluster.edsClusterConfig)
246+
.setServiceName(clusterName)
247+
)
256248
.build()
257249
}
258250

@@ -264,12 +256,14 @@ class EnvoyClustersFactory(
264256
val secondaryCluster = createClusterForGroup(
265257
dependencySettings,
266258
cluster,
267-
getSecondaryClusterName(cluster.name)
259+
"${cluster.name}-${properties.loadBalancing.trafficSplitting.secondaryClusterPostfix}"
268260
)
269261
val aggregateCluster =
270262
createAggregateCluster(mainCluster.name, linkedSetOf(secondaryCluster.name, mainCluster.name))
271263
return listOf(mainCluster, secondaryCluster, aggregateCluster)
272-
.also { logger.debug("Created traffic splitting clusters: {}", it) }
264+
.onEach {
265+
logger.debug("Created set of cluster configs for traffic splitting: {}", it.toString())
266+
}
273267
}
274268

275269
private fun createClusters(
@@ -280,9 +274,6 @@ class EnvoyClustersFactory(
280274
): Collection<Cluster> {
281275
return cluster?.let {
282276
if (enableTrafficSplitting(serviceName, clusterLoadAssignment)) {
283-
logger.debug(
284-
"Creating traffic splitting egress cluster config for ${cluster.name}, service: $serviceName"
285-
)
286277
createSetOfClustersForGroup(dependencySettings, cluster)
287278
} else {
288279
listOf(createClusterForGroup(dependencySettings, cluster))
@@ -358,7 +349,7 @@ class EnvoyClustersFactory(
358349

359350
private fun createAggregateCluster(clusterName: String, aggregatedClusters: Collection<String>): Cluster {
360351
return Cluster.newBuilder()
361-
.setName(getAggregateClusterName(clusterName))
352+
.setName("$clusterName-${properties.loadBalancing.trafficSplitting.aggregateClusterPostfix}")
362353
.setConnectTimeout(Durations.fromMillis(properties.edsConnectionTimeout.toMillis()))
363354
.setLbPolicy(Cluster.LbPolicy.CLUSTER_PROVIDED)
364355
.setClusterType(
@@ -492,7 +483,7 @@ class EnvoyClustersFactory(
492483
)
493484
)
494485
}
495-
)
486+
).setServiceName(clusterConfiguration.serviceName)
496487
)
497488
.setLbPolicy(properties.loadBalancing.policy)
498489
// TODO: if we want to have multiple memory-backend instances of ratelimit

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.aggregateClusterPostfix,
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/clusters/EnvoyClustersFactoryTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ internal class EnvoyClustersFactoryTest {
115115
}
116116
.anySatisfy {
117117
assertThat(it.name).isEqualTo(SECONDARY_CLUSTER_NAME)
118-
assertThat(it.edsClusterConfig).isEqualTo(cluster1.edsClusterConfig)
119118
}
120119
.anySatisfy {
121120
assertThat(it.name).isEqualTo(AGGREGATE_CLUSTER_NAME)

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

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ fun createCluster(
1818
.setType(Cluster.DiscoveryType.EDS)
1919
.setConnectTimeout(Durations.fromMillis(defaultProperties.edsConnectionTimeout.toMillis()))
2020
.setEdsClusterConfig(
21-
Cluster.EdsClusterConfig.newBuilder().setEdsConfig(
22-
ConfigSource.newBuilder().setAds(AggregatedConfigSource.newBuilder())
23-
)
21+
Cluster.EdsClusterConfig.newBuilder()
22+
.setEdsConfig(
23+
ConfigSource.newBuilder().setAds(
24+
AggregatedConfigSource.newBuilder()
25+
)
26+
).setServiceName(clusterName)
2427
)
2528
.setLbPolicy(defaultProperties.loadBalancing.policy)
2629
.setCommonHttpProtocolOptions(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const val CLUSTER_NAME = "cluster-name"
1313
const val CLUSTER_NAME1 = "cluster-1"
1414
const val CLUSTER_NAME2 = "cluster-2"
1515
const val MAIN_CLUSTER_NAME = "cluster-1"
16-
const val SECONDARY_CLUSTER_NAME = "cluster-1-secondary"
17-
const val AGGREGATE_CLUSTER_NAME = "cluster-1-aggregate"
16+
const val SECONDARY_CLUSTER_NAME = "cluster-1-sec"
17+
const val AGGREGATE_CLUSTER_NAME = "cluster-1-agg"
1818
const val TRAFFIC_SPLITTING_FORCE_TRAFFIC_ZONE = "dc2"
1919
const val CURRENT_ZONE = "dc1"
2020

0 commit comments

Comments
 (0)