Skip to content

Commit 1e06196

Browse files
Implemented possibility for configuring traffic splitting, and fallback using aggregate cluster #292
1 parent 1f01680 commit 1e06196

File tree

4 files changed

+10
-155
lines changed

4 files changed

+10
-155
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ class EnvoyClustersFactory(
222222
clusters[it],
223223
globalSnapshot.endpoints[it]
224224
)
225-
226225
}
227226
}
228227
}
@@ -283,10 +282,9 @@ class EnvoyClustersFactory(
283282
clusterLoadAssignment: ClusterLoadAssignment?
284283
): Boolean {
285284
val trafficSplitting = properties.loadBalancing.trafficSplitting
286-
val trafficSplitEnabled = trafficSplitting.serviceByWeightsProperties.keys.contains(serviceName)
287-
&& dependencies.contains(clusterName)
288-
val hasEndpointsInZone = clusterLoadAssignment
289-
?.endpointsList
285+
val trafficSplitEnabled = trafficSplitting.serviceByWeightsProperties.keys.contains(serviceName) &&
286+
dependencies.contains(clusterName)
287+
val hasEndpointsInZone = clusterLoadAssignment?.endpointsList
290288
?.any { e -> trafficSplitting.zoneName == e.locality.zone } ?: false
291289
return trafficSplitEnabled && hasEndpointsInZone
292290
}

envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/trafficsplitting/AggregateClusterFallbackTest.kt

Lines changed: 0 additions & 136 deletions
This file was deleted.
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import TrafficSplittingConstants.upstreamServiceName
1+
import TrafficSplitting.deltaPercentage
2+
import TrafficSplitting.upstreamServiceName
23
import org.assertj.core.api.Assertions
34
import org.assertj.core.data.Percentage
45
import pl.allegro.tech.servicemesh.envoycontrol.assertions.isFrom
@@ -8,9 +9,10 @@ import pl.allegro.tech.servicemesh.envoycontrol.config.envoy.CallStats
89
import pl.allegro.tech.servicemesh.envoycontrol.config.envoy.EnvoyExtension
910
import pl.allegro.tech.servicemesh.envoycontrol.config.service.EchoServiceExtension
1011

11-
internal object TrafficSplittingConstants {
12+
internal object TrafficSplitting {
1213
const val upstreamServiceName = "service-1"
1314
const val serviceName = "echo2"
15+
const val deltaPercentage = 20.0
1416
}
1517

1618
fun EnvoyExtension.verifyIsReachable(echoServiceExtension: EchoServiceExtension, service: String) {
@@ -22,7 +24,7 @@ fun EnvoyExtension.verifyIsReachable(echoServiceExtension: EchoServiceExtension,
2224
}
2325

2426
fun CallStats.verifyCallsCountCloseTo(service: EchoServiceExtension, expectedCount: Int): CallStats {
25-
Assertions.assertThat(this.hits(service)).isCloseTo(expectedCount, Percentage.withPercentage(20.0))
27+
Assertions.assertThat(this.hits(service)).isCloseTo(expectedCount, Percentage.withPercentage(deltaPercentage))
2628
return this
2729
}
2830

@@ -31,13 +33,6 @@ fun CallStats.verifyCallsCountGreaterThan(service: EchoServiceExtension, hits: I
3133
return this
3234
}
3335

34-
fun CallStats.verifyNoCalls(vararg services: EchoServiceExtension): CallStats {
35-
services.forEach {
36-
Assertions.assertThat(this.hits(it)).isEqualTo(0)
37-
}
38-
return this
39-
}
40-
4136
fun EnvoyExtension.callUpstreamServiceRepeatedly(
4237
vararg services: EchoServiceExtension,
4338
numberOfCalls: Int = 100,

envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/trafficsplitting/WeightedClustersRoutingTest.kt

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

3-
import TrafficSplittingConstants.serviceName
4-
import TrafficSplittingConstants.upstreamServiceName
3+
import TrafficSplitting.serviceName
4+
import TrafficSplitting.upstreamServiceName
55
import callUpstreamServiceRepeatedly
66
import org.junit.jupiter.api.Test
77
import org.junit.jupiter.api.extension.RegisterExtension
@@ -97,6 +97,4 @@ class WeightedClustersRoutingTest {
9797
.verifyCallsCountCloseTo(upstreamServiceDC1, 90)
9898
.verifyCallsCountGreaterThan(upstreamServiceDC2, 1)
9999
}
100-
101100
}
102-

0 commit comments

Comments
 (0)