diff --git a/CHANGELOG.md b/CHANGELOG.md index 23a154402..dfb409cae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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.20.20] +### Changed +- Added service_id property to filter metadata + ## [0.20.19] ### Changed - Added http compression filter properties to node metadata diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/Groups.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/Groups.kt index af35d7a1b..00eba523c 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/Groups.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/Groups.kt @@ -5,6 +5,7 @@ import pl.allegro.tech.servicemesh.envoycontrol.snapshot.AccessLogFiltersPropert sealed class Group { abstract val communicationMode: CommunicationMode abstract val serviceName: String + abstract val serviceId: Int? abstract val discoveryServiceName: String? abstract val proxySettings: ProxySettings abstract val pathNormalizationConfig: PathNormalizationConfig @@ -15,6 +16,7 @@ sealed class Group { data class ServicesGroup( override val communicationMode: CommunicationMode, override val serviceName: String = "", + override val serviceId: Int? = null, override val discoveryServiceName: String? = null, override val proxySettings: ProxySettings = ProxySettings(), override val pathNormalizationConfig: PathNormalizationConfig = PathNormalizationConfig(), @@ -25,12 +27,13 @@ data class ServicesGroup( data class AllServicesGroup( override val communicationMode: CommunicationMode, override val serviceName: String = "", + override val serviceId: Int? = null, override val discoveryServiceName: String? = null, override val proxySettings: ProxySettings = ProxySettings(), override val pathNormalizationConfig: PathNormalizationConfig = PathNormalizationConfig(), override val listenersConfig: ListenersConfig? = null, override val compressionConfig: CompressionConfig = CompressionConfig(), - ) : Group() +) : Group() data class PathNormalizationConfig( val normalizationEnabled: Boolean? = null, diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/MetadataNodeGroup.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/MetadataNodeGroup.kt index 3c0928fcd..70fed4e2e 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/MetadataNodeGroup.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/MetadataNodeGroup.kt @@ -174,6 +174,7 @@ class MetadataNodeGroup( private fun createV3Group(node: NodeV3): Group { val nodeMetadata = NodeMetadata(node.metadata, properties) val serviceName = serviceName(nodeMetadata) + val serviceId = nodeMetadata.serviceId val discoveryServiceName = nodeMetadata.discoveryServiceName val proxySettings = proxySettings(nodeMetadata) val listenersConfig = createListenersConfig(node.id, node.metadata, node.userAgentBuildVersion) @@ -182,6 +183,7 @@ class MetadataNodeGroup( AllServicesGroup( nodeMetadata.communicationMode, serviceName, + serviceId, discoveryServiceName, proxySettings, nodeMetadata.pathNormalizationConfig, @@ -192,6 +194,7 @@ class MetadataNodeGroup( ServicesGroup( nodeMetadata.communicationMode, serviceName, + serviceId, discoveryServiceName, proxySettings, nodeMetadata.pathNormalizationConfig, diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/NodeMetadata.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/NodeMetadata.kt index 631c329cb..cd35301b3 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/NodeMetadata.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/NodeMetadata.kt @@ -28,6 +28,8 @@ class NodeMetadata(metadata: Struct, properties: SnapshotProperties) { .fieldsMap["service_name"] ?.stringValue + val serviceId: Int? = metadata.fieldsMap["service_id"]?.numberValue?.toInt() + val discoveryServiceName: String? = metadata .fieldsMap["discovery_service_name"] ?.stringValue diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/LuaFilterFactory.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/LuaFilterFactory.kt index 3e8d217d4..b897ebc92 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/LuaFilterFactory.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/LuaFilterFactory.kt @@ -78,6 +78,7 @@ class LuaFilterFactory(private val snapshotProperties: SnapshotProperties) { ) ), "service_name" to StringPropertyLua(group.serviceName), + "service_id" to StringPropertyLua(group.serviceId?.toString().orEmpty()), "discovery_service_name" to StringPropertyLua(group.discoveryServiceName ?: ""), "rbac_headers_to_log" to ListPropertyLua( snapshotProperties.incomingPermissions.headersToLogInRbac.map(::StringPropertyLua) diff --git a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoySnapshotFactoryTest.kt b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoySnapshotFactoryTest.kt index 4dfc366be..e27446fdd 100644 --- a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoySnapshotFactoryTest.kt +++ b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoySnapshotFactoryTest.kt @@ -404,15 +404,15 @@ class EnvoySnapshotFactoryTest { false -> null } return ServicesGroup( - mode, - serviceName, - discoveryServiceName, - ProxySettings().with( + communicationMode = mode, + serviceName = serviceName, + discoveryServiceName = discoveryServiceName, + proxySettings = ProxySettings().with( serviceDependencies = serviceDependencies(*dependencies), rateLimitEndpoints = rateLimitEndpoints ), - PathNormalizationConfig(), - listenersConfig + pathNormalizationConfig = PathNormalizationConfig(), + listenersConfig = listenersConfig ) } @@ -430,15 +430,15 @@ class EnvoySnapshotFactoryTest { false -> null } return AllServicesGroup( - mode, - serviceName, - discoveryServiceName, - ProxySettings().with( + communicationMode = mode, + serviceName = serviceName, + discoveryServiceName = discoveryServiceName, + proxySettings = ProxySettings().with( serviceDependencies = serviceDependencies(*dependencies), defaultServiceSettings = defaultServiceSettings ), - PathNormalizationConfig(), - listenersConfig + pathNormalizationConfig = PathNormalizationConfig(), + listenersConfig = listenersConfig ) } diff --git a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/MetadataNodeGroupTest.kt b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/MetadataNodeGroupTest.kt index a860a656c..80b9cf4f5 100644 --- a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/MetadataNodeGroupTest.kt +++ b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/MetadataNodeGroupTest.kt @@ -160,6 +160,33 @@ class MetadataNodeGroupTest { ) } + @Test + fun `should set serviceId to group if present`() { + // given + val expectedServiceId = 777 + val nodeGroup = MetadataNodeGroup(createSnapshotProperties(outgoingPermissions = true)) + val node = nodeV3(serviceId = expectedServiceId) + + // when + val group = nodeGroup.hash(node) + + // then + assertThat(group.serviceId).isEqualTo(expectedServiceId) + } + + @Test + fun `should not set serviceId to group if not present`() { + // given + val nodeGroup = MetadataNodeGroup(createSnapshotProperties(outgoingPermissions = true)) + val node = nodeV3() + + // when + val group = nodeGroup.hash(node) + + // then + assertThat(group.serviceId).isNull() + } + @Test fun `should not include service settings when incoming permissions are disabled`() { // given diff --git a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/TestNodeFactory.kt b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/TestNodeFactory.kt index 377582674..6a0277df5 100644 --- a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/TestNodeFactory.kt +++ b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/TestNodeFactory.kt @@ -13,6 +13,7 @@ fun nodeV3( serviceDependencies: Set = emptySet(), ads: Boolean? = null, serviceName: String? = null, + serviceId: Int? = null, discoveryServiceName: String? = null, incomingSettings: Boolean = false, clients: List = listOf("client1"), @@ -30,6 +31,8 @@ fun nodeV3( meta.putFields("service_name", string(serviceName)) } + serviceId?.let { meta.putFields("service_id", integer(serviceId)) } + discoveryServiceName?.let { meta.putFields("discovery_service_name", string(discoveryServiceName)) } diff --git a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/LuaFilterFactoryTest.kt b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/LuaFilterFactoryTest.kt index c346c4bca..d2486c198 100644 --- a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/LuaFilterFactoryTest.kt +++ b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/LuaFilterFactoryTest.kt @@ -45,6 +45,43 @@ internal class LuaFilterFactoryTest { assertThat(givenDiscoveryServiceName).isEqualTo(expectedDiscoveryServiceName) } + @Test + fun `should create filter metadata with serviceId`() { + // given + val expectedServiceId = 777 + val group = ServicesGroup(communicationMode = CommunicationMode.XDS, serviceId = expectedServiceId) + val luaFilterFactory = LuaFilterFactory(properties) + + // when + val metadata = luaFilterFactory.ingressScriptsMetadata(group, currentZone = "dc1") + + val actualServiceId = metadata + .getFilterMetadataOrThrow("envoy.filters.http.lua") + .getFieldsOrThrow("service_id") + .stringValue + + // then + assertThat(actualServiceId).isEqualTo(expectedServiceId.toString()) + } + + @Test + fun `should create filter metadata with empty serviceId`() { + // given + val group = ServicesGroup(communicationMode = CommunicationMode.XDS) + val luaFilterFactory = LuaFilterFactory(properties) + + // when + val metadata = luaFilterFactory.ingressScriptsMetadata(group, currentZone = "dc1") + + val actualServiceId = metadata + .getFilterMetadataOrThrow("envoy.filters.http.lua") + .getFieldsOrThrow("service_id") + .stringValue + + // then + assertThat(actualServiceId).isEmpty() + } + @Test fun `should create metadata with given customMetadata`() { // given diff --git a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/routes/EnvoyIngressRoutesFactoryTest.kt b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/routes/EnvoyIngressRoutesFactoryTest.kt index d769379c4..c9875872a 100644 --- a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/routes/EnvoyIngressRoutesFactoryTest.kt +++ b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/routes/EnvoyIngressRoutesFactoryTest.kt @@ -124,10 +124,10 @@ internal class EnvoyIngressRoutesFactoryTest { ) ) val group = ServicesGroup( - CommunicationMode.XDS, - "service_1", - "service_1", - proxySettingsOneEndpoint + communicationMode = CommunicationMode.XDS, + serviceName = "service_1", + discoveryServiceName = "service_1", + proxySettings = proxySettingsOneEndpoint ) // when @@ -203,10 +203,10 @@ internal class EnvoyIngressRoutesFactoryTest { ) ) val group = ServicesGroup( - CommunicationMode.XDS, - "service_1", - "service_1", - proxySettingsOneEndpoint + communicationMode = CommunicationMode.XDS, + serviceName = "service_1", + discoveryServiceName = "service_1", + proxySettings = proxySettingsOneEndpoint ) // when diff --git a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/utils/GroupsOperations.kt b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/utils/GroupsOperations.kt index b5a26dce3..f5883fb1f 100644 --- a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/utils/GroupsOperations.kt +++ b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/utils/GroupsOperations.kt @@ -24,15 +24,15 @@ fun createServicesGroup( listenersConfig: ListenersConfig? = createListenersConfig(snapshotProperties) ): ServicesGroup { return ServicesGroup( - mode, - serviceName, - discoveryServiceName, - ProxySettings().with( + communicationMode = mode, + serviceName = serviceName, + discoveryServiceName = discoveryServiceName, + proxySettings = ProxySettings().with( serviceDependencies = serviceDependencies(*dependencies), rateLimitEndpoints = rateLimitEndpoints ), - PathNormalizationConfig(), - listenersConfig + pathNormalizationConfig = PathNormalizationConfig(), + listenersConfig = listenersConfig ) } @@ -50,15 +50,15 @@ fun createAllServicesGroup( false -> null } return AllServicesGroup( - mode, - serviceName, - discoveryServiceName, - ProxySettings().with( + communicationMode = mode, + serviceName = serviceName, + discoveryServiceName = discoveryServiceName, + proxySettings = ProxySettings().with( serviceDependencies = serviceDependencies(*dependencies), defaultServiceSettings = defaultServiceSettings ), - PathNormalizationConfig(), - listenersConfig + pathNormalizationConfig = PathNormalizationConfig(), + listenersConfig = listenersConfig ) }