Skip to content

Commit cf97e30

Browse files
logs #292
1 parent 4ce0015 commit cf97e30

File tree

5 files changed

+149
-14
lines changed

5 files changed

+149
-14
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,9 @@ class EnvoySnapshotFactory(
341341
listenersVersion = version.listeners,
342342
routes = routes,
343343
routesVersion = version.routes
344-
)
344+
).also {
345+
logger.info("Snapshot for group: $it")
346+
}
345347
}
346348

347349
private fun createRoutesWhenUsingTransparentProxy(

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,7 @@ class EnvoyClustersFactory(
8686
communicationMode: CommunicationMode
8787
): List<Cluster> {
8888
return services.map { edsCluster(it, communicationMode) }
89-
.also {
90-
it.forEach { cluster ->
91-
logger.debug(" Created cluster config for services: ${cluster.name}")
92-
}
93-
}
89+
.onEach { logger.debug("Created cluster config for services: ${it.toString()}") }
9490
}
9591

9692
fun getSecuredClusters(insecureClusters: List<Cluster>): List<Cluster> {
@@ -247,6 +243,7 @@ class EnvoyClustersFactory(
247243
.setCommonHttpProtocolOptions(HttpProtocolOptions.newBuilder().setIdleTimeout(idleTimeoutPolicy))
248244
.setName(clusterName)
249245
.build()
246+
.also { logger.debug("Created regular cluster config ${it.toString()}") }
250247
}
251248

252249
private fun createSetOfClustersForGroup(
@@ -262,10 +259,8 @@ class EnvoyClustersFactory(
262259
val aggregateCluster =
263260
createAggregateCluster(mainCluster.name, linkedSetOf(secondaryCluster.name, mainCluster.name))
264261
return listOf(mainCluster, secondaryCluster, aggregateCluster)
265-
.also {
266-
it.forEach { cl ->
267-
logger.debug("Created traffic splitting cluster config with cluster name: {}", cl.name)
268-
}
262+
.onEach {
263+
logger.debug("Created set of cluster configs for traffic splitting: {}", it.toString())
269264
}
270265
}
271266

@@ -277,12 +272,8 @@ class EnvoyClustersFactory(
277272
): Collection<Cluster> {
278273
return cluster?.let {
279274
if (enableTrafficSplitting(serviceName, clusterLoadAssignment)) {
280-
logger.debug(
281-
"Creating traffic splitting cluster config for ${cluster.name}, service: $serviceName"
282-
)
283275
createSetOfClustersForGroup(dependencySettings, cluster)
284276
} else {
285-
logger.debug("Creating cluster config for ${cluster.name}, service: $serviceName")
286277
listOf(createClusterForGroup(dependencySettings, cluster))
287278
}
288279
} ?: listOf()

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,20 @@ fun EnvoyExtension.callUpstreamServiceRepeatedly(
4848
)
4949
return stats
5050
}
51+
52+
fun EnvoyExtension.callUpstreamServiceRepeatedly(
53+
vararg services: EchoServiceExtension,
54+
numberOfCalls: Int = 100,
55+
tag: String?
56+
): CallStats {
57+
val stats = CallStats(services.asList())
58+
this.egressOperations.callServiceRepeatedly(
59+
service = upstreamServiceName,
60+
stats = stats,
61+
minRepeat = numberOfCalls,
62+
maxRepeat = numberOfCalls,
63+
repeatUntil = { true },
64+
headers = tag?.let { mapOf("x-service-tag" to it) } ?: emptyMap(),
65+
)
66+
return stats
67+
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ import pl.allegro.tech.servicemesh.envoycontrol.config.consul.ConsulMultiCluster
1010
import pl.allegro.tech.servicemesh.envoycontrol.config.envoy.EnvoyExtension
1111
import pl.allegro.tech.servicemesh.envoycontrol.config.envoycontrol.EnvoyControlClusteredExtension
1212
import pl.allegro.tech.servicemesh.envoycontrol.config.service.EchoServiceExtension
13+
import pl.allegro.tech.servicemesh.envoycontrol.logger
1314
import verifyCallsCountCloseTo
1415
import verifyCallsCountGreaterThan
1516
import verifyIsReachable
1617
import java.time.Duration
1718

1819
class WeightedClustersRoutingTest {
1920
companion object {
21+
val logger by logger()
2022
private const val forceTrafficZone = "dc2"
2123

2224
private val properties = mapOf(
@@ -96,4 +98,19 @@ class WeightedClustersRoutingTest {
9698
.verifyCallsCountCloseTo(upstreamServiceDC1, 90)
9799
.verifyCallsCountGreaterThan(upstreamServiceDC2, 1)
98100
}
101+
102+
@Test
103+
fun `should route traffic according to weights with service tag`() {
104+
consul.serverFirst.operations.registerServiceWithEnvoyOnEgress(echoEnvoyDC1, name = serviceName)
105+
106+
consul.serverFirst.operations.registerService(upstreamServiceDC1, name = upstreamServiceName, tags = listOf("tag"))
107+
echoEnvoyDC1.verifyIsReachable(upstreamServiceDC1, upstreamServiceName)
108+
109+
consul.serverSecond.operations.registerService(upstreamServiceDC2, name = upstreamServiceName, tags = listOf("tag"))
110+
echoEnvoyDC1.verifyIsReachable(upstreamServiceDC2, upstreamServiceName)
111+
112+
echoEnvoyDC1.callUpstreamServiceRepeatedly(upstreamServiceDC1, upstreamServiceDC2, tag = "tag")
113+
.verifyCallsCountCloseTo(upstreamServiceDC1, 90)
114+
.verifyCallsCountGreaterThan(upstreamServiceDC2, 1)
115+
}
99116
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package pl.allegro.tech.servicemesh.envoycontrol.trafficsplitting
2+
3+
import TrafficSplitting.serviceName
4+
import TrafficSplitting.upstreamServiceName
5+
import callUpstreamServiceRepeatedly
6+
import org.junit.jupiter.api.Test
7+
import org.junit.jupiter.api.extension.RegisterExtension
8+
import pl.allegro.tech.servicemesh.envoycontrol.config.Xds
9+
import pl.allegro.tech.servicemesh.envoycontrol.config.consul.ConsulMultiClusterExtension
10+
import pl.allegro.tech.servicemesh.envoycontrol.config.envoy.EnvoyExtension
11+
import pl.allegro.tech.servicemesh.envoycontrol.config.envoycontrol.EnvoyControlClusteredExtension
12+
import pl.allegro.tech.servicemesh.envoycontrol.config.service.EchoServiceExtension
13+
import pl.allegro.tech.servicemesh.envoycontrol.logger
14+
import verifyCallsCountCloseTo
15+
import verifyCallsCountGreaterThan
16+
import verifyIsReachable
17+
import java.time.Duration
18+
19+
class WeightedClustersServiceTagRoutingTest {
20+
companion object {
21+
val logger by logger()
22+
private const val forceTrafficZone = "dc2"
23+
24+
private val properties = mapOf(
25+
"envoy-control.envoy.snapshot.routing.service-tags.enabled" to true,
26+
"envoy-control.envoy.snapshot.routing.service-tags.metadata-key" to "tag",
27+
"envoy-control.envoy.snapshot.routing.service-tags.auto-service-tag-enabled" to true,
28+
"envoy-control.envoy.snapshot.outgoing-permissions.services-allowed-to-use-wildcard" to setOf("echo2", "test-service"),
29+
"logging.level.pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.clusters.EnvoyClustersFactory" to "DEBUG",
30+
"logging.level.pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.routes.EnvoyEgressRoutesFactory" to "DEBUG",
31+
"logging.level.pl.allegro.tech.servicemesh.envoycontrol.snapshot.EnvoySnapshotFactory" to "DEBUG",
32+
"envoy-control.envoy.snapshot.stateSampleDuration" to Duration.ofSeconds(0),
33+
"envoy-control.sync.enabled" to true,
34+
"envoy-control.envoy.snapshot.loadBalancing.trafficSplitting.zoneName" to forceTrafficZone,
35+
"envoy-control.envoy.snapshot.loadBalancing.trafficSplitting.serviceByWeightsProperties.$serviceName.main" to 90,
36+
"envoy-control.envoy.snapshot.loadBalancing.trafficSplitting.serviceByWeightsProperties.$serviceName.secondary" to 10,
37+
"envoy-control.envoy.snapshot.loadBalancing.priorities.zonePriorities" to mapOf(
38+
"dc1" to mapOf(
39+
"dc1" to 0,
40+
"dc2" to 1
41+
),
42+
"dc2" to mapOf(
43+
"dc1" to 1,
44+
"dc2" to 0,
45+
),
46+
)
47+
)
48+
49+
private val echo2Config = """
50+
node:
51+
metadata:
52+
proxy_settings:
53+
outgoing:
54+
dependencies:
55+
- service: "service-1"
56+
""".trimIndent()
57+
58+
private val config = Xds.copy(configOverride = echo2Config, serviceName = "echo2")
59+
60+
@JvmField
61+
@RegisterExtension
62+
val consul = ConsulMultiClusterExtension()
63+
64+
@JvmField
65+
@RegisterExtension
66+
val envoyControl =
67+
EnvoyControlClusteredExtension(consul.serverFirst, { properties }, listOf(consul))
68+
69+
@JvmField
70+
@RegisterExtension
71+
val envoyControl2 =
72+
EnvoyControlClusteredExtension(consul.serverSecond, { properties }, listOf(consul))
73+
74+
@JvmField
75+
@RegisterExtension
76+
val echoServiceDC1 = EchoServiceExtension()
77+
78+
@JvmField
79+
@RegisterExtension
80+
val upstreamServiceDC1 = EchoServiceExtension()
81+
82+
@JvmField
83+
@RegisterExtension
84+
val upstreamServiceDC2 = EchoServiceExtension()
85+
86+
@JvmField
87+
@RegisterExtension
88+
val echoEnvoyDC1 = EnvoyExtension(envoyControl, localService = echoServiceDC1, config)
89+
@JvmField
90+
@RegisterExtension
91+
val echoEnvoyDC2 = EnvoyExtension(envoyControl2)
92+
}
93+
94+
@Test
95+
fun `should route traffic according to weights with service tag`() {
96+
consul.serverFirst.operations.registerServiceWithEnvoyOnEgress(echoEnvoyDC1, name = serviceName)
97+
98+
consul.serverFirst.operations.registerService(upstreamServiceDC1, name = upstreamServiceName, tags = listOf("global", "tag"))
99+
echoEnvoyDC1.verifyIsReachable(upstreamServiceDC1, upstreamServiceName)
100+
101+
consul.serverSecond.operations.registerService(upstreamServiceDC2, name = upstreamServiceName, tags = listOf("global", "tag"))
102+
echoEnvoyDC1.verifyIsReachable(upstreamServiceDC2, upstreamServiceName)
103+
104+
echoEnvoyDC1.callUpstreamServiceRepeatedly(upstreamServiceDC1, upstreamServiceDC2, tag = "tag")
105+
.verifyCallsCountCloseTo(upstreamServiceDC1, 90)
106+
.verifyCallsCountGreaterThan(upstreamServiceDC2, 1)
107+
}
108+
}

0 commit comments

Comments
 (0)