Skip to content

Commit

Permalink
store tags in global snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
KSmigielski committed Jun 4, 2024
1 parent 1f83855 commit 89c3fe3
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 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.20.15]
### Changed
- Add possibility to store service tags in global-snapshot

## [0.20.14]
### Changed
- Added test to check circuit breaker metric value
Expand Down
2 changes: 2 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand Down Expand Up @@ -402,6 +403,19 @@ class EnvoySnapshotFactory(
emptyList<Secret>(),
SecretsVersion.EMPTY_VERSION.value
)

private fun extractTags(tagPrefixes: List<String>, servicesStates: MultiClusterState): Map<String, Set<String>> =
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@ 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<String, Cluster>,
val allServicesNames: Set<String>,
val endpoints: Map<String, ClusterLoadAssignment>,
val clusterConfigurations: Map<String, ClusterConfiguration>,
val securedClusters: Map<String, Cluster>
val clusters: Map<ClusterName, Cluster>,
val allServicesNames: Set<ClusterName>,
val endpoints: Map<ClusterName, ClusterLoadAssignment>,
val clusterConfigurations: Map<ClusterName, ClusterConfiguration>,
val securedClusters: Map<ClusterName, Cluster>,
val tags: Map<ClusterName, Set<Tag>>,
)

@Suppress("LongParameterList")
fun globalSnapshot(
clusters: Iterable<Cluster> = emptyList(),
endpoints: Iterable<ClusterLoadAssignment> = emptyList(),
properties: OutgoingPermissionsProperties = OutgoingPermissionsProperties(),
clusterConfigurations: Map<String, ClusterConfiguration> = emptyMap(),
securedClusters: List<Cluster> = emptyList()
clusterConfigurations: Map<ClusterName, ClusterConfiguration> = emptyMap(),
securedClusters: List<Cluster> = emptyList(),
tags: Map<ClusterName, Set<Tag>> = emptyMap(),
): GlobalSnapshot {
val clusters = SnapshotResources.create<Cluster>(clusters, "").resources()
val securedClusters = SnapshotResources.create<Cluster>(securedClusters, "").resources()
Expand All @@ -29,7 +34,8 @@ fun globalSnapshot(
securedClusters = securedClusters,
endpoints = endpoints,
allServicesNames = allServicesNames,
clusterConfigurations = clusterConfigurations
clusterConfigurations = clusterConfigurations,
tags = tags,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ class ServiceTagsProperties {
var allowedTagsCombinations: MutableList<ServiceTagsCombinationsProperties> = mutableListOf()
var autoServiceTagEnabled = false
var rejectRequestsWithDuplicatedAutoServiceTag = true
var customTagFilterPrefixes = emptyList<String>()

fun isAutoServiceTagEffectivelyEnabled() = enabled && autoServiceTagEnabled
}
Expand Down

0 comments on commit 89c3fe3

Please sign in to comment.