Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[merge] feat/metrics #554

Merged
merged 4 commits into from
Jun 24, 2024
Merged

[merge] feat/metrics #554

merged 4 commits into from
Jun 24, 2024

Conversation

thibaultcha
Copy link
Member

@thibaultcha thibaultcha commented Jun 19, 2024

  • [ ] ngx_wa_* facilities getters
  • default slab?

Accommodating the case when an expression following a variable
declaration is wrapped into multiple lines, e.g.:

size_t size = sizeof(ngx_wa_metrics_histogram_t)
              + sizeof(ngx_wa_metrics_bin_t)
              * metrics->config.max_histogram_bins;
Copy link

codecov bot commented Jun 19, 2024

Codecov Report

Attention: Patch coverage is 93.98625% with 35 lines in your changes missing coverage. Please review.

Project coverage is 90.55719%. Comparing base (ae7b611) to head (0368123).

Additional details and impacted files

Impacted file tree graph

@@                 Coverage Diff                 @@
##                main        #554         +/-   ##
===================================================
+ Coverage   90.36951%   90.55719%   +0.18768%     
===================================================
  Files             47          49          +2     
  Lines          10311       10876        +565     
===================================================
+ Hits            9318        9849        +531     
- Misses           993        1027         +34     
Files Coverage Δ
src/common/ngx_wasm_socket_tcp.c 89.39394% <ø> (ø)
src/common/proxy_wasm/ngx_proxy_wasm.h 91.89189% <ø> (ø)
src/common/shm/ngx_wasm_shm.h 100.00000% <ø> (ø)
src/common/shm/ngx_wasm_shm_kv.c 97.57282% <100.00000%> (+0.20439%) ⬆️
src/wasm/ngx_wasm.h 100.00000% <ø> (ø)
src/wasm/ngx_wasm_core_module.c 92.64706% <ø> (ø)
src/wasm/ngx_wasm_directives.c 96.51741% <100.00000%> (+0.89240%) ⬆️
src/wasm/ngx_wasm_util.c 92.74194% <ø> (ø)
src/common/metrics/ngx_wa_histogram.c 99.09091% <99.09091%> (ø)
src/common/proxy_wasm/ngx_proxy_wasm_properties.c 89.18919% <78.57143%> (-0.36998%) ⬇️
... and 3 more

... and 1 file with indirect coverage changes

Flag Coverage Δ
unit 90.29788% <93.45238%> (+0.15968%) ⬆️
valgrind 81.92479% <93.44894%> (+0.76398%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@thibaultcha thibaultcha force-pushed the feat/metrics-merge branch 4 times, most recently from 824b815 to e54c4fb Compare June 20, 2024 01:32
The change is motivated by the upcoming Proxy-Wasm metrics support,
which will be built atop `ngx_wasm_shm_kv`.

Proxy-Wasm filter developers are expected to define metrics before using
them.  When a metric is defined the host returns an id to the filter
which is later used for updating or retrieving that metric's value.

As such, now `ngx_wasm_shm_kv_get_locked` expects either a key
(`ngx_str_t *`) or its hash (`uint32_t *`). If both are provided, the
hash is used and the key is ignored.

A new function `ngx_wasm_shm_rbtree_lookup` is also introduced allowing
item retrieval using only the key hash.
@thibaultcha thibaultcha force-pushed the feat/metrics-merge branch 5 times, most recently from bd5da65 to f9b61c5 Compare June 21, 2024 03:17
@thibaultcha
Copy link
Member Author

@casimiro I added one more fix that I can squash later, can you take a quick look at it make sure it is sound? I tested the ngx_init_cycle code paths locally.

@casimiro
Copy link
Contributor

casimiro commented Jun 24, 2024

Nice catch @thibaultcha!

The added change indeed fixes the issue, although I think there's a more terse way to fix it.

Originally, we were setting metrics->shm_zone->noreuse to 1 in ngx_wa_metrics_init_conf when the old-cycle's metrics storage couldn't be reused. Then, later in ngx_wa_metrics_init we would check for metrics->shm_zone->noreuse and reallocate the old-cycle's metrics accordingly.

However, we should have set metrics->old_metrics->shm_zone->noreuse to 1 in ngx_wa_metrics_init_conf and check for metrics->old_metrics->shm_zone->noreuse in ngx_wa_metrics_init.

This expresses more clearly what's happening: the new configuration made the old-cycle's metrics storage non-reusable, not the current-cycle's one.

I pushed a commit representing what I mean.

@casimiro
Copy link
Contributor

I thought the commit I pushed was equivalent to the fix you proposed, weird. I'm investigating why it's not.

@casimiro casimiro force-pushed the feat/metrics-merge branch from 86b068f to 5de54b1 Compare June 24, 2024 14:21
@casimiro
Copy link
Contributor

After correcting the fix I proposed, I'm less inclined to prefer it over the one you pushed.

@thibaultcha
Copy link
Member Author

Well are mis-using the noreuse flag in any case so it may not do what we want it to do. At least the original fix fully leans into that misuse and takes advantage of that it's possible to set the flag at reload (although a misuse).

casimiro and others added 2 commits June 24, 2024 08:10
This commit adds support for storing metrics in WasmX shared memory
key-value store facility.

The workflow users are expected to perform follows the Proxy-Wasm
metrics ABI itself: users define metrics before using them. When a
metric is defined, a numeric ID is returned which can later be used for
reading or updating its respective metric. If the system is out of
metrics memory when defining a new metric, the metric definition fails
as eviction support has not been implemented.

The implemented design, described in [1], allows users to perform most
metric updates without synchronizing Nginx workers, i.e. without the
cost of shared memory locks.

Users can refer to [2] for a description of how metrics are represented
in memory and how to estimate the size of the shared memory used for
metrics storage.

Two configuration directives, `slab_size` and `max_metric_name_length`,
are added to configure the size of the shared memory zone dedicated to
metrics and the maximum length of a metric name, respectively.

[1] docs/adr/005-metrics.md
[2] docs/METRICS.md

Co-Authored-By: Thibault Charbonnier <[email protected]>
@thibaultcha thibaultcha merged commit ef0405f into main Jun 24, 2024
31 checks passed
@thibaultcha thibaultcha deleted the feat/metrics-merge branch June 24, 2024 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants