With the observability feature enabled, the Tokio and Embassy adapters
report per-buffer metrics (produced/consumed/dropped counters plus current
occupancy) through Buffer::metrics_snapshot(). The WASM adapter doesn't:
WasmBuffer never embeds the shared BufferCounters and doesn't override
metrics_snapshot(), so the trait's default None kicks in and
observability silently has a blind spot on WASM targets. The crate doesn't
even expose an observability feature yet.
This is a pattern-following task: both other adapters show exactly how the
wiring looks, and the counters type is already portable.
Where to look
What to do
- Add an
observability feature to aimdb-wasm-adapter/Cargo.toml that
forwards to aimdb-core/observability (see how the other adapters do it).
- Embed
BufferCounters in WasmBuffer (an Rc fits the adapter's
single-threaded Rc<RefCell<…>> design).
- Count events with the same semantics as the Tokio and Embassy adapters:
produced on every push, consumed on every successful receive, and
dropped only at reader-side lag detection on the ring — when a reader
discovers it has fallen behind and skips ahead, add the skipped count.
Tokio does this where it maps broadcast::error::RecvError::Lagged(n),
Embassy where it maps WaitResult::Lagged(n), and the WASM ring reader
already computes exactly this lag_count when a reader falls behind.
SingleLatest and Mailbox overwrites are deliberately not counted as
drops in either reference adapter — keep that parity, even though the WASM
buffer stores values directly and could detect them.
- Occupancy per variant: ring length for
SpmcRing; value present → 1 for
SingleLatest and Mailbox (the WASM buffer stores values directly, so it
can report honest occupancy).
- Implement
BufferMetrics and override metrics_snapshot() /
reset_metrics() behind the feature gate.
- Add tests mirroring the Tokio adapter's feature-gated
metrics_tests
module. The WASM adapter's buffer tests run on the host
(cargo test -p aimdb-wasm-adapter --no-default-features --lib), so no
browser or wasm-pack setup is needed for this task.
- Extend the Makefile
test target with a second WASM host-lib run adding
--features observability, mirroring how it already tests the Tokio
adapter both with and without the feature — otherwise the new gated tests
never run in make check.
Done when
- With
observability enabled, metrics_snapshot() returns Some(...) for
all three buffer types on the WASM adapter
- Counter semantics match the Tokio and Embassy adapters for the same
sequence of operations (covered by tests)
make check is green (it includes the WASM host-lib test lane)
With the
observabilityfeature enabled, the Tokio and Embassy adaptersreport per-buffer metrics (produced/consumed/dropped counters plus current
occupancy) through
Buffer::metrics_snapshot(). The WASM adapter doesn't:WasmBuffernever embeds the sharedBufferCountersand doesn't overridemetrics_snapshot(), so the trait's defaultNonekicks in andobservability silently has a blind spot on WASM targets. The crate doesn't
even expose an
observabilityfeature yet.This is a pattern-following task: both other adapters show exactly how the
wiring looks, and the counters type is already portable.
Where to look
BufferCounters, built onportable-atomic; compiles fine onwasm32Buffer::metrics_snapshot()/reset_metrics()defaults and theBufferMetricstrait to implementArc<BufferCounters>field behind#[cfg(feature = "observability")], increments in the push/receive paths, occupancy computed per buffer variantWasmBuffer, theRc<RefCell<…>>single-threaded design this lands inWhat to do
observabilityfeature toaimdb-wasm-adapter/Cargo.tomlthatforwards to
aimdb-core/observability(see how the other adapters do it).BufferCountersinWasmBuffer(anRcfits the adapter'ssingle-threaded
Rc<RefCell<…>>design).produced on every
push, consumed on every successful receive, anddropped only at reader-side lag detection on the ring — when a reader
discovers it has fallen behind and skips ahead, add the skipped count.
Tokio does this where it maps
broadcast::error::RecvError::Lagged(n),Embassy where it maps
WaitResult::Lagged(n), and the WASM ring readeralready computes exactly this
lag_countwhen a reader falls behind.SingleLatestandMailboxoverwrites are deliberately not counted asdrops in either reference adapter — keep that parity, even though the WASM
buffer stores values directly and could detect them.
SpmcRing; value present → 1 forSingleLatestandMailbox(the WASM buffer stores values directly, so itcan report honest occupancy).
BufferMetricsand overridemetrics_snapshot()/reset_metrics()behind the feature gate.metrics_testsmodule. The WASM adapter's buffer tests run on the host
(
cargo test -p aimdb-wasm-adapter --no-default-features --lib), so nobrowser or wasm-pack setup is needed for this task.
testtarget with a second WASM host-lib run adding--features observability, mirroring how it already tests the Tokioadapter both with and without the feature — otherwise the new gated tests
never run in
make check.Done when
observabilityenabled,metrics_snapshot()returnsSome(...)forall three buffer types on the WASM adapter
sequence of operations (covered by tests)
make checkis green (it includes the WASM host-lib test lane)