Skip to content

WASM adapter: implement buffer metrics (observability parity) #188

Description

@lxsaah

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions