Skip to content

Commit

Permalink
[TMP] review(*) duplicated metrics block
Browse files Browse the repository at this point in the history
  • Loading branch information
casimiro committed Jun 11, 2024
1 parent 84b192a commit 7e3c5a4
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/common/metrics/ngx_wa_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ ngx_wa_metrics_init_conf(ngx_wa_metrics_t *metrics, ngx_conf_t *cf)
ngx_cycle_t *cycle = cf->cycle;
ngx_core_conf_t *ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx,
ngx_core_module);
ngx_wa_metrics_t *old_metrics = metrics->old_metrics;;
ngx_wa_metrics_t *old_metrics = metrics->old_metrics;

if (metrics->config.slab_size == NGX_CONF_UNSET_SIZE) {
metrics->config.slab_size = NGX_WA_DEFAULT_METRICS_SLAB_SIZE;
Expand Down
5 changes: 3 additions & 2 deletions src/common/metrics/ngx_wa_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ typedef struct ngx_wa_metrics_s ngx_wa_metrics_t;


typedef struct {
size_t slab_size;
size_t max_metric_name_length;
ngx_uint_t initialized;
size_t slab_size;
size_t max_metric_name_length;
} ngx_wa_metrics_conf_t;


Expand Down
11 changes: 9 additions & 2 deletions src/wasm/ngx_wasm_directives.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,19 @@ ngx_wasm_core_v8_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
char *
ngx_wasm_core_metrics_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *rv;
ngx_conf_t save = *cf;
char *rv;
ngx_conf_t save = *cf;
ngx_wa_conf_t *wacf = (ngx_wa_conf_t *) cf->ctx;

cf->cmd_type = NGX_METRICS_CONF;
cf->module_type = NGX_WASM_MODULE;

if (wacf->metrics->config.initialized) {
return "is duplicate";
}

wacf->metrics->config.initialized = 1;

rv = ngx_conf_parse(cf, NULL);

*cf = save;
Expand Down
27 changes: 21 additions & 6 deletions t/01-wasm/directives/011-metrics_directives.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,22 @@ __DATA__



=== TEST 2: slab_size directive - sanity
=== TEST 2: metrics{} - duplicated block
--- main_config
wasm {
metrics {}
metrics {}
}
--- error_log: is duplicate
--- no_error_log
[error]
[crit]
[stub]
--- must_die



=== TEST 3: slab_size directive - sanity
--- main_config
wasm {
metrics {
Expand All @@ -38,7 +53,7 @@ __DATA__



=== TEST 3: slab_size directive - too small
=== TEST 4: slab_size directive - too small
--- main_config
wasm {
metrics {
Expand All @@ -55,7 +70,7 @@ qr/\[emerg\] .*? \[wasm\] shm size of \d+ bytes is too small, minimum required i



=== TEST 4: slab_size directive - invalid size
=== TEST 5: slab_size directive - invalid size
--- main_config
wasm {
metrics {
Expand All @@ -72,7 +87,7 @@ qr/\[emerg\] .*? \[wasm\] invalid shm size "1x"/



=== TEST 5: slab_size directive - duplicate
=== TEST 6: slab_size directive - duplicate
--- main_config
wasm {
metrics {
Expand All @@ -89,7 +104,7 @@ qr/\[emerg\] .*? \[wasm\] invalid shm size "1x"/



=== TEST 6: max_metric_name_length directive - sanity
=== TEST 7: max_metric_name_length directive - sanity
--- main_config
wasm {
metrics {
Expand All @@ -104,7 +119,7 @@ qr/\[emerg\] .*? \[wasm\] invalid shm size "1x"/



=== TEST 7: max_metric_name_length directive - duplicate
=== TEST 8: max_metric_name_length directive - duplicate
--- main_config
wasm {
metrics {
Expand Down
5 changes: 2 additions & 3 deletions t/03-proxy_wasm/hfuncs/metrics/002-get_metric_misuse.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use strict;
use lib '.';
use t::TestWasmX;

plan_tests(7);
plan_tests(6);
run_tests();

__DATA__
Expand All @@ -22,8 +22,7 @@ __DATA__
--- error_code: 500
--- error_log eval
[
qr/.+on_request_headers.+/,
qr/metric \"0\" not found.*/,
qr/host trap \(internal error\): could not retrieve metric.*/,
]
--- no_error_log
[crit]
Expand Down
4 changes: 2 additions & 2 deletions t/03-proxy_wasm/hfuncs/metrics/003-increment_metric_misuse.t
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ qq{
--- error_code: 500
--- error_log eval
[
qr/\[error\] .+ \[wasm\] attempt to call increment_metric on a gauge; operation not supported/,
qr/\[warn\] .+ \[wasm\] attempt to call increment_metric on a gauge; operation not supported/,
qr/.+on_request_headers.+/,
qr/host trap \(internal error\): could not increment metric.*/,
]
Expand All @@ -51,10 +51,10 @@ qq{
--- error_log eval
[
qr/.+on_request_headers.+/,
qr/metric \"\d+\" not found.*/,
qr/host trap \(internal error\): could not increment metric.*/,
]
--- no_error_log
[crit]
[emerg]
[alert]
[stub]
8 changes: 3 additions & 5 deletions t/03-proxy_wasm/hfuncs/metrics/004-record_metric_misuse.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use strict;
use lib '.';
use t::TestWasmX;

plan_tests(7);
plan_tests(6);
run_tests();

__DATA__
Expand All @@ -24,8 +24,7 @@ __DATA__
--- error_code: 500
--- error_log eval
[
qr/\[error\] .+ \[wasm\] attempt to call record_metric on a counter; operation not supported/,
qr/.+on_request_headers.+/,
qr/\[warn\] .+ \[wasm\] attempt to call record_metric on a counter; operation not supported/,
qr/host trap \(internal error\): could not record metric.*/,
]
--- no_error_log
Expand All @@ -48,8 +47,7 @@ __DATA__
--- error_code: 500
--- error_log eval
[
qr/.+on_request_headers.+/,
qr/metric \"0\" not found.*/,
qr/host trap \(internal error\): could not record metric.*/,
]
--- no_error_log
[crit]
Expand Down

0 comments on commit 7e3c5a4

Please sign in to comment.