Skip to content

Commit

Permalink
path normalization as proxysettings field
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferdudas97 committed Dec 27, 2024
1 parent 866410f commit f644070
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 26 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Lists all changes with user impact.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

## [0.22.6]
### Changed
- Changed api for pathNormalization

## [0.22.5]
### Changed
- Add possibility to create custom routes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ sealed class Group {
abstract val serviceId: Int?
abstract val discoveryServiceName: String?
abstract val proxySettings: ProxySettings
abstract val pathNormalizationConfig: PathNormalizationConfig
abstract val pathNormalizationPolicy: PathNormalizationPolicy
abstract val listenersConfig: ListenersConfig?
abstract val compressionConfig: CompressionConfig
}
Expand All @@ -19,7 +19,7 @@ data class ServicesGroup(
override val serviceId: Int? = null,
override val discoveryServiceName: String? = null,
override val proxySettings: ProxySettings = ProxySettings(),
override val pathNormalizationConfig: PathNormalizationConfig = PathNormalizationConfig(),
override val pathNormalizationPolicy: PathNormalizationPolicy = PathNormalizationPolicy(),
override val listenersConfig: ListenersConfig? = null,
override val compressionConfig: CompressionConfig = CompressionConfig(),
) : Group()
Expand All @@ -30,12 +30,12 @@ data class AllServicesGroup(
override val serviceId: Int? = null,
override val discoveryServiceName: String? = null,
override val proxySettings: ProxySettings = ProxySettings(),
override val pathNormalizationConfig: PathNormalizationConfig = PathNormalizationConfig(),
override val pathNormalizationPolicy: PathNormalizationPolicy = PathNormalizationPolicy(),
override val listenersConfig: ListenersConfig? = null,
override val compressionConfig: CompressionConfig = CompressionConfig(),
) : Group()

