From 2a5c800c0d2d8d2fbd4b8570d1f2161753eaff7b Mon Sep 17 00:00:00 2001 From: uladzislau-dziuba Date: Fri, 2 Aug 2024 13:56:46 +0200 Subject: [PATCH] Add service-id to node metadata --- CHANGELOG.md | 4 ++++ .../servicemesh/envoycontrol/groups/Groups.kt | 5 +++- .../envoycontrol/groups/MetadataNodeGroup.kt | 3 +++ .../envoycontrol/groups/NodeMetadata.kt | 2 ++ .../listeners/filters/LuaFilterFactory.kt | 1 + .../envoycontrol/EnvoySnapshotFactoryTest.kt | 24 +++++++++---------- .../listeners/filters/LuaFilterFactoryTest.kt | 10 +++++++- .../routes/EnvoyIngressRoutesFactoryTest.kt | 16 ++++++------- .../envoycontrol/utils/GroupsOperations.kt | 24 +++++++++---------- 9 files changed, 55 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23a154402..b5e55892d 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 node 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..1ac3cca7c 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: String? 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: String? = 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: String? = 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..7312c890b 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: String? = metadata.fieldsMap["service_id"]?.stringValue + 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..06ef0f6a0 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 ?: ""), "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/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..fefb67480 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 @@ -17,13 +17,15 @@ internal class LuaFilterFactoryTest { val properties = SnapshotProperties().also { it.incomingPermissions = IncomingPermissionsProperties() } @Test - fun `should create metadata with service name and discovery service name`() { + fun `should create metadata with service name and discovery service name and service-id`() { // given val expectedServiceName = "service-1" val expectedDiscoveryServiceName = "consul-service-1" + val expectedServiceId = "777" val group: Group = ServicesGroup( communicationMode = CommunicationMode.XDS, serviceName = expectedServiceName, + serviceId = expectedServiceId, discoveryServiceName = expectedDiscoveryServiceName ) val factory = LuaFilterFactory(properties) @@ -40,9 +42,15 @@ internal class LuaFilterFactoryTest { .getFieldsOrThrow("discovery_service_name") .stringValue + val givenServiceId = metadata + .getFilterMetadataOrThrow("envoy.filters.http.lua") + .getFieldsOrThrow("service_id") + .stringValue + // then assertThat(givenServiceName).isEqualTo(expectedServiceName) assertThat(givenDiscoveryServiceName).isEqualTo(expectedDiscoveryServiceName) + assertThat(givenServiceId).isEqualTo(expectedServiceId) } @Test 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 ) }