Skip to content

Commit 919cff0

Browse files
Implemented possibility for configuring traffic splitting, and fallback using aggregate cluster| Added tests and fixed review issues #292
1 parent a579901 commit 919cff0

File tree

5 files changed

+43
-51
lines changed

5 files changed

+43
-51
lines changed

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

Lines changed: 10 additions & 1 deletion
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.resource.clusters.EnvoyClustersFactory.Companion.getSecondaryClusterName
3636
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.listeners.filters.ServiceTagFilterFactory
37-
import pl.allegro.tech.servicemesh.envoycontrol.utils.withClusterWeight
3837
import pl.allegro.tech.servicemesh.envoycontrol.groups.RetryPolicy as EnvoyControlRetryPolicy
3938

4039
class EnvoyEgressRoutesFactory(
@@ -367,6 +366,16 @@ class EnvoyEgressRoutesFactory(
367366
)
368367
}
369368
}
369+
370+
private fun WeightedCluster.Builder.withClusterWeight(clusterName: String, weight: Int): WeightedCluster.Builder {
371+
this.addClusters(
372+
WeightedCluster.ClusterWeight.newBuilder()
373+
.setName(clusterName)
374+
.setWeight(UInt32Value.of(weight))
375+
.build()
376+
)
377+
return this
378+
}
370379
}
371380

