From 89c3fe3b57159adb63e1212933289c3072f432f0 Mon Sep 17 00:00:00 2001 From: Kamil Smigielski Date: Tue, 4 Jun 2024 20:55:12 +0200 Subject: [PATCH] store tags in global snapshot --- CHANGELOG.md | 4 ++++ docs/configuration.md | 2 ++ .../snapshot/EnvoySnapshotFactory.kt | 16 +++++++++++++- .../envoycontrol/snapshot/GlobalSnapshot.kt | 22 ++++++++++++------- .../snapshot/SnapshotProperties.kt | 1 + 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ec7c22d2..10a790c2a 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.15] +### Changed +- Add possibility to store service tags in global-snapshot + ## [0.20.14] ### Changed - Added test to check circuit breaker metric value diff --git a/docs/configuration.md b/docs/configuration.md index 73b3d69e8..8e765746d 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -155,7 +155,9 @@ Property **(...).allowed-tags-combinations[].tags** | List of tag patterns, that can be combined and requested together | empty list **envoy-control.envoy.snapshot.routing.service-tags.auto-service-tag-enabled** | Enable auto service tag feature. (`enabled` needs also be true) | false **envoy-control.envoy.snapshot.routing.service-tags.reject-requests-with-duplicated-auto-service-tag** | Return 400 for requests with service-tag which duplicates auto service-tag preference | true + **envoy-control.envoy.snapshot.routing.service-tags.customTagFilterPrefixes** | List of prefixes, which tags will be stored in global-snapshot | empty list +customTagFilterPredix ## Outlier detection Property | Description | Default value ------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/EnvoySnapshotFactory.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/EnvoySnapshotFactory.kt index c56165dad..d7e476217 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/EnvoySnapshotFactory.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/EnvoySnapshotFactory.kt @@ -65,7 +65,8 @@ class EnvoySnapshotFactory( clusters = clusters, securedClusters = securedClusters, endpoints = endpoints, - properties = properties.outgoingPermissions + properties = properties.outgoingPermissions, + tags = extractTags(properties.routing.serviceTags.customTagFilterPrefixes, servicesStates) ) sample.stop(meterRegistry.timer("snapshot-factory.new-snapshot.time")) @@ -402,6 +403,19 @@ class EnvoySnapshotFactory( emptyList(), SecretsVersion.EMPTY_VERSION.value ) + + private fun extractTags(tagPrefixes: List, servicesStates: MultiClusterState): Map> = + servicesStates.flatMap { it.servicesState.serviceNameToInstances.asIterable() } + .fold(emptyMap()) { + acc, entry -> + val value = acc.getOrDefault(entry.key, emptySet()) + var newValue = entry.value.instances + .flatMap { it.tags } + if (tagPrefixes.isNotEmpty()) { + newValue = newValue.filter { tag -> tagPrefixes.any { tag.startsWith(it) } } + } + acc.plus(entry.key to (value + newValue)) + } } data class DomainRoutesGrouper( diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/GlobalSnapshot.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/GlobalSnapshot.kt index ae618cd4f..2fd7f1a80 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/GlobalSnapshot.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/GlobalSnapshot.kt @@ -4,12 +4,16 @@ import io.envoyproxy.controlplane.cache.SnapshotResources import io.envoyproxy.envoy.config.cluster.v3.Cluster import io.envoyproxy.envoy.config.endpoint.v3.ClusterLoadAssignment +typealias ClusterName = String +typealias Tag = String + data class GlobalSnapshot( - val clusters: Map, - val allServicesNames: Set, - val endpoints: Map, - val clusterConfigurations: Map, - val securedClusters: Map + val clusters: Map, + val allServicesNames: Set, + val endpoints: Map, + val clusterConfigurations: Map, + val securedClusters: Map, + val tags: Map>, ) @Suppress("LongParameterList") @@ -17,8 +21,9 @@ fun globalSnapshot( clusters: Iterable = emptyList(), endpoints: Iterable = emptyList(), properties: OutgoingPermissionsProperties = OutgoingPermissionsProperties(), - clusterConfigurations: Map = emptyMap(), - securedClusters: List = emptyList() + clusterConfigurations: Map = emptyMap(), + securedClusters: List = emptyList(), + tags: Map> = emptyMap(), ): GlobalSnapshot { val clusters = SnapshotResources.create(clusters, "").resources() val securedClusters = SnapshotResources.create(securedClusters, "").resources() @@ -29,7 +34,8 @@ fun globalSnapshot( securedClusters = securedClusters, endpoints = endpoints, allServicesNames = allServicesNames, - clusterConfigurations = clusterConfigurations + clusterConfigurations = clusterConfigurations, + tags = tags, ) } diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/SnapshotProperties.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/SnapshotProperties.kt index 9eae0d922..94f50b27e 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/SnapshotProperties.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/SnapshotProperties.kt @@ -266,6 +266,7 @@ class ServiceTagsProperties { var allowedTagsCombinations: MutableList = mutableListOf() var autoServiceTagEnabled = false var rejectRequestsWithDuplicatedAutoServiceTag = true + var customTagFilterPrefixes = emptyList() fun isAutoServiceTagEffectivelyEnabled() = enabled && autoServiceTagEnabled }