-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#564 Implemented adding a header for locality weighted load balancing
- Loading branch information
1 parent
db5aeaf
commit fec665f
Showing
11 changed files
with
202 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
envoy-control-core/src/main/resources/lua/ingress_current_zone_header.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function envoy_on_request(handle) | ||
local header_name = handle:metadata():get("traffic_splitting_zone_header_name") or "" | ||
local current_zone = handle:metadata():get("current_zone") or "" | ||
if header_name == "" then | ||
return | ||
end | ||
handle:headers():add(header_name, current_zone) | ||
end | ||
|
||
function envoy_on_response(handle) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,15 @@ import pl.allegro.tech.servicemesh.envoycontrol.groups.CommunicationMode | |
import pl.allegro.tech.servicemesh.envoycontrol.groups.Group | ||
import pl.allegro.tech.servicemesh.envoycontrol.groups.ServicesGroup | ||
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.IncomingPermissionsProperties | ||
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.listeners.filters.LuaMetadataProperty.StructPropertyLua | ||
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.listeners.filters.LuaMetadataProperty.ListPropertyLua | ||
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.listeners.filters.LuaMetadataProperty.StringPropertyLua | ||
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.SnapshotProperties | ||
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.listeners.filters.LuaMetadataProperty.BooleanPropertyLua | ||
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.listeners.filters.LuaMetadataProperty.ListPropertyLua | ||
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.listeners.filters.LuaMetadataProperty.NumberPropertyLua | ||
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.listeners.filters.LuaMetadataProperty.StringPropertyLua | ||
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.listeners.filters.LuaMetadataProperty.StructPropertyLua | ||
|
||
internal class LuaFilterFactoryTest { | ||
val properties = SnapshotProperties().also { it.incomingPermissions = IncomingPermissionsProperties() } | ||
|
||
@Test | ||
fun `should create metadata with service name and discovery service name`() { | ||
|
@@ -24,10 +26,10 @@ internal class LuaFilterFactoryTest { | |
serviceName = expectedServiceName, | ||
discoveryServiceName = expectedDiscoveryServiceName | ||
) | ||
val factory = LuaFilterFactory(IncomingPermissionsProperties()) | ||
val factory = LuaFilterFactory(properties) | ||
|
||
// when | ||
val metadata = factory.ingressScriptsMetadata(group) | ||
val metadata = factory.ingressScriptsMetadata(group, currentZone = "dc1") | ||
val givenServiceName = metadata | ||
.getFilterMetadataOrThrow("envoy.filters.http.lua") | ||
.getFieldsOrThrow("service_name") | ||
|
@@ -62,15 +64,36 @@ internal class LuaFilterFactoryTest { | |
serviceName = expectedServiceName, | ||
discoveryServiceName = expectedDiscoveryServiceName | ||
) | ||
val factory = LuaFilterFactory(IncomingPermissionsProperties()) | ||
val factory = LuaFilterFactory(properties) | ||
|
||
// when | ||
val luaMetadata = factory.ingressScriptsMetadata(group, customMetadata) | ||
val luaMetadata = factory.ingressScriptsMetadata(group, customMetadata, "dc1") | ||
.getFilterMetadataOrThrow("envoy.filters.http.lua").fieldsMap | ||
|
||
// then | ||
assertThat(luaMetadata["flags"]).isEqualTo(customMetadata["flags"]?.toValue()) | ||
assertThat(luaMetadata["list-value"]).isEqualTo(customMetadata["list-value"]?.toValue()) | ||
assertThat(luaMetadata["count"]).isEqualTo(customMetadata["count"]?.toValue()) | ||
} | ||
|
||
@Test | ||
fun `should create metadata with current zone`() { | ||
// given | ||
val expectedServiceName = "service-1" | ||
val expectedDiscoveryServiceName = "consul-service-1" | ||
val expectedCurrentZone = "dc1" | ||
val group: Group = ServicesGroup( | ||
communicationMode = CommunicationMode.XDS, | ||
serviceName = expectedServiceName, | ||
discoveryServiceName = expectedDiscoveryServiceName | ||
) | ||
val factory = LuaFilterFactory(properties) | ||
|
||
// when | ||
val luaMetadata = factory.ingressScriptsMetadata(group, StructPropertyLua(), "dc1") | ||
.getFilterMetadataOrThrow("envoy.filters.http.lua").fieldsMap | ||
|
||
// then | ||
assertThat(luaMetadata["current_zone"]).isEqualTo(expectedCurrentZone) | ||
Check failure on line 97 in envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/LuaFilterFactoryTest.kt GitHub Actions / JUnit Test ReportLuaFilterFactoryTest.should create metadata with current zone()
Raw output
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.