From 134a65588618cf9761a9fc3b1dfc798ba034933f Mon Sep 17 00:00:00 2001 From: Marcin Skalski Date: Fri, 4 Mar 2022 15:54:24 +0100 Subject: [PATCH 1/7] add control-plane identifier in response --- .../servicemesh/envoycontrol/ControlPlane.kt | 6 ++- .../V3DiscoveryServerWithIdentifier.kt | 41 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/V3DiscoveryServerWithIdentifier.kt diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt index bc51a874b..01076824d 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt @@ -92,6 +92,7 @@ class ControlPlane private constructor( var groupSnapshotParallelExecutorSupplier: () -> Executor? = { null } var metrics: EnvoyControlMetrics = DefaultEnvoyControlMetrics(meterRegistry = meterRegistry) var envoyHttpFilters: EnvoyHttpFilters = EnvoyHttpFilters.emptyFilters + var identifier: String? = null var nodeGroup: NodeGroup = MetadataNodeGroup( properties = properties.envoy.snapshot @@ -207,11 +208,12 @@ class ControlPlane private constructor( groupChangeWatcher: GroupChangeWatcher, cachedProtoResourcesSerializer: CachedProtoResourcesSerializer ): V3DiscoveryServer { - return V3DiscoveryServer( + return V3DiscoveryServerWithIdentifier( compositeDiscoveryServerCallbacks, groupChangeWatcher, executorGroup, - cachedProtoResourcesSerializer + cachedProtoResourcesSerializer, + identifier ) } diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/V3DiscoveryServerWithIdentifier.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/V3DiscoveryServerWithIdentifier.kt new file mode 100644 index 000000000..13163c750 --- /dev/null +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/V3DiscoveryServerWithIdentifier.kt @@ -0,0 +1,41 @@ +package pl.allegro.tech.servicemesh.envoycontrol + +import com.google.protobuf.Any +import io.envoyproxy.controlplane.cache.ConfigWatcher +import io.envoyproxy.controlplane.server.DiscoveryServerCallbacks +import io.envoyproxy.controlplane.server.ExecutorGroup +import io.envoyproxy.controlplane.server.V3DiscoveryServer +import io.envoyproxy.controlplane.server.serializer.ProtoResourcesSerializer +import io.envoyproxy.envoy.config.core.v3.ControlPlane +import io.envoyproxy.envoy.service.discovery.v3.DiscoveryResponse + + +class V3DiscoveryServerWithIdentifier( + callbacks: List, + configWatcher: ConfigWatcher, + executorGroup: ExecutorGroup?, + protoResourcesSerializer: ProtoResourcesSerializer, + private val identifier: String? +) : V3DiscoveryServer( + callbacks, + configWatcher, + executorGroup, + protoResourcesSerializer +) { + + override fun makeResponse( + version: String, resources: Collection, + typeUrl: String, + nonce: String + ): DiscoveryResponse? { + return DiscoveryResponse.newBuilder() + .setNonce(nonce) + .setVersionInfo(version) + .apply { identifier?.let { this.setControlPlane(controlPlane(it)) } } + .addAllResources(resources) + .setTypeUrl(typeUrl) + .build() + } + + private fun controlPlane(identifier: String) = ControlPlane.newBuilder().setIdentifier(identifier).build() +} From 0510d33f673b70d73c9999f85a13ee4b5500df05 Mon Sep 17 00:00:00 2001 From: gawarz Date: Fri, 4 Mar 2022 16:13:28 +0100 Subject: [PATCH 2/7] fix detekt --- .../servicemesh/envoycontrol/V3DiscoveryServerWithIdentifier.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/V3DiscoveryServerWithIdentifier.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/V3DiscoveryServerWithIdentifier.kt index 13163c750..366a0ba7b 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/V3DiscoveryServerWithIdentifier.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/V3DiscoveryServerWithIdentifier.kt @@ -9,7 +9,6 @@ import io.envoyproxy.controlplane.server.serializer.ProtoResourcesSerializer import io.envoyproxy.envoy.config.core.v3.ControlPlane import io.envoyproxy.envoy.service.discovery.v3.DiscoveryResponse - class V3DiscoveryServerWithIdentifier( callbacks: List, configWatcher: ConfigWatcher, From cde53e54cb8825a1149e53ea0ee3476943756939 Mon Sep 17 00:00:00 2001 From: gawarz Date: Fri, 4 Mar 2022 16:52:43 +0100 Subject: [PATCH 3/7] add method in builder --- .../pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt index 01076824d..6ab57bb35 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt @@ -308,6 +308,8 @@ class ControlPlane private constructor( this.metrics = metrics return this } + + fun withIdentifier() = apply { this.identifier = identifier } fun withEnvoyHttpFilters(envoyHttpFilters: EnvoyHttpFilters): ControlPlaneBuilder { this.envoyHttpFilters = envoyHttpFilters From af6689c911d5f568b6bb3e701f2f5e4f94475f56 Mon Sep 17 00:00:00 2001 From: gawarz Date: Mon, 4 Apr 2022 12:34:47 +0200 Subject: [PATCH 4/7] fix ktlint --- .../pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt index 6ab57bb35..254afe4e5 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt @@ -308,8 +308,7 @@ class ControlPlane private constructor( this.metrics = metrics return this } - - fun withIdentifier() = apply { this.identifier = identifier } + fun withIdentifier() = apply { this.identifier = identifier } fun withEnvoyHttpFilters(envoyHttpFilters: EnvoyHttpFilters): ControlPlaneBuilder { this.envoyHttpFilters = envoyHttpFilters From c39ec6aa4b4865dd234a349ab0d9e1440d74e829 Mon Sep 17 00:00:00 2001 From: "radoslaw.chrzanowski" Date: Thu, 30 Jun 2022 08:00:43 +0200 Subject: [PATCH 5/7] get controlPlaneIdentifier from env --- build.gradle | 2 +- .../servicemesh/envoycontrol/ControlPlane.kt | 8 ++-- .../envoycontrol/EnvoyControlProperties.kt | 1 + .../V3DiscoveryServerWithIdentifier.kt | 40 ------------------- 4 files changed, 6 insertions(+), 45 deletions(-) delete mode 100644 envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/V3DiscoveryServerWithIdentifier.kt diff --git a/build.gradle b/build.gradle index 55161d172..61a988217 100644 --- a/build.gradle +++ b/build.gradle @@ -48,7 +48,7 @@ allprojects { project.ext.versions = [ kotlin : '1.6.10', - java_controlplane : '0.1.28', + java_controlplane : '0.1.31-control-plane-identifier-SNAPSHOT', spring_boot : '2.3.4.RELEASE', grpc : '1.21.0', jaxb : '2.3.1', diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt index 859898a6b..08d6c6733 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt @@ -43,6 +43,7 @@ import reactor.core.Disposable import reactor.core.publisher.Flux import reactor.core.scheduler.Schedulers import java.time.Clock +import java.util.* import java.util.concurrent.BlockingQueue import java.util.concurrent.Executor import java.util.concurrent.ExecutorService @@ -96,7 +97,6 @@ class ControlPlane private constructor( var metrics: EnvoyControlMetrics = DefaultEnvoyControlMetrics(meterRegistry = meterRegistry) var envoyHttpFilters: EnvoyHttpFilters = EnvoyHttpFilters.emptyFilters var snapshotChangeAuditor: SnapshotChangeAuditor = NoopSnapshotChangeAuditor - var identifier: String? = null var nodeGroup: NodeGroup = MetadataNodeGroup( properties = properties.envoy.snapshot @@ -221,12 +221,13 @@ class ControlPlane private constructor( groupChangeWatcher: GroupChangeWatcher, cachedProtoResourcesSerializer: CachedProtoResourcesSerializer ): V3DiscoveryServer { - return V3DiscoveryServerWithIdentifier( + return V3DiscoveryServer( compositeDiscoveryServerCallbacks, groupChangeWatcher, executorGroup, cachedProtoResourcesSerializer, - identifier + System.getProperty(properties.envoy.controlPlaneIdentifierEnv) ?: UUID.randomUUID().toString() + ) } @@ -331,7 +332,6 @@ class ControlPlane private constructor( this.metrics = metrics return this } - fun withIdentifier() = apply { this.identifier = identifier } fun withEnvoyHttpFilters(envoyHttpFilters: EnvoyHttpFilters): ControlPlaneBuilder { this.envoyHttpFilters = envoyHttpFilters diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoyControlProperties.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoyControlProperties.kt index e328ac8ba..8314f9e93 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoyControlProperties.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoyControlProperties.kt @@ -15,6 +15,7 @@ class EnvoyControlProperties { class EnvoyProperties { var snapshot = SnapshotProperties() + var controlPlaneIdentifierEnv = "HOST" } class ServiceFilters { diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/V3DiscoveryServerWithIdentifier.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/V3DiscoveryServerWithIdentifier.kt deleted file mode 100644 index 366a0ba7b..000000000 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/V3DiscoveryServerWithIdentifier.kt +++ /dev/null @@ -1,40 +0,0 @@ -package pl.allegro.tech.servicemesh.envoycontrol - -import com.google.protobuf.Any -import io.envoyproxy.controlplane.cache.ConfigWatcher -import io.envoyproxy.controlplane.server.DiscoveryServerCallbacks -import io.envoyproxy.controlplane.server.ExecutorGroup -import io.envoyproxy.controlplane.server.V3DiscoveryServer -import io.envoyproxy.controlplane.server.serializer.ProtoResourcesSerializer -import io.envoyproxy.envoy.config.core.v3.ControlPlane -import io.envoyproxy.envoy.service.discovery.v3.DiscoveryResponse - -class V3DiscoveryServerWithIdentifier( - callbacks: List, - configWatcher: ConfigWatcher, - executorGroup: ExecutorGroup?, - protoResourcesSerializer: ProtoResourcesSerializer, - private val identifier: String? -) : V3DiscoveryServer( - callbacks, - configWatcher, - executorGroup, - protoResourcesSerializer -) { - - override fun makeResponse( - version: String, resources: Collection, - typeUrl: String, - nonce: String - ): DiscoveryResponse? { - return DiscoveryResponse.newBuilder() - .setNonce(nonce) - .setVersionInfo(version) - .apply { identifier?.let { this.setControlPlane(controlPlane(it)) } } - .addAllResources(resources) - .setTypeUrl(typeUrl) - .build() - } - - private fun controlPlane(identifier: String) = ControlPlane.newBuilder().setIdentifier(identifier).build() -} From d836f03eee34a7573c60763df5e7ae5be14e45bc Mon Sep 17 00:00:00 2001 From: "radoslaw.chrzanowski" Date: Thu, 30 Jun 2022 08:12:34 +0200 Subject: [PATCH 6/7] update changelog --- CHANGELOG.md | 3 +++ .../pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a949ab4d..aa4d8787d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Changed +- control plane identifier added + ## [0.19.10] ### Changed diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt index 08d6c6733..25b223c08 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt @@ -43,7 +43,7 @@ import reactor.core.Disposable import reactor.core.publisher.Flux import reactor.core.scheduler.Schedulers import java.time.Clock -import java.util.* +import java.util.UUID import java.util.concurrent.BlockingQueue import java.util.concurrent.Executor import java.util.concurrent.ExecutorService From 6320a37df47f38cd6144cd3d6232334e8d05ca38 Mon Sep 17 00:00:00 2001 From: "radoslaw.chrzanowski" Date: Fri, 1 Jul 2022 08:10:07 +0200 Subject: [PATCH 7/7] remove System.getProperty --- .../pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt | 4 +--- .../tech/servicemesh/envoycontrol/EnvoyControlProperties.kt | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt index 25b223c08..574e69f5f 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt @@ -43,7 +43,6 @@ import reactor.core.Disposable import reactor.core.publisher.Flux import reactor.core.scheduler.Schedulers import java.time.Clock -import java.util.UUID import java.util.concurrent.BlockingQueue import java.util.concurrent.Executor import java.util.concurrent.ExecutorService @@ -226,8 +225,7 @@ class ControlPlane private constructor( groupChangeWatcher, executorGroup, cachedProtoResourcesSerializer, - System.getProperty(properties.envoy.controlPlaneIdentifierEnv) ?: UUID.randomUUID().toString() - + properties.envoy.controlPlaneIdentifier ) } diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoyControlProperties.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoyControlProperties.kt index 8314f9e93..0a4ad507d 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoyControlProperties.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/EnvoyControlProperties.kt @@ -5,6 +5,7 @@ package pl.allegro.tech.servicemesh.envoycontrol import pl.allegro.tech.servicemesh.envoycontrol.server.ServerProperties import pl.allegro.tech.servicemesh.envoycontrol.snapshot.SnapshotProperties import pl.allegro.tech.servicemesh.envoycontrol.synchronization.SyncProperties +import java.util.UUID class EnvoyControlProperties { var server = ServerProperties() @@ -15,7 +16,7 @@ class EnvoyControlProperties { class EnvoyProperties { var snapshot = SnapshotProperties() - var controlPlaneIdentifierEnv = "HOST" + var controlPlaneIdentifier = UUID.randomUUID().toString() } class ServiceFilters {