Module adapter

Module adapter 

Source
Expand description

The WASM-to-unified-chain adapter (DW-119).

WasmChainAdapter bridges the proxy-wasm host’s per-request PluginInstances into the unified crate::plugins::PluginChain by implementing crate::plugins::WasmDispatch. The dataplane constructs one adapter per request (holding the PluginInstances for the route’s WASM plugins) and passes it to PluginChain::new; the chain calls back into the adapter once per WASM entry per phase, passing the entry’s NAME, and the adapter dispatches to exactly that plugin’s instance (so a chain interleaving native filters and WASM plugins in one phase runs each entry exactly once, in config order).

This module (and the whole proxy-wasm host) compiles unconditionally in the OSS build — there are no cargo features for it. The unified chain’s no-wasm adapter (crate::plugins::NoWasm) exists for native-only chains and tests.

Dependency direction: wasm depends on plugins (downward — plugins sits below wasm in the dependency table). The adapter converts wasm::host::LocalResponse to plugins::LocalResponse at the dispatch boundary, and attributes traps to the named plugin so the dataplane can record dwara_plugin_failures_total{name,reason} (DW-157).

§HTTP callouts: the pause/resume seam (DW-167)

When a phase dispatch ends with the plugin having registered proxy_http_call callouts (PhaseResult::Pause), the adapter records WHICH plugin paused and reports ChainOutcome::CalloutPending up the chain; the chain stops and the async driver in dataplane::plugin_dispatch takes over:

  1. WasmChainAdapter::pending_callouts drains the paused instance’s queue (FIFO) as transport-ready CalloutRequests;
  2. the driver performs each exchange off-thread (spawn_blocking around the synchronous client) and records the dwara_plugin_callouts_total{name,outcome} metric;
  3. WasmChainAdapter::deliver_callout re-enters the instance (synchronous wasmtime) with proxy_on_http_call_response and returns the plugin’s resumed outcome — Continue, a local response, a trap, or another CalloutPending (the plugin dispatched again; the driver loops, bounded);
  4. on Continue the driver reads the resumed plugin’s phase payload back through this adapter and continues the chain from the entry AFTER the paused one (PluginChain::resume_*).

The wasm runner stays fully synchronous; only the driver awaits.

Structs§

WasmChainAdapter
The per-request WASM dispatch adapter.