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_lua_interface #591

Merged
merged 7 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions config
Original file line number Diff line number Diff line change
Expand Up @@ -137,30 +137,29 @@ NGX_WASMX_DEPS="\
$ngx_addon_dir/src/common/ngx_wasm_subsystem.h \
$ngx_addon_dir/src/common/ngx_wasm_socket_tcp.h \
$ngx_addon_dir/src/common/ngx_wasm_socket_tcp_readers.h \
$ngx_addon_dir/src/common/shm/ngx_wa_shm.h \
$ngx_addon_dir/src/common/shm/ngx_wa_shm_kv.h \
$ngx_addon_dir/src/common/shm/ngx_wa_shm_queue.h \
$ngx_addon_dir/src/common/metrics/ngx_wa_metrics.h \
$ngx_addon_dir/src/common/proxy_wasm/ngx_proxy_wasm.h \
$ngx_addon_dir/src/common/proxy_wasm/ngx_proxy_wasm_maps.h \
$ngx_addon_dir/src/common/proxy_wasm/ngx_proxy_wasm_properties.h \
$ngx_addon_dir/src/common/shm/ngx_wasm_shm.h \
$ngx_addon_dir/src/common/shm/ngx_wasm_shm_kv.h \
$ngx_addon_dir/src/common/shm/ngx_wasm_shm_queue.h \
$ngx_addon_dir/src/common/metrics/ngx_wa_metrics.h \
$ngx_addon_dir/src/common/metrics/ngx_wa_histogram.h"
$ngx_addon_dir/src/common/proxy_wasm/ngx_proxy_wasm_properties.h"

NGX_WASMX_SRCS="\
$ngx_addon_dir/src/ngx_wasmx.c \
$ngx_addon_dir/src/common/ngx_wasm_subsystem.c \
$ngx_addon_dir/src/common/ngx_wasm_socket_tcp.c \
$ngx_addon_dir/src/common/ngx_wasm_socket_tcp_readers.c \
$ngx_addon_dir/src/common/shm/ngx_wa_shm.c \
$ngx_addon_dir/src/common/shm/ngx_wa_shm_kv.c \
$ngx_addon_dir/src/common/shm/ngx_wa_shm_queue.c \
$ngx_addon_dir/src/common/metrics/ngx_wa_metrics.c \
$ngx_addon_dir/src/common/metrics/ngx_wa_histogram.c \
$ngx_addon_dir/src/common/proxy_wasm/ngx_proxy_wasm.c \
$ngx_addon_dir/src/common/proxy_wasm/ngx_proxy_wasm_host.c \
$ngx_addon_dir/src/common/proxy_wasm/ngx_proxy_wasm_maps.c \
$ngx_addon_dir/src/common/proxy_wasm/ngx_proxy_wasm_properties.c \
$ngx_addon_dir/src/common/proxy_wasm/ngx_proxy_wasm_util.c \
$ngx_addon_dir/src/common/shm/ngx_wasm_shm.c \
$ngx_addon_dir/src/common/shm/ngx_wasm_shm_kv.c \
$ngx_addon_dir/src/common/shm/ngx_wasm_shm_queue.c \
$ngx_addon_dir/src/common/metrics/ngx_wa_metrics.c \
$ngx_addon_dir/src/common/metrics/ngx_wa_histogram.c"
$ngx_addon_dir/src/common/proxy_wasm/ngx_proxy_wasm_util.c"

# wasm

Expand Down
22 changes: 22 additions & 0 deletions docs/PROXY_WASM_HOST_DIFFERENCES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Proxy-Wasm Host Differences

Listed here are noteworthy internal discrepancies (implementation differences)
between ngx_wasm_module and other Proxy-Wasm host implementations.

## Table of Contents

- [Metrics Prefixing](#metrics-prefixing)

## Metrics Prefixing

- Envoy internally prefixes metric names with `wasmcustom.*` and only exposes
this prefix in the output of the `/metrics` endpoint.
- For internal implementation reasons, ngx_wasm_module prefixes metric names
with `pw.[filter_name].*`, where `filter_name` is the name of the filter
that defined the metric. Only the ngx_wasm_module FFI library may expose the
existence of this prefix.

Proxy-Wasm SDK users need not worry as metric names are never exposed through
the SDK in the first place.

[Back to TOC](#table-of-contents)
15 changes: 15 additions & 0 deletions lib/resty/wasmx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ local base = require "resty.core.base"


local C = ffi.C
local assert = assert
local get_string_buf = base.get_string_buf
local get_size_ptr = base.get_size_ptr
local DEBUG_MODE = ngx.config.debug


ffi.cdef [[
Expand All @@ -17,6 +19,9 @@ ffi.cdef [[

typedef unsigned char u_char;
typedef intptr_t ngx_int_t;
typedef uintptr_t ngx_uint_t;
typedef ngx_uint_t ngx_msec_t;
typedef struct ngx_log_s ngx_log_t;
typedef struct ngx_wavm_t ngx_wasm_vm_t;
typedef struct ngx_wasm_ops_plan_t ngx_wasm_plan_t;

Expand All @@ -35,6 +40,9 @@ local _M = {
FFI_ABORT = base.FFI_ABORT -- nil in OpenResty 1.21.4.1
and base.FFI_ABORT
or -6,
FFI_BUSY = base.FFI_BUSY -- nil in OpenResty 1.25.3.2
and base.FFI_BUSY
or -3,
FFI_ERROR = base.FFI_ERROR,
FFI_DONE = base.FFI_DONE,
FFI_OK = base.FFI_OK,
Expand All @@ -58,4 +66,11 @@ function _M.get_err_ptr()
end


function _M.assert_debug(...)
if DEBUG_MODE then
return assert(...)
end
end


return _M
Loading
Loading