Skip to content

Commit adddc36

Browse files
authored
path normalization as proxysettings field (#441)
* path normalization as proxysettings field * fix checkstyles * change fields names
1 parent 866410f commit adddc36

File tree

9 files changed

+51
-30
lines changed

9 files changed

+51
-30
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
Lists all changes with user impact.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
55

6+
## [0.22.6]
7+
### Changed
8+
- Changed api for pathNormalization
9+
610
## [0.22.5]
711
### Changed
812
- Add possibility to create custom routes

envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/Groups.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ sealed class Group {
88
abstract val serviceId: Int?
99
abstract val discoveryServiceName: String?
1010
abstract val proxySettings: ProxySettings
11-
abstract val pathNormalizationConfig: PathNormalizationConfig
11+
abstract val pathNormalizationPolicy: PathNormalizationPolicy
1212
abstract val listenersConfig: ListenersConfig?
1313
abstract val compressionConfig: CompressionConfig
1414
}
@@ -19,7 +19,7 @@ data class ServicesGroup(
1919
override val serviceId: Int? = null,
2020
override val discoveryServiceName: String? = null,
2121
override val proxySettings: ProxySettings = ProxySettings(),
22-
override val pathNormalizationConfig: PathNormalizationConfig = PathNormalizationConfig(),
22+
override val pathNormalizationPolicy: PathNormalizationPolicy = PathNormalizationPolicy(),
2323
override val listenersConfig: ListenersConfig? = null,
2424
override val compressionConfig: CompressionConfig = CompressionConfig(),
2525
) : Group()
@@ -30,12 +30,12 @@ data class AllServicesGroup(
3030
override val serviceId: Int? = null,
3131
override val discoveryServiceName: String? = null,
3232
override val proxySettings: ProxySettings = ProxySettings(),
33-
override val pathNormalizationConfig: PathNormalizationConfig = PathNormalizationConfig(),
33+
override val pathNormalizationPolicy: PathNormalizationPolicy = PathNormalizationPolicy(),
3434
override val listenersConfig: ListenersConfig? = null,
3535
override val compressionConfig: CompressionConfig = CompressionConfig(),
3636
) : Group()
3737

38-
data class PathNormalizationConfig(
38+
data class PathNormalizationPolicy(
3939
val normalizationEnabled: Boolean? = null,
4040
val mergeSlashes: Boolean? = null,
4141
val pathWithEscapedSlashesAction: String? = null

envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/NodeMetadata.kt

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,25 @@ data class ProxySettings(
7373
)
7474
}
7575

76-
fun getPathNormalization(proto: Value?, snapshotProperties: SnapshotProperties): PathNormalizationConfig {
77-
val defaultNormalizationConfig = PathNormalizationConfig(
76+
fun Value.toPathNormalization(snapshotProperties: SnapshotProperties): PathNormalizationPolicy {
77+
return PathNormalizationPolicy(
78+
normalizationEnabled = this.field("enabled")?.boolValue ?: snapshotProperties.pathNormalization.enabled,
79+
mergeSlashes = this.field("mergeSlashes")?.boolValue ?: snapshotProperties.pathNormalization.mergeSlashes,
80+
pathWithEscapedSlashesAction = this.field("escapedSlashesAction")?.stringValue
81+
?: snapshotProperties.pathNormalization.pathWithEscapedSlashesAction
82+
)
83+
}
84+
85+
fun getPathNormalization(proto: Value?, snapshotProperties: SnapshotProperties): PathNormalizationPolicy {
86+
val defaultNormalizationConfig = PathNormalizationPolicy(
7887
snapshotProperties.pathNormalization.enabled,
7988
snapshotProperties.pathNormalization.mergeSlashes,
8089
snapshotProperties.pathNormalization.pathWithEscapedSlashesAction
8190
)
8291
if (proto == null) {
8392
return defaultNormalizationConfig
8493
}
85-
return PathNormalizationConfig(
94+
return PathNormalizationPolicy(
8695
normalizationEnabled = proto.field("enabled")?.boolValue ?: defaultNormalizationConfig.normalizationEnabled,
8796
mergeSlashes = proto.field("merge_slashes")?.boolValue ?: defaultNormalizationConfig.mergeSlashes,
8897
pathWithEscapedSlashesAction = proto.field("path_with_escaped_slashes_action")?.stringValue
@@ -357,6 +366,7 @@ fun Value?.toIncoming(properties: SnapshotProperties): Incoming {
357366
rateLimitEndpoints = rateLimitEndpointsField.orEmpty().map(Value::toIncomingRateLimitEndpoint),
358367
// if there is no endpoint field defined in metadata, we allow for all traffic
359368
permissionsEnabled = endpointsField != null,
369+
pathNormalizationPolicy = this?.field("pathNormalizationPolicy")?.toPathNormalization(properties),
360370
healthCheck = this?.field("healthCheck").toHealthCheck(),
361371
roles = this?.field("roles")?.list().orEmpty().map { Role(it) },
362372
timeoutPolicy = this?.field("timeoutPolicy").toIncomingTimeoutPolicy(),
@@ -402,7 +412,8 @@ fun Value.toIncomingEndpoint(properties: SnapshotProperties): IncomingEndpoint {
402412

403413
if (isMoreThanOnePropertyDefined(paths, path, pathPrefix, pathRegex)) {
404414
throw NodeMetadataValidationException(
405-
"Precisely one of 'paths', 'path', 'pathPrefix' or 'pathRegex' field is allowed")
415+
"Precisely one of 'paths', 'path', 'pathPrefix' or 'pathRegex' field is allowed"
416+
)
406417
}
407418

408419
val methods = this.field("methods")?.list().orEmpty().map { it.stringValue }.toSet()
@@ -412,9 +423,13 @@ fun Value.toIncomingEndpoint(properties: SnapshotProperties): IncomingEndpoint {
412423

413424
return when {
414425
paths.isNotEmpty() -> IncomingEndpoint(
415-
paths, "", PathMatchingType.PATH, methods, clients, unlistedClientsPolicy, oauth)
426+
paths, "", PathMatchingType.PATH, methods, clients, unlistedClientsPolicy, oauth
427+
)
428+
416429
path != null -> IncomingEndpoint(
417-
paths, path, PathMatchingType.PATH, methods, clients, unlistedClientsPolicy, oauth)
430+
paths, path, PathMatchingType.PATH, methods, clients, unlistedClientsPolicy, oauth
431+
)
432+
418433
pathPrefix != null -> IncomingEndpoint(
419434
paths, pathPrefix, PathMatchingType.PATH_PREFIX, methods, clients, unlistedClientsPolicy, oauth
420435
)
@@ -424,7 +439,8 @@ fun Value.toIncomingEndpoint(properties: SnapshotProperties): IncomingEndpoint {
424439
)
425440

426441
else -> throw NodeMetadataValidationException(
427-
"One of 'paths', 'path', 'pathPrefix' or 'pathRegex' field is required")
442+
"One of 'paths', 'path', 'pathPrefix' or 'pathRegex' field is required"
443+
)
428444
}
429445
}
430446

@@ -580,6 +596,7 @@ data class Incoming(
580596
val permissionsEnabled: Boolean = false,
581597
val healthCheck: HealthCheck = HealthCheck(),
582598
val roles: List<Role> = emptyList(),
599+
val pathNormalizationPolicy: PathNormalizationPolicy? = null,
583600
val timeoutPolicy: TimeoutPolicy = TimeoutPolicy(
584601
idleTimeout = null, responseTimeout = null, connectionIdleTimeout = null
585602
),

envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/HttpConnectionManagerFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class HttpConnectionManagerFactory(
5151
): HttpConnectionManager? {
5252
val listenersConfig = group.listenersConfig!!
5353

54-
val normalizationConfig = group.pathNormalizationConfig
54+
val normalizationConfig = group.proxySettings.incoming.pathNormalizationPolicy ?: group.pathNormalizationPolicy
5555
val connectionManagerBuilder = HttpConnectionManager.newBuilder()
5656
.setStatPrefix(statPrefix)
5757
.setRds(setupRds(group.communicationMode, initialFetchTimeout, routeConfigName))

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import pl.allegro.tech.servicemesh.envoycontrol.groups.Group
1717
import pl.allegro.tech.servicemesh.envoycontrol.groups.IncomingRateLimitEndpoint
1818
import pl.allegro.tech.servicemesh.envoycontrol.groups.ListenersConfig
1919
import pl.allegro.tech.servicemesh.envoycontrol.groups.Outgoing
20-
import pl.allegro.tech.servicemesh.envoycontrol.groups.PathNormalizationConfig
20+
import pl.allegro.tech.servicemesh.envoycontrol.groups.PathNormalizationPolicy
2121
import pl.allegro.tech.servicemesh.envoycontrol.groups.ProxySettings
2222
import pl.allegro.tech.servicemesh.envoycontrol.groups.ServicesGroup
2323
import pl.allegro.tech.servicemesh.envoycontrol.groups.with
@@ -411,7 +411,7 @@ class EnvoySnapshotFactoryTest {
411411
serviceDependencies = serviceDependencies(*dependencies),
412412
rateLimitEndpoints = rateLimitEndpoints
413413
),
414-
pathNormalizationConfig = PathNormalizationConfig(),
414+
pathNormalizationPolicy = PathNormalizationPolicy(),
415415
listenersConfig = listenersConfig
416416
)
417417
}
@@ -437,7 +437,7 @@ class EnvoySnapshotFactoryTest {
437437
serviceDependencies = serviceDependencies(*dependencies),
438438
defaultServiceSettings = defaultServiceSettings
439439
),
440-
pathNormalizationConfig = PathNormalizationConfig(),
440+
pathNormalizationPolicy = PathNormalizationPolicy(),
441441
listenersConfig = listenersConfig
442442
)
443443
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import io.envoyproxy.envoy.config.core.v3.Node as NodeV3
2525

2626
class MetadataNodeGroupTest {
2727

28-
private val defaultNormalizationConfig = PathNormalizationConfig(
28+
private val defaultNormalizationConfig = PathNormalizationPolicy(
2929
normalizationEnabled = true,
3030
mergeSlashes = true,
3131
pathWithEscapedSlashesAction = "KEEP_UNCHANGED"
@@ -49,7 +49,7 @@ class MetadataNodeGroupTest {
4949
// because service may define different settings for different dependencies (for example endpoints, which
5050
// will be implemented in https://github.com/allegro/envoy-control/issues/6
5151
communicationMode = XDS,
52-
pathNormalizationConfig = defaultNormalizationConfig,
52+
pathNormalizationPolicy = defaultNormalizationConfig,
5353
proxySettings = ProxySettings().with(
5454
serviceDependencies = serviceDependencies("a", "b", "c"),
5555
allServicesDependencies = true
@@ -71,7 +71,7 @@ class MetadataNodeGroupTest {
7171
assertThat(group).isEqualTo(
7272
ServicesGroup(
7373
proxySettings = ProxySettings().with(serviceDependencies = setOf()),
74-
pathNormalizationConfig = defaultNormalizationConfig,
74+
pathNormalizationPolicy = defaultNormalizationConfig,
7575
communicationMode = XDS,
7676
compressionConfig = compressionConfig
7777
)
@@ -91,7 +91,7 @@ class MetadataNodeGroupTest {
9191
assertThat(group).isEqualTo(
9292
ServicesGroup(
9393
proxySettings = ProxySettings().with(serviceDependencies = serviceDependencies("a", "b", "c")),
94-
pathNormalizationConfig = defaultNormalizationConfig,
94+
pathNormalizationPolicy = defaultNormalizationConfig,
9595
communicationMode = XDS,
9696
compressionConfig = compressionConfig
9797
)
@@ -111,7 +111,7 @@ class MetadataNodeGroupTest {
111111
assertThat(group).isEqualTo(
112112
AllServicesGroup(
113113
communicationMode = ADS,
114-
pathNormalizationConfig = defaultNormalizationConfig,
114+
pathNormalizationPolicy = defaultNormalizationConfig,
115115
proxySettings = ProxySettings().with(allServicesDependencies = true),
116116
compressionConfig = compressionConfig
117117
)
@@ -131,7 +131,7 @@ class MetadataNodeGroupTest {
131131
assertThat(group).isEqualTo(
132132
ServicesGroup(
133133
proxySettings = ProxySettings().with(serviceDependencies = serviceDependencies("a", "b", "c")),
134-
pathNormalizationConfig = defaultNormalizationConfig,
134+
pathNormalizationPolicy = defaultNormalizationConfig,
135135
communicationMode = ADS,
136136
compressionConfig = compressionConfig
137137
)
@@ -153,7 +153,7 @@ class MetadataNodeGroupTest {
153153
// we have to preserve all services even if outgoingPermissions is disabled,
154154
// because service may define different settings for different dependencies (for example retry config)
155155
communicationMode = ADS,
156-
pathNormalizationConfig = defaultNormalizationConfig,
156+
pathNormalizationPolicy = defaultNormalizationConfig,
157157
proxySettings = ProxySettings().with(serviceDependencies = serviceDependencies("a", "b", "c")),
158158
compressionConfig = compressionConfig
159159
)
@@ -204,7 +204,7 @@ class MetadataNodeGroupTest {
204204
assertThat(group).isEqualTo(
205205
ServicesGroup(
206206
proxySettings = ProxySettings().with(serviceDependencies = serviceDependencies("a", "b", "c")),
207-
pathNormalizationConfig = defaultNormalizationConfig,
207+
pathNormalizationPolicy = defaultNormalizationConfig,
208208
communicationMode = XDS,
209209
serviceName = "app1",
210210
compressionConfig = compressionConfig
@@ -246,7 +246,7 @@ class MetadataNodeGroupTest {
246246
ServicesGroup(
247247
communicationMode = ADS,
248248
serviceName = "app1",
249-
pathNormalizationConfig = defaultNormalizationConfig,
249+
pathNormalizationPolicy = defaultNormalizationConfig,
250250
proxySettings = addedProxySettings.with(serviceDependencies = serviceDependencies("a", "b")),
251251
compressionConfig = compressionConfig
252252
)
@@ -269,7 +269,7 @@ class MetadataNodeGroupTest {
269269
AllServicesGroup(
270270
communicationMode = XDS,
271271
serviceName = "app1",
272-
pathNormalizationConfig = defaultNormalizationConfig,
272+
pathNormalizationPolicy = defaultNormalizationConfig,
273273
proxySettings = addedProxySettings.with(allServicesDependencies = true),
274274
compressionConfig = compressionConfig
275275
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ class NodeMetadataValidatorTest {
265265
fun `should throw an exception when PathWithEscapedSlashesAction is invalid`() {
266266
// given
267267
val node = nodeV3(
268-
pathNormalization = PathNormalizationConfig(pathWithEscapedSlashesAction = "foo", normalizationEnabled = true, mergeSlashes = true)
268+
pathNormalization = PathNormalizationPolicy(pathWithEscapedSlashesAction = "foo", normalizationEnabled = true, mergeSlashes = true)
269269
)
270270
val request = DiscoveryRequestV3.newBuilder()
271271
.setNode(node)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fun nodeV3(
2323
healthCheckPath: String? = null,
2424
healthCheckClusterName: String? = null,
2525
rateLimit: String? = null,
26-
pathNormalization: PathNormalizationConfig? = null
26+
pathNormalization: PathNormalizationPolicy? = null
2727
): NodeV3 {
2828
val meta = NodeV3.newBuilder().metadataBuilder
2929

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import pl.allegro.tech.servicemesh.envoycontrol.groups.DependencySettings
77
import pl.allegro.tech.servicemesh.envoycontrol.groups.IncomingRateLimitEndpoint
88
import pl.allegro.tech.servicemesh.envoycontrol.groups.ListenersConfig
99
import pl.allegro.tech.servicemesh.envoycontrol.groups.Outgoing
10-
import pl.allegro.tech.servicemesh.envoycontrol.groups.PathNormalizationConfig
10+
import pl.allegro.tech.servicemesh.envoycontrol.groups.PathNormalizationPolicy
1111
import pl.allegro.tech.servicemesh.envoycontrol.groups.ProxySettings
1212
import pl.allegro.tech.servicemesh.envoycontrol.groups.ServicesGroup
1313
import pl.allegro.tech.servicemesh.envoycontrol.groups.with
@@ -31,7 +31,7 @@ fun createServicesGroup(
3131
serviceDependencies = serviceDependencies(*dependencies),
3232
rateLimitEndpoints = rateLimitEndpoints
3333
),
34-
pathNormalizationConfig = PathNormalizationConfig(),
34+
pathNormalizationPolicy = PathNormalizationPolicy(),
3535
listenersConfig = listenersConfig
3636
)
3737
}
@@ -57,7 +57,7 @@ fun createAllServicesGroup(
5757
serviceDependencies = serviceDependencies(*dependencies),
5858
defaultServiceSettings = defaultServiceSettings
5959
),
60-
pathNormalizationConfig = PathNormalizationConfig(),
60+
pathNormalizationPolicy = PathNormalizationPolicy(),
6161
listenersConfig = listenersConfig
6262
)
6363
}

0 commit comments

Comments
 (0)