The config of my cluster is as below:
clusters:
- name: service_addmachine
connect_timeout: 30s
type: STATIC
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: service_addmachine
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 20000
metadata:
filter_metadata:
envoy.lb:
canary: 0
- endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 20001
metadata:
filter_metadata:
envoy.lb:
canary: 1
Now I want to set the value of canary
in the Lua filter so that requests can be routed to the correct endpoint.
- name: envoy.filters.http.lua
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua
default_source_code:
inline_string: |
function envoy_on_request(request_handle)
local ori = request_handle:streamInfo():dynamicMetadata():get("envoy.filters.http.jwt_authn")
local mark = 0
if not ori == nil then
mark = 1
end
-- HOW TO CODE HERE???
-- request_handle:streamInfo():dynamicMetadata():set("envoy.filters.http.router", "envoy.lb", {canary=mark})
-- request_handle:streamInfo():dynamicMetadata():set("envoy.lb", "canary", mark)
-- request_handle:metadata():set("envoy.lb", "canary", mark)
end
I’ve read the official doc about Lua filter: https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/lua_filter
The doc says that we could set the value of envoy.lb
. But the requests can’t be routed to the correct endpoint even if there is no grammar error of Lua filter with my config above.
So, it doesn’t seem that I could set the value of canary
in the Lua filter?