pub struct ExplainStore { /* private fields */ }Expand description
A bounded, in-memory store of recent request explanations.
A single-instance affordance backing /debug/explain/{request_id} (docs/05
§5 ring buffer). Oldest entries are evicted past capacity, so memory is
bounded regardless of traffic.
It retains the assembled trace, not a serialized document: /debug/explain
is read for a vanishing fraction of requests, so building the JSON eagerly on
every request was pure waste (~12µs/req of allocation + serialization). The doc
is built lazily in ExplainStore::get instead; record only clones the
(small, owned) trace and pushes it under the lock.
Implementations§
Source§impl ExplainStore
impl ExplainStore
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Creates a store holding at most capacity recent explanations.
Sourcepub fn record(&self, request_id: RequestId, trace: &RequestTrace)
pub fn record(&self, request_id: RequestId, trace: &RequestTrace)
Records the trace for request_id, evicting the oldest if full. Retains the
trace as-is, the explain document is assembled lazily on Self::get.