Skip to content

Commit

Permalink
Add service-id to node metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
uladzislau-dziuba committed Aug 7, 2024
1 parent fe83881 commit b2f55ea
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 34 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.20]
### Changed
- Added service-id property to node metadata

## [0.20.19]
### Changed
- Added http compression filter properties to node metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -182,6 +183,7 @@ class MetadataNodeGroup(
AllServicesGroup(
nodeMetadata.communicationMode,
serviceName,
serviceId,
discoveryServiceName,
proxySettings,
nodeMetadata.pathNormalizationConfig,
Expand All @@ -192,6 +194,7 @@ class MetadataNodeGroup(
ServicesGroup(
nodeMetadata.communicationMode,
serviceName,
serviceId,
discoveryServiceName,
proxySettings,
nodeMetadata.pathNormalizationConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Expand All @@ -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
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 scid`() {
// 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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Expand All @@ -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
)
}

Expand Down

0 comments on commit b2f55ea

Please sign in to comment.