data class PathNormalizationConfig(
data class PathNormalizationPolicy(
val normalizationEnabled: Boolean? = null,
val mergeSlashes: Boolean? = null,
val pathWithEscapedSlashesAction: String? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,25 @@ data class ProxySettings(
)
}

fun getPathNormalization(proto: Value?, snapshotProperties: SnapshotProperties): PathNormalizationConfig {
val defaultNormalizationConfig = PathNormalizationConfig(

fun Value.toPathNormalization(snapshotProperties: SnapshotProperties): PathNormalizationPolicy {
return PathNormalizationPolicy(
normalizationEnabled = this.field("enabled")?.boolValue ?: snapshotProperties.pathNormalization.enabled,
mergeSlashes = this.field("merge_slashes")?.boolValue ?: snapshotProperties.pathNormalization.mergeSlashes,
pathWithEscapedSlashesAction = this.field("path_with_escaped_slashes_action")?.stringValue
?: snapshotProperties.pathNormalization.pathWithEscapedSlashesAction
)
}
fun getPathNormalization(proto: Value?, snapshotProperties: SnapshotProperties): PathNormalizationPolicy {
val defaultNormalizationConfig = PathNormalizationPolicy(
snapshotProperties.pathNormalization.enabled,
snapshotProperties.pathNormalization.mergeSlashes,
snapshotProperties.pathNormalization.pathWithEscapedSlashesAction
)
if (proto == null) {
return defaultNormalizationConfig
}
return PathNormalizationConfig(
return PathNormalizationPolicy(
normalizationEnabled = proto.field("enabled")?.boolValue ?: defaultNormalizationConfig.normalizationEnabled,
mergeSlashes = proto.field("merge_slashes")?.boolValue ?: defaultNormalizationConfig.mergeSlashes,
pathWithEscapedSlashesAction = proto.field("path_with_escaped_slashes_action")?.stringValue
Expand Down Expand Up @@ -357,6 +366,7 @@ fun Value?.toIncoming(properties: SnapshotProperties): Incoming {
rateLimitEndpoints = rateLimitEndpointsField.orEmpty().map(Value::toIncomingRateLimitEndpoint),
// if there is no endpoint field defined in metadata, we allow for all traffic
permissionsEnabled = endpointsField != null,
pathNormalizationPolicy = this?.field("path_normalization")?.toPathNormalization(properties),
healthCheck = this?.field("healthCheck").toHealthCheck(),
roles = this?.field("roles")?.list().orEmpty().map { Role(it) },
timeoutPolicy = this?.field("timeoutPolicy").toIncomingTimeoutPolicy(),
Expand Down Expand Up @@ -580,6 +590,7 @@ data class Incoming(
val permissionsEnabled: Boolean = false,
val healthCheck: HealthCheck = HealthCheck(),
val roles: List<Role> = emptyList(),
val pathNormalizationPolicy: PathNormalizationPolicy? = null,
val timeoutPolicy: TimeoutPolicy = TimeoutPolicy(
idleTimeout = null, responseTimeout = null, connectionIdleTimeout = null
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class HttpConnectionManagerFactory(
): HttpConnectionManager? {
val listenersConfig = group.listenersConfig!!

val normalizationConfig = group.pathNormalizationConfig
val normalizationConfig = group.proxySettings.incoming.pathNormalizationPolicy ?: group.pathNormalizationPolicy
val connectionManagerBuilder = HttpConnectionManager.newBuilder()
.setStatPrefix(statPrefix)
.setRds(setupRds(group.communicationMode, initialFetchTimeout, routeConfigName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import pl.allegro.tech.servicemesh.envoycontrol.groups.Group
import pl.allegro.tech.servicemesh.envoycontrol.groups.IncomingRateLimitEndpoint
import pl.allegro.tech.servicemesh.envoycontrol.groups.ListenersConfig
import pl.allegro.tech.servicemesh.envoycontrol.groups.Outgoing
import pl.allegro.tech.servicemesh.envoycontrol.groups.PathNormalizationConfig
import pl.allegro.tech.servicemesh.envoycontrol.groups.PathNormalizationPolicy
import pl.allegro.tech.servicemesh.envoycontrol.groups.ProxySettings
import pl.allegro.tech.servicemesh.envoycontrol.groups.ServicesGroup
import pl.allegro.tech.servicemesh.envoycontrol.groups.with
Expand Down Expand Up @@ -411,7 +411,7 @@ class EnvoySnapshotFactoryTest {
serviceDependencies = serviceDependencies(*dependencies),
rateLimitEndpoints = rateLimitEndpoints
),
pathNormalizationConfig = PathNormalizationConfig(),
pathNormalizationPolicy = PathNormalizationPolicy(),
listenersConfig = listenersConfig
)
}
Expand All @@ -437,7 +437,7 @@ class EnvoySnapshotFactoryTest {
serviceDependencies = serviceDependencies(*dependencies),
defaultServiceSettings = defaultServiceSettings
),
pathNormalizationConfig = PathNormalizationConfig(),
pathNormalizationPolicy = PathNormalizationPolicy(),
listenersConfig = listenersConfig
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import io.envoyproxy.envoy.config.core.v3.Node as NodeV3

class MetadataNodeGroupTest {

private val defaultNormalizationConfig = PathNormalizationConfig(
private val defaultNormalizationConfig = PathNormalizationPolicy(
normalizationEnabled = true,
mergeSlashes = true,
pathWithEscapedSlashesAction = "KEEP_UNCHANGED"
Expand All @@ -49,7 +49,7 @@ class MetadataNodeGroupTest {
// because service may define different settings for different dependencies (for example endpoints, which
// will be implemented in https://github.com/allegro/envoy-control/issues/6
communicationMode = XDS,
pathNormalizationConfig = defaultNormalizationConfig,
pathNormalizationPolicy = defaultNormalizationConfig,
proxySettings = ProxySettings().with(
serviceDependencies = serviceDependencies("a", "b", "c"),
allServicesDependencies = true
Expand All @@ -71,7 +71,7 @@ class MetadataNodeGroupTest {
assertThat(group).isEqualTo(
ServicesGroup(
proxySettings = ProxySettings().with(serviceDependencies = setOf()),
pathNormalizationConfig = defaultNormalizationConfig,
pathNormalizationPolicy = defaultNormalizationConfig,
communicationMode = XDS,
compressionConfig = compressionConfig
)
Expand All @@ -91,7 +91,7 @@ class MetadataNodeGroupTest {
assertThat(group).isEqualTo(
ServicesGroup(
proxySettings = ProxySettings().with(serviceDependencies = serviceDependencies("a", "b", "c")),
pathNormalizationConfig = defaultNormalizationConfig,
pathNormalizationPolicy = defaultNormalizationConfig,
communicationMode = XDS,
compressionConfig = compressionConfig
)
Expand All @@ -111,7 +111,7 @@ class MetadataNodeGroupTest {
assertThat(group).isEqualTo(
AllServicesGroup(
communicationMode = ADS,
pathNormalizationConfig = defaultNormalizationConfig,
pathNormalizationPolicy = defaultNormalizationConfig,
proxySettings = ProxySettings().with(allServicesDependencies = true),
compressionConfig = compressionConfig
)
Expand All @@ -131,7 +131,7 @@ class MetadataNodeGroupTest {
assertThat(group).isEqualTo(
ServicesGroup(
proxySettings = ProxySettings().with(serviceDependencies = serviceDependencies("a", "b", "c")),
pathNormalizationConfig = defaultNormalizationConfig,
pathNormalizationPolicy = defaultNormalizationConfig,
communicationMode = ADS,
compressionConfig = compressionConfig
)
Expand All @@ -153,7 +153,7 @@ class MetadataNodeGroupTest {
// we have to preserve all services even if outgoingPermissions is disabled,
// because service may define different settings for different dependencies (for example retry config)
communicationMode = ADS,
pathNormalizationConfig = defaultNormalizationConfig,
pathNormalizationPolicy = defaultNormalizationConfig,
proxySettings = ProxySettings().with(serviceDependencies = serviceDependencies("a", "b", "c")),
compressionConfig = compressionConfig
)
Expand Down Expand Up @@ -204,7 +204,7 @@ class MetadataNodeGroupTest {
assertThat(group).isEqualTo(
ServicesGroup(
proxySettings = ProxySettings().with(serviceDependencies = serviceDependencies("a", "b", "c")),
pathNormalizationConfig = defaultNormalizationConfig,
pathNormalizationPolicy = defaultNormalizationConfig,
communicationMode = XDS,
serviceName = "app1",
compressionConfig = compressionConfig
Expand Down Expand Up @@ -246,7 +246,7 @@ class MetadataNodeGroupTest {
ServicesGroup(
communicationMode = ADS,
serviceName = "app1",
pathNormalizationConfig = defaultNormalizationConfig,
pathNormalizationPolicy = defaultNormalizationConfig,
proxySettings = addedProxySettings.with(serviceDependencies = serviceDependencies("a", "b")),
compressionConfig = compressionConfig
)
Expand All @@ -269,7 +269,7 @@ class MetadataNodeGroupTest {
AllServicesGroup(
communicationMode = XDS,
serviceName = "app1",
pathNormalizationConfig = defaultNormalizationConfig,
pathNormalizationPolicy = defaultNormalizationConfig,
proxySettings = addedProxySettings.with(allServicesDependencies = true),
compressionConfig = compressionConfig
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class NodeMetadataValidatorTest {
fun `should throw an exception when PathWithEscapedSlashesAction is invalid`() {
// given
val node = nodeV3(
pathNormalization = PathNormalizationConfig(pathWithEscapedSlashesAction = "foo", normalizationEnabled = true, mergeSlashes = true)
pathNormalization = PathNormalizationPolicy(pathWithEscapedSlashesAction = "foo", normalizationEnabled = true, mergeSlashes = true)
)
val request = DiscoveryRequestV3.newBuilder()
.setNode(node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fun nodeV3(
healthCheckPath: String? = null,
healthCheckClusterName: String? = null,
rateLimit: String? = null,
pathNormalization: PathNormalizationConfig? = null
pathNormalization: PathNormalizationPolicy? = null
): NodeV3 {
val meta = NodeV3.newBuilder().metadataBuilder

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import pl.allegro.tech.servicemesh.envoycontrol.groups.DependencySettings
import pl.allegro.tech.servicemesh.envoycontrol.groups.IncomingRateLimitEndpoint
import pl.allegro.tech.servicemesh.envoycontrol.groups.ListenersConfig
import pl.allegro.tech.servicemesh.envoycontrol.groups.Outgoing
import pl.allegro.tech.servicemesh.envoycontrol.groups.PathNormalizationConfig
import pl.allegro.tech.servicemesh.envoycontrol.groups.PathNormalizationPolicy
import pl.allegro.tech.servicemesh.envoycontrol.groups.ProxySettings
import pl.allegro.tech.servicemesh.envoycontrol.groups.ServicesGroup
import pl.allegro.tech.servicemesh.envoycontrol.groups.with
Expand All @@ -31,7 +31,7 @@ fun createServicesGroup(
serviceDependencies = serviceDependencies(*dependencies),
rateLimitEndpoints = rateLimitEndpoints
),
pathNormalizationConfig = PathNormalizationConfig(),
pathNormalizationPolicy = PathNormalizationPolicy(),
listenersConfig = listenersConfig
)
}
Expand All @@ -57,7 +57,7 @@ fun createAllServicesGroup(
serviceDependencies = serviceDependencies(*dependencies),
defaultServiceSettings = defaultServiceSettings
),
pathNormalizationConfig = PathNormalizationConfig(),
pathNormalizationPolicy = PathNormalizationPolicy(),
listenersConfig = listenersConfig
)
}
Expand Down

0 comments on commit f644070

Please sign in to comment.