-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(proxy-wasm) add get_property, supporting Nginx variables
Implements the `get_property` call for the proxy-wasm SDK. The actual properties themselves are not listed by the proxy-wasm specification, so they seem to be proxy-specific. In this initial iteration, the only properties implemented are Nginx variables, obtained using the Nginx API via `ngx_http_get_variable` and hence exposed in the `ngx.http.*` property path. The ABI for property path values (that is, how they should be parsed by a host implementation) is not specified in the proxy-wasm spec docs either, so I have followed an implementation compatible with the input produced by the proxy-wasm-rust-sdk, which expects from the user a path as a vector of strings (`vec!["ngx", "http", "pid"]`) and produces a byte string to the host by joining them using `\0` bytes. With regard to property support, we could mimic the support for many Envoy attributes which are exposed via `get_property` by mapping them to the equivalent Nginx data. The list is available here: https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes.html?highlight=attributes However, the future of `get_property` and `set_property` is currently put into question: they are not included in the vNEXT docs, at least as of their state in 2020: see https://github.com/proxy-wasm/spec/pull/1/files#r472951567 — "I've dropped `{get,set}_property` from this iteration, since the current implementation is not really portable (it's an opaque pass-through to CEL), and I wanted to get a consensus on this MVP first... but we should definitely add something that can be standardized in its place as soon as this is merged.". More info about the current lack of standardization of properties here: proxy-wasm/proxy-wasm-cpp-host#90 The Envoy properties seem to be the "de facto" properties for proxy-wasm and which properties are proxy-specific or proxy-independent are ill-defined (they just map to the Envoy internals), but on our side, we start from a clean slate by using the `ngx` namespace for entries that map 1-to-1 to Nginx values.
- Loading branch information
Showing
4 changed files
with
196 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# vim:set ft= ts=4 sts=4 sw=4 et fdm=marker: | ||
|
||
use strict; | ||
use lib '.'; | ||
use t::TestWasm; | ||
|
||
skip_valgrind(); | ||
|
||
plan tests => repeat_each() * (blocks() * 4); | ||
|
||
run_tests(); | ||
|
||
__DATA__ | ||
=== TEST 1: proxy_wasm - get_property() gets Nginx $hostname variable | ||
--- wasm_modules: hostcalls | ||
--- load_nginx_modules: ngx_http_echo_module | ||
--- config | ||
location /t { | ||
proxy_wasm hostcalls 'test=/t/log/property name=ngx.http.hostname'; | ||
echo ok; | ||
} | ||
--- response_body | ||
ok | ||
--- error_log eval | ||
[ | ||
qr/\[info\] .*? ngx.http.hostname: [a-z0-9]+/, | ||
] | ||
--- no_error_log | ||
[error] | ||
=== TEST 2: proxy_wasm - get_property() gets an Nginx $pid variable | ||
All get_property calls for Nginx variables return strings, so this | ||
should print the $pid as ASCII numbers. | ||
--- wasm_modules: hostcalls | ||
--- load_nginx_modules: ngx_http_echo_module | ||
--- config | ||
location /t { | ||
proxy_wasm hostcalls 'test=/t/log/property name=ngx.http.pid'; | ||
echo ok; | ||
} | ||
--- response_body | ||
ok | ||
--- error_log eval | ||
[ | ||
qr/\[info\] .*? ngx.http.pid: [0-9]+/, | ||
] | ||
--- no_error_log | ||
[error] | ||
=== TEST 3: proxy_wasm - get_property() reports if an ngx.http.* property is not found | ||
--- wasm_modules: hostcalls | ||
--- load_nginx_modules: ngx_http_echo_module | ||
--- config | ||
location /t { | ||
proxy_wasm hostcalls 'test=/t/log/property name=ngx.http.nonexistent_property'; | ||
echo ok; | ||
} | ||
--- response_body | ||
ok | ||
--- error_log eval | ||
[ | ||
qr/\[info\] .*? property not found: ngx.http.nonexistent_property/, | ||
] | ||
--- no_error_log | ||
[error] | ||
=== TEST 4: proxy_wasm - get_property() reports if a generic property is not found | ||
--- wasm_modules: hostcalls | ||
--- load_nginx_modules: ngx_http_echo_module | ||
--- config | ||
location /t { | ||
proxy_wasm hostcalls 'test=/t/log/property name=nonexistent_property'; | ||
echo ok; | ||
} | ||
--- response_body | ||
ok | ||
--- error_log eval | ||
[ | ||
qr/\[info\] .*? property not found: nonexistent_property/, | ||
] | ||
--- no_error_log | ||
[error] |
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