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

feat(proxy-wasm) metrics #530

Closed
wants to merge 3 commits into from
Closed

feat(proxy-wasm) metrics #530

wants to merge 3 commits into from

Conversation

casimiro
Copy link
Contributor

@casimiro casimiro commented Apr 11, 2024

This PR adds support for storing metrics in WasmX shared-memory key-value store facility.

The workflow users are expected to perform follows from 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 hasn't been implemented.

The implemented design, described at [1], allows users to perform most metric updates without synchronizing Nginx workers, i.e. without the aid of 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

Copy link

codecov bot commented Apr 11, 2024

Codecov Report

Attention: Patch coverage is 94.05405% with 33 lines in your changes missing coverage. Please review.

Project coverage is 90.55212%. Comparing base (223a346) to head (3c18dda).

Additional details and impacted files

Impacted file tree graph

@@                 Coverage Diff                 @@
##                main        #530         +/-   ##
===================================================
+ Coverage   90.37921%   90.55212%   +0.17291%     
===================================================
  Files             47          49          +2     
  Lines          10311       10849        +538     
===================================================
+ Hits            9319        9824        +505     
- Misses           992        1025         +33     
Files Coverage Δ
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.42857% <100.00000%> (+0.80356%) ⬆️
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%) ⬇️
src/ngx_wasmx.c 89.31298% <81.25000%> (-1.12181%) ⬇️
src/common/proxy_wasm/ngx_proxy_wasm_host.c 94.09722% <92.37288%> (-0.28030%) ⬇️
... and 1 more

... and 2 files with indirect coverage changes

Flag Coverage Δ
unit 90.29341% <93.52818%> (+0.14415%) ⬆️
valgrind 81.92417% <94.09369%> (+0.71011%) ⬆️

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

@casimiro casimiro force-pushed the feat/metrics branch 3 times, most recently from eb34343 to 7897be6 Compare May 22, 2024 13:32
@casimiro casimiro removed the pr/work-in-progress PR: Work in progress label May 22, 2024
Copy link
Member

@thibaultcha thibaultcha left a comment

Choose a reason for hiding this comment

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

Just a first pass on test cases and discussing behavior.

t/01-wasm/directives/011-metrics_directives.t Outdated Show resolved Hide resolved
src/common/proxy_wasm/ngx_proxy_wasm_properties.c Outdated Show resolved Hide resolved
t/03-proxy_wasm/hfuncs/contexts/150-proxy_define_metric.t Outdated Show resolved Hide resolved
t/03-proxy_wasm/hfuncs/contexts/150-proxy_define_metric.t Outdated Show resolved Hide resolved
t/TestWasmX.pm Outdated Show resolved Hide resolved
t/lib/proxy-wasm-tests/hostcalls/src/filter.rs Outdated Show resolved Hide resolved
t/lib/proxy-wasm-tests/hostcalls/src/lib.rs Outdated Show resolved Hide resolved
t/lib/proxy-wasm-tests/hostcalls/src/types/test_http.rs Outdated Show resolved Hide resolved
Copy link
Member

@thibaultcha thibaultcha left a comment

Choose a reason for hiding this comment

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

Looked at the docs + code except histogram this time.

src/wasm/ngx_wasm_directives.c Outdated Show resolved Hide resolved
src/wasm/ngx_wasm_directives.c Outdated Show resolved Hide resolved
src/common/metrics/ngx_wa_metrics.c Outdated Show resolved Hide resolved
docs/METRICS.md Show resolved Hide resolved
src/common/metrics/ngx_wa_metrics.c Outdated Show resolved Hide resolved
src/common/metrics/ngx_wa_metrics.h Outdated Show resolved Hide resolved
src/wasm/ngx_wasm_directives.c Outdated Show resolved Hide resolved
src/common/metrics/ngx_wa_metrics.h Outdated Show resolved Hide resolved
src/common/metrics/ngx_wa_metrics.c Outdated Show resolved Hide resolved
src/common/proxy_wasm/ngx_proxy_wasm_properties.c Outdated Show resolved Hide resolved
@thibaultcha
Copy link
Member

thibaultcha commented Jun 12, 2024

@casimiro I'm looking at coverage which looks mostly good except for this branch (open ngx_proxy_wasm_host.c file), I'm wondering how come it isn't covered, since I'm sure we have histogram tests already?

@casimiro
Copy link
Contributor Author

@thibaultcha thank you for the new round of review!

I'm surprised as well with the missing coverage in ngx_proxy_wasm_host.c. I'm pretty sure I saw those lines covered before. I'll investigate that.

@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

@thibaultcha
Copy link
Member

thibaultcha commented Jun 12, 2024

I think I looked at everything now and the changeset looks all good. Once the last couple things are addressed I'll do a local merge with the minor stuff like docs wording, style etc which I left out of reviews. Let me know when ready!

@thibaultcha
Copy link
Member

@casimiro Before pushing to this branch again, could you rebase it on the latest main for the CodeQL changes, so that the code analysis integration doesn't get confused again (I deleted all old CodeQL results from the CI workflow).

@casimiro casimiro force-pushed the feat/metrics branch 2 times, most recently from e4aca26 to 92fc9aa Compare June 12, 2024 17:58
hishamhm added a commit that referenced this pull request Jun 12, 2024
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.
@casimiro
Copy link
Contributor Author

@thibaultcha thank you for the reviews. The PR is ready.

@thibaultcha thibaultcha added the pr/merge-in-progress PR: Merge in progress (do not push) label Jun 13, 2024
This commit adds support for storing metrics in WasmX shared-memory
key-value store facility.

The workflow users are expected to perform follows from 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 hasn't been implemented.

The implemented design, described at [1], allows users to perform most metric
updates without synchronizing Nginx workers, i.e. without the aid of 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
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;
@thibaultcha thibaultcha deleted the feat/metrics 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
pr/merge-in-progress PR: Merge in progress (do not push)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants