Skip to content

Commit

Permalink
[TMP] review(*) proper split between contextual and functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
casimiro committed Jun 11, 2024
1 parent 7e3c5a4 commit 0313c03
Show file tree
Hide file tree
Showing 20 changed files with 904 additions and 577 deletions.
7 changes: 2 additions & 5 deletions src/common/metrics/ngx_wa_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,11 @@ ngx_wa_metrics_add(ngx_wa_metrics_t *metrics, ngx_str_t *name,

rc = ngx_wasm_shm_kv_get_locked(metrics->shm, NULL, &mid, &p, &cas);
if (rc == NGX_OK) {
ngx_log_debug1(NGX_LOG_DEBUG_WASM, metrics->shm->log, 0,
"wasm returning existing metric \"%z\"", mid);
goto done;
}

dd("adding new metric");

ngx_memzero(buf, size);
m = (ngx_wa_metric_t *) buf;
m->type = type;
Expand Down Expand Up @@ -363,9 +363,6 @@ ngx_wa_metrics_get(ngx_wa_metrics_t *metrics, uint32_t mid, ngx_uint_t *out)
return NGX_ERROR;
}

ngx_log_debug2(NGX_LOG_DEBUG_WASM, metrics->shm->log, 0,
"wasm retrieving metric \"%z\" as %d", mid, *out);

return NGX_OK;
}

Expand Down
231 changes: 124 additions & 107 deletions t/03-proxy_wasm/hfuncs/contexts/150-proxy_define_metric.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,167 +4,184 @@ use strict;
use lib '.';
use t::TestWasmX;

our $workers = 2;
skip_hup();

workers($workers);
if ($workers > 1) {
master_on();
}

plan_tests(6);
plan_tests(4);
run_tests();

__DATA__

=== TEST 1: proxy_wasm contexts - proxy_define_metric - on_vm_start
Hostcalls filter prefixes the name of a metric with the phase in which it's
defined. A metric c1 defined within on_configure ends up named c1_Configure.
=== TEST 1: proxy_wasm contexts - define_metric on_vm_start
--- main_config
env WASMTIME_BACKTRACE_DETAILS=1;
wasm {
module context_checks $TEST_NGINX_CRATES_DIR/context_checks.wasm 'define_metric';
}
--- config
location /t {
proxy_wasm context_checks;
return 200;
}
--- ignore_response_body
--- error_log
define_metric status: 0
--- no_error_log
[error]
[crit]


--- skip_no_debug
--- valgrind

=== TEST 2: proxy_wasm contexts - define_metric - on_configure
--- main_config
wasm {
module hostcalls $TEST_NGINX_CRATES_DIR/hostcalls.wasm 'define_metric';
module context_checks $TEST_NGINX_CRATES_DIR/context_checks.wasm;
}
--- config
location /t {
proxy_wasm hostcalls;
proxy_wasm context_checks 'on_configure=define_metric';
return 200;
}
--- error_log eval
qr/defined counter ".+c1_OnVMStart" with id \d+/
--- ignore_response_body
--- error_log
define_metric status: 0
--- no_error_log
[error]
[crit]
[emerg]
[alert]



=== TEST 2: proxy_wasm contexts - proxy_define_metric - on_configure
--- valgrind
--- wasm_modules: hostcalls
--- load_nginx_modules: ngx_http_echo_module
=== TEST 3: proxy_wasm contexts - define_metric - on_tick
--- main_config
wasm {
module context_checks $TEST_NGINX_CRATES_DIR/context_checks.wasm;
}
--- config
location /t {
proxy_wasm hostcalls 'on_configure=define_metrics \
metrics=c1,g1';
echo ok;
proxy_wasm context_checks 'on_tick=define_metric';
return 200;
}
--- grep_error_log eval: qr/defined metric \w+ as \d+ at \w+/
--- grep_error_log_out eval
qr/defined metric c1_Configure as \d+ at Configure
defined metric g1_Configure as \d+ at Configure\n/
--- ignore_response_body
--- error_log
define_metric status: 0
--- no_error_log
[error]
[crit]
[emerg]
[alert]



=== TEST 3: proxy_wasm contexts - proxy_define_metric - on_tick
--- wasm_modules: hostcalls
--- load_nginx_modules: ngx_http_echo_module
=== TEST 4: proxy_wasm contexts - define_metric on_http_dispatch_response
--- wasm_modules: context_checks
--- config
location /t {
proxy_wasm hostcalls 'on_tick=define_metrics \
tick_period=500 \
n_sync_calls=1 \
metrics=c1,g1';
echo ok;
proxy_wasm context_checks 'on_http_dispatch_response=define_metric \
host=127.0.0.1:$TEST_NGINX_SERVER_PORT';
return 200;
}

location /dispatch {
return 200;
}
--- ignore_response_body
--- error_log
define_metric status: 0
--- no_error_log
[error]
[crit]



=== TEST 5: proxy_wasm contexts - define_metric on_request_headers
--- wasm_modules: context_checks
--- metrics: 16k
--- config
location /t {
proxy_wasm context_checks 'on_request_headers=define_metric';
return 200;
}
--- grep_error_log eval: qr/defined metric \w+ as \d+ at \w+/
--- grep_error_log_out eval
qr/defined metric c1_Tick as \d+ at Tick
defined metric g1_Tick as \d+ at Tick\n/
--- ignore_response_body
--- error_log
define_metric status: 0
--- no_error_log
[error]
[crit]
[emerg]
[alert]



=== TEST 4: proxy_wasm contexts - proxy_define_metric - on: request_headers, request_body, response_headers, response_body, log
=== TEST 6: proxy_wasm contexts - define_metric on_request_body
--- load_nginx_modules: ngx_http_echo_module
--- wasm_modules: hostcalls
--- config eval
my $phases = CORE::join(',', qw(
request_headers
request_body
response_headers
response_body
log
));

qq{
--- main_config
wasm {
module context_checks $TEST_NGINX_CRATES_DIR/context_checks.wasm;
}
--- config
location /t {
proxy_wasm hostcalls 'on=$phases \
test=/t/metrics/define \
metrics=c1,g1';
proxy_wasm context_checks 'on_request_body=define_metric';
echo ok;
}
}
--- request
POST /t
hello
--- grep_error_log eval: qr/defined metric \w+ as \d+ at \w+/
--- grep_error_log_out eval
my $checks;
my @phases = qw(
RequestHeaders
RequestBody
ResponseHeaders
ResponseBody
ResponseBody
Log
);

foreach my $p (@phases) {
my $suffixed_c1 = "c1_" . $p;
my $suffixed_g1 = "g1_" . $p;
$checks .= "
?defined metric $suffixed_c1 as [0-9]+ at $p
defined metric $suffixed_g1 as [0-9]+ at $p\n";
}

qr/$checks/
payload
--- ignore_response_body
--- error_log
define_metric status: 0
--- no_error_log
[error]
[crit]
[emerg]
[alert]



=== TEST 5: proxy_wasm contexts - proxy_define_metric - on_http_call_response
--- wasm_modules: hostcalls
--- load_nginx_modules: ngx_http_echo_module
--- http_config eval
--- config eval
qq{
listen unix:$ENV{TEST_NGINX_UNIX_SOCKET};

location /dispatched {
return 200 "Hello back";
=== TEST 7: proxy_wasm contexts - define_metric on_response_headers
--- main_config
wasm {
module context_checks $TEST_NGINX_CRATES_DIR/context_checks.wasm;
}
--- config
location /t {
proxy_wasm context_checks 'on_response_headers=define_metric';
return 200;
}
--- ignore_response_body
--- error_log
define_metric status: 0
--- no_error_log
[error]
[crit]



=== TEST 8: proxy_wasm contexts - define_metric on_response_body
--- load_nginx_modules: ngx_http_echo_module
--- main_config
wasm {
module context_checks $TEST_NGINX_CRATES_DIR/context_checks.wasm;
}
--- config
location /t {
proxy_wasm hostcalls 'test=/t/dispatch_http_call \
host=unix:$ENV{TEST_NGINX_UNIX_SOCKET} \
path=/dispatched \
on_http_call_response=define_metrics \
metrics=c1,g1';
proxy_wasm context_checks 'on_response_body=define_metric';
echo ok;
}
}
--- grep_error_log eval: qr/defined metric \w+ as \d+ at \w+/
--- grep_error_log_out eval
qr/defined metric c1_HTTPCallResponse as \d+ at HTTPCallResponse
defined metric g1_HTTPCallResponse as \d+ at HTTPCallResponse\n/
--- ignore_response_body
--- error_log
define_metric status: 0
--- no_error_log
[error]
[crit]



=== TEST 9: proxy_wasm contexts - define_metric on_log
--- main_config
wasm {
module context_checks $TEST_NGINX_CRATES_DIR/context_checks.wasm;
}
--- config
location /t {
proxy_wasm context_checks 'on_log=define_metric';
return 200;
}
--- ignore_response_body
--- error_log
define_metric status: 0
--- no_error_log
[error]
[crit]
[emerg]
[alert]
Loading

1 comment on commit 0313c03

@thibaultcha
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great now!

Please sign in to comment.