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(metrics) histograms with user-defined bins #608

Closed
wants to merge 1 commit into from

Conversation

casimiro
Copy link
Contributor

@casimiro casimiro commented Oct 14, 2024

This feature is only available through the FFI.

If a user provides a list of numbers when defining a histogram, those numbers will be used as the upper-bounds of the histogram's bins.

For instance, the following code:

shm.metrics:define("h", shm.metrics.HISTOGRAM, { bins = { 1, 3, 5 } })

Creates a histogram with bins [0, 1], (1, 3], (3, 5] and (5, Inf+].

@casimiro casimiro added the pr/work-in-progress PR: Work in progress label Oct 14, 2024
Copy link

codecov bot commented Oct 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.83281%. Comparing base (ea1475c) to head (353bc71).
Report is 7 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@                 Coverage Diff                 @@
##                main        #608         +/-   ##
===================================================
+ Coverage   90.73673%   90.83281%   +0.09608%     
===================================================
  Files             52          52                 
  Lines          11076       11203        +127     
===================================================
+ Hits           10050       10176        +126     
- Misses          1026        1027          +1     
Files with missing lines Coverage Δ
src/common/lua/ngx_wasm_lua_ffi.c 95.91837% <100.00000%> (+0.02092%) ⬆️
src/common/lua/ngx_wasm_lua_ffi.h 100.00000% <100.00000%> (ø)
src/common/metrics/ngx_wa_histogram.c 99.35065% <100.00000%> (+0.21272%) ⬆️
src/common/metrics/ngx_wa_metrics.c 92.21790% <100.00000%> (+0.03040%) ⬆️
src/common/metrics/ngx_wa_metrics.h 100.00000% <ø> (ø)
src/common/proxy_wasm/ngx_proxy_wasm_host.c 93.91206% <100.00000%> (+0.00686%) ⬆️

... and 27 files with indirect coverage changes

Flag Coverage Δ
unit 90.58177% <100.00000%> (+0.13453%) ⬆️
valgrind 82.44410% <100.00000%> (+0.01354%) ⬆️

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

@casimiro casimiro force-pushed the feat/custom-histograms branch 10 times, most recently from 5d7227c to bbfdd98 Compare October 15, 2024 00:23
@casimiro casimiro changed the title feat(metrics) support for histograms with user-defined bins feat(metrics) histograms with user-defined bins Oct 15, 2024
@casimiro casimiro removed the pr/work-in-progress PR: Work in progress label Oct 15, 2024
lib/resty/wasmx/shm.lua Outdated Show resolved Hide resolved
src/common/metrics/ngx_wa_histogram.c Outdated Show resolved Hide resolved
src/common/metrics/ngx_wa_histogram.c Show resolved Hide resolved
src/common/metrics/ngx_wa_histogram.c Outdated Show resolved Hide resolved
src/common/metrics/ngx_wa_metrics.c Outdated Show resolved Hide resolved
src/common/metrics/ngx_wa_histogram.c Outdated Show resolved Hide resolved
lib/resty/wasmx/shm.lua Outdated Show resolved Hide resolved
lib/resty/wasmx/shm.lua Outdated Show resolved Hide resolved
@casimiro casimiro force-pushed the feat/custom-histograms branch 2 times, most recently from afae383 to 9fc9b7f Compare October 15, 2024 22:09
@casimiro casimiro force-pushed the feat/custom-histograms branch 3 times, most recently from 81d4024 to 4cdb29e Compare October 17, 2024 19:52
This feature is only available through the FFI.

If a user provides a list of numbers when defining a histogram, those
numbers will be used as the upper-bounds of the histogram's bins.

For instance, the following code:

```
local shm = require "resty.wasmx.shm"
shm.metrics:define("h", shm.metrics.HISTOGRAM, { bins = { 1, 3, 5 } })
```

Creates a histogram with bins `[0, 1]`, `(1, 3]`, `(3, 5]` and
`(5, Inf+]`
@thibaultcha thibaultcha added the pr/merge-in-progress PR: Merge in progress (do not push) label Oct 22, 2024
ngx_wa_metrics_histogram_t **h;

if (bins) {
if (cn_bins > NGX_WA_METRICS_BINS_MAX) {
Copy link
Member

@thibaultcha thibaultcha Oct 22, 2024

Choose a reason for hiding this comment

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

One last thing before merge: a logarithmic histogram can contain up to 18 bins as per the existing design, but this specific condition and the extra bin on line 197 mean that a custom binning histogram can contain up to 19 bins (18 defined + the MAX_UINT32 bin). Is this analysis correct? If so, is the behavior correct or could the number of bins difference cause problems?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that was a deliberate decision.

Although it is an inconsistent application of the limit of bins, this seemed like an implementation detail that the FFI layer could be spared from; since the limit of bins is rather arbitrary.

In retrospective, though, I admit that having a check for #bins > HISTOGRAM_MAX_BINS - 1 accompanied by a comment in shm.lua seems like a low price to pay to achieve consistence between logarithmic and standard histograms.

Copy link
Member

Choose a reason for hiding this comment

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

I made this change in the merge PR. The change makes the documentation easier to read and understand: "all histograms can only have 18 bins"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for addressing it in the merge PR.

@thibaultcha thibaultcha deleted the feat/custom-histograms branch October 23, 2024 18:24
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.

2 participants