Skip to content

Commit

Permalink
Implemented possibility for configuring traffic splitting, and fallba…
Browse files Browse the repository at this point in the history
…ck using aggregate cluster #292
  • Loading branch information
nastassia-dailidava committed Aug 25, 2023
1 parent 1f01680 commit 1e06196
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ class EnvoyClustersFactory(
clusters[it],
globalSnapshot.endpoints[it]
)

}
}
}
Expand Down Expand Up @@ -283,10 +282,9 @@ class EnvoyClustersFactory(
clusterLoadAssignment: ClusterLoadAssignment?
): Boolean {
val trafficSplitting = properties.loadBalancing.trafficSplitting
val trafficSplitEnabled = trafficSplitting.serviceByWeightsProperties.keys.contains(serviceName)
&& dependencies.contains(clusterName)
val hasEndpointsInZone = clusterLoadAssignment
?.endpointsList
val trafficSplitEnabled = trafficSplitting.serviceByWeightsProperties.keys.contains(serviceName) &&
dependencies.contains(clusterName)
val hasEndpointsInZone = clusterLoadAssignment?.endpointsList
?.any { e -> trafficSplitting.zoneName == e.locality.zone } ?: false
return trafficSplitEnabled && hasEndpointsInZone
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import TrafficSplittingConstants.upstreamServiceName
import TrafficSplitting.deltaPercentage
import TrafficSplitting.upstreamServiceName
import org.assertj.core.api.Assertions
import org.assertj.core.data.Percentage
import pl.allegro.tech.servicemesh.envoycontrol.assertions.isFrom
Expand All @@ -8,9 +9,10 @@ import pl.allegro.tech.servicemesh.envoycontrol.config.envoy.CallStats
import pl.allegro.tech.servicemesh.envoycontrol.config.envoy.EnvoyExtension
import pl.allegro.tech.servicemesh.envoycontrol.config.service.EchoServiceExtension

internal object TrafficSplittingConstants {
internal object TrafficSplitting {
const val upstreamServiceName = "service-1"
const val serviceName = "echo2"
const val deltaPercentage = 20.0
}

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

fun CallStats.verifyCallsCountCloseTo(service: EchoServiceExtension, expectedCount: Int): CallStats {
Assertions.assertThat(this.hits(service)).isCloseTo(expectedCount, Percentage.withPercentage(20.0))
Assertions.assertThat(this.hits(service)).isCloseTo(expectedCount, Percentage.withPercentage(deltaPercentage))
return this
}

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

fun CallStats.verifyNoCalls(vararg services: EchoServiceExtension): CallStats {
services.forEach {
Assertions.assertThat(this.hits(it)).isEqualTo(0)
}
return this
}

fun EnvoyExtension.callUpstreamServiceRepeatedly(
vararg services: EchoServiceExtension,
numberOfCalls: Int = 100,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pl.allegro.tech.servicemesh.envoycontrol.trafficsplitting

import TrafficSplittingConstants.serviceName
import TrafficSplittingConstants.upstreamServiceName
import TrafficSplitting.serviceName
import TrafficSplitting.upstreamServiceName
import callUpstreamServiceRepeatedly
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.RegisterExtension
Expand Down Expand Up @@ -97,6 +97,4 @@ class WeightedClustersRoutingTest {
.verifyCallsCountCloseTo(upstreamServiceDC1, 90)
.verifyCallsCountGreaterThan(upstreamServiceDC2, 1)
}

}

0 comments on commit 1e06196

Please sign in to comment.