proxy-wasm-go-sdk icon indicating copy to clipboard operation
proxy-wasm-go-sdk copied to clipboard

Unable to use the route filter metadata

Open Brunomachadob opened this issue 2 years ago • 3 comments

Describe the bug / error

I'm trying to query the route filter metadata, using the GetProperty function, based on the docs: https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes

The problem is that I can't get the values I would like from it, using the format I was expecting it to be :{"route_metadata", "envoy.lua", "authorization"} or {"route_metadata", "envoy", "lua", "authorization"}. Just as a sanity check, {"request", "path"} works as expected.

If I query for the root route_metadata I get an weird string representation. From the docs, I believe that should be a map or structured values are converted to a sequence of pairs recursively. but apparently it is none of those. I've tried unmarshal the bytes to a map, also without success.

Please check the code and logs bellow.

Would this be a bug or maybe I'm doing something wrong?

What is your Envoy/Istio version?

Tested with Envoy 1.17 and 1.22

What is the SDK version?

v0.18.0

What is your TinyGo version?

tinygo version 0.23.0 darwin/amd64 (using go version go1.17.2 and LLVM version 14.0.0)

URL or snippet of your code including Envoy configuration

routes:
- match:
    prefix: "/"
  route:
    cluster: mockserver
  metadata:
    filter_metadata:
      envoy.lua:
        authorization:
          - TOKEN

func (ctx *httpContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action {
	proxywasm.LogInfo("OnHttpRequestHeaders")

	fieldsToTest := [][]string {
		{"request", "path"},
		{"route_metadata"},
		{"metadata"},
		{"route_metadata", "envoy.lua"},
		{"route_metadata", "envoy.lua", "authorization"},
		{"route_metadata.envoy.lua.authorization"},
	}

	for _, field := range fieldsToTest {
		value, err := proxywasm.GetProperty(field)

		if err != nil {
			proxywasm.LogErrorf("failure: %s", field)
		} else {
			proxywasm.LogInfof("success: %s=%s", field, value)
		}
	}

	return types.ActionContinue
}

Additional context (Optional)

Logs:

proxy_1         | [2022-05-17 18:20:00.633][18][info][wasm] [source/extensions/common/wasm/context.cc:1170] wasm log my_vm: OnHttpRequestHeaders
proxy_1         | [2022-05-17 18:20:00.633][18][info][wasm] [source/extensions/common/wasm/context.cc:1170] wasm log my_vm: success: [request path]=/test
proxy_1         | [2022-05-17 18:20:00.634][18][info][wasm] [source/extensions/common/wasm/context.cc:1170] wasm log my_vm: success: [route_metadata]=
proxy_1         | +
proxy_1         |       envoy.lua
proxy_1         | 
authorization   | 
             2  
proxy_1         | TOKEN
proxy_1         | [2022-05-17 18:20:00.634][18][info][wasm] [source/extensions/common/wasm/context.cc:1170] wasm log my_vm: success: [metadata]=
proxy_1         | [2022-05-17 18:20:00.634][18][error][wasm] [source/extensions/common/wasm/context.cc:1176] wasm log my_vm: failure: [route_metadata envoy.lua]
proxy_1         | [2022-05-17 18:20:00.634][18][error][wasm] [source/extensions/common/wasm/context.cc:1176] wasm log my_vm: failure: [route_metadata envoy.lua authorization]
proxy_1         | [2022-05-17 18:20:00.634][18][error][wasm] [source/extensions/common/wasm/context.cc:1176] wasm log my_vm: failure: [route_metadata.envoy.lua.authorization]

Brunomachadob avatar May 17 '22 18:05 Brunomachadob

maybe you want to take a look at #310

mathetake avatar Aug 22 '22 03:08 mathetake

as for the list types, I see that Envoy always returns NotFound, which I think is a bug of Envoy.

mathetake avatar Aug 22 '22 03:08 mathetake

Nice, thanks! I'll take a look and test this

Brunomachadob avatar Aug 23 '22 10:08 Brunomachadob