372381
class RequestPolicyMapper private constructor() {

envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/utils/Clusters.kt

Lines changed: 0 additions & 15 deletions
This file was deleted.

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

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
package pl.allegro.tech.servicemesh.envoycontrol
22

3-
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.AGGREGATE_CLUSTER_NAME
4-
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.CLUSTER_NAME1
5-
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.CLUSTER_NAME2
6-
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.DEFAULT_DISCOVERY_SERVICE_NAME
7-
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.DEFAULT_SERVICE_NAME
8-
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.EGRESS_HOST
9-
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.EGRESS_PORT
10-
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.INGRESS_HOST
11-
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.INGRESS_PORT
12-
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.MAIN_CLUSTER_NAME
13-
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.SECONDARY_CLUSTER_NAME
143
import io.envoyproxy.controlplane.cache.SnapshotResources
154
import io.envoyproxy.envoy.config.cluster.v3.Cluster
165
import io.envoyproxy.envoy.config.core.v3.Metadata
@@ -31,7 +20,6 @@ import pl.allegro.tech.servicemesh.envoycontrol.groups.Outgoing
3120
import pl.allegro.tech.servicemesh.envoycontrol.groups.ProxySettings
3221
import pl.allegro.tech.servicemesh.envoycontrol.groups.ServicesGroup
3322
import pl.allegro.tech.servicemesh.envoycontrol.groups.with
34-
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.ClusterWeights
3523
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.EnvoySnapshotFactory
3624
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.GlobalSnapshot
3725
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.SnapshotProperties
@@ -45,6 +33,18 @@ import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.routes.EnvoyEg
4533
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.routes.EnvoyIngressRoutesFactory
4634
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.routes.ServiceTagMetadataGenerator
4735
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.serviceDependencies
36+
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.AGGREGATE_CLUSTER_NAME
37+
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.CLUSTER_NAME1
38+
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.CLUSTER_NAME2
39+
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.DEFAULT_CLUSTER_WEIGHTS
40+
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.DEFAULT_DISCOVERY_SERVICE_NAME
41+
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.DEFAULT_SERVICE_NAME
42+
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.EGRESS_HOST
43+
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.EGRESS_PORT
44+
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.INGRESS_HOST
45+
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.INGRESS_PORT
46+
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.MAIN_CLUSTER_NAME
47+
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.SECONDARY_CLUSTER_NAME
4848
import pl.allegro.tech.servicemesh.envoycontrol.utils.createCluster
4949
import pl.allegro.tech.servicemesh.envoycontrol.utils.createClusterConfigurations
5050
import pl.allegro.tech.servicemesh.envoycontrol.utils.createLoadAssignments
@@ -57,15 +57,9 @@ class EnvoySnapshotFactoryTest {
5757
const val FORCE_TRAFFIC_ZONE = "dc2"
5858
}
5959

60-
private val defaultClusterWeights = ClusterWeights().apply {
61-
mainClusterWeight = 50
62-
secondaryClusterWeight = 50
63-
}
64-
6560
private val snapshotPropertiesWithWeights = SnapshotProperties().also {
66-
it.dynamicListeners.enabled = false
6761
it.loadBalancing.trafficSplitting.serviceByWeightsProperties = mapOf(
68-
DEFAULT_SERVICE_NAME to defaultClusterWeights
62+
DEFAULT_SERVICE_NAME to DEFAULT_CLUSTER_WEIGHTS
6963
)
7064
it.loadBalancing.trafficSplitting.zoneName = FORCE_TRAFFIC_ZONE
7165
}
@@ -273,9 +267,8 @@ class EnvoySnapshotFactoryTest {
273267
fun `should not create traffic splitting configuration when zone condition isn't complied`() {
274268
// given
275269
val defaultProperties = SnapshotProperties().also {
276-
it.dynamicListeners.enabled = false
277270
it.loadBalancing.trafficSplitting.serviceByWeightsProperties = mapOf(
278-
DEFAULT_SERVICE_NAME to defaultClusterWeights
271+
DEFAULT_SERVICE_NAME to DEFAULT_CLUSTER_WEIGHTS
279272
)
280273
it.loadBalancing.trafficSplitting.zoneName = "not-matching-dc"
281274
}
@@ -318,7 +311,8 @@ class EnvoySnapshotFactoryTest {
318311

319312
// then
320313
assertThat(snapshot.clusters().resources())
321-
.containsKeys(MAIN_CLUSTER_NAME,
314+
.containsKeys(
315+
MAIN_CLUSTER_NAME,
322316
SECONDARY_CLUSTER_NAME,
323317
AGGREGATE_CLUSTER_NAME,
324318
CLUSTER_NAME2,

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
package pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.clusters
22

3-
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.AGGREGATE_CLUSTER_NAME
4-
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.CLUSTER_NAME1
5-
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.CLUSTER_NAME2
6-
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.DEFAULT_SERVICE_NAME
7-
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.MAIN_CLUSTER_NAME
8-
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.SECONDARY_CLUSTER_NAME
9-
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.TRAFFIC_SPLITTING_FORCE_TRAFFIC_ZONE
103
import io.envoyproxy.controlplane.cache.SnapshotResources
114
import io.envoyproxy.envoy.config.cluster.v3.Cluster
125
import io.envoyproxy.envoy.config.endpoint.v3.ClusterLoadAssignment
136
import org.assertj.core.api.Assertions.assertThat
147
import org.junit.jupiter.api.Test
158
import pl.allegro.tech.servicemesh.envoycontrol.groups.DependencySettings
16-
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.ClusterWeights
179
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.GlobalSnapshot
1810
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.SnapshotProperties
11+
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.AGGREGATE_CLUSTER_NAME
12+
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.CLUSTER_NAME1
13+
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.CLUSTER_NAME2
14+
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.DEFAULT_CLUSTER_WEIGHTS
15+
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.DEFAULT_SERVICE_NAME
16+
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.MAIN_CLUSTER_NAME
17+
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.SECONDARY_CLUSTER_NAME
18+
import pl.allegro.tech.servicemesh.envoycontrol.utils.TestData.TRAFFIC_SPLITTING_FORCE_TRAFFIC_ZONE
1919
import pl.allegro.tech.servicemesh.envoycontrol.utils.createAllServicesGroup
2020
import pl.allegro.tech.servicemesh.envoycontrol.utils.createCluster
2121
import pl.allegro.tech.servicemesh.envoycontrol.utils.createClusterConfigurations
@@ -29,10 +29,7 @@ internal class EnvoyClustersFactoryTest {
2929
private val factory = EnvoyClustersFactory(SnapshotProperties())
3030
private val snapshotPropertiesWithWeights = SnapshotProperties().apply {
3131
loadBalancing.trafficSplitting.serviceByWeightsProperties = mapOf(
32-
DEFAULT_SERVICE_NAME to ClusterWeights().apply {
33-
mainClusterWeight = 50
34-
secondaryClusterWeight = 50
35-
}
32+
DEFAULT_SERVICE_NAME to DEFAULT_CLUSTER_WEIGHTS
3633
)
3734
loadBalancing.trafficSplitting.zoneName = TRAFFIC_SPLITTING_FORCE_TRAFFIC_ZONE
3835
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package pl.allegro.tech.servicemesh.envoycontrol.utils
22

3-
object TestData {
3+
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.ClusterWeights
4+
5+
internal object TestData {
46
const val INGRESS_HOST = "ingress-host"
57
const val INGRESS_PORT = 3380
68
const val EGRESS_HOST = "egress-host"
@@ -13,4 +15,9 @@ object TestData {
1315
const val SECONDARY_CLUSTER_NAME = "cluster-1-secondary"
1416
const val AGGREGATE_CLUSTER_NAME = "cluster-1-aggregate"
1517
const val TRAFFIC_SPLITTING_FORCE_TRAFFIC_ZONE = "dc2"
18+
19+
val DEFAULT_CLUSTER_WEIGHTS = ClusterWeights().apply {
20+
mainClusterWeight = 50
21+
secondaryClusterWeight = 50
22+
}
1623
}

0 commit comments

Comments
 (0)